diff options
author | mirabilos <m@mirbsd.org> | 2017-01-29 15:30:50 +0100 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2017-01-29 20:07:28 +0100 |
commit | 9b457baf8d46329f7d7ee2aa084022bb0df88551 (patch) | |
tree | 87b726f65dd2223975c89ce98a180e792017d7f3 /libc/sysdeps/linux | |
parent | 2d3403be6c680fddcc66238baa0a25c0554e2227 (diff) |
use safe, even if possibly a few cycles slower, six-argument syscall implementation
Signed-off-by: mirabilos <m@mirbsd.org>
Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
Diffstat (limited to 'libc/sysdeps/linux')
-rw-r--r-- | libc/sysdeps/linux/i386/Makefile.arch | 4 | ||||
-rw-r--r-- | libc/sysdeps/linux/i386/bits/syscalls.h | 10 | ||||
-rw-r--r-- | libc/sysdeps/linux/i386/syscall6.S | 67 |
3 files changed, 74 insertions, 7 deletions
diff --git a/libc/sysdeps/linux/i386/Makefile.arch b/libc/sysdeps/linux/i386/Makefile.arch index 6c9eed897..3722fd5bb 100644 --- a/libc/sysdeps/linux/i386/Makefile.arch +++ b/libc/sysdeps/linux/i386/Makefile.arch @@ -6,8 +6,8 @@ # CSRC-y := brk.c __syscall_error.c sigaction.c -SSRC-y := __longjmp.S setjmp.S bsd-setjmp.S bsd-_setjmp.S \ - sync_file_range.S syscall.S mmap.S mmap64.S vfork.S clone.S +SSRC-y := __longjmp.S bsd-_setjmp.S bsd-setjmp.S clone.S mmap.S mmap64.S \ + setjmp.S sync_file_range.S syscall.S syscall6.S vfork.S SSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.S SSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += makecontext.S setcontext.S getcontext.S swapcontext.S diff --git a/libc/sysdeps/linux/i386/bits/syscalls.h b/libc/sysdeps/linux/i386/bits/syscalls.h index e76a45653..70ee825a5 100644 --- a/libc/sysdeps/linux/i386/bits/syscalls.h +++ b/libc/sysdeps/linux/i386/bits/syscalls.h @@ -36,7 +36,11 @@ #define INTERNAL_SYSCALL_NCS_X86_3 INTERNAL_SYSCALL_NCS_X86_UPTOFIVE #define INTERNAL_SYSCALL_NCS_X86_4 INTERNAL_SYSCALL_NCS_X86_UPTOFIVE #define INTERNAL_SYSCALL_NCS_X86_5 INTERNAL_SYSCALL_NCS_X86_UPTOFIVE -#define INTERNAL_SYSCALL_NCS_X86_6 INTERNAL_SYSCALL_NCS_X86_UPTOFIVE + +extern long __libc_i386_syscall6(unsigned long, ...) + __attribute__((__cdecl__)); +#define INTERNAL_SYSCALL_NCS_X86_6(name, err, nr, args...) \ + __libc_i386_syscall6((unsigned long)name, args) #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \ INTERNAL_SYSCALL_NCS_X86_##nr(name, err, nr, args) @@ -104,7 +108,6 @@ __asm__ ( #define LOADARGS_3 LOADARGS_1 #define LOADARGS_4 LOADARGS_1 #define LOADARGS_5 LOADARGS_1 -#define LOADARGS_6 LOADARGS_1 "push %%ebp\n\t" "movl %7, %%ebp\n\t" #define RESTOREARGS_0 #define RESTOREARGS_1 "bpopl .L__X'%k2, %k2\n\t" @@ -112,7 +115,6 @@ __asm__ ( #define RESTOREARGS_3 RESTOREARGS_1 #define RESTOREARGS_4 RESTOREARGS_1 #define RESTOREARGS_5 RESTOREARGS_1 -#define RESTOREARGS_6 "pop %%ebp\n\t" RESTOREARGS_1 #define ASMFMT_0() /* "acdSD" constraint would work too, but "SD" would use esi/edi and cause @@ -132,8 +134,6 @@ __asm__ ( , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4) #define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \ , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5) -#define ASMFMT_6(arg1, arg2, arg3, arg4, arg5, arg6) \ - , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5), "g" (arg6) #endif /* __ASSEMBLER__ */ #endif /* _BITS_SYSCALLS_H */ diff --git a/libc/sysdeps/linux/i386/syscall6.S b/libc/sysdeps/linux/i386/syscall6.S new file mode 100644 index 000000000..488f11afc --- /dev/null +++ b/libc/sysdeps/linux/i386/syscall6.S @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 2017 + * mirabilos <m@mirbsd.org> + * + * Provided that these terms and disclaimer and all copyright notices + * are retained or reproduced in an accompanying document, permission + * is granted to deal in this work without restriction, including un- + * limited rights to use, publicly perform, distribute, sell, modify, + * merge, give away, or sublicence. + * + * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to + * the utmost extent permitted by applicable law, neither express nor + * implied; without malicious intent or gross negligence. In no event + * may a licensor, author or contributor be held liable for indirect, + * direct, other damage, loss, or other issues arising in any way out + * of dealing in the work, even if advised of the possibility of such + * damage or existence of a defect, except proven that it results out + * of said person's immediate fault when using the work as intended. + */ + + .intel_syntax noprefix + .text + +/*- + * long __libc_i386_syscall6(unsigned long nr, ...) with six varargs + * + * C definition: + * extern long __libc_i386_syscall6(unsigned long, ...) + * __attribute__((__cdecl__)); + * + * Stack layout upon entry: Offsets after saving: + * [esp + 28] arg6 -> ebp ! [esp + 44] + * [esp + 24] arg5 -> edi ! [esp + 40] + * [esp + 20] arg4 -> esi ! [esp + 36] + * [esp + 16] arg3 -> edx [esp + 32] + * [esp + 12] arg2 -> ecx [esp + 28] + * [esp + 8] arg1 -> ebx ! [esp + 24] + * [esp + 4] nr -> eax [esp + 20] + * [esp] return address [esp + 16] + * [esp + 12] saved ebp + * [esp + 8] saved ebx + * [esp + 4] saved esi + * [esp] saved edi + */ + + .p2align 4,0x90 + .globl __libc_i386_syscall6 + .type __libc_i386_syscall6,@function +__libc_i386_syscall6: + push ebp + push ebx + push esi + push edi + mov eax,[esp + 20] /* nr */ + mov ebx,[esp + 24] /* arg1 */ + mov ecx,[esp + 28] /* arg2 */ + mov edx,[esp + 32] /* arg3 */ + mov esi,[esp + 36] /* arg4 */ + mov edi,[esp + 40] /* arg5 */ + mov ebp,[esp + 44] /* arg6 */ + int 0x80 + pop edi + pop esi + pop ebx + pop ebp + ret + .size __libc_i386_syscall6,.-__libc_i386_syscall6 |