tls.c 1.4 KB

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