Skip to contentSkip to conversation

x86&x86-64 support for sys_indirect

PATCH Superseded Ulrich Drepper 4 participants 7 messages Nov 15, 2007 – Nov 16, 2007 x86

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 2/4 x86&x86-64 support for sys_indirect

This part adds support for sys_indirect on x86 and x86-64.

 arch/x86/ia32/ia32entry.S            |    1 +
 b/arch/x86/kernel/syscall_table_32.S |    1 +
 b/include/asm-x86/indirect.h         |    5 +++++
 b/include/asm-x86/indirect_32.h      |   23 +++++++++++++++++++++++
 b/include/asm-x86/indirect_64.h      |   24 ++++++++++++++++++++++++
 b/include/asm-x86/unistd_32.h        |    3 ++-
 b/include/asm-x86/unistd_64.h        |    2 ++
 7 files changed, 58 insertions(+), 1 deletion(-)
arch/x86/ia32/ia32entry.S +1 -0
@@ -726,4 +726,5 @@ ia32_sys_call_table:
 	.quad compat_sys_timerfd
 	.quad sys_eventfd
 	.quad sys32_fallocate
+	.quad sys_indirect		/* 325  */
 ia32_syscall_end:
arch/x86/kernel/syscall_table_32.S +1 -0
index 8344c70..92095b2 100644
@@ -324,3 +324,4 @@ ENTRY(sys_call_table)
 	.long sys_timerfd
 	.long sys_eventfd
 	.long sys_fallocate
+	.long sys_indirect		/* 325 */
include/asm-x86/unistd_32.h +2 -1
index 9b15545..8ee0b20 100644
@@ -330,10 +330,11 @@
 #define __NR_timerfd		322
 #define __NR_eventfd		323
 #define __NR_fallocate		324
+#define __NR_indirect		325
 
 #ifdef __KERNEL__
 
-#define NR_syscalls 325
+#define NR_syscalls 326
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
include/asm-x86/unistd_64.h +2 -0
index 5ff4d3e..66eab33 100644
@@ -635,6 +635,8 @@ __SYSCALL(__NR_timerfd, sys_timerfd)
 __SYSCALL(__NR_eventfd, sys_eventfd)
 #define __NR_fallocate				285
 __SYSCALL(__NR_fallocate, sys_fallocate)
+#define __NR_indirect				286
+__SYSCALL(__NR_indirect, sys_indirect)
 
 #ifndef __NO_STUBS
 #define __ARCH_WANT_OLD_READDIR
include/asm-x86/indirect_32.h new file +23 -0
index ee800e7..e4e8a22 100644
@@ -0,0 +1,23 @@
+#ifndef _ASM_X86_INDIRECT_32_H
+#define _ASM_X86_INDIRECT_32_H
+
+struct indirect_registers {
+  __u32 eax;
+  __u32 ebx;
+  __u32 ecx;
+  __u32 edx;
+  __u32 esi;
+  __u32 edi;
+  __u32 ebp;
+};
+
+#define INDIRECT_SYSCALL(regs) (regs)->eax
+
+#define CALL_INDIRECT(regs) \
+  ({ extern long (*sys_call_table[]) (__u32, __u32, __u32, __u32, __u32, __u32); \
+     sys_call_table[INDIRECT_SYSCALL(regs)->eax] ((regs)->ebx, (regs)->ecx, \
+						  (regs)->edx, (regs)->esi, \
+						  (regs)->edi, (regs)->ebp); \
+     })
+
+#endif
include/asm-x86/indirect_64.h new file +24 -0
@@ -0,0 +1,24 @@
+#ifndef _ASM_X86_INDIRECT_64_H
+#define _ASM_X86_INDIRECT_64_H
+
+struct indirect_registers {
+  __u64 rax;
+  __u64 rdi;
+  __u64 rsi;
+  __u64 rdx;
+  __u64 r10;
+  __u64 r8;
+  __u64 r9;
+};
+
+
+#define INDIRECT_SYSCALL(regs) (regs)->rax
+
+#define CALL_INDIRECT(regs) \
+  ({ extern long (*sys_call_table[]) (__u64, __u64, __u64, __u64, __u64, __u64); \
+     sys_call_table[INDIRECT_SYSCALL(regs)] ((regs)->rdi, (regs)->rsi, \
+					     (regs)->rdx, (regs)->r10, \
+					     (regs)->r8, (regs)->r9); \
+     })
+
+#endif
include/asm-x86/indirect.h new file +5 -0
@@ -0,0 +1,5 @@
+#ifdef CONFIG_X86_32
+# include "indirect_32.h"
+#else
+# include "indirect_64.h"
+#endif
#1 lore raw

Hello Ulrich,

Quoted 4 lines · Ulrich Drepper
include/asm-x86/indirect_32.h new file +0 -0
index ee800e7..e4e8a22 100644

[...]

Quoted 1 line

+#define INDIRECT_SYSCALL(regs) (regs)->eax

                                        ^^^^^

include/asm-x86/indirect_32.h line 18

Quoted 4 lines
include/asm-x86/indirect_32.h new file +4 -0
+
+#define CALL_INDIRECT(regs) \
+  ({ extern long (*sys_call_table[]) (__u32, __u32, __u32, __u32, __u32, __u32); \
+     sys_call_table[INDIRECT_SYSCALL(regs)->eax] ((regs)->ebx, (regs)->ecx, \
                                             ^^^^^-> I take it that ->eax is wrong here? 

include/asm-x86/indirect_32.h line 23

Quoted 5 lines
include/asm-x86/indirect_32.h new file +5 -0
+						  (regs)->edx, (regs)->esi, \
+						  (regs)->edi, (regs)->ebp); \
+     })
+
+#endif

Regards,
Frederik

#2 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Frederik Deweerdt wrote:
\>> + sys_call_table[INDIRECT_SYSCALL(regs)->eax] ((regs)->ebx,
(regs)->ecx, \

Quoted 1 line
                                             ^^^^^-> I take it that ->eax is wrong here? 

Yep, my bad. I've retired the 32-bit machines around here.

- --
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖ -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFHPKcp2ijCOnn/RHQRAjqMAKCLra+KisV6inTbPrbLtqruDVKyxACgxRLf kFDyFNbnhqyj3MUkmzV0S2o=
=HQcV
-----END PGP SIGNATURE-----

#3 lore raw
Quoted 9 lines · Ulrich Drepper

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Frederik Deweerdt wrote:
\>> + sys_call_table[INDIRECT_SYSCALL(regs)->eax] ((regs)->ebx,
(regs)->ecx, \

Quoted 1 line
                                             ^^^^^-> I take it that ->eax is wrong here? 

Yep, my bad. I've retired the 32-bit machines around here.

weird - i built it on 32-bit and it should have failed the build?

Ingo

#4 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 1 line · Ingo Molnar

weird - i built it on 32-bit and it should have failed the build?

Not weird, since I've changed that file after Linus' comment. The mistake I made was to reuse the old 0/0 mail with your s-o-b line without asking you again. Sorry.

- --
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖ -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFHPKkm2ijCOnn/RHQRAkY2AKCRfOhk5pUrYuTSMWnBBgu0Ou0fJACfQVz1 qzhRYyWgS1xGQwI2eoHHTgc=
=DkS8
-----END PGP SIGNATURE-----

#5 lore raw
In reply to Ulrich Drepper
Quoted 10 lines · Ulrich Drepper

This part adds support for sys_indirect on x86 and x86-64.

 arch/x86/ia32/ia32entry.S            |    1 +
 b/arch/x86/kernel/syscall_table_32.S |    1 +
 b/include/asm-x86/indirect.h         |    5 +++++
 b/include/asm-x86/indirect_32.h      |   23 +++++++++++++++++++++++
 b/include/asm-x86/indirect_64.h      |   24 ++++++++++++++++++++++++
 b/include/asm-x86/unistd_32.h        |    3 ++-
 b/include/asm-x86/unistd_64.h        |    2 ++
 7 files changed, 58 insertions(+), 1 deletion(-)

I am not sure how compat is handled ? (ie running a 32bit task in a 64bit kernel)

#6 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 2 lines · Eric Dumazet

I am not sure how compat is handled ? (ie running a 32bit task in a 64bit kernel)

I already mentioned that I have a patch here. I'll test it first, though.

- --
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖ -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFHPQtU2ijCOnn/RHQRAqRYAKCA6x79xzmYxS0WjdoB29+1bIcP4gCgpAj3 VmOkji7I1Ec+FaMeLSf1fSA=
=7jn7
-----END PGP SIGNATURE-----