syscall.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include <linux/types.h>
  2. #include <asm/unistd.h>
  3. #ifndef _dl_MAX_ERRNO
  4. #define _dl_MAX_ERRNO 4096
  5. #endif
  6. #define _dl_mmap_check_error(__res) \
  7. (((int)__res) < 0 && ((int)__res) >= -_dl_MAX_ERRNO)
  8. /* Here are the definitions for some syscalls that are used
  9. by the dynamic linker. The idea is that we want to be able
  10. to call these before the errno symbol is dynamicly linked, so
  11. we use our own version here. Note that we cannot assume any
  12. dynamic linking at all, so we cannot return any error codes.
  13. We just punt if there is an error. */
  14. /* Do not include unistd.h, so gcc doesn't whine about
  15. * _exit returning. It really doesn't return... */
  16. #define __NR__dl_exit __NR_exit
  17. static inline _syscall1(void, _dl_exit, int, status);
  18. #define __NR__dl_close __NR_close
  19. static inline _syscall1(int, _dl_close, int, fd);
  20. #define __NR__dl_mmap_real __NR_mmap
  21. static inline _syscall1(void *, _dl_mmap_real, unsigned long *, buffer);
  22. static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
  23. int flags, int fd, unsigned long offset)
  24. {
  25. unsigned long buffer[6];
  26. buffer[0] = (unsigned long) addr;
  27. buffer[1] = (unsigned long) size;
  28. buffer[2] = (unsigned long) prot;
  29. buffer[3] = (unsigned long) flags;
  30. buffer[4] = (unsigned long) fd;
  31. buffer[5] = (unsigned long) offset;
  32. return (void *) _dl_mmap_real(buffer);
  33. }
  34. #define __NR__dl_open __NR_open
  35. static inline _syscall2(int, _dl_open, const char *, fn, int, flags);
  36. #define __NR__dl_write __NR_write
  37. static inline _syscall3(unsigned long, _dl_write, int, fd,
  38. const void *, buf, unsigned long, count);
  39. #define __NR__dl_read __NR_read
  40. static inline _syscall3(unsigned long, _dl_read, int, fd,
  41. const void *, buf, unsigned long, count);
  42. #define __NR__dl_mprotect __NR_mprotect
  43. static inline _syscall3(int, _dl_mprotect, const void *, addr, unsigned long, len, int, prot);
  44. /* Pull in whatever this particular arch's kernel thinks the kernel version of
  45. * struct stat should look like. It turns out that each arch has a different
  46. * opinion on the subject, and different kernel revs use different names... */
  47. #define __NR__dl_stat __NR_stat
  48. #define stat kernel_stat
  49. #define new_stat kernel_stat
  50. #include <asm/stat.h>
  51. #undef new_stat
  52. #undef stat
  53. static inline _syscall2(int, _dl_stat, const char *, file_name, struct kernel_stat *, buf);
  54. #define __NR__dl_munmap __NR_munmap
  55. static inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length);
  56. #define __NR__dl_getuid __NR_getuid
  57. static inline _syscall0(gid_t, _dl_getuid);
  58. #define __NR__dl_geteuid __NR_geteuid
  59. static inline _syscall0(uid_t, _dl_geteuid);
  60. #define __NR__dl_getgid __NR_getgid
  61. static inline _syscall0(gid_t, _dl_getgid);
  62. #define __NR__dl_getegid __NR_getegid
  63. static inline _syscall0(gid_t, _dl_getegid);
  64. /*
  65. * Not an actual syscall, but we need something in assembly to say whether
  66. * this is OK or not.
  67. */
  68. extern inline int _dl_suid_ok(void)
  69. {
  70. uid_t uid, euid, gid, egid;
  71. uid = _dl_getuid();
  72. euid = _dl_geteuid();
  73. gid = _dl_getgid();
  74. egid = _dl_getegid();
  75. if(uid == euid && gid == egid)
  76. return 1;
  77. else
  78. return 0;
  79. }