Skip to content

Commit bd6d9ff

Browse files
committed
Get deathstar demo working again on metal
1 parent 15ea052 commit bd6d9ff

File tree

6 files changed

+21
-17
lines changed

6 files changed

+21
-17
lines changed

libc/calls/ucontext.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int __tailcontext(const ucontext_t *);
3434
* @see getcontext()
3535
*/
3636
int setcontext(const ucontext_t *uc) {
37-
if (IsWindows()) {
37+
if (IsWindows() || IsMetal()) {
3838
atomic_store_explicit(&__get_tls()->tib_sigmask, uc->uc_sigmask,
3939
memory_order_release);
4040
} else {
@@ -44,7 +44,7 @@ int setcontext(const ucontext_t *uc) {
4444
}
4545

4646
int __getcontextsig(ucontext_t *uc) {
47-
if (IsWindows()) {
47+
if (IsWindows() || IsMetal()) {
4848
uc->uc_sigmask =
4949
atomic_load_explicit(&__get_tls()->tib_sigmask, memory_order_acquire);
5050
return 0;
@@ -54,7 +54,7 @@ int __getcontextsig(ucontext_t *uc) {
5454
}
5555

5656
int __swapcontextsig(ucontext_t *x, const ucontext_t *y) {
57-
if (IsWindows()) {
57+
if (IsWindows() || IsMetal()) {
5858
x->uc_sigmask = atomic_exchange_explicit(
5959
&__get_tls()->tib_sigmask, y->uc_sigmask, memory_order_acquire);
6060
return 0;

libc/intrin/mman.greg.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#ifdef __x86_64__
4646

4747
#define INVERT(x) (BANE + PHYSICAL((uintptr_t)(x)))
48-
#define NOPAGE ((uint64_t) - 1)
48+
#define NOPAGE ((uint64_t)-1)
4949

5050
#define APE_STACK_VADDR \
5151
({ \
@@ -69,9 +69,9 @@ texthead uint64_t __new_page(struct mman *mm) {
6969
if (p != NOPAGE) {
7070
uint64_t q;
7171
struct ReclaimedPage *rp = (struct ReclaimedPage *)(BANE + p);
72-
unassert(p == (p & PAGE_TA));
72+
/* unassert(p == (p & PAGE_TA)); */
7373
q = rp->next;
74-
unassert(q == (q & PAGE_TA) || q == NOPAGE);
74+
/* unassert(q == (q & PAGE_TA) || q == NOPAGE); */
7575
mm->frp = q;
7676
return p;
7777
}
@@ -200,7 +200,7 @@ void __ref_pages(struct mman *mm, uint64_t *pml4t, uint64_t ps, uint64_t size) {
200200
*/
201201
static void __reclaim_page(struct mman *mm, uint64_t p) {
202202
struct ReclaimedPage *rp = (struct ReclaimedPage *)(BANE + p);
203-
unassert(p == (p & PAGE_TA));
203+
/* unassert(p == (p & PAGE_TA)); */
204204
rp->next = mm->frp;
205205
mm->frp = p;
206206
}

libc/intrin/pthread_mutex_lock.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "libc/runtime/internal.h"
2626
#include "libc/thread/lock.h"
2727
#include "libc/thread/thread.h"
28-
#include "libc/thread/tls.h"
2928
#include "third_party/nsync/mu.h"
3029

3130
/**

libc/intrin/sig.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
struct Signals __sig;
2828

2929
sigset_t __sig_block(void) {
30-
if (IsWindows()) {
31-
return atomic_exchange_explicit(&__get_tls()->tib_sigmask, -1,
32-
memory_order_acquire);
30+
if (IsWindows() || IsMetal()) {
31+
if (__tls_enabled)
32+
return atomic_exchange_explicit(&__get_tls()->tib_sigmask, -1,
33+
memory_order_acquire);
34+
else
35+
return 0;
3336
} else {
3437
sigset_t res, neu = -1;
3538
sys_sigprocmask(SIG_SETMASK, &neu, &res);
@@ -38,10 +41,12 @@ sigset_t __sig_block(void) {
3841
}
3942

4043
void __sig_unblock(sigset_t m) {
41-
if (IsWindows()) {
42-
atomic_store_explicit(&__get_tls()->tib_sigmask, m, memory_order_release);
43-
if (_weaken(__sig_check)) {
44-
_weaken(__sig_check)();
44+
if (IsWindows() || IsMetal()) {
45+
if (__tls_enabled) {
46+
atomic_store_explicit(&__get_tls()->tib_sigmask, m, memory_order_release);
47+
if (_weaken(__sig_check)) {
48+
_weaken(__sig_check)();
49+
}
4550
}
4651
} else {
4752
sys_sigprocmask(SIG_SETMASK, &m, 0);

libc/runtime/set_tls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ dontinstrument textstartup void __set_tls(struct CosmoTib *tib) {
5757
uint64_t val = (uint64_t)tib;
5858
asm volatile("wrmsr"
5959
: /* no outputs */
60-
: "c"(MSR_IA32_FS_BASE), "a"((uint32_t)val),
60+
: "c"(MSR_IA32_GS_BASE), "a"((uint32_t)val),
6161
"d"((uint32_t)(val >> 32)));
6262
}
6363
#elif defined(__aarch64__)

libc/thread/pthread_create.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static int PosixThread(void *arg, int tid) {
118118
// set long jump handler so pthread_exit can bring control back here
119119
if (!setjmp(pt->pt_exiter)) {
120120
sigdelset(&pt->pt_attr.__sigmask, SIGTHR);
121-
if (IsWindows()) {
121+
if (IsWindows() || IsMetal()) {
122122
atomic_store_explicit(&__get_tls()->tib_sigmask, pt->pt_attr.__sigmask,
123123
memory_order_release);
124124
} else {

0 commit comments

Comments
 (0)