tls.c 1.3 KB

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