summaryrefslogtreecommitdiff
path: root/repo/qt5-qtwebengine/qt-musl-tid-caching.patch
blob: acbee2516d5737ff4750c105af8a0055151bdf85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
--- ./src/3rdparty/chromium/sandbox/linux/services/namespace_sandbox.cc.orig
+++ ./src/3rdparty/chromium/sandbox/linux/services/namespace_sandbox.cc
@@ -209,6 +209,70 @@
   return base::LaunchProcess(argv, launch_options_copy);
 }
 
+#if defined(__aarch64__) || defined(__arm__)
+#define TLS_ABOVE_TP
+#endif
+
+struct musl_pthread
+{
+  /* Part 1 -- these fields may be external or
+  * internal (accessed via asm) ABI. Do not change. */
+  struct pthread *self;
+#ifndef TLS_ABOVE_TP
+  uintptr_t *dtv;
+#endif
+  struct pthread *prev, *next; /* non-ABI */
+  uintptr_t sysinfo;
+#ifndef TLS_ABOVE_TP
+#ifdef CANARY_PAD
+  uintptr_t canary_pad;
+#endif
+  uintptr_t canary;
+#endif
+
+/* Part 2 -- implementation details, non-ABI. */
+  int tid;
+  int errno_val;
+  volatile int detach_state;
+  volatile int cancel;
+  volatile unsigned char canceldisable, cancelasync;
+  unsigned char tsd_used:1;
+  unsigned char dlerror_flag:1;
+  unsigned char *map_base;
+  size_t map_size;
+  void *stack;
+  size_t stack_size;
+  size_t guard_size;
+  void *result;
+  struct __ptcb *cancelbuf;
+  void **tsd;
+  struct {
+    volatile void *volatile head;
+    long off;
+    volatile void *volatile pending;
+  } robust_list;
+  int h_errno_val;
+  volatile int timer_id;
+  locale_t locale;
+  volatile int killlock[1];
+  char *dlerror_buf;
+  void *stdio_locks;
+
+  /* Part 3 -- the positions of these fields relative to
+  * the end of the structure is external and internal ABI. */
+#ifdef TLS_ABOVE_TP
+  uintptr_t canary;
+  uintptr_t *dtv;
+#endif
+};
+
+void MaybeUpdateMuslTidCache()
+{
+  pid_t real_tid = sys_gettid();
+  pid_t* cached_tid_location = &reinterpret_cast<struct musl_pthread*>(pthread_self())->tid;
+  *cached_tid_location = real_tid;
+}
+
 // static
 pid_t NamespaceSandbox::ForkInNewPidNamespace(bool drop_capabilities_in_child) {
   const pid_t pid =
@@ -226,6 +290,7 @@
 #if defined(LIBC_GLIBC)
     MaybeUpdateGlibcTidCache();
 #endif
+    MaybeUpdateMuslTidCache();
     return 0;
   }