syscalls.c 3.7 KB

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