It used to be the case that if you needed to make a system call directly in linux without the use of an existing library, you could just include <linux/unistd.h>
and it would define a macro similar to this:
#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
type name(type1 arg1,type2 arg2,type3 arg3) \
{ \
long __res; \
__asm__ volatile ("int $0x80" \
: "=a" (__res) \
: "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
"d" ((long)(arg3))); \
if (__res>=0) \
return (type) __res; \
errno=-__res; \
return -1; \
}
Then you could just put somewhere in your code:
_syscall3(ssize_t, write, int, fd, const void *, buf, size_t, count);
which would define a write
function for you that properly performed the system call.
It seems that this system has been superseded by something (i am guessing that "[vsyscall]" page that every process gets) more robust.
So what is the proper way (please be specific) for a program to perform a system call directly on newer linux kernels? I realize that I should be using libc and let it do the work for me. But let's assume that I have a decent reason for wanting to know how to do this :-).