Remove ifdef BOOTSTRAP from musl patches.

This commit is contained in:
rick-masters 2023-04-07 12:57:24 +00:00
parent c1ceabb9c4
commit fb4930c2f9
4 changed files with 31 additions and 69 deletions

View File

@ -2,58 +2,42 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
diff -r -u musl-1.1.24.orig/arch/i386/pthread_arch.h musl-1.1.24/arch/i386/pthread_arch.h diff -r -u musl-1.1.24.orig/arch/i386/pthread_arch.h musl-1.1.24/arch/i386/pthread_arch.h
--- arch/i386/pthread_arch.h 2019-10-13 21:58:27.000000000 +0000 --- arch/i386/pthread_arch.h 2019-10-13 21:58:27.000000000 +0000
+++ arch/i386/pthread_arch.h 2023-02-28 14:06:10.700603762 +0000 +++ arch/i386/pthread_arch.h 2023-04-07 11:56:04.649119523 +0000
@@ -1,8 +1,18 @@ @@ -1,8 +1,8 @@
+#define BOOTSTRAP
+
+#ifdef BOOTSTRAP
+extern pthread_t g_pthread; +extern pthread_t g_pthread;
+#endif
+ +
static inline struct pthread *__pthread_self() static inline struct pthread *__pthread_self()
{ {
+#ifndef BOOTSTRAP - struct pthread *self;
struct pthread *self; - __asm__ ("movl %%gs:0,%0" : "=r" (self) );
__asm__ ("movl %%gs:0,%0" : "=r" (self) ); - return self;
return self;
+#else
+ return g_pthread; + return g_pthread;
+#endif
} }
#define TP_ADJ(p) (p) #define TP_ADJ(p) (p)
diff -r -u musl-1.1.24.orig/src/env/__init_tls.c musl-1.1.24/src/env/__init_tls.c diff -r -u musl-1.1.24.orig/src/env/__init_tls.c musl-1.1.24/src/env/__init_tls.c
--- src/env/__init_tls.c 2019-10-13 21:58:27.000000000 +0000 --- src/env/__init_tls.c 2019-10-13 21:58:27.000000000 +0000
+++ src/env/__init_tls.c 2023-02-28 14:07:04.956604831 +0000 +++ src/env/__init_tls.c 2023-04-07 11:56:43.565120289 +0000
@@ -8,22 +8,31 @@ @@ -10,20 +10,19 @@
#include "libc.h"
#include "atomic.h"
#include "syscall.h" #include "syscall.h"
+#define BOOTSTRAP
volatile int __thread_list_lock; volatile int __thread_list_lock;
+#ifdef BOOTSTRAP
+pthread_t g_pthread; +pthread_t g_pthread;
+#endif
int __init_tp(void *p) int __init_tp(void *p)
{ {
pthread_t td = p; pthread_t td = p;
td->self = td; td->self = td;
+#ifndef BOOTSTRAP - int r = __set_thread_area(TP_ADJ(p));
int r = __set_thread_area(TP_ADJ(p)); - if (r < 0) return -1;
if (r < 0) return -1; - if (!r) libc.can_do_threads = 1;
if (!r) libc.can_do_threads = 1;
+#endif
td->detach_state = DT_JOINABLE; td->detach_state = DT_JOINABLE;
td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock); td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock);
td->locale = &libc.global_locale; td->locale = &libc.global_locale;
td->robust_list.head = &td->robust_list.head; td->robust_list.head = &td->robust_list.head;
td->sysinfo = __sysinfo; td->sysinfo = __sysinfo;
td->next = td->prev = td; td->next = td->prev = td;
+#ifdef BOOTSTRAP
+ g_pthread = td; + g_pthread = td;
+#endif
return 0; return 0;
} }

View File

@ -1,29 +1,17 @@
# SPDX-FileCopyrightText: 2023 Richard Masters <grick23@gmail.com> # SPDX-FileCopyrightText: 2023 Richard Masters <grick23@gmail.com>
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
diff -r -u musl-1.1.24.orig/src/process/posix_spawn.c musl-1.1.24/src/process/posix_spawn.c
--- src/process/posix_spawn.c 2019-10-13 21:58:27.000000000 +0000 --- src/process/posix_spawn.c 2019-10-13 21:58:27.000000000 +0000
+++ src/process/posix_spawn.c 2023-02-28 14:08:18.636606282 +0000 +++ src/process/posix_spawn.c 2023-04-07 11:50:47.253113271 +0000
@@ -8,6 +8,7 @@ @@ -182,8 +182,11 @@
#include "syscall.h"
#include "pthread_impl.h"
#include "fdop.h"
+#define BOOTSTRAP
struct args {
int p[2];
@@ -182,8 +183,16 @@
args.envp = envp; args.envp = envp;
pthread_sigmask(SIG_BLOCK, SIGALL_SET, &args.oldmask); pthread_sigmask(SIG_BLOCK, SIGALL_SET, &args.oldmask);
+#ifndef BOOTSTRAP - pid = __clone(child, stack+sizeof stack,
pid = __clone(child, stack+sizeof stack, - CLONE_VM|CLONE_VFORK|SIGCHLD, &args);
CLONE_VM|CLONE_VFORK|SIGCHLD, &args);
+#else
+ pid = fork(); + pid = fork();
+ if (pid == 0) { + if (pid == 0) {
+ _exit(child(&args)); + _exit(child(&args));
+ } + }
+#endif
+ +
close(args.p[1]); close(args.p[1]);

View File

@ -1,24 +1,20 @@
# SPDX-FileCopyrightText: 2023 Richard Masters <grick23@gmail.com> # SPDX-FileCopyrightText: 2023 Richard Masters <grick23@gmail.com>
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
diff -u -r musl-1.2.3.orig/arch/i386/pthread_arch.h musl-1.2.3/arch/i386/pthread_arch.h diff -r -u musl-1.2.3.orig/arch/i386/pthread_arch.h musl-1.2.3/arch/i386/pthread_arch.h
--- arch/i386/pthread_arch.h 2022-04-07 17:12:40.000000000 +0000 --- arch/i386/pthread_arch.h 2022-04-07 17:12:40.000000000 +0000
+++ arch/i386/pthread_arch.h 2022-12-19 23:39:10.890414014 +0000 +++ arch/i386/pthread_arch.h 2023-04-07 12:07:07.929132587 +0000
@@ -1,8 +1,14 @@ @@ -1,8 +1,7 @@
+#define BOOTSTRAP
+extern uintptr_t g_pthread; +extern uintptr_t g_pthread;
static inline uintptr_t __get_tp() static inline uintptr_t __get_tp()
{ {
+#ifndef BOOTSTRAP - uintptr_t tp;
uintptr_t tp; - __asm__ ("movl %%gs:0,%0" : "=r" (tp) );
__asm__ ("movl %%gs:0,%0" : "=r" (tp) ); - return tp;
return tp;
+#else
+ return g_pthread; + return g_pthread;
+#endif
} }
#define MC_PC gregs[REG_EIP] #define MC_PC gregs[REG_EIP]
diff -u -r musl-1.2.3.orig/arch/i386/syscall_arch.h musl-1.2.3/arch/i386/syscall_arch.h diff -r -u musl-1.2.3.orig/arch/i386/syscall_arch.h musl-1.2.3/arch/i386/syscall_arch.h
--- arch/i386/syscall_arch.h 2022-04-07 17:12:40.000000000 +0000 --- arch/i386/syscall_arch.h 2022-04-07 17:12:40.000000000 +0000
+++ arch/i386/syscall_arch.h 2022-12-20 17:28:21.734839560 +0000 +++ arch/i386/syscall_arch.h 2022-12-20 17:28:21.734839560 +0000
@@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
@ -26,25 +22,22 @@ diff -u -r musl-1.2.3.orig/arch/i386/syscall_arch.h musl-1.2.3/arch/i386/syscall
#define __SYSCALL_LL_E(x) \ #define __SYSCALL_LL_E(x) \
((union { long long ll; long l[2]; }){ .ll = x }).l[0], \ ((union { long long ll; long l[2]; }){ .ll = x }).l[0], \
((union { long long ll; long l[2]; }){ .ll = x }).l[1] ((union { long long ll; long l[2]; }){ .ll = x }).l[1]
diff -u -r musl-1.2.3.orig/src/env/__init_tls.c musl-1.2.3/src/env/__init_tls.c diff -r -u musl-1.2.3.orig/src/env/__init_tls.c musl-1.2.3/src/env/__init_tls.c
--- src/env/__init_tls.c 2022-04-07 17:12:40.000000000 +0000 --- src/env/__init_tls.c 2022-04-07 17:12:40.000000000 +0000
+++ src/env/__init_tls.c 2022-12-19 23:39:42.362414223 +0000 +++ src/env/__init_tls.c 2023-04-07 12:07:38.677133193 +0000
@@ -10,20 +10,25 @@ @@ -10,20 +10,19 @@
#include "syscall.h" #include "syscall.h"
volatile int __thread_list_lock; volatile int __thread_list_lock;
+#define BOOTSTRAP
+uintptr_t g_pthread; +uintptr_t g_pthread;
int __init_tp(void *p) int __init_tp(void *p)
{ {
pthread_t td = p; pthread_t td = p;
td->self = td; td->self = td;
+#ifndef BOOTSTRAP - int r = __set_thread_area(TP_ADJ(p));
int r = __set_thread_area(TP_ADJ(p)); - if (r < 0) return -1;
if (r < 0) return -1; - if (!r) libc.can_do_threads = 1;
if (!r) libc.can_do_threads = 1;
+#endif
td->detach_state = DT_JOINABLE; td->detach_state = DT_JOINABLE;
td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock); td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock);
td->locale = &libc.global_locale; td->locale = &libc.global_locale;

View File

@ -1,16 +1,13 @@
# SPDX-FileCopyrightText: 2023 Richard Masters <grick23@gmail.com> # SPDX-FileCopyrightText: 2023 Richard Masters <grick23@gmail.com>
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
diff -u -r musl-1.2.3.orig/src/process/posix_spawn.c musl-1.2.3/src/process/posix_spawn.c
--- src/process/posix_spawn.c 2022-04-07 17:12:40.000000000 +0000 --- src/process/posix_spawn.c 2022-04-07 17:12:40.000000000 +0000
+++ src/process/posix_spawn.c 2022-12-19 23:47:31.858417338 +0000 +++ src/process/posix_spawn.c 2023-04-07 12:01:57.217126467 +0000
@@ -190,8 +190,15 @@ @@ -190,8 +190,11 @@
goto fail; goto fail;
} }
+#if 0 - pid = __clone(child, stack+sizeof stack,
pid = __clone(child, stack+sizeof stack, - CLONE_VM|CLONE_VFORK|SIGCHLD, &args);
CLONE_VM|CLONE_VFORK|SIGCHLD, &args);
+#endif
+ pid = fork(); + pid = fork();
+ if (pid == 0) { + if (pid == 0) {
+ _exit(child(&args)); + _exit(child(&args));