aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorChris Wright <chrisw@sous-sol.org>2008-01-30 07:33:10 -0500
committerIngo Molnar <mingo@elte.hu>2008-01-30 07:33:10 -0500
commita1bf250a6f31afb8caac166ae50dc7b89c38084c (patch)
tree71d2525cd3b8583655e9e733d8c9033214fd9657 /arch
parent9718769d298f8642d5ef41eb5f55669d7c5b9fd6 (diff)
x86: refactor ioport unification
Refactor ioport unification to pull out common code. Cc: mboton@gmail.com Cc: Kevin Winchester <kjwinchester@gmail.com> Cc: Zach Brown <zach.brown@oracle.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Signed-off-by: Chris Wright <chrisw@sous-sol.org> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch')
-rw-r--r--arch/x86/kernel/ioport.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
index be72d809bce7..50e5e4a31c85 100644
--- a/arch/x86/kernel/ioport.c
+++ b/arch/x86/kernel/ioport.c
@@ -113,13 +113,9 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
113 * on system-call entry - see also fork() and the signal handling 113 * on system-call entry - see also fork() and the signal handling
114 * code. 114 * code.
115 */ 115 */
116#ifdef CONFIG_X86_32 116static int do_iopl(unsigned int level, struct pt_regs *regs)
117asmlinkage long sys_iopl(unsigned long regsp)
118{ 117{
119 struct pt_regs *regs = (struct pt_regs *)&regsp;
120 unsigned int level = regs->bx;
121 unsigned int old = (regs->flags >> 12) & 3; 118 unsigned int old = (regs->flags >> 12) & 3;
122 struct thread_struct *t = &current->thread;
123 119
124 if (level > 3) 120 if (level > 3)
125 return -EINVAL; 121 return -EINVAL;
@@ -128,25 +124,31 @@ asmlinkage long sys_iopl(unsigned long regsp)
128 if (!capable(CAP_SYS_RAWIO)) 124 if (!capable(CAP_SYS_RAWIO))
129 return -EPERM; 125 return -EPERM;
130 } 126 }
131 t->iopl = level << 12;
132 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12); 127 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
133 set_iopl_mask(t->iopl); 128
134 return 0; 129 return 0;
135} 130}
136#else 131
137asmlinkage long sys_iopl(unsigned int level, struct pt_regs *regs) 132#ifdef CONFIG_X86_32
133asmlinkage long sys_iopl(unsigned long regsp)
138{ 134{
139 unsigned int old = (regs->flags >> 12) & 3; 135 struct pt_regs *regs = (struct pt_regs *)&regsp;
136 unsigned int level = regs->bx;
137 struct thread_struct *t = &current->thread;
138 int rc;
140 139
141 if (level > 3) 140 rc = do_iopl(level, regs);
142 return -EINVAL; 141 if (rc < 0)
143 /* Trying to gain more privileges? */ 142 goto out;
144 if (level > old) {
145 if (!capable(CAP_SYS_RAWIO))
146 return -EPERM;
147 }
148 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
149 143
150 return 0; 144 t->iopl = level << 12;
145 set_iopl_mask(t->iopl);
146out:
147 return rc;
148}
149#else
150asmlinkage long sys_iopl(unsigned int level, struct pt_regs *regs)
151{
152 return do_iopl(level, regs);
151} 153}
152#endif 154#endif