Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/entry: Add do_syscall_32(), a C function to do 32-bit syscalls

System calls are really quite simple. Add a helper to call
a 32-bit system call.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Link: http://lkml.kernel.org/r/a77ed179834c27da436fb4a7fb23c8ee77abc11c.1444091585.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Andy Lutomirski and committed by
Ingo Molnar
bd2d3a3b eb974c62

+43
+43
arch/x86/entry/common.c
··· 318 318 local_irq_disable(); 319 319 prepare_exit_to_usermode(regs); 320 320 } 321 + 322 + #if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION) 323 + /* 324 + * Does a 32-bit syscall. Called with IRQs off and does all entry and 325 + * exit work. 326 + */ 327 + __visible void do_int80_syscall_32(struct pt_regs *regs) 328 + { 329 + struct thread_info *ti = pt_regs_to_thread_info(regs); 330 + unsigned int nr = (unsigned int)regs->orig_ax; 331 + 332 + #ifdef CONFIG_IA32_EMULATION 333 + ti->status |= TS_COMPAT; 334 + #endif 335 + 336 + local_irq_enable(); 337 + 338 + if (READ_ONCE(ti->flags) & _TIF_WORK_SYSCALL_ENTRY) { 339 + /* 340 + * Subtlety here: if ptrace pokes something larger than 341 + * 2^32-1 into orig_ax, this truncates it. This may or 342 + * may not be necessary, but it matches the old asm 343 + * behavior. 344 + */ 345 + nr = syscall_trace_enter(regs); 346 + } 347 + 348 + if (nr < IA32_NR_syscalls) { 349 + /* 350 + * It's possible that a 32-bit syscall implementation 351 + * takes a 64-bit parameter but nonetheless assumes that 352 + * the high bits are zero. Make sure we zero-extend all 353 + * of the args. 354 + */ 355 + regs->ax = ia32_sys_call_table[nr]( 356 + (unsigned int)regs->bx, (unsigned int)regs->cx, 357 + (unsigned int)regs->dx, (unsigned int)regs->si, 358 + (unsigned int)regs->di, (unsigned int)regs->bp); 359 + } 360 + 361 + syscall_return_slowpath(regs); 362 + } 363 + #endif