]> git.proxmox.com Git - mirror_qemu.git/blame - util/sys_membarrier.c
Merge tag 'pull-aspeed-20240201' of https://github.com/legoater/qemu into staging
[mirror_qemu.git] / util / sys_membarrier.c
CommitLineData
a40161cb
PB
1/*
2 * Process-global memory barriers
3 *
4 * Copyright (c) 2018 Red Hat, Inc.
5 *
6 * Author: Paolo Bonzini <pbonzini@redhat.com>
7 */
8
d6974846
BR
9#include "qemu/osdep.h"
10#include "qemu/sys_membarrier.h"
11#include "qemu/error-report.h"
a40161cb
PB
12
13#ifdef CONFIG_LINUX
14#include <linux/membarrier.h>
15#include <sys/syscall.h>
16
17static int
18membarrier(int cmd, int flags)
19{
20 return syscall(__NR_membarrier, cmd, flags);
21}
22#endif
23
24void smp_mb_global(void)
25{
26#if defined CONFIG_WIN32
27 FlushProcessWriteBuffers();
28#elif defined CONFIG_LINUX
29 membarrier(MEMBARRIER_CMD_SHARED, 0);
30#else
31#error --enable-membarrier is not supported on this operating system.
32#endif
33}
34
35void smp_mb_global_init(void)
36{
37#ifdef CONFIG_LINUX
38 int ret = membarrier(MEMBARRIER_CMD_QUERY, 0);
39 if (ret < 0) {
40 error_report("This QEMU binary requires the membarrier system call.");
41 error_report("Please upgrade your system to a newer version of Linux");
42 exit(1);
43 }
44 if (!(ret & MEMBARRIER_CMD_SHARED)) {
45 error_report("This QEMU binary requires MEMBARRIER_CMD_SHARED support.");
46 error_report("Please upgrade your system to a newer version of Linux");
47 exit(1);
48 }
49#endif
50}