Patchwork Add REGISTERS_CLOBBERED_BY_SYSCALL for x86-64

login
register
mail settings
Submitter H.J. Lu
Date Dec. 15, 2015, 8:57 p.m.
Message ID <20151215205725.GA11164@intel.com>
Download mbox | patch
Permalink /patch/10026/
State New
Headers show

Comments

H.J. Lu - Dec. 15, 2015, 8:57 p.m.
X86-64 system calls use a different calling convention, which clobbers
CC, %r11 an %rcx registers.  Define REGISTERS_CLOBBERED_BY_SYSCALL for
x86-64 inline asm statements.

Tested on x86-64.  OK for master?


H.J.
---
	* sysdeps/unix/sysv/linux/x86_64/sysdep.h
	(REGISTERS_CLOBBERED_BY_SYSCALL): New.
	(INTERNAL_SYSCALL_NCS): Use it.
	(INTERNAL_SYSCALL_NCS_TYPES): Likewise.
---
 sysdeps/unix/sysv/linux/x86_64/sysdep.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Mike Frysinger - Dec. 15, 2015, 11:03 p.m.
On 15 Dec 2015 12:57, H.J. Lu wrote:
> X86-64 system calls use a different calling convention, which clobbers
> CC, %r11 an %rcx registers.  Define REGISTERS_CLOBBERED_BY_SYSCALL for
> x86-64 inline asm statements.
> 
> Tested on x86-64.  OK for master?

lgtm
-mike
Andreas Schwab - Dec. 15, 2015, 11:32 p.m.
"H.J. Lu" <hongjiu.lu@intel.com> writes:

> X86-64 system calls use a different calling convention, which clobbers

Different than what?

Andreas.
H.J. Lu - Dec. 15, 2015, 11:33 p.m.
On Tue, Dec 15, 2015 at 3:32 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> "H.J. Lu" <hongjiu.lu@intel.com> writes:
>
>> X86-64 system calls use a different calling convention, which clobbers
>
> Different than what?
>

Different from x86-64 function calls.
Rich Felker - Dec. 16, 2015, 5:08 p.m.
On Tue, Dec 15, 2015 at 12:57:25PM -0800, H.J. Lu wrote:
> X86-64 system calls use a different calling convention, which clobbers
> CC, %r11 an %rcx registers.  Define REGISTERS_CLOBBERED_BY_SYSCALL for
> x86-64 inline asm statements.
> 
> Tested on x86-64.  OK for master?

I don't object, but is there a purpose to it? I agree the "different"
wording is confusing since there's normally no reason to expect
syscalls to look anything like function calls.

Rich

Patch

diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
index fc132f6..c364d08 100644
--- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
@@ -218,6 +218,9 @@ 
 # undef INTERNAL_SYSCALL_DECL
 # define INTERNAL_SYSCALL_DECL(err) do { } while (0)
 
+/* Registers clobbered by syscall.  */
+# define REGISTERS_CLOBBERED_BY_SYSCALL "cc", "r11", "cx"
+
 # define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
   ({									      \
     unsigned long int resultvar;					      \
@@ -226,7 +229,7 @@ 
     asm volatile (							      \
     "syscall\n\t"							      \
     : "=a" (resultvar)							      \
-    : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx");		      \
+    : "0" (name) ASM_ARGS_##nr : "memory", REGISTERS_CLOBBERED_BY_SYSCALL);   \
     (long int) resultvar; })
 # undef INTERNAL_SYSCALL
 # define INTERNAL_SYSCALL(name, err, nr, args...) \
@@ -240,7 +243,7 @@ 
     asm volatile (							      \
     "syscall\n\t"							      \
     : "=a" (resultvar)							      \
-    : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx");		      \
+    : "0" (name) ASM_ARGS_##nr : "memory", REGISTERS_CLOBBERED_BY_SYSCALL);   \
     (long int) resultvar; })
 # undef INTERNAL_SYSCALL_TYPES
 # define INTERNAL_SYSCALL_TYPES(name, err, nr, args...) \