qemu-e2k/util
Emilio Cota 1ff4a81bd3 tcg: use QTree instead of GTree
qemu-user can hang in a multi-threaded fork. One common
reason is that when creating a TB, between fork and exec
we manipulate a GTree whose memory allocator (GSlice) is
not fork-safe.

Although POSIX does not mandate it, the system's allocator
(e.g. tcmalloc, libc malloc) is probably fork-safe.

Fix some of these hangs by using QTree, which uses the system's
allocator regardless of the Glib version that we used at
configuration time.

Tested with the test program in the original bug report, i.e.:
```

void garble() {
  int pid = fork();
  if (pid == 0) {
    exit(0);
  } else {
    int wstatus;
    waitpid(pid, &wstatus, 0);
  }
}

void supragarble(unsigned depth) {
  if (depth == 0)
    return ;

  std::thread a(supragarble, depth-1);
  std::thread b(supragarble, depth-1);
  garble();
  a.join();
  b.join();
}

int main() {
  supragarble(10);
}
```

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/285
Reported-by: Valentin David <me@valentindavid.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Emilio Cota <cota@braap.org>
Message-Id: <20230205163758.416992-3-cota@braap.org>
[rth: Add QEMU_DISABLE_CFI for all callback using functions.]
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2023-03-28 15:23:10 -07:00
..
aio-posix.c aio: make aio_set_fd_poll() static to aio-posix.c 2023-03-13 15:23:37 +04:00
aio-posix.h
aio-wait.c
aio-win32.c win32: avoid mixing SOCKET and file descriptor space 2023-03-13 15:39:31 +04:00
aiocb.c
async-teardown.c Fix non-first inclusions of qemu/osdep.h 2023-02-08 07:28:05 +01:00
async.c async: clarify usage of barriers in the polling case 2023-03-07 12:39:53 +01:00
atomic64.c
base64.c
bitmap.c migration: Use non-atomic ops for clear log bitmap 2022-11-21 11:58:10 +01:00
bitops.c replace TABs with spaces 2023-03-20 12:43:50 +01:00
block-helpers.c
block-helpers.h
buffer.c
bufferiszero.c include/qemu/cpuid: Introduce xgetbv_low 2023-03-05 13:44:07 -08:00
cacheflush.c util/cacheflush: fix cache on windows-arm64 2023-02-21 08:53:03 -10:00
compatfd.c
coroutine-sigaltstack.c
coroutine-ucontext.c
coroutine-win32.c
crc32c.c
crc-ccitt.c
cutils.c util: remove support for hex numbers with a scaling suffix 2023-01-06 00:51:02 +01:00
dbus.c
drm.c
envlist.c replace TABs with spaces 2023-03-20 12:43:50 +01:00
error-report.c util/error: add G_GNUC_PRINTF for various functions 2023-01-11 10:44:34 +01:00
error.c error: add global &error_warn destination 2023-03-13 15:23:37 +04:00
event_notifier-posix.c
event_notifier-win32.c
fdmon-epoll.c aio-posix: fix race between epoll upgrade and aio_set_fd_handler() 2023-03-27 15:12:17 +02:00
fdmon-io_uring.c
fdmon-poll.c
fifo8.c
filemonitor-inotify.c
filemonitor-stub.c
getauxval.c
guest-random.c replay: Extract core API to 'exec/replay-core.h' 2023-02-27 22:29:01 +01:00
hbitmap.c hbitmap: fix hbitmap_status() return value for first dirty bit case 2023-02-17 14:34:24 +01:00
hexdump.c
host-utils.c
id.c
int128.c include/qemu/int128: Use Int128 structure for TCI 2023-02-04 06:19:42 -10:00
interval-tree.c util: Add interval-tree.c 2022-12-20 17:09:41 -08:00
iov.c util: make do_send_recv work with partial send/recv 2022-10-12 19:22:01 +04:00
iova-tree.c util: accept iova_tree_remove_parameter by value 2022-09-02 10:22:39 +08:00
keyval.c
lockcnt.c
log.c log: Remove unneeded new line 2023-03-08 00:37:48 +01:00
main-loop.c main-loop: remove qemu_fd_register(), win32/slirp/socket specific 2023-03-13 15:39:31 +04:00
memalign.c
memfd.c
meson.build util: import GTree as QTree 2023-03-28 15:23:10 -07:00
mmap-alloc.c util/mmap-alloc: Remove qemu_mempath_getpagesize() 2022-08-26 13:34:21 +02:00
module.c module: add Error arguments to module_load and module_load_qom 2022-11-06 09:48:50 +01:00
notify.c
nvdimm-utils.c
osdep.c error handling: Use RETRY_ON_EINTR() macro where applicable 2023-01-09 13:50:47 +01:00
oslib-posix.c util: drop qemu_fork() 2023-03-13 15:23:37 +04:00
oslib-win32.c win32: add qemu_close_socket_osfhandle() 2023-03-21 11:16:03 +04:00
path.c
qdist.c
qemu-co-shared-resource.c
qemu-co-timeout.c
qemu-config.c error: Drop superfluous #include "qapi/qmp/qerror.h" 2023-02-23 13:56:14 +01:00
qemu-coroutine-io.c
qemu-coroutine-lock.c qemu-coroutine-lock: add smp_mb__after_rmw() 2023-03-07 12:39:53 +01:00
qemu-coroutine-sleep.c coroutine: Clean up superfluous inclusion of qemu/coroutine.h 2023-01-19 10:18:28 +01:00
qemu-coroutine.c coroutine: Clean up superfluous inclusion of qemu/coroutine.h 2023-01-19 10:18:28 +01:00
qemu-option.c
qemu-print.c
qemu-progress.c
qemu-sockets.c win32: replace closesocket() with close() wrapper 2023-03-13 15:39:31 +04:00
qemu-thread-common.h
qemu-thread-posix.c qemu-thread-posix: cleanup, fix, document QemuEvent 2023-03-07 12:38:40 +01:00
qemu-thread-win32.c qemu-thread-win32: cleanup, fix, document QemuEvent 2023-03-07 12:38:40 +01:00
qemu-timer-common.c
qemu-timer.c
qht.c util/qht: use striped locks under TSAN 2023-02-02 11:48:20 +00:00
qsp.c
qtree.c tcg: use QTree instead of GTree 2023-03-28 15:23:10 -07:00
range.c
rcu.c
readline.c readline: Extract readline_add_completion_of() from monitor 2023-02-04 07:56:54 +01:00
selfmap.c
stats64.c
sys_membarrier.c
systemd.c
thread-context.c qapi: Use returned bool to check for failure (again) 2022-12-14 16:19:35 +01:00
thread-pool.c
throttle.c
timed-average.c
trace-events util/userfaultfd: Support /dev/userfaultfd 2023-02-11 16:51:09 +01:00
trace.h
transactions.c
unicode.c
uri.c Updated the FSF address to <https://www.gnu.org/licenses/> 2023-02-27 09:15:39 +01:00
userfaultfd.c util/userfaultfd: Support /dev/userfaultfd 2023-02-11 16:51:09 +01:00
uuid.c
vfio-helpers.c error handling: Use RETRY_ON_EINTR() macro where applicable 2023-01-09 13:50:47 +01:00
vhost-user-server.c block/export: only acquire AioContext once for vhost_user_server_stop() 2023-03-27 13:46:30 +02:00
yank.c