IS it possible to write a (linux kernel)sycall function that has more than 6 input parameters? Looking at the header I see that the defined syscall macros have a maximum of 6 parameters. I'm tempted to try to define SYSCALL7 and SYSCALL8 to allow for 7 and 8 parameters but I'm not quite sure if that will actually work.
-
FWIW MIPS O32 ABI has syscalls with 7 arguments: [`sys32_fadvise64_64`](https://elixir.bootlin.com/linux/v5.17/source/arch/mips/kernel/linux32.c#L118). Weird, but possible, though not using `SYSCALL_DEFINEn` macros, which go up to 6. – Marco Bonelli Jul 12 '22 at 01:09
3 Answers
For x86, the following function (from x86...syscall.h) copies the arguments over:
static inline void syscall_get_arguments(struct task_struct *task,
struct pt_regs *regs,
unsigned int i, unsigned int n,
unsigned long *args)
{
BUG_ON(i + n > 6);
memcpy(args, ®s->bx + i, n * sizeof(args[0]));
}
This function is described well in the comments in asm_generic/syscall.h. It copies the arguments into the syscall, and there is a limit of 6 arguments. It may be implemented in a number of ways depending on architecture. For x86 (from the snippet above) it looks like the arguments are all passed by register.
So, if you want to pass more than 6 arguments, use a struct. If you must have a SYSCALL7, then you are going to have to create a custom kernel and likely modify almost every step of the syscall process. x86_64 would likely accommodate this change easier, since it has more registers than x86.

- 1,162
- 11
- 24
-
I think system call parameters are not passed using stack, they are passed using processor registers, so there is a limit on number of parameters passed to system call. Ya but as MSI mentioned passing struct solves the problem. – ART Feb 03 '14 at 12:21
-
Yeah, you are absolutely correct: for x86 the parameters are all passed in registers. – superdesk Feb 03 '14 at 12:57
-
@AnkurTank Thanks, you are correct. I have edited my answer to reflect your input and some further research on my part. – superdesk Feb 03 '14 at 13:17
What if one day you need 20 parameters ? I think the best way to go around your syscall problem is to use a pointer to *void
.
This way you can pass a struct
containing an unlimited amount of parameters.

- 844
- 9
- 8
Generally there is no limit to the number of parameter. But all these things need a standard: all kernel module write and user or caller will need to agree on a standard way to pass information from caller to callee (and vice versa) - whether it is passing by stack or register. It is called "ABI" or calling convention. There are different standard for x86 and AMD64, and generally it is the same for all UNIX in x86: Linux, FreeBSD etc.
http://www.x86-64.org/documentation/abi.pdf
Eg, x86 syscall ABI:
http://lwn.net/Articles/456731/
http://esec-lab.sogeti.com/post/2011/07/05/Linux-syscall-ABI
More details please see (to avoid repetition):
What are the calling conventions for UNIX & Linux system calls on x86-64
Why does Windows64 use a different calling convention from all other OSes on x86-64?
And userspace will have its own ABI as well:
https://www.kernel.org/doc/Documentation/ABI/README

- 1
- 1

- 6,337
- 4
- 42
- 58