home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / KERNEL-S / V1.2 / LINUX-1.2 / LINUX-1 / linux / include / asm-i386 / unistd.h < prev   
Encoding:
C/C++ Source or Header  |  1995-02-24  |  3.3 KB  |  124 lines

  1. #ifndef _ASM_I386_UNISTD_H_
  2. #define _ASM_I386_UNISTD_H_
  3.  
  4. /* XXX - _foo needs to be __foo, while __NR_bar could be _NR_bar. */
  5. #define _syscall0(type,name) \
  6. type name(void) \
  7. { \
  8. long __res; \
  9. __asm__ volatile ("int $0x80" \
  10.     : "=a" (__res) \
  11.     : "0" (__NR_##name)); \
  12. if (__res >= 0) \
  13.     return (type) __res; \
  14. errno = -__res; \
  15. return -1; \
  16. }
  17.  
  18. #define _syscall1(type,name,type1,arg1) \
  19. type name(type1 arg1) \
  20. { \
  21. long __res; \
  22. __asm__ volatile ("int $0x80" \
  23.     : "=a" (__res) \
  24.     : "0" (__NR_##name),"b" ((long)(arg1))); \
  25. if (__res >= 0) \
  26.     return (type) __res; \
  27. errno = -__res; \
  28. return -1; \
  29. }
  30.  
  31. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  32. type name(type1 arg1,type2 arg2) \
  33. { \
  34. long __res; \
  35. __asm__ volatile ("int $0x80" \
  36.     : "=a" (__res) \
  37.     : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2))); \
  38. if (__res >= 0) \
  39.     return (type) __res; \
  40. errno = -__res; \
  41. return -1; \
  42. }
  43.  
  44. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  45. type name(type1 arg1,type2 arg2,type3 arg3) \
  46. { \
  47. long __res; \
  48. __asm__ volatile ("int $0x80" \
  49.     : "=a" (__res) \
  50.     : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
  51.           "d" ((long)(arg3))); \
  52. if (__res>=0) \
  53.     return (type) __res; \
  54. errno=-__res; \
  55. return -1; \
  56. }
  57.  
  58. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  59. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  60. { \
  61. long __res; \
  62. __asm__ volatile ("int $0x80" \
  63.     : "=a" (__res) \
  64.     : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
  65.       "d" ((long)(arg3)),"S" ((long)(arg4))); \
  66. if (__res>=0) \
  67.     return (type) __res; \
  68. errno=-__res; \
  69. return -1; \
  70.  
  71. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  72.       type5,arg5) \
  73. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  74. { \
  75. long __res; \
  76. __asm__ volatile ("int $0x80" \
  77.     : "=a" (__res) \
  78.     : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
  79.       "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \
  80. if (__res>=0) \
  81.     return (type) __res; \
  82. errno=-__res; \
  83. return -1; \
  84. }
  85.  
  86. #ifdef __KERNEL_SYSCALLS__
  87.  
  88. /*
  89.  * we need this inline - forking from kernel space will result
  90.  * in NO COPY ON WRITE (!!!), until an execve is executed. This
  91.  * is no problem, but for the stack. This is handled by not letting
  92.  * main() use the stack at all after fork(). Thus, no function
  93.  * calls - which means inline code for fork too, as otherwise we
  94.  * would use the stack upon exit from 'fork()'.
  95.  *
  96.  * Actually only pause and fork are needed inline, so that there
  97.  * won't be any messing with the stack from main(), but we define
  98.  * some others too.
  99.  */
  100. #define __NR__exit __NR_exit
  101. static inline _syscall0(int,idle)
  102. static inline _syscall0(int,fork)
  103. static inline _syscall0(int,pause)
  104. static inline _syscall0(int,setup)
  105. static inline _syscall0(int,sync)
  106. static inline _syscall0(pid_t,setsid)
  107. static inline _syscall3(int,write,int,fd,const char *,buf,off_t,count)
  108. static inline _syscall1(int,dup,int,fd)
  109. static inline _syscall3(int,execve,const char *,file,char **,argv,char **,envp)
  110. static inline _syscall3(int,open,const char *,file,int,flag,int,mode)
  111. static inline _syscall1(int,close,int,fd)
  112. static inline _syscall1(int,_exit,int,exitcode)
  113. static inline _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options)
  114.  
  115. static inline pid_t wait(int * wait_stat)
  116. {
  117.     return waitpid(-1,wait_stat,0);
  118. }
  119.  
  120. #endif
  121.  
  122. #endif /* _ASM_I386_UNISTD_H_ */
  123.