tls.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <errno.h>
  2. #include <sys/ptrace.h>
  3. #include <sys/syscall.h>
  4. #include <asm/ldt.h>
  5. #include "sysdep/tls.h"
  6. #include "uml-config.h"
  7. /* TLS support - we basically rely on the host's one.*/
  8. /* In TT mode, this should be called only by the tracing thread, and makes sense
  9. * only for PTRACE_SET_THREAD_AREA. In SKAS mode, it's used normally.
  10. *
  11. */
  12. #ifndef PTRACE_GET_THREAD_AREA
  13. #define PTRACE_GET_THREAD_AREA 25
  14. #endif
  15. #ifndef PTRACE_SET_THREAD_AREA
  16. #define PTRACE_SET_THREAD_AREA 26
  17. #endif
  18. int os_set_thread_area(user_desc_t *info, int pid)
  19. {
  20. int ret;
  21. ret = ptrace(PTRACE_SET_THREAD_AREA, pid, info->entry_number,
  22. (unsigned long) info);
  23. if (ret < 0)
  24. ret = -errno;
  25. return ret;
  26. }
  27. #ifdef UML_CONFIG_MODE_SKAS
  28. int os_get_thread_area(user_desc_t *info, int pid)
  29. {
  30. int ret;
  31. ret = ptrace(PTRACE_GET_THREAD_AREA, pid, info->entry_number,
  32. (unsigned long) info);
  33. if (ret < 0)
  34. ret = -errno;
  35. return ret;
  36. }
  37. #endif
  38. #ifdef UML_CONFIG_MODE_TT
  39. #include "linux/unistd.h"
  40. int do_set_thread_area_tt(user_desc_t *info)
  41. {
  42. int ret;
  43. ret = syscall(__NR_set_thread_area,info);
  44. if (ret < 0) {
  45. ret = -errno;
  46. }
  47. return ret;
  48. }
  49. int do_get_thread_area_tt(user_desc_t *info)
  50. {
  51. int ret;
  52. ret = syscall(__NR_get_thread_area,info);
  53. if (ret < 0) {
  54. ret = -errno;
  55. }
  56. return ret;
  57. }
  58. #endif /* UML_CONFIG_MODE_TT */