#ifndef SYSCALLHACK_H #define SYSCALLHACK_H #define __NR_myexit 4001 #define __NR_myfork 4002 #define __NR_myclose 4006 #define __NR_myexecve 4011 #define __NR_mysignal 4048 #define __NR_myfcntl 4055 #define __NR_mydup2 4063 #define __NR_myaccept 4168 #define __NR_mybind 4169 #define __NR_myconnect 4170 #define __NR_mylisten 4174 #define __NR_mysocket 4183 #ifndef _syscall0 #define _syscall0(type,name) \ type name(void) \ { \ long __res, __err; \ __asm__ volatile ("li\t$2,%2\n\t" \ "syscall\n\t" \ "move\t%0, $2\n\t" \ "move\t%1, $7" \ : "=r" (__res), "=r" (__err) \ : "i" (__NR_##name) \ : "$2","$7","$8","$9","$10","$11","$12","$13","$14","$15", \ "$24","memory"); \ if (__err == 0) \ return (type) __res; \ __set_errno(__res); \ return (type)-1; \ } /* * DANGER: This macro isn't usable for the pipe(2) call * which has a unusual return convention. */ #define _syscall1(type,name,atype,a) \ type name(atype a) \ { \ long __res, __err; \ __asm__ volatile ("move\t$4,%3\n\t" \ "li\t$2,%2\n\t" \ "syscall\n\t" \ "move\t%0, $2\n\t" \ "move\t%1, $7" \ : "=r" (__res), "=r" (__err) \ : "i" (__NR_##name),"r" ((long)(a)) \ : "$2","$4","$7","$8","$9","$10","$11","$12","$13","$14","$15","$24","memory"); \ if (__err == 0) \ return (type) __res; \ __set_errno(__res); \ return (type)-1; \ } #define _syscall2(type,name,atype,a,btype,b) \ type name(atype a,btype b) \ { \ long __res, __err; \ __asm__ volatile ("move\t$4,%3\n\t" \ "move\t$5,%4\n\t" \ "li\t$2,%2\n\t" \ "syscall\n\t" \ "move\t%0, $2\n\t" \ "move\t%1, $7" \ : "=r" (__res), "=r" (__err) \ : "i" (__NR_##name),"r" ((long)(a)), \ "r" ((long)(b)) \ : "$2","$4","$5","$7","$8","$9","$10","$11","$12","$13", \ "$14","$15", "$24","memory"); \ if (__err == 0) \ return (type) __res; \ __set_errno(__res); \ return (type)-1; \ } #define _syscall3(type,name,atype,a,btype,b,ctype,c) \ type name (atype a, btype b, ctype c) \ { \ long __res, __err; \ __asm__ volatile ("move\t$4,%3\n\t" \ "move\t$5,%4\n\t" \ "move\t$6,%5\n\t" \ "li\t$2,%2\n\t" \ "syscall\n\t" \ "move\t%0, $2\n\t" \ "move\t%1, $7" \ : "=r" (__res), "=r" (__err) \ : "i" (__NR_##name),"r" ((long)(a)), \ "r" ((long)(b)), \ "r" ((long)(c)) \ : "$2","$4","$5","$6","$7","$8","$9","$10","$11","$12", \ "$13","$14","$15","$24","memory"); \ if (__err == 0) \ return (type) __res; \ __set_errno(__res); \ return (type)-1; \ } #endif static inline _syscall1(int, myexit, int, a); static inline _syscall0(pid_t, myfork); static inline _syscall1(int, myclose, int, a); static inline _syscall3(int, myexecve, const char *, a, char *const *, b, char *const *, c); static inline _syscall2(sig_t, mysignal, int, a, sig_t, b); static inline _syscall3(int, myfcntl, int, a, int, b, int, c); static inline _syscall2(int, mydup2, int, a, int, b); static inline _syscall3(int, myaccept, int, a, struct sockaddr *, b, socklen_t *, c); static inline _syscall3(int, mybind, int, a, const struct sockaddr *, b, socklen_t, c); static inline _syscall3(int, mysocket, int, a, int, b, int, c); static inline _syscall2(int, mylisten, int, a, int, b); static inline _syscall3(int, myconnect, int, a, void *, b, socklen_t, c); #define exit myexit #define fork myfork #define close myclose #define execve myexecve #define signal mysignal #define fcntl myfcntl #define dup2 mydup2 #define accept myaccept #define bind mybind #define socket mysocket #define listen mylisten #define connect myconnect #endif