summary refs log tree commit diff stats
path: root/results/classifier/qwen3:32b/output/runtime/1907969
blob: 58e7ba57ad0fa2cfc28c39faed01487753a3f0ef (plain) (blame)
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
linux-user/i386: Segfault when mixing threads and signals

Given the following C program, qemu-i386 will surely and certainly segfault when executing it.
The problem is only noticeable if the program is statically linked to musl's libc and, as written
in the title, it only manifests when targeting i386.

Removing the pthread calls or the second raise() makes it not segfault.

The crash is in some part of the TCG-generated code, right when it tries to perform a
%gs-relative access.

If you want a quick way of cross-compiling this binary:

* Download a copy of the Zig compiler from https://ziglang.org/download/
* Compile it with
  `zig cc -target i386-linux-musl <C-FILE> -o <OUT>`

```
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <asm/prctl.h>
#include <sys/syscall.h>

void sig_func(int sig)
{
    write(1, "hi!\n", strlen("hi!\n"));
}

void func(void *p) { }

typedef void *(*F)(void *);

int main()
{
    pthread_t tid;

    struct sigaction action;
    action.sa_flags = 0;
    action.sa_handler = sig_func;

    if (sigaction(SIGUSR1, &action, NULL) == -1) {
        return 1;
    }

    // This works.
    raise(SIGUSR1);

    pthread_create(&tid, NULL, (F)func, NULL);
    pthread_join(tid, NULL);

    // This makes qemu segfault.
    raise(SIGUSR1);
}
```