]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
sh: wire up SET/GET_UNALIGN_CTL.
authorPaul Mundt <lethal@linux-sh.org>
Tue, 23 Feb 2010 03:56:30 +0000 (12:56 +0900)
committerPaul Mundt <lethal@linux-sh.org>
Tue, 23 Feb 2010 03:56:30 +0000 (12:56 +0900)
This hooks up the SET/GET_UNALIGN_CTL knobs cribbing the bulk of it from
the PPC and ia64 implementations. The thread flags happen to be the
logical inverse of what the global fault mode is set to, so this works
out pretty cleanly. By default the global fault mode is used, with tasks
now being able to override their own settings via prctl().

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
arch/sh/include/asm/processor.h
arch/sh/include/asm/processor_32.h
arch/sh/include/asm/processor_64.h
arch/sh/mm/alignment.c

index 87a8d1ef64e433ea09dc7e0aacaf792ebf6aa1d5..9605e062840fc6d2323e4fabb09cb604b444e384 100644 (file)
@@ -107,6 +107,13 @@ extern unsigned int xstate_size;
 extern void free_thread_xstate(struct task_struct *);
 extern struct kmem_cache *task_xstate_cachep;
 
+/* arch/sh/mm/alignment.c */
+extern int get_unalign_ctl(struct task_struct *, unsigned long addr);
+extern int set_unalign_ctl(struct task_struct *, unsigned int val);
+
+#define GET_UNALIGN_CTL(tsk, addr)     get_unalign_ctl((tsk), (addr))
+#define SET_UNALIGN_CTL(tsk, val)      set_unalign_ctl((tsk), (val))
+
 /* arch/sh/mm/init.c */
 extern unsigned int mem_init_done;
 
@@ -114,6 +121,11 @@ extern unsigned int mem_init_done;
 const char *get_cpu_subtype(struct sh_cpuinfo *c);
 extern const struct seq_operations cpuinfo_op;
 
+/* thread_struct flags */
+#define SH_THREAD_UAC_NOPRINT  (1 << 0)
+#define SH_THREAD_UAC_SIGBUS   (1 << 1)
+#define SH_THREAD_UAC_MASK     (SH_THREAD_UAC_NOPRINT | SH_THREAD_UAC_SIGBUS)
+
 /* processor boot mode configuration */
 #define MODE_PIN0 (1 << 0)
 #define MODE_PIN1 (1 << 1)
index 488f0a906a41641eac16d828a1808334a54a68d4..572b4eb094932ca80e9024728a83eedb63fbf9ea 100644 (file)
@@ -101,8 +101,11 @@ struct thread_struct {
        unsigned long sp;
        unsigned long pc;
 
+       /* Various thread flags, see SH_THREAD_xxx */
+       unsigned long flags;
+
        /* Save middle states of ptrace breakpoints */
-       struct perf_event       *ptrace_bps[HBP_NUM];
+       struct perf_event *ptrace_bps[HBP_NUM];
 
 #ifdef CONFIG_SH_DSP
        /* Dsp status information */
@@ -115,6 +118,7 @@ struct thread_struct {
 
 #define INIT_THREAD  {                                         \
        .sp = sizeof(init_stack) + (long) &init_stack,          \
+       .flags = 0,                                             \
 }
 
 /* Forward declaration, a strange C thing */
index 7b1560f03d14b062aa927c6e36d40391e50a846c..621bc4618c6b2ed168dfb4c90d911bc2c6d423f7 100644 (file)
@@ -108,6 +108,10 @@ union thread_xstate {
 struct thread_struct {
        unsigned long sp;
        unsigned long pc;
+
+       /* Various thread flags, see SH_THREAD_xxx */
+       unsigned long flags;
+
        /* This stores the address of the pt_regs built during a context
           switch, or of the register save area built for a kernel mode
           exception.  It is used for backtracing the stack of a sleeping task
@@ -138,6 +142,7 @@ struct thread_struct {
        .trap_no        = 0,                    \
        .error_code     = 0,                    \
        .address        = 0,                    \
+       .flags          = 0,                    \
 }
 
 /*
index 00fb9e3f057c972cb09a07920b468a59ac505a39..b2595b8548ee353b4c5099be26ba6fa940565cb7 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/proc_fs.h>
 #include <linux/uaccess.h>
 #include <asm/alignment.h>
+#include <asm/processor.h>
 
 static unsigned long se_user;
 static unsigned long se_sys;
@@ -59,9 +60,36 @@ void inc_unaligned_kernel_access(void)
        se_sys++;
 }
 
+/*
+ * This defaults to the global policy which can be set from the command
+ * line, while processes can overload their preferences via prctl().
+ */
 unsigned int unaligned_user_action(void)
 {
-       return se_usermode;
+       unsigned int action = se_usermode;
+
+       if (current->thread.flags & SH_THREAD_UAC_SIGBUS) {
+               action &= ~UM_FIXUP;
+               action |= UM_SIGNAL;
+       }
+
+       if (current->thread.flags & SH_THREAD_UAC_NOPRINT)
+               action &= ~UM_WARN;
+
+       return action;
+}
+
+int get_unalign_ctl(struct task_struct *tsk, unsigned long addr)
+{
+       return put_user(tsk->thread.flags & SH_THREAD_UAC_MASK,
+                       (unsigned int __user *)addr);
+}
+
+int set_unalign_ctl(struct task_struct *tsk, unsigned int val)
+{
+       tsk->thread.flags = (tsk->thread.flags & ~SH_THREAD_UAC_MASK) |
+                           (val & SH_THREAD_UAC_MASK);
+       return 0;
 }
 
 void unaligned_fixups_notify(struct task_struct *tsk, insn_size_t insn,