1*344aa361SAndroid Build Coastguard Workerlibsyscall: A system call handling framework 2*344aa361SAndroid Build Coastguard Worker============================================ 3*344aa361SAndroid Build Coastguard Worker 4*344aa361SAndroid Build Coastguard Workerlibsyscall provides a table based framework for handling system calls. A 5*344aa361SAndroid Build Coastguard Workeruser of this library just provides a file named syscall_table.h with a 6*344aa361SAndroid Build Coastguard Workertable of function pointers defined using the DEF_SYSCALL macro: 7*344aa361SAndroid Build Coastguard Worker 8*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(nr, fn, rtype, nargs, ...) 9*344aa361SAndroid Build Coastguard Worker 10*344aa361SAndroid Build Coastguard Workernr : system call number to use. Should not be zero or negative 11*344aa361SAndroid Build Coastguard Workerfn : name of the system call. E.g, "read", "write" etc. 12*344aa361SAndroid Build Coastguard Workerrtype: type of return value for this syscall 13*344aa361SAndroid Build Coastguard Workernargs: number of arguments accepted by this system call. System calls 14*344aa361SAndroid Build Coastguard Workersupported by this library can take upto 4 arguments. 15*344aa361SAndroid Build Coastguard Worker 16*344aa361SAndroid Build Coastguard WorkerThese parameters are followed by types (and optionally names) names of 17*344aa361SAndroid Build Coastguard Workerarguments to the system call. This information is useful for 18*344aa361SAndroid Build Coastguard Workerauto-generating C function prototypes for userspace (see below). 19*344aa361SAndroid Build Coastguard Worker 20*344aa361SAndroid Build Coastguard WorkerAn example system call table: 21*344aa361SAndroid Build Coastguard Worker 22*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(0x3, read, long, 3, uint32_t fd, void* msg, uint32_t size) 23*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(0x4, write, long, 3, uint32_t fd, void* msg, uint32_t size) 24*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(0x5, open, long, 0) 25*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(0x2d, brk, long, 1, uint32_t brk) 26*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(0x36, ioctl, long, 3, uint32_t d, uint32_t req, void *msg) 27*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(0x4e, gettimeofday, long, 0) 28*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(0x5b, munmap, long, 2, addr_t addr, uint32_t size) 29*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(0x7d, mprotect, long, 0) 30*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(0xa2, usleep, long, 1, struct timespec *ts) 31*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(0xc0, mmap2, long, 4, addr_t addr, uint32_t length, uint32_t prot, uint32_t flags) 32*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(0xc5, fstat, long, 0) 33*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(0xdc, madvise, long, 0) 34*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(0xe0, gettid, long, 0) 35*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(0xf8, exit_group, long, 0) 36*344aa361SAndroid Build Coastguard WorkerDEF_SYSCALL(0x107, clock_gettime, long, 0) 37*344aa361SAndroid Build Coastguard Worker 38*344aa361SAndroid Build Coastguard WorkerFunction names get expanded to sys_{fn_name} by the macro in the kernel. 39*344aa361SAndroid Build Coastguard WorkerIn the table above, syscall 0x3 "read" causes sys_read() to be called, 40*344aa361SAndroid Build Coastguard Workerand syscall 0x4 causes sys_write() to be called by the syscall hander. 41*344aa361SAndroid Build Coastguard Worker 42*344aa361SAndroid Build Coastguard WorkerSyscall vector handler and ABI 43*344aa361SAndroid Build Coastguard Worker============================== 44*344aa361SAndroid Build Coastguard Worker 45*344aa361SAndroid Build Coastguard WorkerThe system call vector handler provided as part of this library simply 46*344aa361SAndroid Build Coastguard Workerjumps to the right function in the table based on system call number 47*344aa361SAndroid Build Coastguard Workerprovided in a register. 48*344aa361SAndroid Build Coastguard Worker 49*344aa361SAndroid Build Coastguard WorkerThe system call ABI for a given architecture is documented in 50*344aa361SAndroid Build Coastguard Workerarch/$(ARCH)/syscall.S 51*344aa361SAndroid Build Coastguard Worker 52*344aa361SAndroid Build Coastguard WorkerSystem calls are executed with interrupts turned on. 53*344aa361SAndroid Build Coastguard Worker 54*344aa361SAndroid Build Coastguard WorkerStub and C prototype autogeneration 55*344aa361SAndroid Build Coastguard Worker=================================== 56*344aa361SAndroid Build Coastguard Worker 57*344aa361SAndroid Build Coastguard WorkerThis library also provides a python script to generate system call stub 58*344aa361SAndroid Build Coastguard Workerfunctions for userspace in GNU assembler syntax and a C header file with 59*344aa361SAndroid Build Coastguard Workermacros defining syscall numbers and C function prototypes for all 60*344aa361SAndroid Build Coastguard Workerfunctions. For more info: 61*344aa361SAndroid Build Coastguard Worker 62*344aa361SAndroid Build Coastguard Workerpython stubgen.py --help 63