ivmai / bdwgc

The Boehm-Demers-Weiser conservative C/C++ Garbage Collector (bdwgc, also known as bdw-gc, boehm-gc, libgc)
https://www.hboehm.info/gc/
Other
3.01k stars 406 forks source link

SIGPWR signal on Debian #552

Open ivmai opened 1 year ago

ivmai commented 1 year ago

On behalf of @michaellilltokiwa (moved from #544 ): I hit an issue that seems to be very similar to this. Using libgc1 Version on debian is 8.2.2-3 Attached is a the source code to reproduce the issue. SIGPWR.zip

PS: The C-code is generated by the Fuzion compiler so unfortunately it is ~60000 lines long but what 'm trying to do is simple. I'm starting a process cat and in a thread, start reading from a pipe connected to its stdout. In the main thread I'm sleeping for 10 sec.

  match process.create ["cat"]
    p fuzion.sys.process.r_processes =>
      concur.thread.spawn (() ->
        say (p.read_bytes 100)
      )
    error => say "error"

  say "sleeping"
  time.nano.sleep (time.durations.seconds 10)
  say "sleeping finished"

is this correct that the issue is not reproducible if either -DNO_SOFT_VDB or -DNO_VDB_FOR_STATIC_ROOTS is passed to CFLAGS_EXTRA?

I cloned this https://github.com/ivmai/bdwgc then tried both flags, followed by rebuilding libgc: make clean, ./configure.sh, make. I also made sure with strace that my program is not using the debian libgc:

sam@debian ~/n/fuzion (lib/process_wip_strange_err)$ strace ./test_process 2>&1 |grep open ... openat(AT_FDCWD, "/home/not_synced/bdwgc/.libs/libgc.so.1", O_RDONLY|O_CLOEXEC) = 3 ... It did not seem to make a difference.

So, the issue is still reproducible with the above flags, right? Just to clarify it.

Yes, it is still reproducible.

ivmai commented 1 year ago

@michaellilltokiwa, I failed to reproduce the issue. I used the following command to build and run test: gcc -I include -I libatomic_ops/src -DGC_THREADS test_process.c extra/gc.c -lpthread && ./a.out

ivmai commented 1 year ago

@michaellilltokiwa commented 2 hours ago:

@ivmai I used clang originally: clang -L ../bdwgc/.libs/ -O3 -lgc -lm -lpthread -o test_process test_process.c`

but it seems to be the same with gcc:

sam@debian /home/not_synced/bdwgc (master)$ gcc -I include -DGC_THREADS test_process.c extra/gc.c -lpthread sam@debian /home/not_synced/bdwgc (master)130$ gdb a.out GNU gdb (Debian 13.1-3) 13.1 Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: https://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: http://www.gnu.org/software/gdb/documentation/.

For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from a.out... (No debugging symbols found in a.out) (gdb) r Starting program: /home/not_synced/bdwgc/a.out [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". [Detaching after vfork from child process 44578] created process 44578, 4, 5, 7 [New Thread 0x7ffff7d766c0 (LWP 44579)] [New Thread 0x7ffff75756c0 (LWP 44580)] reading 100 bytes from 44578 5

Thread 1 "a.out" received signal SIGPWR, Power fail/restart. __futex_abstimed_wait_common64 (private=, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x7fffffffdb70) at ./nptl/futex-internal.c:57 57 ./nptl/futex-internal.c: No such file or directory. (gdb) c Continuing.

Thread 1 "a.out" received signal SIGXCPU, CPU time limit exceeded. 0x00007ffff7e06241 in __GI___sigsuspend (set=0x5555555e8f00 ) at ../sysdeps/unix/sysv/linux/sigsuspend.c:26 26 ../sysdeps/unix/sysv/linux/sigsuspend.c: No such file or directory. (gdb) c Continuing.

@michaellilltokiwa commented 1 hour ago:

It seems that this problem does not occur on every execution. Here is an strace of a run where the problem did not occur:

execve("./a.out", ["./a.out"], 0x7fff2c338bb0 /* 49 vars */) = 0
brk(NULL)                               = 0x556672d48000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7feab76f8000
access("/etc/ld.so.preload", R_OK)      = 0
openat(AT_FDCWD, "/etc/ld.so.preload", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
close(3)                                = 0
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95494, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 95494, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7feab76e0000
close(3)                                = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0Ps\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=1922136, ...}, AT_EMPTY_PATH) = 0
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
mmap(NULL, 1970000, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7feab74ff000
mmap(0x7feab7525000, 1396736, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x26000) = 0x7feab7525000
mmap(0x7feab767a000, 339968, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17b000) = 0x7feab767a000
mmap(0x7feab76cd000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1ce000) = 0x7feab76cd000
mmap(0x7feab76d3000, 53072, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7feab76d3000
close(3)                                = 0
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7feab74fc000
arch_prctl(ARCH_SET_FS, 0x7feab74fc740) = 0
set_tid_address(0x7feab74fca10)         = 44994
set_robust_list(0x7feab74fca20, 24)     = 0
rseq(0x7feab74fd060, 0x20, 0, 0x53053053) = 0
mprotect(0x7feab76cd000, 16384, PROT_READ) = 0
mprotect(0x5566728bb000, 4096, PROT_READ) = 0
mprotect(0x7feab772a000, 8192, PROT_READ) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
munmap(0x7feab76e0000, 95494)           = 0
getrandom("\xcf\xdd\xed\x37\x8b\x04\x5c\xae", 8, GRND_NONBLOCK) = 8
brk(NULL)                               = 0x556672d48000
brk(0x556672d69000)                     = 0x556672d69000
openat(AT_FDCWD, "/proc/self/maps", O_RDONLY|O_CLOEXEC) = 3
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
newfstatat(3, "", {st_mode=S_IFREG|0444, st_size=0, ...}, AT_EMPTY_PATH) = 0
read(3, "556672865000-556672867000 r--p 0"..., 1024) = 1024
read(3, "000-7feab76d1000 r--p 001ce000 f"..., 1024) = 1024
close(3)                                = 0
sched_getaffinity(44994, 32, [0 1 2 3 4 5 6 7]) = 8
mmap(NULL, 65536, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7feab76e8000
mmap(0x7feab76f8000, 65536, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7feab74ec000
mmap(0x7feab74fc000, 65536, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7feab74dc000
mmap(0x7feab74ec000, 65536, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7feab74cc000
mmap(0x7feab74dc000, 65536, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7feab74bc000
openat(AT_FDCWD, "/proc/stat", O_RDONLY) = 3
read(3, "cpu  882391 8647 177311 13436756"..., 1700) = 1700
close(3)                                = 0
rt_sigaction(SIGPWR, {sa_handler=0x5566728a3d79, sa_mask=~[INT QUIT ABRT BUS SEGV TERM RTMIN RT_1], sa_flags=SA_RESTORER|SA_RESTART|SA_SIGINFO, sa_restorer=0x7feab753af90}, NULL, 8) = 0
rt_sigaction(SIGXCPU, {sa_handler=0x5566728a41df, sa_mask=~[INT QUIT ABRT BUS SEGV TERM RTMIN RT_1], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7feab753af90}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [XCPU PWR], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
pipe2([3, 4], 0)                        = 0
pipe2([5, 6], 0)                        = 0
pipe2([7, 8], 0)                        = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
mmap(NULL, 36864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7feab74b3000
rt_sigprocmask(SIG_BLOCK, ~[], [], 8)   = 0
clone3({flags=CLONE_VM|CLONE_VFORK, exit_signal=SIGCHLD, stack=0x7feab74b3000, stack_size=0x9000}, 88) = 44995
munmap(0x7feab74b3000, 36864)           = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
close(3)                                = 0
close(6)                                = 0
close(8)                                = 0
mmap(0x7feab74cc000, 65536, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7feab74ac000
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
newfstatat(1, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x2), ...}, AT_EMPTY_PATH) = 0
write(1, "created process 44995, 4, 5, 7", 30) = 30
write(1, "\n", 1)                       = 1
rt_sigaction(SIGRT_1, {sa_handler=0x7feab7585540, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK|SA_RESTART|SA_SIGINFO, sa_restorer=0x7feab753af90}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
mmap(NULL, 8392704, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7feab6cab000
mprotect(0x7feab6cac000, 8388608, PROT_READ|PROT_WRITE) = 0
rt_sigprocmask(SIG_BLOCK, ~[], [], 8)   = 0
clone3({flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, child_tid=0x7feab74ab990, parent_tid=0x7feab74ab990, exit_signal=0, stack=0x7feab6cab000, stack_size=0x7fff80, tls=0x7feab74ab6c0} => {parent_tid=[44996]}, 88) = 44996
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
sched_yield()                           = 0
sched_yield()                           = 0
mmap(NULL, 8392704, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7feab64aa000
mprotect(0x7feab64ab000, 8388608, PROT_READ|PROT_WRITE) = 0
rt_sigprocmask(SIG_BLOCK, ~[], [], 8)   = 0
clone3({flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, child_tid=0x7feab6caa990, parent_tid=0x7feab6caa990, exit_signal=0, stack=0x7feab64aa000, stack_size=0x7fff80, tls=0x7feab6caa6c0} => {parent_tid=[44997]}, 88) = 44997
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
write(1, "sleeping", 8)                 = 8
futex(0x7feab76d3a10, FUTEX_WAKE_PRIVATE, 1) = 1
--- SIGPWR {si_signo=SIGPWR, si_code=SI_TKILL, si_pid=44994, si_uid=1000} ---
futex(0x5566728f9fa0, FUTEX_WAKE_PRIVATE, 1) = 1
rt_sigsuspend(~[INT QUIT ABRT BUS SEGV TERM XCPU RTMIN RT_1], 8) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGXCPU {si_signo=SIGXCPU, si_code=SI_TKILL, si_pid=44994, si_uid=1000} ---
rt_sigreturn({mask=~[INT QUIT ABRT BUS KILL SEGV TERM STOP RTMIN RT_1]}) = -1 EINTR (Interrupted system call)
futex(0x5566728f9fa0, FUTEX_WAKE_PRIVATE, 1) = 1
rt_sigreturn({mask=[]})                 = 1
sched_yield()                           = 0
write(1, "hello from thread 2\n", 20)   = 20
futex(0x7feab76d3a10, FUTEX_WAKE_PRIVATE, 1) = 1
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=10, tv_nsec=0}, 0x7ffe919f7470) = 0
write(1, "sleeping finished", 17)       = 17
write(1, "\n", 1)                       = 1
exit_group(0)                           = ?
+++ exited with 0 +++
And an strace of the same program where the problem occurred (nanosleep is interupted by signal):

execve("./a.out", ["./a.out"], 0x7ffda2ece960 /* 49 vars */) = 0
brk(NULL)                               = 0x55dccaa18000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f55533bf000
access("/etc/ld.so.preload", R_OK)      = 0
openat(AT_FDCWD, "/etc/ld.so.preload", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
close(3)                                = 0
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95494, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 95494, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f55533a7000
close(3)                                = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0Ps\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=1922136, ...}, AT_EMPTY_PATH) = 0
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
mmap(NULL, 1970000, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f55531c6000
mmap(0x7f55531ec000, 1396736, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x26000) = 0x7f55531ec000
mmap(0x7f5553341000, 339968, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17b000) = 0x7f5553341000
mmap(0x7f5553394000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1ce000) = 0x7f5553394000
mmap(0x7f555339a000, 53072, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f555339a000
close(3)                                = 0
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f55531c3000
arch_prctl(ARCH_SET_FS, 0x7f55531c3740) = 0
set_tid_address(0x7f55531c3a10)         = 45006
set_robust_list(0x7f55531c3a20, 24)     = 0
rseq(0x7f55531c4060, 0x20, 0, 0x53053053) = 0
mprotect(0x7f5553394000, 16384, PROT_READ) = 0
mprotect(0x55dcc9a5c000, 4096, PROT_READ) = 0
mprotect(0x7f55533f1000, 8192, PROT_READ) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
munmap(0x7f55533a7000, 95494)           = 0
getrandom("\x12\x8a\x96\x46\xf8\xab\x21\x5b", 8, GRND_NONBLOCK) = 8
brk(NULL)                               = 0x55dccaa18000
brk(0x55dccaa39000)                     = 0x55dccaa39000
openat(AT_FDCWD, "/proc/self/maps", O_RDONLY|O_CLOEXEC) = 3
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
newfstatat(3, "", {st_mode=S_IFREG|0444, st_size=0, ...}, AT_EMPTY_PATH) = 0
read(3, "55dcc9a06000-55dcc9a08000 r--p 0"..., 1024) = 1024
read(3, "000-7f5553398000 r--p 001ce000 f"..., 1024) = 1024
close(3)                                = 0
sched_getaffinity(45006, 32, [0 1 2 3 4 5 6 7]) = 8
mmap(NULL, 65536, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f55533af000
mmap(0x7f55533bf000, 65536, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f55531b3000
mmap(0x7f55531c3000, 65536, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f55531a3000
mmap(0x7f55531b3000, 65536, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5553193000
mmap(0x7f55531a3000, 65536, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5553183000
openat(AT_FDCWD, "/proc/stat", O_RDONLY) = 3
read(3, "cpu  882487 8649 177369 13448079"..., 1700) = 1700
close(3)                                = 0
rt_sigaction(SIGPWR, {sa_handler=0x55dcc9a44d79, sa_mask=~[INT QUIT ABRT BUS SEGV TERM RTMIN RT_1], sa_flags=SA_RESTORER|SA_RESTART|SA_SIGINFO, sa_restorer=0x7f5553201f90}, NULL, 8) = 0
rt_sigaction(SIGXCPU, {sa_handler=0x55dcc9a451df, sa_mask=~[INT QUIT ABRT BUS SEGV TERM RTMIN RT_1], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f5553201f90}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [XCPU PWR], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
pipe2([3, 4], 0)                        = 0
pipe2([5, 6], 0)                        = 0
pipe2([7, 8], 0)                        = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0
mmap(NULL, 36864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f555317a000
rt_sigprocmask(SIG_BLOCK, ~[], [], 8)   = 0
clone3({flags=CLONE_VM|CLONE_VFORK, exit_signal=SIGCHLD, stack=0x7f555317a000, stack_size=0x9000}, 88) = 45007
munmap(0x7f555317a000, 36864)           = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
close(3)                                = 0
close(6)                                = 0
close(8)                                = 0
mmap(0x7f5553193000, 65536, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5553173000
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
newfstatat(1, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x2), ...}, AT_EMPTY_PATH) = 0
write(1, "created process 45007, 4, 5, 7", 30) = 30
write(1, "\n", 1)                       = 1
rt_sigaction(SIGRT_1, {sa_handler=0x7f555324c540, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK|SA_RESTART|SA_SIGINFO, sa_restorer=0x7f5553201f90}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
mmap(NULL, 8392704, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f5552972000
mprotect(0x7f5552973000, 8388608, PROT_READ|PROT_WRITE) = 0
rt_sigprocmask(SIG_BLOCK, ~[], [], 8)   = 0
clone3({flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, child_tid=0x7f5553172990, parent_tid=0x7f5553172990, exit_signal=0, stack=0x7f5552972000, stack_size=0x7fff80, tls=0x7f55531726c0} => {parent_tid=[45008]}, 88) = 45008
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
sched_yield()                           = 0
sched_yield()                           = 0
mmap(NULL, 8392704, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f5552171000
mprotect(0x7f5552172000, 8388608, PROT_READ|PROT_WRITE) = 0
rt_sigprocmask(SIG_BLOCK, ~[], [], 8)   = 0
clone3({flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, child_tid=0x7f5552971990, parent_tid=0x7f5552971990, exit_signal=0, stack=0x7f5552171000, stack_size=0x7fff80, tls=0x7f55529716c0} => {parent_tid=[45009]}, 88) = 45009
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
write(1, "sleeping", 8)                 = 8
write(1, "\n", 1)                       = 1
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=10, tv_nsec=0}, {tv_sec=10, tv_nsec=13979}) = ? ERESTART_RESTARTBLOCK (Interrupted by signal)
--- SIGPWR {si_signo=SIGPWR, si_code=SI_TKILL, si_pid=45006, si_uid=1000} ---
futex(0x55dcc9a9afa0, FUTEX_WAKE_PRIVATE, 1) = 1
rt_sigsuspend(~[INT QUIT ABRT BUS SEGV TERM XCPU RTMIN RT_1], 8) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGXCPU {si_signo=SIGXCPU, si_code=SI_TKILL, si_pid=45006, si_uid=1000} ---
rt_sigreturn({mask=~[INT QUIT ABRT BUS KILL SEGV TERM STOP RTMIN RT_1]}) = -1 EINTR (Interrupted system call)
futex(0x55dcc9a9afa0, FUTEX_WAKE_PRIVATE, 1) = 1
rt_sigreturn({mask=[]})                 = -1 EINTR (Interrupted system call)
write(1, "sleeping finished", 17)       = 17
sched_yield()                           = 0
write(1, "\n", 1)                       = 1
exit_group(0)                           = ?
+++ exited with 0 +++
ivmai commented 1 year ago

I've executed the code 10K times and haven't seen any crash.

Thread 1 "a.out" received signal SIGPWR, Power fail/restart. __futex_abstimed_wait_common64 (private=, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x7fffffffdb70)

I should tell you that this is normal on Linux platform - SIGPWR and SIGXCPU are sued by libgc internally to suspend and resume threads.