Skip to content

Commit fae0c02

Browse files
committed
Workaround WSL not supporting x87 in ucontext_t
1 parent d6ff4c7 commit fae0c02

File tree

8 files changed

+13
-11
lines changed

8 files changed

+13
-11
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
# build/config.mk
6161

6262
SHELL = build/bootstrap/cocmd.com
63-
HOSTS ?= freebsd openbsd netbsd rhel7 rhel5 win10 xnu
63+
HOSTS ?= freebsd openbsd netbsd rhel7 rhel5 xnu win10 win10:31338
6464
MAKEFLAGS += -j --no-builtin-rules
6565

6666
.SUFFIXES:

libc/calls/ntcontext2linux.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
privileged void _ntcontext2linux(ucontext_t *ctx, const struct NtContext *cr) {
2525
if (!cr) return;
26-
ctx->uc_flags = cr->EFlags;
2726
ctx->uc_mcontext.eflags = cr->EFlags;
2827
ctx->uc_mcontext.rax = cr->Rax;
2928
ctx->uc_mcontext.rbx = cr->Rbx;
@@ -51,7 +50,6 @@ privileged void _ntcontext2linux(ucontext_t *ctx, const struct NtContext *cr) {
5150

5251
privileged void _ntlinux2context(struct NtContext *cr, const ucontext_t *ctx) {
5352
if (!cr) return;
54-
cr->EFlags = ctx->uc_flags;
5553
cr->EFlags = ctx->uc_mcontext.eflags;
5654
cr->Rax = ctx->uc_mcontext.rax;
5755
cr->Rbx = ctx->uc_mcontext.rbx;

libc/calls/sigenter-freebsd.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ privileged void __sigenter_freebsd(int sig, struct siginfo_freebsd *freebsdinfo,
5151
g.uc.uc_stack.ss_sp = ctx->uc_stack.ss_sp;
5252
g.uc.uc_stack.ss_size = ctx->uc_stack.ss_size;
5353
g.uc.uc_stack.ss_flags = ctx->uc_stack.ss_flags;
54-
g.uc.uc_flags = ctx->uc_flags;
5554
__repmovsb(&g.uc.uc_sigmask, &ctx->uc_sigmask,
5655
MIN(sizeof(g.uc.uc_sigmask), sizeof(ctx->uc_sigmask)));
5756
g.uc.uc_mcontext.r8 = ctx->uc_mcontext.mc_r8;

libc/calls/sigenter-netbsd.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ privileged void __sigenter_netbsd(int sig, struct siginfo_netbsd *si,
4747
__repstosb(&uc, 0, sizeof(uc));
4848
__siginfo2cosmo(&si2, (void *)si);
4949
uc.uc_mcontext.fpregs = &uc.__fpustate;
50-
uc.uc_flags = ctx->uc_flags;
5150
uc.uc_stack.ss_sp = ctx->uc_stack.ss_sp;
5251
uc.uc_stack.ss_size = ctx->uc_stack.ss_size;
5352
uc.uc_stack.ss_flags = ctx->uc_stack.ss_flags;

libc/calls/sigenter-xnu.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ privileged void __sigenter_xnu(void *fn, int infostyle, int sig,
471471
} else {
472472
__repstosb(&g, 0, sizeof(g));
473473
if (xnuctx) {
474-
g.uc.uc_flags = xnuctx->uc_onstack ? SA_ONSTACK : 0;
475474
g.uc.uc_sigmask.__bits[0] = xnuctx->uc_sigmask;
476475
g.uc.uc_sigmask.__bits[1] = 0;
477476
g.uc.uc_stack.ss_sp = xnuctx->uc_stack.ss_sp;

libc/calls/ucontext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct MachineContext {
7272
typedef struct MachineContext mcontext_t;
7373

7474
struct ucontext {
75-
uint64_t uc_flags;
75+
uint64_t uc_flags; /* don't use this */
7676
struct ucontext *uc_link;
7777
stack_t uc_stack;
7878
mcontext_t uc_mcontext; /* use this */

test/libc/calls/sigaction_test.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
#include "libc/dce.h"
2626
#include "libc/errno.h"
2727
#include "libc/nexgen32e/nexgen32e.h"
28+
#include "libc/runtime/internal.h"
2829
#include "libc/runtime/runtime.h"
2930
#include "libc/sysv/consts/sa.h"
3031
#include "libc/sysv/consts/sig.h"
32+
#include "libc/sysv/consts/uc.h"
3133
#include "libc/testlib/testlib.h"
3234
#include "third_party/xed/x86.h"
3335

@@ -196,6 +198,8 @@ TEST(sigaction, autoZombieSlayer) {
196198
// verify it works
197199
ASSERT_NE(-1, (pid = fork()));
198200
if (!pid) _Exit(0);
201+
// XXX: WSL does the wrong thing here.
202+
if (__is_wsl()) usleep(10);
199203
ASSERT_SYS(ECHILD, -1, wait(0));
200204
// clean up
201205
ASSERT_SYS(0, 0, sigaction(SIGCHLD, &sa, 0));

test/libc/log/backtrace_test.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,13 @@ TEST(ShowCrashReports, testDivideByZero) {
325325
_gc(IndentLines(output, -1, 0, 4)));
326326
__die();
327327
}
328-
if (!strstr(output, "3.141")) {
329-
fprintf(stderr, "ERROR: crash report didn't have fpu register\n%s\n",
330-
_gc(IndentLines(output, -1, 0, 4)));
331-
__die();
328+
// XXX: WSL doesn't save and restore x87 registers to ucontext_t
329+
if (!__is_wsl()) {
330+
if (!strstr(output, "3.141")) {
331+
fprintf(stderr, "ERROR: crash report didn't have fpu register\n%s\n",
332+
_gc(IndentLines(output, -1, 0, 4)));
333+
__die();
334+
}
332335
}
333336
if (!strstr(output, "0f0e0d0c0b0a09080706050403020100")) {
334337
fprintf(stderr, "ERROR: crash report didn't have sse register\n%s\n",

0 commit comments

Comments
 (0)