[klibc] [PATCH] Add syscall wrappers required by libkeyutils

H. Peter Anvin hpa at zytor.com
Mon Jul 27 20:11:03 PDT 2020


On 2020-07-27 19:20, hpa at zytor.com wrote:
> 
> I'm not so sure they have dealt with it in the sense of having it work on all architectures. *Most* of the problems are related to the shifting the arguments by one, which can cause a bunch of problems, especially if it means the arguments spill to memory. However, I have absolutely no idea how to correctly implement syscall(3) on s390 without a full table.
> 
> It is of course possible to implement using stdarg.h and a big switch statement, but that is anything but cheap.
> 
> Now, thinking about it, it *might* be possible to implement some of this using varadic macros. Let me play around with it a little bit.
> 

This might actually work:

/*
 * Not prototyped on purpose, as (...) isn't a valid prototype.
 * __extension__ prevents erroring out due to lack of prototype.
 */
__extension__ extern long long ___syscall();
extern long ___syscall_num;

#define syscall(n, ...)					\
  (___syscall_num = (n), ___syscall(__VA_ARGS__))

... then have ___syscall() get the system call number from the memory variable
___syscall_num (If klibc were multithreaded it would have to be a thread-local
variable, of course) and call the common syscall handler code.

Interestingly enough, on i386 the prototypeless function appears to be called
with the regparm convention, not the varadic convention -- not a problem, just
a matter of which handler to call.

Still not entirely sure what to do with s390, nor have I audited all the other
architectures but perhaps there are ways around that.

	-hpa


More information about the klibc mailing list