syscall_generic.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-11-10 RT-Thread The first version
  9. * 2023-03-13 WangXiaoyao syscall metadata as structure
  10. */
  11. #ifndef __SYSCALL_DATA_H__
  12. #define __SYSCALL_DATA_H__
  13. #include <rtthread.h>
  14. typedef long sysret_t;
  15. struct rt_syscall_def
  16. {
  17. void *func;
  18. char *name;
  19. };
  20. /**
  21. * @brief signature for syscall, used to locate syscall metadata.
  22. *
  23. * We don't allocate an exclusive section in ELF like Linux do
  24. * to avoid initializing necessary data by iterating that section,
  25. * which increases system booting time. We signature a pointer
  26. * just below each syscall entry in syscall table to make it
  27. * easy to locate every syscall's metadata by using syscall id.
  28. */
  29. #define SYSCALL_SIGN(func) { \
  30. (void *)(func), \
  31. &RT_STRINGIFY(func)[4], \
  32. }
  33. #define SET_ERRNO(no) rt_set_errno(-(no))
  34. #define GET_ERRNO() ({int _errno = rt_get_errno(); _errno > 0 ? -_errno : _errno;})
  35. #define _SYS_WRAP(func) ({int _ret = func; _ret < 0 ? GET_ERRNO() : _ret;})
  36. #endif /* __SYSCALL_DATA_H__ */