syscalls.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #include <reent.h>
  2. #include <sys/errno.h>
  3. #include <rtthread.h>
  4. /* Reentrant versions of system calls. */
  5. int
  6. _close_r(struct _reent *ptr, int fd)
  7. {
  8. return close(fd);
  9. }
  10. int
  11. _execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env)
  12. {
  13. /* return "not supported" */
  14. ptr->_errno = ENOTSUP;
  15. return -1;
  16. }
  17. int
  18. _fcntl_r(struct _reent *ptr, int fd, int cmd, int arg)
  19. {
  20. /* return "not supported" */
  21. ptr->_errno = ENOTSUP;
  22. return -1;
  23. }
  24. int
  25. _fork_r(struct _reent *ptr)
  26. {
  27. /* return "not supported" */
  28. ptr->_errno = ENOTSUP;
  29. return -1;
  30. }
  31. int
  32. _fstat_r(struct _reent *ptr, int fd, struct stat *pstat)
  33. {
  34. /* return "not supported" */
  35. ptr->_errno = ENOTSUP;
  36. return -1;
  37. }
  38. int
  39. _getpid_r(struct _reent *ptr)
  40. {
  41. return 0;
  42. }
  43. int
  44. _isatty_r(struct _reent *ptr, int fd)
  45. {
  46. if (fd >=0 && fd < 3) return 1;
  47. /* return "not supported" */
  48. ptr->_errno = ENOTSUP;
  49. return -1;
  50. }
  51. int
  52. _kill_r(struct _reent *ptr, int pid, int sig)
  53. {
  54. /* return "not supported" */
  55. ptr->_errno = ENOTSUP;
  56. return -1;
  57. }
  58. int
  59. _link_r(struct _reent *ptr, const char *old, const char *new)
  60. {
  61. /* return "not supported" */
  62. ptr->_errno = ENOTSUP;
  63. return -1;
  64. }
  65. _off_t
  66. _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
  67. {
  68. _off_t rc;
  69. rc = lseek(fd, pos, whence);
  70. return rc;
  71. }
  72. int
  73. _mkdir_r(struct _reent *ptr, const char *name, int mode)
  74. {
  75. int rc;
  76. rc = mkdir(name, mode);
  77. return rc;
  78. }
  79. int
  80. _open_r(struct _reent *ptr, const char *file, int flags, int mode)
  81. {
  82. int rc;
  83. rc = open(file, flags, mode);
  84. return rc;
  85. }
  86. _ssize_t
  87. _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
  88. {
  89. _ssize_t rc;
  90. rc = read(fd, buf, nbytes);
  91. return rc;
  92. }
  93. int
  94. _rename_r(struct _reent *ptr, const char *old, const char *new)
  95. {
  96. int rc;
  97. rc = rename(old, new);
  98. return rc;
  99. }
  100. void *
  101. _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
  102. {
  103. /* no use this routine to get memory */
  104. return RT_NULL;
  105. }
  106. int
  107. _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
  108. {
  109. int rc;
  110. rc = stat(file, pstat);
  111. return rc;
  112. }
  113. _CLOCK_T_
  114. _times_r(struct _reent *ptr, struct tms *ptms)
  115. {
  116. /* return "not supported" */
  117. ptr->_errno = ENOTSUP;
  118. return -1;
  119. }
  120. int
  121. _unlink_r(struct _reent *ptr, const char *file)
  122. {
  123. int rc;
  124. rc = unlink(file);
  125. return rc;
  126. }
  127. int
  128. _wait_r(struct _reent *ptr, int *status)
  129. {
  130. /* return "not supported" */
  131. ptr->_errno = ENOTSUP;
  132. return -1;
  133. }
  134. _ssize_t
  135. _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
  136. {
  137. _ssize_t rc;
  138. rc = write(fd, buf, nbytes);
  139. return rc;
  140. }
  141. int
  142. _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp)
  143. {
  144. /* return "not supported" */
  145. ptr->_errno = ENOTSUP;
  146. return -1;
  147. }
  148. /* Memory routine */
  149. void *
  150. _malloc_r (struct _reent *ptr, size_t size)
  151. {
  152. return (void*)rt_malloc (size);
  153. }
  154. void *
  155. _realloc_r (struct _reent *ptr, void *old, size_t newlen)
  156. {
  157. return (void*)rt_realloc (old, newlen);
  158. }
  159. void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
  160. {
  161. return (void*)rt_calloc (size, len);
  162. }
  163. void
  164. _free_r (struct _reent *ptr, void *addr)
  165. {
  166. rt_free (addr);
  167. }
  168. #if 0
  169. void __assert(const char *file, int line, const char *failedexpr)
  170. {
  171. rt_kprintf("assertion \"%s\" failed: file \"%s\", line %d\n",
  172. failedexpr, file, line);
  173. RT_ASSERT(0);
  174. }
  175. #endif
  176. void
  177. _exit (int status)
  178. {
  179. rt_kprintf("thread:%s exit with %d\n", rt_thread_self()->name, status);
  180. RT_ASSERT(0);
  181. }