syscall.h 3.3 KB

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