* [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers
@ 2025-04-22 5:27 Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 01/20] hw/core/loader.c: Fix type conflict of GLib function pointers Kohei Tokunaga
` (19 more replies)
0 siblings, 20 replies; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
V2:
- Updated the commit message to explicitly explain that function pointer
casts are performed internally by GLib.
- Fixed typo in the comment in include/glib-compat.h: s/insted/instead/
- In util/cacheflush.c patch, added an explanation for the change to both
the code comment and the commit message.
- Split the block/file-posix.c hunk that adds "#include <sys/ioctl.h>" into
a separate commit and revised the commit message to clarify the purpose of
the patch.
- Removed the Emscripten-specific stub of copy_file_range in
stubs/emscripten.c. Instead, updated the type of the existing
copy_file_range stub in block/file-posix.c to match the declaration in the
Emscripten headers and avoid a compilation error.
- Moved the change that was incorrectly applied to os-posix.h into os-wasm.h
- Split MAINTAINERS file change to each commit that adds new files.
- Unified two consecutive #ifndef macros into a single condition in
qemu-options.hx.
- Instead of porting mmap-alloc.c to Emscripten, this version excludes the
file entirely. The rationale is described in the commit message.
- In meson.build, added a check to ensure TCI is enabled for the wasm build.
- Split the Dockerfile addition from the previous 18th patch into a separate
commit.
V1:
This patch series is split from the original "Enable QEMU to run on
browsers" series, focusing solely on the essential code changes needed to
compile QEMU TCI with Emscripten. It also inclues fixes based on feedback
received in the original series, thank you for the comments.
# Supported features in this series
This patch series enables TCI interpreter mode with 32bit guest
support. While the original series included the non-TCI backend and 9pfs
patches, those components are not included here. They will be reintroduced
in follow-up series after the foundational patches have been merged.
# Emscripten-Based Coroutine Backend
Emscripten does not support couroutine methods currently used by QEMU but
provides a coroutine implementation called "fiber". This patch series
introduces a coroutine backend using fiber. However, fiber does not support
submitting coroutines to other threads. As a result, this patch series
doesn't support components like hw/9pfs, which rely on that behavior.
# Overview of build process
This section provides an overview of the build process for compiling QEMU
using Emscripten. Full instructions are available in the sample
repository[1].
To compile QEMU with Emscripten, the following dependencies are required.
The emsdk-wasm32-cross.docker environment includes all necessary components
and can be used as the build environment:
- Emscripten SDK (emsdk) v3.1.50
- Libraries cross-compiled with Emscripten (refer to
emsdk-wasm32-cross.docker for build steps)
- GLib v2.84.0
- zlib v1.3.1
- libffi v3.4.7
- Pixman v0.44.2
QEMU can be compiled using Emscripten's emconfigure and emmake, which
automatically set environment variables such as CC for targeting Emscripten.
emconfigure configure --static --disable-tools \
--target-list=arm-softmmu --enable-tcg-interpreter
emmake make -j$(nproc)
This process generates the following files:
- qemu-system-arm.js
- qemu-system-arm.wasm
- qemu-system-arm.worker.js
Guest images can be packaged using Emscripten's file_packager.py tool.
For example, if the images are stored in a directory named "pack", the
following command packages them, allowing QEMU to access them through
Emscripten's virtual filesystem:
/path/to/file_packager.py qemu-system-arm.data --preload pack > load.js
This process generates the following files:
- qemu-system-arm.data
- load.js
Emscripten allows passing arguments to the QEMU command via the Module
object in JavaScript:
Module['arguments'] = [
'-nographic', '-m', '512M', '-machine', 'virt',
'-L', 'pack/',
'-global', 'virtio-mmio.force-legacy=false',
'-device', 'virtio-blk-device,drive=d0',
'-drive', 'file=pack/rootfs.bin,if=none,format=raw,id=d0',
'-kernel', 'pack/kernel.img',
'-append', 'console=ttyAMA0 root=/dev/vda loglevel=7',
];
The sample repository[1] provides a complete setup, including an HTML file
that implements a terminal UI.
[1] https://github.com/ktock/qemu-wasm-sample/tree/tcidev
# Additional references
- Original patch series "Enable QEMU to run on browsers":
https://patchew.org/QEMU/cover.1744032780.git.ktokunaga.mail@gmail.com/
- A talk at FOSDEM 2025:
https://fosdem.org/2025/schedule/event/fosdem-2025-6290-running-qemu-inside-browser/
Kohei Tokunaga (20):
hw/core/loader.c: Fix type conflict of GLib function pointers
qom/object.c: Fix type conflict of GLib function pointers
system/vl.c: Fix type conflict of GLib function pointers
target/arm/helper.c: Fix type conflict of GLib function pointers
target/i386/cpu.c: Fix type conflict of GLib function pointers
contrib/plugins: Fix type conflict of GLib function pointers
hw/net/can: Fix type conflict of GLib function pointers
target/ppc: Fix type conflict of GLib function pointers
target/s390x: Fix type conflict of GLib function pointers
include/glib-compat.h: Poison g_list_sort and g_slist_sort
util/cacheflush.c: Update cache flushing mechanism for Emscripten
block: Add including of ioctl header for Emscripten build
block: Fix type confict of the copy_file_range stub
include/qemu/osdep.h: Add Emscripten-specific OS dependencies
Disable options unsupported on Emscripten
util: exclude mmap-alloc.c from compilation target on Emscripten
util: Add coroutine backend for emscripten
meson: Add wasm build in build scripts
tests: Add Dockerfile containing dependencies for Emscripten build
gitlab: Enable CI for wasm build
.gitlab-ci.d/buildtest-template.yml | 27 ++++
.gitlab-ci.d/buildtest.yml | 9 ++
.gitlab-ci.d/container-cross.yml | 5 +
MAINTAINERS | 9 ++
backends/meson.build | 6 +-
block/file-posix.c | 8 +-
configs/meson/emscripten.txt | 8 +
configure | 7 +
contrib/plugins/cache.c | 12 +-
contrib/plugins/cflow.c | 10 +-
contrib/plugins/hotblocks.c | 4 +-
contrib/plugins/hotpages.c | 4 +-
contrib/plugins/howvec.c | 4 +-
contrib/plugins/hwprofile.c | 8 +-
hw/core/loader.c | 4 +-
hw/net/can/xlnx-versal-canfd.c | 4 +-
include/glib-compat.h | 6 +
include/qemu/cacheflush.h | 7 +
include/qemu/osdep.h | 8 +-
include/system/os-wasm.h | 104 +++++++++++++
meson.build | 29 +++-
meson_options.txt | 2 +-
os-wasm.c | 119 ++++++++++++++
qemu-options.hx | 4 +-
qom/object.c | 7 +-
scripts/meson-buildoptions.sh | 2 +-
system/memory.c | 2 +-
system/physmem.c | 9 +-
system/vl.c | 8 +-
target/arm/helper.c | 4 +-
target/i386/cpu.c | 11 +-
target/ppc/cpu_init.c | 4 +-
target/s390x/cpu_models.c | 4 +-
.../dockerfiles/emsdk-wasm32-cross.docker | 145 ++++++++++++++++++
tests/tcg/plugins/mem.c | 4 +-
tests/tcg/plugins/syscall.c | 4 +-
util/cacheflush.c | 4 +
util/coroutine-wasm.c | 127 +++++++++++++++
util/meson.build | 4 +-
util/oslib-posix.c | 28 ++++
40 files changed, 709 insertions(+), 66 deletions(-)
create mode 100644 configs/meson/emscripten.txt
create mode 100644 include/system/os-wasm.h
create mode 100644 os-wasm.c
create mode 100644 tests/docker/dockerfiles/emsdk-wasm32-cross.docker
create mode 100644 util/coroutine-wasm.c
--
2.25.1
^ permalink raw reply [flat|nested] 41+ messages in thread
* [PATCH v2 01/20] hw/core/loader.c: Fix type conflict of GLib function pointers
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-22 6:41 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 02/20] qom/object.c: " Kohei Tokunaga
` (18 subsequent siblings)
19 siblings, 1 reply; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On Emscripten, function pointer casts can result in runtime failures due to
strict function signature checks. This affects the use of g_list_sort and
g_slist_sort, which internally perform function pointer casts that are not
supported by Emscripten. To avoid these issues, g_list_sort_with_data and
g_slist_sort_with_data should be used instead, as they do not rely on
function pointer casting.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
hw/core/loader.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
V2:
- Updated the commit message to explicitly explain that function pointer
casts are performed internally by GLib.
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 2e35f0aa90..93a8b45d28 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -1410,7 +1410,7 @@ typedef struct RomSec {
* work, but this way saves a little work later by avoiding
* dealing with "gaps" of 0 length.
*/
-static gint sort_secs(gconstpointer a, gconstpointer b)
+static gint sort_secs(gconstpointer a, gconstpointer b, gpointer d)
{
RomSec *ra = (RomSec *) a;
RomSec *rb = (RomSec *) b;
@@ -1463,7 +1463,7 @@ RomGap rom_find_largest_gap_between(hwaddr base, size_t size)
/* sentinel */
secs = add_romsec_to_list(secs, base + size, 1);
- secs = g_list_sort(secs, sort_secs);
+ secs = g_list_sort_with_data(secs, sort_secs, NULL);
for (it = g_list_first(secs); it; it = g_list_next(it)) {
cand = (RomSec *) it->data;
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 02/20] qom/object.c: Fix type conflict of GLib function pointers
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 01/20] hw/core/loader.c: Fix type conflict of GLib function pointers Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-25 14:53 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 03/20] system/vl.c: " Kohei Tokunaga
` (17 subsequent siblings)
19 siblings, 1 reply; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On Emscripten, function pointer casts can result in runtime failures due to
strict function signature checks. This affects the use of g_list_sort and
g_slist_sort, which internally perform function pointer casts that are not
supported by Emscripten. To avoid these issues, g_list_sort_with_data and
g_slist_sort_with_data should be used instead, as they do not rely on
function pointer casting.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
qom/object.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
V2:
- Updated the commit message to explicitly explain that function pointer
casts are performed internally by GLib.
diff --git a/qom/object.c b/qom/object.c
index 01618d06bd..87f84bac41 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1191,7 +1191,7 @@ GSList *object_class_get_list(const char *implements_type,
return list;
}
-static gint object_class_cmp(gconstpointer a, gconstpointer b)
+static gint object_class_cmp(gconstpointer a, gconstpointer b, gpointer d)
{
return strcasecmp(object_class_get_name((ObjectClass *)a),
object_class_get_name((ObjectClass *)b));
@@ -1200,8 +1200,9 @@ static gint object_class_cmp(gconstpointer a, gconstpointer b)
GSList *object_class_get_list_sorted(const char *implements_type,
bool include_abstract)
{
- return g_slist_sort(object_class_get_list(implements_type, include_abstract),
- object_class_cmp);
+ return g_slist_sort_with_data(
+ object_class_get_list(implements_type, include_abstract),
+ object_class_cmp, NULL);
}
Object *object_ref(void *objptr)
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 03/20] system/vl.c: Fix type conflict of GLib function pointers
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 01/20] hw/core/loader.c: Fix type conflict of GLib function pointers Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 02/20] qom/object.c: " Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-22 6:41 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 04/20] target/arm/helper.c: " Kohei Tokunaga
` (16 subsequent siblings)
19 siblings, 1 reply; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On Emscripten, function pointer casts can result in runtime failures due to
strict function signature checks. This affects the use of g_list_sort and
g_slist_sort, which internally perform function pointer casts that are not
supported by Emscripten. To avoid these issues, g_list_sort_with_data and
g_slist_sort_with_data should be used instead, as they do not rely on
function pointer casting.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
system/vl.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
V2:
- Updated the commit message to explicitly explain that function pointer
casts are performed internally by GLib.
diff --git a/system/vl.c b/system/vl.c
index ec93988a03..8d89394b45 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -1523,7 +1523,7 @@ static bool debugcon_parse(const char *devname, Error **errp)
return true;
}
-static gint machine_class_cmp(gconstpointer a, gconstpointer b)
+static gint machine_class_cmp(gconstpointer a, gconstpointer b, gpointer d)
{
const MachineClass *mc1 = a, *mc2 = b;
int res;
@@ -1573,7 +1573,7 @@ static void machine_help_func(const QDict *qdict)
}
printf("Supported machines are:\n");
- machines = g_slist_sort(machines, machine_class_cmp);
+ machines = g_slist_sort_with_data(machines, machine_class_cmp, NULL);
for (el = machines; el; el = el->next) {
MachineClass *mc = el->data;
if (mc->alias) {
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 04/20] target/arm/helper.c: Fix type conflict of GLib function pointers
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (2 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 03/20] system/vl.c: " Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-25 14:53 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 05/20] target/i386/cpu.c: " Kohei Tokunaga
` (15 subsequent siblings)
19 siblings, 1 reply; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On Emscripten, function pointer casts can result in runtime failures due to
strict function signature checks. This affects the use of g_list_sort and
g_slist_sort, which internally perform function pointer casts that are not
supported by Emscripten. To avoid these issues, g_list_sort_with_data and
g_slist_sort_with_data should be used instead, as they do not rely on
function pointer casting.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
target/arm/helper.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
V2:
- Updated the commit message to explicitly explain that function pointer
casts are performed internally by GLib.
diff --git a/target/arm/helper.c b/target/arm/helper.c
index bb445e30cd..05793a6c97 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -220,7 +220,7 @@ static void count_cpreg(gpointer key, gpointer opaque)
}
}
-static gint cpreg_key_compare(gconstpointer a, gconstpointer b)
+static gint cpreg_key_compare(gconstpointer a, gconstpointer b, void *d)
{
uint64_t aidx = cpreg_to_kvm_id((uintptr_t)a);
uint64_t bidx = cpreg_to_kvm_id((uintptr_t)b);
@@ -244,7 +244,7 @@ void init_cpreg_list(ARMCPU *cpu)
int arraylen;
keys = g_hash_table_get_keys(cpu->cp_regs);
- keys = g_list_sort(keys, cpreg_key_compare);
+ keys = g_list_sort_with_data(keys, cpreg_key_compare, NULL);
cpu->cpreg_array_len = 0;
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 05/20] target/i386/cpu.c: Fix type conflict of GLib function pointers
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (3 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 04/20] target/arm/helper.c: " Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 06/20] contrib/plugins: " Kohei Tokunaga
` (14 subsequent siblings)
19 siblings, 0 replies; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On Emscripten, function pointer casts can result in runtime failures due to
strict function signature checks. This affects the use of g_list_sort and
g_slist_sort, which internally perform function pointer casts that are not
supported by Emscripten. To avoid these issues, g_list_sort_with_data and
g_slist_sort_with_data should be used instead, as they do not rely on
function pointer casting.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
target/i386/cpu.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
V2:
- Updated the commit message to explicitly explain that function pointer
casts are performed internally by GLib.
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 1b64ceaaba..2c494e4b0b 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6226,7 +6226,7 @@ static void listflags(GList *features)
}
/* Sort alphabetically by type name, respecting X86CPUClass::ordering. */
-static gint x86_cpu_list_compare(gconstpointer a, gconstpointer b)
+static gint x86_cpu_list_compare(gconstpointer a, gconstpointer b, gpointer d)
{
ObjectClass *class_a = (ObjectClass *)a;
ObjectClass *class_b = (ObjectClass *)b;
@@ -6247,7 +6247,7 @@ static gint x86_cpu_list_compare(gconstpointer a, gconstpointer b)
static GSList *get_sorted_cpu_model_list(void)
{
GSList *list = object_class_get_list(TYPE_X86_CPU, false);
- list = g_slist_sort(list, x86_cpu_list_compare);
+ list = g_slist_sort_with_data(list, x86_cpu_list_compare, NULL);
return list;
}
@@ -6304,6 +6304,11 @@ static void x86_cpu_list_entry(gpointer data, gpointer user_data)
qemu_printf(" %-20s %s\n", name, desc);
}
+static gint strcmp_wrap(gconstpointer a, gconstpointer b, gpointer d)
+{
+ return strcmp(a, b);
+}
+
/* list available CPU models and flags */
void x86_cpu_list(void)
{
@@ -6326,7 +6331,7 @@ void x86_cpu_list(void)
}
}
- names = g_list_sort(names, (GCompareFunc)strcmp);
+ names = g_list_sort_with_data(names, strcmp_wrap, NULL);
qemu_printf("\nRecognized CPUID flags:\n");
listflags(names);
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 06/20] contrib/plugins: Fix type conflict of GLib function pointers
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (4 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 05/20] target/i386/cpu.c: " Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-22 6:40 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 07/20] hw/net/can: " Kohei Tokunaga
` (13 subsequent siblings)
19 siblings, 1 reply; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On Emscripten, function pointer casts can result in runtime failures due to
strict function signature checks. This affects the use of g_list_sort and
g_slist_sort, which internally perform function pointer casts that are not
supported by Emscripten. To avoid these issues, g_list_sort_with_data and
g_slist_sort_with_data should be used instead, as they do not rely on
function pointer casting.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
contrib/plugins/cache.c | 12 ++++++------
contrib/plugins/cflow.c | 10 +++++-----
contrib/plugins/hotblocks.c | 4 ++--
contrib/plugins/hotpages.c | 4 ++--
contrib/plugins/howvec.c | 4 ++--
contrib/plugins/hwprofile.c | 8 ++++----
tests/tcg/plugins/mem.c | 4 ++--
tests/tcg/plugins/syscall.c | 4 ++--
8 files changed, 25 insertions(+), 25 deletions(-)
V2:
- Updated the commit message to explicitly explain that function pointer
casts are performed internally by GLib.
diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c
index 7cfd3df249..56508587d3 100644
--- a/contrib/plugins/cache.c
+++ b/contrib/plugins/cache.c
@@ -576,7 +576,7 @@ static void sum_stats(void)
}
}
-static int dcmp(gconstpointer a, gconstpointer b)
+static int dcmp(gconstpointer a, gconstpointer b, gpointer d)
{
InsnData *insn_a = (InsnData *) a;
InsnData *insn_b = (InsnData *) b;
@@ -584,7 +584,7 @@ static int dcmp(gconstpointer a, gconstpointer b)
return insn_a->l1_dmisses < insn_b->l1_dmisses ? 1 : -1;
}
-static int icmp(gconstpointer a, gconstpointer b)
+static int icmp(gconstpointer a, gconstpointer b, gpointer d)
{
InsnData *insn_a = (InsnData *) a;
InsnData *insn_b = (InsnData *) b;
@@ -592,7 +592,7 @@ static int icmp(gconstpointer a, gconstpointer b)
return insn_a->l1_imisses < insn_b->l1_imisses ? 1 : -1;
}
-static int l2_cmp(gconstpointer a, gconstpointer b)
+static int l2_cmp(gconstpointer a, gconstpointer b, gpointer d)
{
InsnData *insn_a = (InsnData *) a;
InsnData *insn_b = (InsnData *) b;
@@ -645,7 +645,7 @@ static void log_top_insns(void)
InsnData *insn;
miss_insns = g_hash_table_get_values(miss_ht);
- miss_insns = g_list_sort(miss_insns, dcmp);
+ miss_insns = g_list_sort_with_data(miss_insns, dcmp, NULL);
g_autoptr(GString) rep = g_string_new("");
g_string_append_printf(rep, "%s", "address, data misses, instruction\n");
@@ -659,7 +659,7 @@ static void log_top_insns(void)
insn->l1_dmisses, insn->disas_str);
}
- miss_insns = g_list_sort(miss_insns, icmp);
+ miss_insns = g_list_sort_with_data(miss_insns, icmp, NULL);
g_string_append_printf(rep, "%s", "\naddress, fetch misses, instruction\n");
for (curr = miss_insns, i = 0; curr && i < limit; i++, curr = curr->next) {
@@ -676,7 +676,7 @@ static void log_top_insns(void)
goto finish;
}
- miss_insns = g_list_sort(miss_insns, l2_cmp);
+ miss_insns = g_list_sort_with_data(miss_insns, l2_cmp, NULL);
g_string_append_printf(rep, "%s", "\naddress, L2 misses, instruction\n");
for (curr = miss_insns, i = 0; curr && i < limit; i++, curr = curr->next) {
diff --git a/contrib/plugins/cflow.c b/contrib/plugins/cflow.c
index 930ecb46fc..b5e33f25f9 100644
--- a/contrib/plugins/cflow.c
+++ b/contrib/plugins/cflow.c
@@ -98,7 +98,7 @@ static GHashTable *nodes;
struct qemu_plugin_scoreboard *state;
/* SORT_HOTTEST */
-static gint hottest(gconstpointer a, gconstpointer b)
+static gint hottest(gconstpointer a, gconstpointer b, gpointer d)
{
NodeData *na = (NodeData *) a;
NodeData *nb = (NodeData *) b;
@@ -107,7 +107,7 @@ static gint hottest(gconstpointer a, gconstpointer b)
na->dest_count == nb->dest_count ? 0 : 1;
}
-static gint exception(gconstpointer a, gconstpointer b)
+static gint exception(gconstpointer a, gconstpointer b, gpointer d)
{
NodeData *na = (NodeData *) a;
NodeData *nb = (NodeData *) b;
@@ -116,7 +116,7 @@ static gint exception(gconstpointer a, gconstpointer b)
na->early_exit == nb->early_exit ? 0 : 1;
}
-static gint popular(gconstpointer a, gconstpointer b)
+static gint popular(gconstpointer a, gconstpointer b, gpointer d)
{
NodeData *na = (NodeData *) a;
NodeData *nb = (NodeData *) b;
@@ -138,7 +138,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
{
g_autoptr(GString) result = g_string_new("collected ");
GList *data;
- GCompareFunc sort = &hottest;
+ GCompareDataFunc sort = &hottest;
int i = 0;
g_mutex_lock(&node_lock);
@@ -162,7 +162,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
break;
}
- data = g_list_sort(data, sort);
+ data = g_list_sort_with_data(data, sort, NULL);
for (GList *l = data;
l != NULL && i < topn;
diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c
index f12bfb7a26..98404b6885 100644
--- a/contrib/plugins/hotblocks.c
+++ b/contrib/plugins/hotblocks.c
@@ -39,7 +39,7 @@ typedef struct {
unsigned long insns;
} ExecCount;
-static gint cmp_exec_count(gconstpointer a, gconstpointer b)
+static gint cmp_exec_count(gconstpointer a, gconstpointer b, gpointer d)
{
ExecCount *ea = (ExecCount *) a;
ExecCount *eb = (ExecCount *) b;
@@ -79,7 +79,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
g_string_append_printf(report, "%d entries in the hash table\n",
g_hash_table_size(hotblocks));
counts = g_hash_table_get_values(hotblocks);
- it = g_list_sort(counts, cmp_exec_count);
+ it = g_list_sort_with_data(counts, cmp_exec_count, NULL);
if (it) {
g_string_append_printf(report, "pc, tcount, icount, ecount\n");
diff --git a/contrib/plugins/hotpages.c b/contrib/plugins/hotpages.c
index c6e6493719..9d48ac969e 100644
--- a/contrib/plugins/hotpages.c
+++ b/contrib/plugins/hotpages.c
@@ -48,7 +48,7 @@ typedef struct {
static GMutex lock;
static GHashTable *pages;
-static gint cmp_access_count(gconstpointer a, gconstpointer b)
+static gint cmp_access_count(gconstpointer a, gconstpointer b, gpointer d)
{
PageCounters *ea = (PageCounters *) a;
PageCounters *eb = (PageCounters *) b;
@@ -83,7 +83,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
if (counts && g_list_next(counts)) {
GList *it;
- it = g_list_sort(counts, cmp_access_count);
+ it = g_list_sort_with_data(counts, cmp_access_count, NULL);
for (i = 0; i < limit && it->next; i++, it = it->next) {
PageCounters *rec = (PageCounters *) it->data;
diff --git a/contrib/plugins/howvec.c b/contrib/plugins/howvec.c
index 2aa9029c3f..42bddb6566 100644
--- a/contrib/plugins/howvec.c
+++ b/contrib/plugins/howvec.c
@@ -155,7 +155,7 @@ static ClassSelector class_tables[] = {
static InsnClassExecCount *class_table;
static int class_table_sz;
-static gint cmp_exec_count(gconstpointer a, gconstpointer b)
+static gint cmp_exec_count(gconstpointer a, gconstpointer b, gpointer d)
{
InsnExecCount *ea = (InsnExecCount *) a;
InsnExecCount *eb = (InsnExecCount *) b;
@@ -208,7 +208,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
counts = g_hash_table_get_values(insns);
if (counts && g_list_next(counts)) {
g_string_append_printf(report, "Individual Instructions:\n");
- counts = g_list_sort(counts, cmp_exec_count);
+ counts = g_list_sort_with_data(counts, cmp_exec_count, NULL);
for (i = 0; i < limit && g_list_next(counts);
i++, counts = g_list_next(counts)) {
diff --git a/contrib/plugins/hwprofile.c b/contrib/plugins/hwprofile.c
index 2a4cbc47d4..a9838ccc87 100644
--- a/contrib/plugins/hwprofile.c
+++ b/contrib/plugins/hwprofile.c
@@ -71,7 +71,7 @@ static void plugin_init(void)
devices = g_hash_table_new(NULL, NULL);
}
-static gint sort_cmp(gconstpointer a, gconstpointer b)
+static gint sort_cmp(gconstpointer a, gconstpointer b, gpointer d)
{
DeviceCounts *ea = (DeviceCounts *) a;
DeviceCounts *eb = (DeviceCounts *) b;
@@ -79,7 +79,7 @@ static gint sort_cmp(gconstpointer a, gconstpointer b)
eb->totals.reads + eb->totals.writes ? -1 : 1;
}
-static gint sort_loc(gconstpointer a, gconstpointer b)
+static gint sort_loc(gconstpointer a, gconstpointer b, gpointer d)
{
IOLocationCounts *ea = (IOLocationCounts *) a;
IOLocationCounts *eb = (IOLocationCounts *) b;
@@ -126,13 +126,13 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
if (counts && g_list_next(counts)) {
GList *it;
- it = g_list_sort(counts, sort_cmp);
+ it = g_list_sort_with_data(counts, sort_cmp, NULL);
while (it) {
DeviceCounts *rec = (DeviceCounts *) it->data;
if (rec->detail) {
GList *accesses = g_hash_table_get_values(rec->detail);
- GList *io_it = g_list_sort(accesses, sort_loc);
+ GList *io_it = g_list_sort_with_data(accesses, sort_loc, NULL);
const char *prefix = pattern ? "off" : "pc";
g_string_append_printf(report, "%s @ 0x%"PRIx64"\n",
rec->name, rec->base);
diff --git a/tests/tcg/plugins/mem.c b/tests/tcg/plugins/mem.c
index d87d6628e0..ca4e8883dd 100644
--- a/tests/tcg/plugins/mem.c
+++ b/tests/tcg/plugins/mem.c
@@ -67,7 +67,7 @@ static enum qemu_plugin_mem_rw rw = QEMU_PLUGIN_MEM_RW;
static GMutex lock;
static GHashTable *regions;
-static gint addr_order(gconstpointer a, gconstpointer b)
+static gint addr_order(gconstpointer a, gconstpointer b, gpointer d)
{
RegionInfo *na = (RegionInfo *) a;
RegionInfo *nb = (RegionInfo *) b;
@@ -94,7 +94,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
if (do_region_summary) {
GList *counts = g_hash_table_get_values(regions);
- counts = g_list_sort(counts, addr_order);
+ counts = g_list_sort_with_data(counts, addr_order, NULL);
g_string_printf(out, "Region Base, Reads, Writes, Seen all\n");
diff --git a/tests/tcg/plugins/syscall.c b/tests/tcg/plugins/syscall.c
index 47aad55fc1..42801f5c86 100644
--- a/tests/tcg/plugins/syscall.c
+++ b/tests/tcg/plugins/syscall.c
@@ -180,7 +180,7 @@ static void print_entry(gpointer val, gpointer user_data)
qemu_plugin_outs(out);
}
-static gint comp_func(gconstpointer ea, gconstpointer eb)
+static gint comp_func(gconstpointer ea, gconstpointer eb, gpointer d)
{
SyscallStats *ent_a = (SyscallStats *) ea;
SyscallStats *ent_b = (SyscallStats *) eb;
@@ -197,7 +197,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
g_mutex_lock(&lock);
GList *entries = g_hash_table_get_values(statistics);
- entries = g_list_sort(entries, comp_func);
+ entries = g_list_sort_with_data(entries, comp_func, NULL);
qemu_plugin_outs("syscall no. calls errors\n");
g_list_foreach(entries, print_entry, NULL);
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 07/20] hw/net/can: Fix type conflict of GLib function pointers
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (5 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 06/20] contrib/plugins: " Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-25 14:51 ` Philippe Mathieu-Daudé
2025-04-25 15:03 ` Francisco Iglesias
2025-04-22 5:27 ` [PATCH v2 08/20] target/ppc: " Kohei Tokunaga
` (12 subsequent siblings)
19 siblings, 2 replies; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On Emscripten, function pointer casts can result in runtime failures due to
strict function signature checks. This affects the use of g_list_sort and
g_slist_sort, which internally perform function pointer casts that are not
supported by Emscripten. To avoid these issues, g_list_sort_with_data and
g_slist_sort_with_data should be used instead, as they do not rely on
function pointer casting.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
hw/net/can/xlnx-versal-canfd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
V2:
- Updated the commit message to explicitly explain that function pointer
casts are performed internally by GLib.
diff --git a/hw/net/can/xlnx-versal-canfd.c b/hw/net/can/xlnx-versal-canfd.c
index dc242e9215..013ebc10dc 100644
--- a/hw/net/can/xlnx-versal-canfd.c
+++ b/hw/net/can/xlnx-versal-canfd.c
@@ -1278,7 +1278,7 @@ static void tx_fifo_stamp(XlnxVersalCANFDState *s, uint32_t tb0_regid)
}
}
-static gint g_cmp_ids(gconstpointer data1, gconstpointer data2)
+static gint g_cmp_ids(gconstpointer data1, gconstpointer data2, gpointer d)
{
tx_ready_reg_info *tx_reg_1 = (tx_ready_reg_info *) data1;
tx_ready_reg_info *tx_reg_2 = (tx_ready_reg_info *) data2;
@@ -1318,7 +1318,7 @@ static GSList *prepare_tx_data(XlnxVersalCANFDState *s)
temp->can_id = s->regs[reg_num];
temp->reg_num = reg_num;
list = g_slist_prepend(list, temp);
- list = g_slist_sort(list, g_cmp_ids);
+ list = g_slist_sort_with_data(list, g_cmp_ids, NULL);
}
reg_ready >>= 1;
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 08/20] target/ppc: Fix type conflict of GLib function pointers
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (6 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 07/20] hw/net/can: " Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 09/20] target/s390x: " Kohei Tokunaga
` (11 subsequent siblings)
19 siblings, 0 replies; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On Emscripten, function pointer casts can result in runtime failures due to
strict function signature checks. This affects the use of g_list_sort and
g_slist_sort, which internally perform function pointer casts that are not
supported by Emscripten. To avoid these issues, g_list_sort_with_data and
g_slist_sort_with_data should be used instead, as they do not rely on
function pointer casting.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
target/ppc/cpu_init.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
V2:
- Updated the commit message to explicitly explain that function pointer
casts are performed internally by GLib.
diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index f81cb680fc..f03e48ba31 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -7115,7 +7115,7 @@ PowerPCCPUClass *ppc_cpu_get_family_class(PowerPCCPUClass *pcc)
}
/* Sort by PVR, ordering special case "host" last. */
-static gint ppc_cpu_list_compare(gconstpointer a, gconstpointer b)
+static gint ppc_cpu_list_compare(gconstpointer a, gconstpointer b, gpointer d)
{
ObjectClass *oc_a = (ObjectClass *)a;
ObjectClass *oc_b = (ObjectClass *)b;
@@ -7183,7 +7183,7 @@ void ppc_cpu_list(void)
qemu_printf("Available CPUs:\n");
list = object_class_get_list(TYPE_POWERPC_CPU, false);
- list = g_slist_sort(list, ppc_cpu_list_compare);
+ list = g_slist_sort_with_data(list, ppc_cpu_list_compare, NULL);
g_slist_foreach(list, ppc_cpu_list_entry, NULL);
g_slist_free(list);
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 09/20] target/s390x: Fix type conflict of GLib function pointers
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (7 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 08/20] target/ppc: " Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-25 9:33 ` Thomas Huth
2025-04-22 5:27 ` [PATCH v2 10/20] include/glib-compat.h: Poison g_list_sort and g_slist_sort Kohei Tokunaga
` (10 subsequent siblings)
19 siblings, 1 reply; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On Emscripten, function pointer casts can result in runtime failures due to
strict function signature checks. This affects the use of g_list_sort and
g_slist_sort, which internally perform function pointer casts that are not
supported by Emscripten. To avoid these issues, g_list_sort_with_data and
g_slist_sort_with_data should be used instead, as they do not rely on
function pointer casting.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
target/s390x/cpu_models.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
V2:
- Updated the commit message to explicitly explain that function pointer
casts are performed internally by GLib.
diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
index 93a05e43d7..48cdef285d 100644
--- a/target/s390x/cpu_models.c
+++ b/target/s390x/cpu_models.c
@@ -373,7 +373,7 @@ static void s390_print_cpu_model_list_entry(gpointer data, gpointer user_data)
g_free(name);
}
-static gint s390_cpu_list_compare(gconstpointer a, gconstpointer b)
+static gint s390_cpu_list_compare(gconstpointer a, gconstpointer b, gpointer d)
{
const S390CPUClass *cc_a = S390_CPU_CLASS((ObjectClass *)a);
const S390CPUClass *cc_b = S390_CPU_CLASS((ObjectClass *)b);
@@ -415,7 +415,7 @@ void s390_cpu_list(void)
qemu_printf("Available CPUs:\n");
list = object_class_get_list(TYPE_S390_CPU, false);
- list = g_slist_sort(list, s390_cpu_list_compare);
+ list = g_slist_sort_with_data(list, s390_cpu_list_compare, NULL);
g_slist_foreach(list, s390_print_cpu_model_list_entry, NULL);
g_slist_free(list);
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 10/20] include/glib-compat.h: Poison g_list_sort and g_slist_sort
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (8 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 09/20] target/s390x: " Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-25 9:36 ` Thomas Huth
2025-04-22 5:27 ` [PATCH v2 11/20] util/cacheflush.c: Update cache flushing mechanism for Emscripten Kohei Tokunaga
` (9 subsequent siblings)
19 siblings, 1 reply; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On Emscripten, function pointer casts can result in runtime failures due to
strict function signature checks. This affects the use of g_list_sort and
g_slist_sort, which internally perform function pointer casts that are not
supported by Emscripten. To avoid these issues, g_list_sort_with_data and
g_slist_sort_with_data should be used instead, as they do not rely on
function pointer casting.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
include/glib-compat.h | 6 ++++++
1 file changed, 6 insertions(+)
V2:
- Fixed typo in the comment: s/insted/instead/
- Updated the commit message to explicitly explain that function pointer
casts are performed internally by GLib.
diff --git a/include/glib-compat.h b/include/glib-compat.h
index 86be439ba0..53f8ea38d3 100644
--- a/include/glib-compat.h
+++ b/include/glib-compat.h
@@ -36,6 +36,12 @@
#include <pwd.h>
#endif
+/* These functions perform function pointer casts which can cause function call
+ * failure on Emscripten. Use g_slist_sort_with_data and g_list_sort_with_data
+ * instead of these functions.
+ */
+#pragma GCC poison g_slist_sort g_list_sort
+
/*
* Note that because of the GLIB_VERSION_MAX_ALLOWED constant above, allowing
* use of functions from newer GLib via this compat header needs a little
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 11/20] util/cacheflush.c: Update cache flushing mechanism for Emscripten
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (9 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 10/20] include/glib-compat.h: Poison g_list_sort and g_slist_sort Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-22 6:43 ` Philippe Mathieu-Daudé
2025-04-22 6:48 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 12/20] block: Add including of ioctl header for Emscripten build Kohei Tokunaga
` (8 subsequent siblings)
19 siblings, 2 replies; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
Although __builtin___clear_cache is used to flush the instruction cache for
a specified memory region[1], this operation doesn't apply to wasm, as its
memory isn't executable. Moreover, Emscripten does not support this builtin
and fails to compile it with the following error.
> fatal error: error in backend: llvm.clear_cache is not supported on wasm
To resolve this, this commit removes the call to __builtin___clear_cache for
Emscripten build.
[1] https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005f_005f_005fclear_005fcache
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
include/qemu/cacheflush.h | 7 +++++++
util/cacheflush.c | 4 ++++
2 files changed, 11 insertions(+)
V2:
- Added an explanation for the change to both the code comment and the
commit message.
diff --git a/include/qemu/cacheflush.h b/include/qemu/cacheflush.h
index ae20bcda73..76eb55d818 100644
--- a/include/qemu/cacheflush.h
+++ b/include/qemu/cacheflush.h
@@ -26,6 +26,13 @@ static inline void flush_idcache_range(uintptr_t rx, uintptr_t rw, size_t len)
/* icache is coherent and does not require flushing. */
}
+#elif defined(EMSCRIPTEN)
+
+static inline void flush_idcache_range(uintptr_t rx, uintptr_t rw, size_t len)
+{
+ /* Wasm doesn't have executable region of memory. */
+}
+
#else
void flush_idcache_range(uintptr_t rx, uintptr_t rw, size_t len);
diff --git a/util/cacheflush.c b/util/cacheflush.c
index 1d12899a39..17c58918de 100644
--- a/util/cacheflush.c
+++ b/util/cacheflush.c
@@ -229,6 +229,10 @@ static void __attribute__((constructor)) init_cache_info(void)
/* Caches are coherent and do not require flushing; symbol inline. */
+#elif defined(EMSCRIPTEN)
+
+/* Wasm doesn't have executable region of memory. */
+
#elif defined(__aarch64__) && !defined(CONFIG_WIN32)
/*
* For Windows, we use generic implementation of flush_idcache_range, that
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 12/20] block: Add including of ioctl header for Emscripten build
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (10 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 11/20] util/cacheflush.c: Update cache flushing mechanism for Emscripten Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-22 6:52 ` Philippe Mathieu-Daudé
2025-04-22 14:02 ` Stefan Hajnoczi
2025-04-22 5:27 ` [PATCH v2 13/20] block: Fix type confict of the copy_file_range stub Kohei Tokunaga
` (7 subsequent siblings)
19 siblings, 2 replies; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
Including <sys/ioctl.h> is still required on Emscripten, just like on other
platforms, to make the ioctl function available.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
block/file-posix.c | 4 ++++
1 file changed, 4 insertions(+)
V2:
- Split this from the previous 12th patch into a separate commit and revised
the commit message to clarify the purpose of the patch.
diff --git a/block/file-posix.c b/block/file-posix.c
index 56d1972d15..69257c0891 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -110,6 +110,10 @@
#include <sys/diskslice.h>
#endif
+#ifdef EMSCRIPTEN
+#include <sys/ioctl.h>
+#endif
+
/* OS X does not have O_DSYNC */
#ifndef O_DSYNC
#ifdef O_SYNC
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 13/20] block: Fix type confict of the copy_file_range stub
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (11 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 12/20] block: Add including of ioctl header for Emscripten build Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-22 6:43 ` Philippe Mathieu-Daudé
2025-04-22 14:01 ` Stefan Hajnoczi
2025-04-22 5:27 ` [PATCH v2 14/20] include/qemu/osdep.h: Add Emscripten-specific OS dependencies Kohei Tokunaga
` (6 subsequent siblings)
19 siblings, 2 replies; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
Emscripten doesn't provide copy_file_range implementation but it declares
this function in its headers. Meson correctly detects the missing
implementation and unsets HAVE_COPY_FILE_RANGE. However, the stub defined in
file-posix.c causes a type conflict with the declaration from Emscripten
during compilation.
To fix this error, this commit updates the stub implementation in
file-posix.c to exactly match the declaration in Emscripten's headers. The
manpage also aligns with this signature.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
block/file-posix.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
V2:
- Removed the Emscripten-specific stub of copy_file_range in
stubs/emscripten.c. Instead, updated the type of the existing
copy_file_range stub in block/file-posix.c to match the declaration in the
Emscripten headers and avoid a compilation error.
diff --git a/block/file-posix.c b/block/file-posix.c
index 69257c0891..2758f31844 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2015,8 +2015,8 @@ static int handle_aiocb_write_zeroes_unmap(void *opaque)
}
#ifndef HAVE_COPY_FILE_RANGE
-static off_t copy_file_range(int in_fd, off_t *in_off, int out_fd,
- off_t *out_off, size_t len, unsigned int flags)
+ssize_t copy_file_range(int in_fd, off_t *in_off, int out_fd,
+ off_t *out_off, size_t len, unsigned int flags)
{
#ifdef __NR_copy_file_range
return syscall(__NR_copy_file_range, in_fd, in_off, out_fd,
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 14/20] include/qemu/osdep.h: Add Emscripten-specific OS dependencies
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (12 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 13/20] block: Fix type confict of the copy_file_range stub Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 15/20] Disable options unsupported on Emscripten Kohei Tokunaga
` (5 subsequent siblings)
19 siblings, 0 replies; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On emscripten, some implementations in os-posix.c can't be used such as
daemonizing and changing user. This commit introduces os-wasm.c and
os-wasm.h which are forked from os-posix.c and os-posix.h and patched for
targetting Emscripten.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
MAINTAINERS | 6 ++
include/qemu/osdep.h | 8 ++-
include/system/os-wasm.h | 104 ++++++++++++++++++++++++++++++++++
os-wasm.c | 119 +++++++++++++++++++++++++++++++++++++++
4 files changed, 235 insertions(+), 2 deletions(-)
create mode 100644 include/system/os-wasm.h
create mode 100644 os-wasm.c
V2:
- Moved the change that was incorrectly applied to os-posix.h into os-wasm.h
- Split the MAINTAINERS file change that adds os-wasm.c and os-wasm.h from
the previous 19th patch into this commit.
diff --git a/MAINTAINERS b/MAINTAINERS
index d54b5578f8..c7a20ac8d7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -619,6 +619,12 @@ F: .gitlab-ci.d/cirrus/macos-*
F: */*.m
F: scripts/entitlement.sh
+WebAssembly
+M: Kohei Tokunaga <ktokunaga.mail@gmail.com>
+S: Maintained
+F: include/system/os-wasm.h
+F: os-wasm.c
+
Alpha Machines
--------------
M: Richard Henderson <richard.henderson@linaro.org>
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 4397a90680..96fe51bc39 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -8,7 +8,7 @@
* To avoid getting into possible circular include dependencies, this
* file should not include any other QEMU headers, with the exceptions
* of config-host.h, config-target.h, qemu/compiler.h,
- * system/os-posix.h, system/os-win32.h, glib-compat.h and
+ * system/os-posix.h, system/os-win32.h, system/os-wasm.h, glib-compat.h and
* qemu/typedefs.h, all of which are doing a similar job to this file
* and are under similar constraints.
*
@@ -164,10 +164,14 @@ QEMU_EXTERN_C int daemon(int, int);
#include "system/os-win32.h"
#endif
-#ifdef CONFIG_POSIX
+#if defined(CONFIG_POSIX) && !defined(EMSCRIPTEN)
#include "system/os-posix.h"
#endif
+#if defined(EMSCRIPTEN)
+#include "system/os-wasm.h"
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/include/system/os-wasm.h b/include/system/os-wasm.h
new file mode 100644
index 0000000000..3abb3aaa03
--- /dev/null
+++ b/include/system/os-wasm.h
@@ -0,0 +1,104 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * posix specific declarations forked from os-posix.h, removing functions not
+ * working on Emscripten
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Jes Sorensen <Jes.Sorensen@redhat.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef QEMU_OS_WASM_H
+#define QEMU_OS_WASM_H
+
+#include <sys/mman.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <sys/un.h>
+
+#ifdef CONFIG_SYSMACROS
+#include <sys/sysmacros.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void os_set_line_buffering(void);
+void os_setup_early_signal_handling(void);
+void os_set_proc_name(const char *s);
+void os_setup_signal_handling(void);
+void os_setup_limits(void);
+void os_setup_post(void);
+int os_mlock(bool on_fault);
+static inline int os_set_daemonize(bool d)
+{
+ return -1;
+};
+bool is_daemonized(void);
+static inline void os_daemonize(void) {}
+
+/**
+ * qemu_alloc_stack:
+ * @sz: pointer to a size_t holding the requested usable stack size
+ *
+ * Allocate memory that can be used as a stack, for instance for
+ * coroutines. If the memory cannot be allocated, this function
+ * will abort (like g_malloc()). This function also inserts an
+ * additional guard page to catch a potential stack overflow.
+ * Note that the memory required for the guard page and alignment
+ * and minimal stack size restrictions will increase the value of sz.
+ *
+ * The allocated stack must be freed with qemu_free_stack().
+ *
+ * Returns: pointer to (the lowest address of) the stack memory.
+ */
+void *qemu_alloc_stack(size_t *sz);
+
+/**
+ * qemu_free_stack:
+ * @stack: stack to free
+ * @sz: size of stack in bytes
+ *
+ * Free a stack allocated via qemu_alloc_stack(). Note that sz must
+ * be exactly the adjusted stack size returned by qemu_alloc_stack.
+ */
+void qemu_free_stack(void *stack, size_t sz);
+
+/* POSIX and Mingw32 differ in the name of the stdio lock functions. */
+
+static inline void qemu_flockfile(FILE *f)
+{
+ flockfile(f);
+}
+
+static inline void qemu_funlockfile(FILE *f)
+{
+ funlockfile(f);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/os-wasm.c b/os-wasm.c
new file mode 100644
index 0000000000..d240c180c5
--- /dev/null
+++ b/os-wasm.c
@@ -0,0 +1,119 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * os-wasm.c
+ * Forked from os-posix.c, removing functions not working on Emscripten
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include <pwd.h>
+#include <grp.h>
+#include <libgen.h>
+
+#include "qemu/error-report.h"
+#include "qemu/log.h"
+#include "system/runstate.h"
+#include "qemu/cutils.h"
+
+void os_setup_post(void){}
+void os_set_line_buffering(void)
+{
+ setvbuf(stdout, NULL, _IOLBF, 0);
+}
+void os_setup_early_signal_handling(void)
+{
+ struct sigaction act;
+ sigfillset(&act.sa_mask);
+ act.sa_flags = 0;
+ act.sa_handler = SIG_IGN;
+ sigaction(SIGPIPE, &act, NULL);
+}
+void os_set_proc_name(const char *s)
+{
+ error_report("Change of process name not supported by your OS");
+ exit(1);
+}
+static void termsig_handler(int signal, siginfo_t *info, void *c)
+{
+ qemu_system_killed(info->si_signo, info->si_pid);
+}
+
+void os_setup_signal_handling(void)
+{
+ struct sigaction act;
+
+ memset(&act, 0, sizeof(act));
+ act.sa_sigaction = termsig_handler;
+ act.sa_flags = SA_SIGINFO;
+ sigaction(SIGINT, &act, NULL);
+ sigaction(SIGHUP, &act, NULL);
+ sigaction(SIGTERM, &act, NULL);
+}
+void os_setup_limits(void)
+{
+ struct rlimit nofile;
+
+ if (getrlimit(RLIMIT_NOFILE, &nofile) < 0) {
+ warn_report("unable to query NOFILE limit: %s", strerror(errno));
+ return;
+ }
+
+ if (nofile.rlim_cur == nofile.rlim_max) {
+ return;
+ }
+
+ nofile.rlim_cur = nofile.rlim_max;
+
+ if (setrlimit(RLIMIT_NOFILE, &nofile) < 0) {
+ warn_report("unable to set NOFILE limit: %s", strerror(errno));
+ return;
+ }
+}
+int os_mlock(bool on_fault)
+{
+#ifdef HAVE_MLOCKALL
+ int ret = 0;
+ int flags = MCL_CURRENT | MCL_FUTURE;
+
+ if (on_fault) {
+#ifdef HAVE_MLOCK_ONFAULT
+ flags |= MCL_ONFAULT;
+#else
+ error_report("mlockall: on_fault not supported");
+ return -EINVAL;
+#endif
+ }
+
+ ret = mlockall(flags);
+ if (ret < 0) {
+ error_report("mlockall: %s", strerror(errno));
+ }
+
+ return ret;
+#else
+ (void)on_fault;
+ return -ENOSYS;
+#endif
+}
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 15/20] Disable options unsupported on Emscripten
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (13 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 14/20] include/qemu/osdep.h: Add Emscripten-specific OS dependencies Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-22 6:53 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 16/20] util: exclude mmap-alloc.c from compilation target " Kohei Tokunaga
` (4 subsequent siblings)
19 siblings, 1 reply; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
Daemonizing and run-with aren't supported on Emscripten so disable these
flags.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
qemu-options.hx | 4 ++--
system/vl.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
V2:
- Unified two consecutive #ifndef macros into a single condition in
qemu-options.hx.
diff --git a/qemu-options.hx b/qemu-options.hx
index dc694a99a3..aab53bcfe8 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -4862,7 +4862,7 @@ SRST
Start right away with a saved state (``loadvm`` in monitor)
ERST
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(EMSCRIPTEN)
DEF("daemonize", 0, QEMU_OPTION_daemonize, \
"-daemonize daemonize QEMU after initializing\n", QEMU_ARCH_ALL)
#endif
@@ -5249,7 +5249,7 @@ HXCOMM Internal use
DEF("qtest", HAS_ARG, QEMU_OPTION_qtest, "", QEMU_ARCH_ALL)
DEF("qtest-log", HAS_ARG, QEMU_OPTION_qtest_log, "", QEMU_ARCH_ALL)
-#ifdef CONFIG_POSIX
+#if defined(CONFIG_POSIX) && !defined(EMSCRIPTEN)
DEF("run-with", HAS_ARG, QEMU_OPTION_run_with,
"-run-with [async-teardown=on|off][,chroot=dir][user=username|uid:gid]\n"
" Set miscellaneous QEMU process lifecycle options:\n"
diff --git a/system/vl.c b/system/vl.c
index 8d89394b45..255ea3be6b 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -766,7 +766,7 @@ static QemuOptsList qemu_smp_opts = {
},
};
-#if defined(CONFIG_POSIX)
+#if defined(CONFIG_POSIX) && !defined(EMSCRIPTEN)
static QemuOptsList qemu_run_with_opts = {
.name = "run-with",
.head = QTAILQ_HEAD_INITIALIZER(qemu_run_with_opts.head),
@@ -3677,7 +3677,7 @@ void qemu_init(int argc, char **argv)
case QEMU_OPTION_nouserconfig:
/* Nothing to be parsed here. Especially, do not error out below. */
break;
-#if defined(CONFIG_POSIX)
+#if defined(CONFIG_POSIX) && !defined(EMSCRIPTEN)
case QEMU_OPTION_daemonize:
os_set_daemonize(true);
break;
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 16/20] util: exclude mmap-alloc.c from compilation target on Emscripten
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (14 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 15/20] Disable options unsupported on Emscripten Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 17/20] util: Add coroutine backend for emscripten Kohei Tokunaga
` (3 subsequent siblings)
19 siblings, 0 replies; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
Emscripten does not support partial unmapping of mmapped memory
regions[1]. This limitation prevents correct implementation of qemu_ram_mmap
and qemu_ram_munmap, which rely on partial unmap behavior.
As a workaround, this commit excludes mmap-alloc.c from the Emscripten
build. Instead, for Emscripten build, this modifies qemu_anon_ram_alloc to
use qemu_memalign in place of qemu_ram_mmap, and disable memory backends
that rely on mmap, such as memory-backend-file and memory-backend-shm.
[1] https://github.com/emscripten-core/emscripten/blob/d4a74336f23214bf3304d9eb0d03966786b30a36/system/lib/libc/emscripten_mmap.c#L61
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
backends/meson.build | 6 ++++--
system/memory.c | 2 +-
system/physmem.c | 9 +++++----
util/meson.build | 4 +++-
util/oslib-posix.c | 28 ++++++++++++++++++++++++++++
5 files changed, 41 insertions(+), 8 deletions(-)
V2:
- Instead of porting mmap-alloc.c to Emscripten, this version excludes the
file entirely. The rationale is described in the commit message.
diff --git a/backends/meson.build b/backends/meson.build
index da714b93d1..9b88d22685 100644
--- a/backends/meson.build
+++ b/backends/meson.build
@@ -12,8 +12,10 @@ system_ss.add([files(
if host_os != 'windows'
system_ss.add(files('rng-random.c'))
- system_ss.add(files('hostmem-file.c'))
- system_ss.add([files('hostmem-shm.c'), rt])
+ if host_os != 'emscripten'
+ system_ss.add(files('hostmem-file.c'))
+ system_ss.add([files('hostmem-shm.c'), rt])
+ endif
endif
if host_os == 'linux'
system_ss.add(files('hostmem-memfd.c'))
diff --git a/system/memory.c b/system/memory.c
index 4c829793a0..f5fcbfa799 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -1636,7 +1636,7 @@ bool memory_region_init_resizeable_ram(MemoryRegion *mr,
return true;
}
-#ifdef CONFIG_POSIX
+#if defined(CONFIG_POSIX) && !defined(EMSCRIPTEN)
bool memory_region_init_ram_from_file(MemoryRegion *mr,
Object *owner,
const char *name,
diff --git a/system/physmem.c b/system/physmem.c
index 333a5eb94d..76c65edb62 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -1242,7 +1242,7 @@ long qemu_maxrampagesize(void)
return pagesize;
}
-#ifdef CONFIG_POSIX
+#if defined(CONFIG_POSIX) && !defined(EMSCRIPTEN)
static int64_t get_file_size(int fd)
{
int64_t size;
@@ -1977,7 +1977,7 @@ out_free:
}
}
-#ifdef CONFIG_POSIX
+#if defined(CONFIG_POSIX) && !defined(EMSCRIPTEN)
RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, ram_addr_t max_size,
qemu_ram_resize_cb resized, MemoryRegion *mr,
uint32_t ram_flags, int fd, off_t offset,
@@ -2157,7 +2157,8 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
assert(!host ^ (ram_flags & RAM_PREALLOC));
assert(max_size >= size);
-#ifdef CONFIG_POSIX /* ignore RAM_SHARED for Windows */
+ /* ignore RAM_SHARED for Windows and emscripten*/
+#if defined(CONFIG_POSIX) && !defined(EMSCRIPTEN)
if (!host) {
if (!share_flags && current_machine->aux_ram_share) {
ram_flags |= RAM_SHARED;
@@ -2254,7 +2255,7 @@ static void reclaim_ramblock(RAMBlock *block)
;
} else if (xen_enabled()) {
xen_invalidate_map_cache_entry(block->host);
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(EMSCRIPTEN)
} else if (block->fd >= 0) {
qemu_ram_munmap(block->fd, block->host, block->max_length);
close(block->fd);
diff --git a/util/meson.build b/util/meson.build
index 780b5977a8..e5cd327e27 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -11,7 +11,9 @@ if host_os != 'windows'
endif
util_ss.add(files('compatfd.c'))
util_ss.add(files('event_notifier-posix.c'))
- util_ss.add(files('mmap-alloc.c'))
+ if host_os != 'emscripten'
+ util_ss.add(files('mmap-alloc.c'))
+ endif
freebsd_dep = []
if host_os == 'freebsd'
freebsd_dep = util
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index a697c602c6..4ff577e5de 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -58,6 +58,7 @@
#include <lwp.h>
#endif
+#include "qemu/memalign.h"
#include "qemu/mmap-alloc.h"
#define MAX_MEM_PREALLOC_THREAD_COUNT 16
@@ -210,11 +211,21 @@ void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared,
const uint32_t qemu_map_flags = (shared ? QEMU_MAP_SHARED : 0) |
(noreserve ? QEMU_MAP_NORESERVE : 0);
size_t align = QEMU_VMALLOC_ALIGN;
+#ifndef EMSCRIPTEN
void *ptr = qemu_ram_mmap(-1, size, align, qemu_map_flags, 0);
if (ptr == MAP_FAILED) {
return NULL;
}
+#else
+ /*
+ * qemu_ram_mmap is not implemented for Emscripten. Use qemu_memalign
+ * for the anonymous allocation. noreserve is ignored as there is no swap
+ * space on Emscripten, and shared is ignored as there is no other
+ * processes on Emscripten.
+ */
+ void *ptr = qemu_memalign(align, size);
+#endif
if (alignment) {
*alignment = align;
@@ -227,7 +238,16 @@ void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared,
void qemu_anon_ram_free(void *ptr, size_t size)
{
trace_qemu_anon_ram_free(ptr, size);
+#ifndef EMSCRIPTEN
qemu_ram_munmap(-1, ptr, size);
+#else
+ /*
+ * qemu_ram_munmap is not implemented for Emscripten and qemu_memalign
+ * was used for the allocation. Use the corresponding freeing function
+ * here.
+ */
+ qemu_vfree(ptr);
+#endif
}
void qemu_socket_set_block(int fd)
@@ -588,7 +608,15 @@ bool qemu_prealloc_mem(int fd, char *area, size_t sz, int max_threads,
{
static gsize initialized;
int ret;
+#ifndef EMSCRIPTEN
size_t hpagesize = qemu_fd_getpagesize(fd);
+#else
+ /*
+ * mmap-alloc.c is excluded from Emscripten build, so qemu_fd_getpagesize
+ * is unavailable. Fallback to the lower level implementation.
+ */
+ size_t hpagesize = qemu_real_host_page_size();
+#endif
size_t numpages = DIV_ROUND_UP(sz, hpagesize);
bool use_madv_populate_write;
struct sigaction act;
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 17/20] util: Add coroutine backend for emscripten
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (15 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 16/20] util: exclude mmap-alloc.c from compilation target " Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-22 13:59 ` Stefan Hajnoczi
2025-04-22 5:27 ` [PATCH v2 18/20] meson: Add wasm build in build scripts Kohei Tokunaga
` (2 subsequent siblings)
19 siblings, 1 reply; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
Emscripten does not support couroutine methods currently used by QEMU but
provides a coroutine implementation called "fiber". This commit introduces a
coroutine backend using fiber. Note that fiber does not support submitting
coroutines to other threads.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
MAINTAINERS | 1 +
util/coroutine-wasm.c | 127 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 128 insertions(+)
create mode 100644 util/coroutine-wasm.c
V2:
- Split the MAINTAINERS file change that adds coroutine-wasm.c from the
previous 19th patch into this commit.
diff --git a/MAINTAINERS b/MAINTAINERS
index c7a20ac8d7..72319f804e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -624,6 +624,7 @@ M: Kohei Tokunaga <ktokunaga.mail@gmail.com>
S: Maintained
F: include/system/os-wasm.h
F: os-wasm.c
+F: util/coroutine-wasm.c
Alpha Machines
--------------
diff --git a/util/coroutine-wasm.c b/util/coroutine-wasm.c
new file mode 100644
index 0000000000..cb1ec92509
--- /dev/null
+++ b/util/coroutine-wasm.c
@@ -0,0 +1,127 @@
+/*
+ * emscripten fiber coroutine initialization code
+ * based on coroutine-ucontext.c
+ *
+ * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>
+ * Copyright (C) 2011 Kevin Wolf <kwolf@redhat.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.0 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/coroutine_int.h"
+#include "qemu/coroutine-tls.h"
+
+#include <emscripten/fiber.h>
+
+typedef struct {
+ Coroutine base;
+ void *stack;
+ size_t stack_size;
+
+ void *asyncify_stack;
+ size_t asyncify_stack_size;
+
+ CoroutineAction action;
+
+ emscripten_fiber_t fiber;
+} CoroutineEmscripten;
+
+/**
+ * Per-thread coroutine bookkeeping
+ */
+QEMU_DEFINE_STATIC_CO_TLS(Coroutine *, current);
+QEMU_DEFINE_STATIC_CO_TLS(CoroutineEmscripten *, leader);
+size_t leader_asyncify_stack_size = COROUTINE_STACK_SIZE;
+
+static void coroutine_trampoline(void *co_)
+{
+ Coroutine *co = co_;
+
+ while (true) {
+ co->entry(co->entry_arg);
+ qemu_coroutine_switch(co, co->caller, COROUTINE_TERMINATE);
+ }
+}
+
+Coroutine *qemu_coroutine_new(void)
+{
+ CoroutineEmscripten *co;
+
+ co = g_malloc0(sizeof(*co));
+
+ co->stack_size = COROUTINE_STACK_SIZE;
+ co->stack = qemu_alloc_stack(&co->stack_size);
+
+ co->asyncify_stack_size = COROUTINE_STACK_SIZE;
+ co->asyncify_stack = g_malloc0(co->asyncify_stack_size);
+ emscripten_fiber_init(&co->fiber, coroutine_trampoline, &co->base,
+ co->stack, co->stack_size, co->asyncify_stack,
+ co->asyncify_stack_size);
+
+ return &co->base;
+}
+
+void qemu_coroutine_delete(Coroutine *co_)
+{
+ CoroutineEmscripten *co = DO_UPCAST(CoroutineEmscripten, base, co_);
+
+ qemu_free_stack(co->stack, co->stack_size);
+ g_free(co->asyncify_stack);
+ g_free(co);
+}
+
+CoroutineAction qemu_coroutine_switch(Coroutine *from_, Coroutine *to_,
+ CoroutineAction action)
+{
+ CoroutineEmscripten *from = DO_UPCAST(CoroutineEmscripten, base, from_);
+ CoroutineEmscripten *to = DO_UPCAST(CoroutineEmscripten, base, to_);
+
+ set_current(to_);
+ to->action = action;
+ emscripten_fiber_swap(&from->fiber, &to->fiber);
+ return from->action;
+}
+
+Coroutine *qemu_coroutine_self(void)
+{
+ Coroutine *self = get_current();
+
+ if (!self) {
+ CoroutineEmscripten *leaderp = get_leader();
+ if (!leaderp) {
+ leaderp = g_malloc0(sizeof(*leaderp));
+ leaderp->asyncify_stack = g_malloc0(leader_asyncify_stack_size);
+ leaderp->asyncify_stack_size = leader_asyncify_stack_size;
+ emscripten_fiber_init_from_current_context(
+ &leaderp->fiber,
+ leaderp->asyncify_stack,
+ leaderp->asyncify_stack_size);
+ leaderp->stack = leaderp->fiber.stack_limit;
+ leaderp->stack_size =
+ leaderp->fiber.stack_base - leaderp->fiber.stack_limit;
+ set_leader(leaderp);
+ }
+ self = &leaderp->base;
+ set_current(self);
+ }
+ return self;
+}
+
+bool qemu_in_coroutine(void)
+{
+ Coroutine *self = get_current();
+
+ return self && self->caller;
+}
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 18/20] meson: Add wasm build in build scripts
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (16 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 17/20] util: Add coroutine backend for emscripten Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 19/20] tests: Add Dockerfile containing dependencies for Emscripten build Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 20/20] gitlab: Enable CI for wasm build Kohei Tokunaga
19 siblings, 0 replies; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
has_int128_type is set to false on emscripten as of now to avoid errors by
libffi. Tests are disabled on emscripten because they rely on host
features that aren't supported by emscripten (e.g. fork and unix
socket).
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
MAINTAINERS | 1 +
configs/meson/emscripten.txt | 8 ++++++++
configure | 7 +++++++
meson.build | 29 ++++++++++++++++++++++++-----
meson_options.txt | 2 +-
scripts/meson-buildoptions.sh | 2 +-
6 files changed, 42 insertions(+), 7 deletions(-)
create mode 100644 configs/meson/emscripten.txt
V2:
- In meson.build, added a check to ensure TCI is enabled for the wasm build.
- Split the MAINTAINERS file change that adds emscripten.txt from the
previous 19th patch into this commit.
diff --git a/MAINTAINERS b/MAINTAINERS
index 72319f804e..0fb7fd79b6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -625,6 +625,7 @@ S: Maintained
F: include/system/os-wasm.h
F: os-wasm.c
F: util/coroutine-wasm.c
+F: configs/meson/emscripten.txt
Alpha Machines
--------------
diff --git a/configs/meson/emscripten.txt b/configs/meson/emscripten.txt
new file mode 100644
index 0000000000..4230e88005
--- /dev/null
+++ b/configs/meson/emscripten.txt
@@ -0,0 +1,8 @@
+[built-in options]
+c_args = ['-pthread']
+cpp_args = ['-pthread']
+objc_args = ['-pthread']
+# -sPROXY_TO_PTHREAD link time flag always requires -pthread even during
+# configuration so explicitly add the flag here.
+c_link_args = ['-pthread','-sASYNCIFY=1','-sPROXY_TO_PTHREAD=1','-sFORCE_FILESYSTEM','-sALLOW_TABLE_GROWTH','-sTOTAL_MEMORY=2GB','-sWASM_BIGINT','-sEXPORT_ES6=1','-sASYNCIFY_IMPORTS=ffi_call_js','-sEXPORTED_RUNTIME_METHODS=addFunction,removeFunction,TTY,FS']
+cpp_link_args = ['-pthread','-sASYNCIFY=1','-sPROXY_TO_PTHREAD=1','-sFORCE_FILESYSTEM','-sALLOW_TABLE_GROWTH','-sTOTAL_MEMORY=2GB','-sWASM_BIGINT','-sEXPORT_ES6=1','-sASYNCIFY_IMPORTS=ffi_call_js','-sEXPORTED_RUNTIME_METHODS=addFunction,removeFunction,TTY,FS']
diff --git a/configure b/configure
index 02f1dd2311..a1fe6e11cd 100755
--- a/configure
+++ b/configure
@@ -360,6 +360,10 @@ elif check_define __NetBSD__; then
host_os=netbsd
elif check_define __APPLE__; then
host_os=darwin
+elif check_define EMSCRIPTEN ; then
+ host_os=emscripten
+ cpu=wasm32
+ cross_compile="yes"
else
# This is a fatal error, but don't report it yet, because we
# might be going to just print the --help text, or it might
@@ -526,6 +530,9 @@ case "$cpu" in
linux_arch=x86
CPU_CFLAGS="-m64"
;;
+ wasm32)
+ CPU_CFLAGS="-m32"
+ ;;
esac
if test -n "$host_arch" && {
diff --git a/meson.build b/meson.build
index 41f68d3806..a7bffd76d0 100644
--- a/meson.build
+++ b/meson.build
@@ -50,9 +50,9 @@ genh = []
qapi_trace_events = []
bsd_oses = ['gnu/kfreebsd', 'freebsd', 'netbsd', 'openbsd', 'dragonfly', 'darwin']
-supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux']
+supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux', 'emscripten']
supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv32', 'riscv64', 'x86', 'x86_64',
- 'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64']
+ 'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64', 'wasm32']
cpu = host_machine.cpu_family()
@@ -353,6 +353,8 @@ foreach lang : all_languages
# endif
#endif''')
# ok
+ elif compiler.get_id() == 'emscripten'
+ # ok
else
error('You either need GCC v7.4 or Clang v10.0 (or XCode Clang v15.0) to compile QEMU')
endif
@@ -470,7 +472,10 @@ endif
# instead, we can't add -no-pie because it overrides -shared: the linker then
# tries to build an executable instead of a shared library and fails. So
# don't add -no-pie anywhere and cross fingers. :(
-if not get_option('b_pie')
+#
+# Emscripten doesn't support -no-pie but meson can't catch the compiler
+# warning. So explicitly omit the flag for Emscripten.
+if not get_option('b_pie') and host_os != 'emscripten'
qemu_common_flags += cc.get_supported_arguments('-fno-pie', '-no-pie')
endif
@@ -514,6 +519,8 @@ ucontext_probe = '''
supported_backends = []
if host_os == 'windows'
supported_backends += ['windows']
+elif host_os == 'emscripten'
+ supported_backends += ['wasm']
else
if host_os != 'darwin' and cc.links(ucontext_probe)
supported_backends += ['ucontext']
@@ -902,6 +909,10 @@ if get_option('tcg').allowed()
if not get_option('tcg_interpreter')
error('Unsupported CPU @0@, try --enable-tcg-interpreter'.format(cpu))
endif
+ elif host_arch == 'wasm32'
+ if not get_option('tcg_interpreter')
+ error('WebAssembly host requires --enable-tcg-interpreter')
+ endif
elif get_option('tcg_interpreter')
warning('Use of the TCG interpreter is not recommended on this host')
warning('architecture. There is a native TCG execution backend available')
@@ -2962,7 +2973,9 @@ config_host_data.set('CONFIG_ATOMIC64', cc.links('''
return 0;
}''', args: qemu_isa_flags))
-has_int128_type = cc.compiles('''
+# has_int128_type is set to false on Emscripten to avoid errors by libffi
+# during runtime.
+has_int128_type = host_os != 'emscripten' and cc.compiles('''
__int128_t a;
__uint128_t b;
int main(void) { b = a; }''')
@@ -3774,6 +3787,8 @@ if have_block
# os-win32.c does not
if host_os == 'windows'
system_ss.add(files('os-win32.c'))
+ elif host_os == 'emscripten'
+ blockdev_ss.add(files('os-wasm.c'))
else
blockdev_ss.add(files('os-posix.c'))
endif
@@ -4456,7 +4471,11 @@ subdir('scripts')
subdir('tools')
subdir('pc-bios')
subdir('docs')
-subdir('tests')
+# Tests are disabled on emscripten because they rely on host features that aren't
+# supported by emscripten (e.g. fork and unix socket).
+if host_os != 'emscripten'
+ subdir('tests')
+endif
if gtk.found()
subdir('po')
endif
diff --git a/meson_options.txt b/meson_options.txt
index 59d973bca0..45772484cc 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -34,7 +34,7 @@ option('fuzzing_engine', type : 'string', value : '',
option('trace_file', type: 'string', value: 'trace',
description: 'Trace file prefix for simple backend')
option('coroutine_backend', type: 'combo',
- choices: ['ucontext', 'sigaltstack', 'windows', 'auto'],
+ choices: ['ucontext', 'sigaltstack', 'windows', 'wasm', 'auto'],
value: 'auto', description: 'coroutine backend to use')
# Everything else can be set via --enable/--disable-* option
diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh
index 3e8e00852b..0568385f00 100644
--- a/scripts/meson-buildoptions.sh
+++ b/scripts/meson-buildoptions.sh
@@ -80,7 +80,7 @@ meson_options_help() {
printf "%s\n" ' --tls-priority=VALUE Default TLS protocol/cipher priority string'
printf "%s\n" ' [NORMAL]'
printf "%s\n" ' --with-coroutine=CHOICE coroutine backend to use (choices:'
- printf "%s\n" ' auto/sigaltstack/ucontext/windows)'
+ printf "%s\n" ' auto/sigaltstack/ucontext/windows/wasm)'
printf "%s\n" ' --with-pkgversion=VALUE use specified string as sub-version of the'
printf "%s\n" ' package'
printf "%s\n" ' --with-suffix=VALUE Suffix for QEMU data/modules/config directories'
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 19/20] tests: Add Dockerfile containing dependencies for Emscripten build
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (17 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 18/20] meson: Add wasm build in build scripts Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 20/20] gitlab: Enable CI for wasm build Kohei Tokunaga
19 siblings, 0 replies; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
The added Dockerfile is based on the emsdk image, which includes the
Emscripten toolchain. It also cross-compiles the necessary dependencies
(glib, libffi, pixman, and zlib) for the Emscripten target environment.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
MAINTAINERS | 1 +
.../dockerfiles/emsdk-wasm32-cross.docker | 145 ++++++++++++++++++
2 files changed, 146 insertions(+)
create mode 100644 tests/docker/dockerfiles/emsdk-wasm32-cross.docker
V2:
- Split the Dockerfile addition from the previous 18th patch into a separate
commit.
- Split the MAINTAINERS file change that adds emsdk-wasm32-cross.docker from
the previous 19th patch into this commit.
diff --git a/MAINTAINERS b/MAINTAINERS
index 0fb7fd79b6..58e4bdedba 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -626,6 +626,7 @@ F: include/system/os-wasm.h
F: os-wasm.c
F: util/coroutine-wasm.c
F: configs/meson/emscripten.txt
+F: tests/docker/dockerfiles/emsdk-wasm32-cross.docker
Alpha Machines
--------------
diff --git a/tests/docker/dockerfiles/emsdk-wasm32-cross.docker b/tests/docker/dockerfiles/emsdk-wasm32-cross.docker
new file mode 100644
index 0000000000..60a7d02f56
--- /dev/null
+++ b/tests/docker/dockerfiles/emsdk-wasm32-cross.docker
@@ -0,0 +1,145 @@
+# syntax = docker/dockerfile:1.5
+
+ARG EMSDK_VERSION_QEMU=3.1.50
+ARG ZLIB_VERSION=1.3.1
+ARG GLIB_MINOR_VERSION=2.84
+ARG GLIB_VERSION=${GLIB_MINOR_VERSION}.0
+ARG PIXMAN_VERSION=0.44.2
+ARG FFI_VERSION=v3.4.7
+ARG MESON_VERSION=1.5.0
+
+FROM emscripten/emsdk:$EMSDK_VERSION_QEMU AS build-base
+ARG MESON_VERSION
+ENV TARGET=/builddeps/target
+ENV CPATH="$TARGET/include"
+ENV PKG_CONFIG_PATH="$TARGET/lib/pkgconfig"
+ENV EM_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
+ENV CFLAGS="-O3 -pthread -DWASM_BIGINT"
+ENV CXXFLAGS="$CFLAGS"
+ENV LDFLAGS="-sWASM_BIGINT -sASYNCIFY=1 -L$TARGET/lib"
+RUN apt-get update && apt-get install -y \
+ autoconf \
+ build-essential \
+ libglib2.0-dev \
+ libtool \
+ pkgconf \
+ ninja-build \
+ python3-pip
+RUN pip3 install meson==${MESON_VERSION} tomli
+RUN mkdir /build
+WORKDIR /build
+RUN mkdir -p $TARGET
+RUN <<EOF
+cat <<EOT > /cross.meson
+[host_machine]
+system = 'emscripten'
+cpu_family = 'wasm32'
+cpu = 'wasm32'
+endian = 'little'
+
+[binaries]
+c = 'emcc'
+cpp = 'em++'
+ar = 'emar'
+ranlib = 'emranlib'
+pkgconfig = ['pkg-config', '--static']
+EOT
+EOF
+
+FROM build-base AS zlib-dev
+ARG ZLIB_VERSION
+RUN mkdir -p /zlib
+RUN curl -Ls https://zlib.net/zlib-$ZLIB_VERSION.tar.xz | \
+ tar xJC /zlib --strip-components=1
+WORKDIR /zlib
+RUN emconfigure ./configure --prefix=$TARGET --static
+RUN emmake make install -j$(nproc)
+
+FROM build-base AS libffi-dev
+ARG FFI_VERSION
+RUN mkdir -p /libffi
+RUN git clone https://github.com/libffi/libffi /libffi
+WORKDIR /libffi
+RUN git checkout $FFI_VERSION
+RUN autoreconf -fiv
+RUN emconfigure ./configure --host=wasm32-unknown-linux \
+ --prefix=$TARGET --enable-static \
+ --disable-shared --disable-dependency-tracking \
+ --disable-builddir --disable-multi-os-directory \
+ --disable-raw-api --disable-docs
+RUN emmake make install SUBDIRS='include' -j$(nproc)
+
+FROM build-base AS pixman-dev
+ARG PIXMAN_VERSION
+RUN mkdir /pixman/
+RUN git clone https://gitlab.freedesktop.org/pixman/pixman /pixman/
+WORKDIR /pixman
+RUN git checkout pixman-$PIXMAN_VERSION
+RUN <<EOF
+cat <<EOT >> /cross.meson
+[built-in options]
+c_args = [$(printf "'%s', " $CFLAGS | sed 's/, $//')]
+cpp_args = [$(printf "'%s', " $CFLAGS | sed 's/, $//')]
+objc_args = [$(printf "'%s', " $CFLAGS | sed 's/, $//')]
+c_link_args = [$(printf "'%s', " $LDFLAGS | sed 's/, $//')]
+cpp_link_args = [$(printf "'%s', " $LDFLAGS | sed 's/, $//')]
+EOT
+EOF
+RUN meson setup _build --prefix=$TARGET --cross-file=/cross.meson \
+ --default-library=static \
+ --buildtype=release -Dtests=disabled -Ddemos=disabled
+RUN meson install -C _build
+
+FROM build-base AS glib-dev
+ARG GLIB_VERSION
+ARG GLIB_MINOR_VERSION
+RUN mkdir -p /stub
+WORKDIR /stub
+RUN <<EOF
+cat <<'EOT' > res_query.c
+#include <netdb.h>
+int res_query(const char *name, int class,
+ int type, unsigned char *dest, int len)
+{
+ h_errno = HOST_NOT_FOUND;
+ return -1;
+}
+EOT
+EOF
+RUN emcc ${CFLAGS} -c res_query.c -fPIC -o libresolv.o
+RUN ar rcs libresolv.a libresolv.o
+RUN mkdir -p $TARGET/lib/
+RUN cp libresolv.a $TARGET/lib/
+
+RUN mkdir -p /glib
+RUN curl -Lks https://download.gnome.org/sources/glib/${GLIB_MINOR_VERSION}/glib-$GLIB_VERSION.tar.xz | \
+ tar xJC /glib --strip-components=1
+
+COPY --link --from=zlib-dev /builddeps/ /builddeps/
+COPY --link --from=libffi-dev /builddeps/ /builddeps/
+
+WORKDIR /glib
+RUN <<EOF
+CFLAGS="$CFLAGS -Wno-incompatible-function-pointer-types" ;
+cat <<EOT >> /cross.meson
+[built-in options]
+c_args = [$(printf "'%s', " $CFLAGS | sed 's/, $//')]
+cpp_args = [$(printf "'%s', " $CFLAGS | sed 's/, $//')]
+objc_args = [$(printf "'%s', " $CFLAGS | sed 's/, $//')]
+c_link_args = [$(printf "'%s', " $LDFLAGS | sed 's/, $//')]
+cpp_link_args = [$(printf "'%s', " $LDFLAGS | sed 's/, $//')]
+EOT
+EOF
+RUN meson setup _build --prefix=$TARGET --cross-file=/cross.meson \
+ --default-library=static --buildtype=release --force-fallback-for=pcre2 \
+ -Dselinux=disabled -Dxattr=false -Dlibmount=disabled -Dnls=disabled \
+ -Dtests=false -Dglib_debug=disabled -Dglib_assert=false -Dglib_checks=false
+# FIXME: emscripten doesn't provide some pthread functions in the final link,
+# which isn't detected during meson setup.
+RUN sed -i -E "/#define HAVE_POSIX_SPAWN 1/d" ./_build/config.h
+RUN sed -i -E "/#define HAVE_PTHREAD_GETNAME_NP 1/d" ./_build/config.h
+RUN meson install -C _build
+
+FROM build-base
+COPY --link --from=glib-dev /builddeps/ /builddeps/
+COPY --link --from=pixman-dev /builddeps/ /builddeps/
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v2 20/20] gitlab: Enable CI for wasm build
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
` (18 preceding siblings ...)
2025-04-22 5:27 ` [PATCH v2 19/20] tests: Add Dockerfile containing dependencies for Emscripten build Kohei Tokunaga
@ 2025-04-22 5:27 ` Kohei Tokunaga
19 siblings, 0 replies; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-22 5:27 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Thomas Huth,
Kevin Wolf, Hanna Reitz, Kohei Tokunaga, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
Add GitLab CI job that builds QEMU using emscripten. The build runs in the
container defined in tests/docker/dockerfiles/emsdk-wasm32-cross.docker.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
.gitlab-ci.d/buildtest-template.yml | 27 +++++++++++++++++++++++++++
.gitlab-ci.d/buildtest.yml | 9 +++++++++
.gitlab-ci.d/container-cross.yml | 5 +++++
3 files changed, 41 insertions(+)
V2:
- Split the Dockerfile addition from the previous 18th patch into a separate
commit.
diff --git a/.gitlab-ci.d/buildtest-template.yml b/.gitlab-ci.d/buildtest-template.yml
index 39da7698b0..67167d68a5 100644
--- a/.gitlab-ci.d/buildtest-template.yml
+++ b/.gitlab-ci.d/buildtest-template.yml
@@ -126,3 +126,30 @@
- du -chs ${CI_PROJECT_DIR}/*-cache
variables:
QEMU_JOB_AVOCADO: 1
+
+.wasm_build_job_template:
+ extends: .base_job_template
+ stage: build
+ image: $CI_REGISTRY_IMAGE/qemu/$IMAGE:$QEMU_CI_CONTAINER_TAG
+ before_script:
+ - source scripts/ci/gitlab-ci-section
+ - section_start setup "Pre-script setup"
+ - JOBS=$(expr $(nproc) + 1)
+ - section_end setup
+ script:
+ - du -sh .git
+ - mkdir build
+ - cd build
+ - section_start configure "Running configure"
+ - emconfigure ../configure --disable-docs
+ ${TARGETS:+--target-list="$TARGETS"}
+ $CONFIGURE_ARGS ||
+ { cat config.log meson-logs/meson-log.txt && exit 1; }
+ - if test -n "$LD_JOBS";
+ then
+ pyvenv/bin/meson configure . -Dbackend_max_links="$LD_JOBS" ;
+ fi || exit 1;
+ - section_end configure
+ - section_start build "Building QEMU"
+ - emmake make -j"$JOBS"
+ - section_end build
diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml
index 00f4bfcd9f..0f92d5313a 100644
--- a/.gitlab-ci.d/buildtest.yml
+++ b/.gitlab-ci.d/buildtest.yml
@@ -801,3 +801,12 @@ coverity:
when: never
# Always manual on forks even if $QEMU_CI == "2"
- when: manual
+
+build-wasm:
+ extends: .wasm_build_job_template
+ timeout: 2h
+ needs:
+ job: wasm-emsdk-cross-container
+ variables:
+ IMAGE: emsdk-wasm32-cross
+ CONFIGURE_ARGS: --static --disable-tools --enable-debug --enable-tcg-interpreter
diff --git a/.gitlab-ci.d/container-cross.yml b/.gitlab-ci.d/container-cross.yml
index 34c0e729ad..3ea4971950 100644
--- a/.gitlab-ci.d/container-cross.yml
+++ b/.gitlab-ci.d/container-cross.yml
@@ -94,3 +94,8 @@ win64-fedora-cross-container:
extends: .container_job_template
variables:
NAME: fedora-win64-cross
+
+wasm-emsdk-cross-container:
+ extends: .container_job_template
+ variables:
+ NAME: emsdk-wasm32-cross
--
2.25.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [PATCH v2 06/20] contrib/plugins: Fix type conflict of GLib function pointers
2025-04-22 5:27 ` [PATCH v2 06/20] contrib/plugins: " Kohei Tokunaga
@ 2025-04-22 6:40 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 41+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-04-22 6:40 UTC (permalink / raw)
To: Kohei Tokunaga, qemu-devel
Cc: Alex Bennée, Thomas Huth, Kevin Wolf, Hanna Reitz,
Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier,
Pavel Pisa, Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On 22/4/25 07:27, Kohei Tokunaga wrote:
> On Emscripten, function pointer casts can result in runtime failures due to
> strict function signature checks. This affects the use of g_list_sort and
> g_slist_sort, which internally perform function pointer casts that are not
> supported by Emscripten. To avoid these issues, g_list_sort_with_data and
> g_slist_sort_with_data should be used instead, as they do not rely on
> function pointer casting.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> contrib/plugins/cache.c | 12 ++++++------
> contrib/plugins/cflow.c | 10 +++++-----
> contrib/plugins/hotblocks.c | 4 ++--
> contrib/plugins/hotpages.c | 4 ++--
> contrib/plugins/howvec.c | 4 ++--
> contrib/plugins/hwprofile.c | 8 ++++----
> tests/tcg/plugins/mem.c | 4 ++--
> tests/tcg/plugins/syscall.c | 4 ++--
> 8 files changed, 25 insertions(+), 25 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 03/20] system/vl.c: Fix type conflict of GLib function pointers
2025-04-22 5:27 ` [PATCH v2 03/20] system/vl.c: " Kohei Tokunaga
@ 2025-04-22 6:41 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 41+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-04-22 6:41 UTC (permalink / raw)
To: Kohei Tokunaga, qemu-devel
Cc: Alex Bennée, Thomas Huth, Kevin Wolf, Hanna Reitz,
Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier,
Pavel Pisa, Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On 22/4/25 07:27, Kohei Tokunaga wrote:
> On Emscripten, function pointer casts can result in runtime failures due to
> strict function signature checks. This affects the use of g_list_sort and
> g_slist_sort, which internally perform function pointer casts that are not
> supported by Emscripten. To avoid these issues, g_list_sort_with_data and
> g_slist_sort_with_data should be used instead, as they do not rely on
> function pointer casting.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> system/vl.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 01/20] hw/core/loader.c: Fix type conflict of GLib function pointers
2025-04-22 5:27 ` [PATCH v2 01/20] hw/core/loader.c: Fix type conflict of GLib function pointers Kohei Tokunaga
@ 2025-04-22 6:41 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 41+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-04-22 6:41 UTC (permalink / raw)
To: Kohei Tokunaga, qemu-devel
Cc: Alex Bennée, Thomas Huth, Kevin Wolf, Hanna Reitz,
Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier,
Pavel Pisa, Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On 22/4/25 07:27, Kohei Tokunaga wrote:
> On Emscripten, function pointer casts can result in runtime failures due to
> strict function signature checks. This affects the use of g_list_sort and
> g_slist_sort, which internally perform function pointer casts that are not
> supported by Emscripten. To avoid these issues, g_list_sort_with_data and
> g_slist_sort_with_data should be used instead, as they do not rely on
> function pointer casting.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> hw/core/loader.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 11/20] util/cacheflush.c: Update cache flushing mechanism for Emscripten
2025-04-22 5:27 ` [PATCH v2 11/20] util/cacheflush.c: Update cache flushing mechanism for Emscripten Kohei Tokunaga
@ 2025-04-22 6:43 ` Philippe Mathieu-Daudé
2025-04-22 6:48 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 41+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-04-22 6:43 UTC (permalink / raw)
To: Kohei Tokunaga, qemu-devel
Cc: Alex Bennée, Thomas Huth, Kevin Wolf, Hanna Reitz,
Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier,
Pavel Pisa, Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On 22/4/25 07:27, Kohei Tokunaga wrote:
> Although __builtin___clear_cache is used to flush the instruction cache for
> a specified memory region[1], this operation doesn't apply to wasm, as its
> memory isn't executable. Moreover, Emscripten does not support this builtin
> and fails to compile it with the following error.
>
>> fatal error: error in backend: llvm.clear_cache is not supported on wasm
>
> To resolve this, this commit removes the call to __builtin___clear_cache for
> Emscripten build.
>
> [1] https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005f_005f_005fclear_005fcache
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> include/qemu/cacheflush.h | 7 +++++++
> util/cacheflush.c | 4 ++++
> 2 files changed, 11 insertions(+)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 13/20] block: Fix type confict of the copy_file_range stub
2025-04-22 5:27 ` [PATCH v2 13/20] block: Fix type confict of the copy_file_range stub Kohei Tokunaga
@ 2025-04-22 6:43 ` Philippe Mathieu-Daudé
2025-04-22 14:01 ` Stefan Hajnoczi
1 sibling, 0 replies; 41+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-04-22 6:43 UTC (permalink / raw)
To: Kohei Tokunaga, qemu-devel
Cc: Alex Bennée, Thomas Huth, Kevin Wolf, Hanna Reitz,
Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier,
Pavel Pisa, Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On 22/4/25 07:27, Kohei Tokunaga wrote:
> Emscripten doesn't provide copy_file_range implementation but it declares
> this function in its headers. Meson correctly detects the missing
> implementation and unsets HAVE_COPY_FILE_RANGE. However, the stub defined in
> file-posix.c causes a type conflict with the declaration from Emscripten
> during compilation.
>
> To fix this error, this commit updates the stub implementation in
> file-posix.c to exactly match the declaration in Emscripten's headers. The
> manpage also aligns with this signature.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> block/file-posix.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 11/20] util/cacheflush.c: Update cache flushing mechanism for Emscripten
2025-04-22 5:27 ` [PATCH v2 11/20] util/cacheflush.c: Update cache flushing mechanism for Emscripten Kohei Tokunaga
2025-04-22 6:43 ` Philippe Mathieu-Daudé
@ 2025-04-22 6:48 ` Philippe Mathieu-Daudé
2025-04-23 6:01 ` Kohei Tokunaga
1 sibling, 1 reply; 41+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-04-22 6:48 UTC (permalink / raw)
To: Kohei Tokunaga, qemu-devel
Cc: Alex Bennée, Thomas Huth, Kevin Wolf, Hanna Reitz,
Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier,
Pavel Pisa, Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On 22/4/25 07:27, Kohei Tokunaga wrote:
> Although __builtin___clear_cache is used to flush the instruction cache for
> a specified memory region[1], this operation doesn't apply to wasm, as its
> memory isn't executable. Moreover, Emscripten does not support this builtin
> and fails to compile it with the following error.
>
>> fatal error: error in backend: llvm.clear_cache is not supported on wasm
Note, you mix LLVM error ...
>
> To resolve this, this commit removes the call to __builtin___clear_cache for
> Emscripten build.
>
> [1] https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005f_005f_005fclear_005fcache
... with this GCC documentation:
If the target does not require instruction cache flushes,
__builtin___clear_cache has no effect.
I'd expect __builtin___clear_cache() to be OK, having no effect on a GCC
WASM implementation.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> include/qemu/cacheflush.h | 7 +++++++
> util/cacheflush.c | 4 ++++
> 2 files changed, 11 insertions(+)
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 12/20] block: Add including of ioctl header for Emscripten build
2025-04-22 5:27 ` [PATCH v2 12/20] block: Add including of ioctl header for Emscripten build Kohei Tokunaga
@ 2025-04-22 6:52 ` Philippe Mathieu-Daudé
2025-04-22 14:02 ` Stefan Hajnoczi
1 sibling, 0 replies; 41+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-04-22 6:52 UTC (permalink / raw)
To: Kohei Tokunaga, qemu-devel
Cc: Alex Bennée, Thomas Huth, Kevin Wolf, Hanna Reitz,
Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier,
Pavel Pisa, Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On 22/4/25 07:27, Kohei Tokunaga wrote:
> Including <sys/ioctl.h> is still required on Emscripten, just like on other
> platforms, to make the ioctl function available.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> block/file-posix.c | 4 ++++
> 1 file changed, 4 insertions(+)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 15/20] Disable options unsupported on Emscripten
2025-04-22 5:27 ` [PATCH v2 15/20] Disable options unsupported on Emscripten Kohei Tokunaga
@ 2025-04-22 6:53 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 41+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-04-22 6:53 UTC (permalink / raw)
To: Kohei Tokunaga, qemu-devel
Cc: Alex Bennée, Thomas Huth, Kevin Wolf, Hanna Reitz,
Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier,
Pavel Pisa, Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On 22/4/25 07:27, Kohei Tokunaga wrote:
> Daemonizing and run-with aren't supported on Emscripten so disable these
> flags.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> qemu-options.hx | 4 ++--
> system/vl.c | 4 ++--
> 2 files changed, 4 insertions(+), 4 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 17/20] util: Add coroutine backend for emscripten
2025-04-22 5:27 ` [PATCH v2 17/20] util: Add coroutine backend for emscripten Kohei Tokunaga
@ 2025-04-22 13:59 ` Stefan Hajnoczi
0 siblings, 0 replies; 41+ messages in thread
From: Stefan Hajnoczi @ 2025-04-22 13:59 UTC (permalink / raw)
To: Kohei Tokunaga
Cc: qemu-devel, Alex Bennée, Philippe Mathieu-Daudé,
Thomas Huth, Kevin Wolf, Hanna Reitz, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, qemu-block, qemu-arm, qemu-ppc, qemu-s390x
[-- Attachment #1: Type: text/plain, Size: 776 bytes --]
On Tue, Apr 22, 2025 at 02:27:21PM +0900, Kohei Tokunaga wrote:
> Emscripten does not support couroutine methods currently used by QEMU but
> provides a coroutine implementation called "fiber". This commit introduces a
> coroutine backend using fiber. Note that fiber does not support submitting
> coroutines to other threads.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> MAINTAINERS | 1 +
> util/coroutine-wasm.c | 127 ++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 128 insertions(+)
> create mode 100644 util/coroutine-wasm.c
>
> V2:
> - Split the MAINTAINERS file change that adds coroutine-wasm.c from the
> previous 19th patch into this commit.
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 13/20] block: Fix type confict of the copy_file_range stub
2025-04-22 5:27 ` [PATCH v2 13/20] block: Fix type confict of the copy_file_range stub Kohei Tokunaga
2025-04-22 6:43 ` Philippe Mathieu-Daudé
@ 2025-04-22 14:01 ` Stefan Hajnoczi
1 sibling, 0 replies; 41+ messages in thread
From: Stefan Hajnoczi @ 2025-04-22 14:01 UTC (permalink / raw)
To: Kohei Tokunaga
Cc: qemu-devel, Alex Bennée, Philippe Mathieu-Daudé,
Thomas Huth, Kevin Wolf, Hanna Reitz, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, qemu-block, qemu-arm, qemu-ppc, qemu-s390x
[-- Attachment #1: Type: text/plain, Size: 1071 bytes --]
On Tue, Apr 22, 2025 at 02:27:17PM +0900, Kohei Tokunaga wrote:
> Emscripten doesn't provide copy_file_range implementation but it declares
> this function in its headers. Meson correctly detects the missing
> implementation and unsets HAVE_COPY_FILE_RANGE. However, the stub defined in
> file-posix.c causes a type conflict with the declaration from Emscripten
> during compilation.
>
> To fix this error, this commit updates the stub implementation in
> file-posix.c to exactly match the declaration in Emscripten's headers. The
> manpage also aligns with this signature.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> block/file-posix.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> V2:
> - Removed the Emscripten-specific stub of copy_file_range in
> stubs/emscripten.c. Instead, updated the type of the existing
> copy_file_range stub in block/file-posix.c to match the declaration in the
> Emscripten headers and avoid a compilation error.
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 12/20] block: Add including of ioctl header for Emscripten build
2025-04-22 5:27 ` [PATCH v2 12/20] block: Add including of ioctl header for Emscripten build Kohei Tokunaga
2025-04-22 6:52 ` Philippe Mathieu-Daudé
@ 2025-04-22 14:02 ` Stefan Hajnoczi
1 sibling, 0 replies; 41+ messages in thread
From: Stefan Hajnoczi @ 2025-04-22 14:02 UTC (permalink / raw)
To: Kohei Tokunaga
Cc: qemu-devel, Alex Bennée, Philippe Mathieu-Daudé,
Thomas Huth, Kevin Wolf, Hanna Reitz, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, qemu-block, qemu-arm, qemu-ppc, qemu-s390x
[-- Attachment #1: Type: text/plain, Size: 541 bytes --]
On Tue, Apr 22, 2025 at 02:27:16PM +0900, Kohei Tokunaga wrote:
> Including <sys/ioctl.h> is still required on Emscripten, just like on other
> platforms, to make the ioctl function available.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> block/file-posix.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> V2:
> - Split this from the previous 12th patch into a separate commit and revised
> the commit message to clarify the purpose of the patch.
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 11/20] util/cacheflush.c: Update cache flushing mechanism for Emscripten
2025-04-22 6:48 ` Philippe Mathieu-Daudé
@ 2025-04-23 6:01 ` Kohei Tokunaga
0 siblings, 0 replies; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-23 6:01 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Alex Bennée, Thomas Huth, Kevin Wolf, Hanna Reitz,
Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier,
Pavel Pisa, Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
[-- Attachment #1: Type: text/plain, Size: 1239 bytes --]
Hi Philippe,
>On 22/4/25 07:27, Kohei Tokunaga wrote:
>> Although __builtin___clear_cache is used to flush the instruction cache
for
>> a specified memory region[1], this operation doesn't apply to wasm, as
its
>> memory isn't executable. Moreover, Emscripten does not support this
builtin
>> and fails to compile it with the following error.
>>
>>> fatal error: error in backend: llvm.clear_cache is not supported on wasm
>
>Note, you mix LLVM error ...
>
>>
>> To resolve this, this commit removes the call to __builtin___clear_cache
for
>> Emscripten build.
>>
>> [1]
https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005f_005f_005fclear_005fcache
>
>... with this GCC documentation:
>
> If the target does not require instruction cache flushes,
> __builtin___clear_cache has no effect.
>
>I'd expect __builtin___clear_cache() to be OK, having no effect on a GCC
>WASM implementation.
Thank you for the feedback.
Although Emscripten supports built-in functions using GCC-compatible syntax,
the corner-case behavior looks different from what's described in the GCC
documentation, as shown in this patch. To avoid the confusion, I'll remove
that link in the next version of the patch series.
[-- Attachment #2: Type: text/html, Size: 1682 bytes --]
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 09/20] target/s390x: Fix type conflict of GLib function pointers
2025-04-22 5:27 ` [PATCH v2 09/20] target/s390x: " Kohei Tokunaga
@ 2025-04-25 9:33 ` Thomas Huth
0 siblings, 0 replies; 41+ messages in thread
From: Thomas Huth @ 2025-04-25 9:33 UTC (permalink / raw)
To: Kohei Tokunaga, qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Kevin Wolf,
Hanna Reitz, Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour,
Pierrick Bouvier, Pavel Pisa, Francisco Iglesias, Vikram Garhwal,
Jason Wang, Marc-André Lureau, Daniel P . Berrangé,
Eduardo Habkost, Peter Xu, David Hildenbrand, Peter Maydell,
Zhao Liu, Nicholas Piggin, Daniel Henrique Barboza,
Richard Henderson, Ilya Leoshkevich, Stefan Hajnoczi, qemu-block,
qemu-arm, qemu-ppc, qemu-s390x
On 22/04/2025 07.27, Kohei Tokunaga wrote:
> On Emscripten, function pointer casts can result in runtime failures due to
> strict function signature checks. This affects the use of g_list_sort and
> g_slist_sort, which internally perform function pointer casts that are not
> supported by Emscripten. To avoid these issues, g_list_sort_with_data and
> g_slist_sort_with_data should be used instead, as they do not rely on
> function pointer casting.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> target/s390x/cpu_models.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Thomas Huth <thuth@redhat.com>
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 10/20] include/glib-compat.h: Poison g_list_sort and g_slist_sort
2025-04-22 5:27 ` [PATCH v2 10/20] include/glib-compat.h: Poison g_list_sort and g_slist_sort Kohei Tokunaga
@ 2025-04-25 9:36 ` Thomas Huth
2025-04-26 6:36 ` Kohei Tokunaga
0 siblings, 1 reply; 41+ messages in thread
From: Thomas Huth @ 2025-04-25 9:36 UTC (permalink / raw)
To: Kohei Tokunaga, qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Kevin Wolf,
Hanna Reitz, Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour,
Pierrick Bouvier, Pavel Pisa, Francisco Iglesias, Vikram Garhwal,
Jason Wang, Marc-André Lureau, Daniel P . Berrangé,
Eduardo Habkost, Peter Xu, David Hildenbrand, Peter Maydell,
Zhao Liu, Nicholas Piggin, Daniel Henrique Barboza,
Richard Henderson, Ilya Leoshkevich, Stefan Hajnoczi, qemu-block,
qemu-arm, qemu-ppc, qemu-s390x
On 22/04/2025 07.27, Kohei Tokunaga wrote:
> On Emscripten, function pointer casts can result in runtime failures due to
> strict function signature checks. This affects the use of g_list_sort and
> g_slist_sort, which internally perform function pointer casts that are not
> supported by Emscripten. To avoid these issues, g_list_sort_with_data and
> g_slist_sort_with_data should be used instead, as they do not rely on
> function pointer casting.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> include/glib-compat.h | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> V2:
> - Fixed typo in the comment: s/insted/instead/
> - Updated the commit message to explicitly explain that function pointer
> casts are performed internally by GLib.
>
> diff --git a/include/glib-compat.h b/include/glib-compat.h
> index 86be439ba0..53f8ea38d3 100644
> --- a/include/glib-compat.h
> +++ b/include/glib-compat.h
> @@ -36,6 +36,12 @@
> #include <pwd.h>
> #endif
>
> +/* These functions perform function pointer casts which can cause function call
Cosmetic nit: Multiline comments in QEMU should start with "/*" on their own
line.
> + * failure on Emscripten. Use g_slist_sort_with_data and g_list_sort_with_data
> + * instead of these functions.
> + */
> +#pragma GCC poison g_slist_sort g_list_sort
> +
> /*
> * Note that because of the GLIB_VERSION_MAX_ALLOWED constant above, allowing
> * use of functions from newer GLib via this compat header needs a little
With the nit fixed:
Reviewed-by: Thomas Huth <thuth@redhat.com>
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 07/20] hw/net/can: Fix type conflict of GLib function pointers
2025-04-22 5:27 ` [PATCH v2 07/20] hw/net/can: " Kohei Tokunaga
@ 2025-04-25 14:51 ` Philippe Mathieu-Daudé
2025-04-25 15:03 ` Francisco Iglesias
1 sibling, 0 replies; 41+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-04-25 14:51 UTC (permalink / raw)
To: Kohei Tokunaga, qemu-devel
Cc: Alex Bennée, Thomas Huth, Kevin Wolf, Hanna Reitz,
Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier,
Pavel Pisa, Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On 22/4/25 07:27, Kohei Tokunaga wrote:
> On Emscripten, function pointer casts can result in runtime failures due to
> strict function signature checks. This affects the use of g_list_sort and
> g_slist_sort, which internally perform function pointer casts that are not
> supported by Emscripten. To avoid these issues, g_list_sort_with_data and
> g_slist_sort_with_data should be used instead, as they do not rely on
> function pointer casting.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> hw/net/can/xlnx-versal-canfd.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 04/20] target/arm/helper.c: Fix type conflict of GLib function pointers
2025-04-22 5:27 ` [PATCH v2 04/20] target/arm/helper.c: " Kohei Tokunaga
@ 2025-04-25 14:53 ` Philippe Mathieu-Daudé
2025-04-26 6:38 ` Kohei Tokunaga
0 siblings, 1 reply; 41+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-04-25 14:53 UTC (permalink / raw)
To: Kohei Tokunaga, qemu-devel
Cc: Alex Bennée, Thomas Huth, Kevin Wolf, Hanna Reitz,
Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier,
Pavel Pisa, Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
Hi Kohei,
On 22/4/25 07:27, Kohei Tokunaga wrote:
> On Emscripten, function pointer casts can result in runtime failures due to
> strict function signature checks. This affects the use of g_list_sort and
> g_slist_sort, which internally perform function pointer casts that are not
> supported by Emscripten. To avoid these issues, g_list_sort_with_data and
> g_slist_sort_with_data should be used instead, as they do not rely on
> function pointer casting.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> target/arm/helper.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> V2:
> - Updated the commit message to explicitly explain that function pointer
> casts are performed internally by GLib.
>
> diff --git a/target/arm/helper.c b/target/arm/helper.c
> index bb445e30cd..05793a6c97 100644
> --- a/target/arm/helper.c
> +++ b/target/arm/helper.c
> @@ -220,7 +220,7 @@ static void count_cpreg(gpointer key, gpointer opaque)
> }
> }
>
> -static gint cpreg_key_compare(gconstpointer a, gconstpointer b)
> +static gint cpreg_key_compare(gconstpointer a, gconstpointer b, void *d)
Why not use a gpointer for @d like in other patches?
> {
> uint64_t aidx = cpreg_to_kvm_id((uintptr_t)a);
> uint64_t bidx = cpreg_to_kvm_id((uintptr_t)b);
> @@ -244,7 +244,7 @@ void init_cpreg_list(ARMCPU *cpu)
> int arraylen;
>
> keys = g_hash_table_get_keys(cpu->cp_regs);
> - keys = g_list_sort(keys, cpreg_key_compare);
> + keys = g_list_sort_with_data(keys, cpreg_key_compare, NULL);
>
> cpu->cpreg_array_len = 0;
>
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 02/20] qom/object.c: Fix type conflict of GLib function pointers
2025-04-22 5:27 ` [PATCH v2 02/20] qom/object.c: " Kohei Tokunaga
@ 2025-04-25 14:53 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 41+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-04-25 14:53 UTC (permalink / raw)
To: Kohei Tokunaga, qemu-devel
Cc: Alex Bennée, Thomas Huth, Kevin Wolf, Hanna Reitz,
Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier,
Pavel Pisa, Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
On 22/4/25 07:27, Kohei Tokunaga wrote:
> On Emscripten, function pointer casts can result in runtime failures due to
> strict function signature checks. This affects the use of g_list_sort and
> g_slist_sort, which internally perform function pointer casts that are not
> supported by Emscripten. To avoid these issues, g_list_sort_with_data and
> g_slist_sort_with_data should be used instead, as they do not rely on
> function pointer casting.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
> ---
> qom/object.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 07/20] hw/net/can: Fix type conflict of GLib function pointers
2025-04-22 5:27 ` [PATCH v2 07/20] hw/net/can: " Kohei Tokunaga
2025-04-25 14:51 ` Philippe Mathieu-Daudé
@ 2025-04-25 15:03 ` Francisco Iglesias
1 sibling, 0 replies; 41+ messages in thread
From: Francisco Iglesias @ 2025-04-25 15:03 UTC (permalink / raw)
To: Kohei Tokunaga
Cc: qemu-devel, Alex Bennée, Philippe Mathieu-Daudé,
Thomas Huth, Kevin Wolf, Hanna Reitz, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier, Pavel Pisa,
Vikram Garhwal, Jason Wang, Marc-André Lureau,
Daniel P . Berrangé, Eduardo Habkost, Peter Xu,
David Hildenbrand, Peter Maydell, Zhao Liu, Nicholas Piggin,
Daniel Henrique Barboza, Richard Henderson, Ilya Leoshkevich,
Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc, qemu-s390x
On Tue, Apr 22, 2025 at 02:27:11PM +0900, Kohei Tokunaga wrote:
> On Emscripten, function pointer casts can result in runtime failures due to
> strict function signature checks. This affects the use of g_list_sort and
> g_slist_sort, which internally perform function pointer casts that are not
> supported by Emscripten. To avoid these issues, g_list_sort_with_data and
> g_slist_sort_with_data should be used instead, as they do not rely on
> function pointer casting.
>
> Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
Acked-by: Francisco Iglesias <francisco.iglesias@amd.com>
> ---
> hw/net/can/xlnx-versal-canfd.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> V2:
> - Updated the commit message to explicitly explain that function pointer
> casts are performed internally by GLib.
>
> diff --git a/hw/net/can/xlnx-versal-canfd.c b/hw/net/can/xlnx-versal-canfd.c
> index dc242e9215..013ebc10dc 100644
> --- a/hw/net/can/xlnx-versal-canfd.c
> +++ b/hw/net/can/xlnx-versal-canfd.c
> @@ -1278,7 +1278,7 @@ static void tx_fifo_stamp(XlnxVersalCANFDState *s, uint32_t tb0_regid)
> }
> }
>
> -static gint g_cmp_ids(gconstpointer data1, gconstpointer data2)
> +static gint g_cmp_ids(gconstpointer data1, gconstpointer data2, gpointer d)
> {
> tx_ready_reg_info *tx_reg_1 = (tx_ready_reg_info *) data1;
> tx_ready_reg_info *tx_reg_2 = (tx_ready_reg_info *) data2;
> @@ -1318,7 +1318,7 @@ static GSList *prepare_tx_data(XlnxVersalCANFDState *s)
> temp->can_id = s->regs[reg_num];
> temp->reg_num = reg_num;
> list = g_slist_prepend(list, temp);
> - list = g_slist_sort(list, g_cmp_ids);
> + list = g_slist_sort_with_data(list, g_cmp_ids, NULL);
> }
>
> reg_ready >>= 1;
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 10/20] include/glib-compat.h: Poison g_list_sort and g_slist_sort
2025-04-25 9:36 ` Thomas Huth
@ 2025-04-26 6:36 ` Kohei Tokunaga
0 siblings, 0 replies; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-26 6:36 UTC (permalink / raw)
To: Thomas Huth, qemu-devel
Cc: Alex Bennée, Philippe Mathieu-Daudé, Kevin Wolf,
Hanna Reitz, Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour,
Pierrick Bouvier, Pavel Pisa, Francisco Iglesias, Vikram Garhwal,
Jason Wang, Marc-André Lureau, Daniel P . Berrangé,
Eduardo Habkost, Peter Xu, David Hildenbrand, Peter Maydell,
Zhao Liu, Nicholas Piggin, Daniel Henrique Barboza,
Richard Henderson, Ilya Leoshkevich, Stefan Hajnoczi, qemu-block,
qemu-arm, qemu-ppc, qemu-s390x
[-- Attachment #1: Type: text/plain, Size: 177 bytes --]
Hi Thomas,
> Cosmetic nit: Multiline comments in QEMU should start with "/*" on their
own
> line.
Thank you for the feedback. I'll fix this in the next version of the series.
[-- Attachment #2: Type: text/html, Size: 324 bytes --]
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v2 04/20] target/arm/helper.c: Fix type conflict of GLib function pointers
2025-04-25 14:53 ` Philippe Mathieu-Daudé
@ 2025-04-26 6:38 ` Kohei Tokunaga
0 siblings, 0 replies; 41+ messages in thread
From: Kohei Tokunaga @ 2025-04-26 6:38 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Alex Bennée, Thomas Huth, Kevin Wolf, Hanna Reitz,
Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier,
Pavel Pisa, Francisco Iglesias, Vikram Garhwal, Jason Wang,
Marc-André Lureau, Daniel P . Berrangé, Eduardo Habkost,
Peter Xu, David Hildenbrand, Peter Maydell, Zhao Liu,
Nicholas Piggin, Daniel Henrique Barboza, Richard Henderson,
Ilya Leoshkevich, Stefan Hajnoczi, qemu-block, qemu-arm, qemu-ppc,
qemu-s390x
[-- Attachment #1: Type: text/plain, Size: 165 bytes --]
Hi Philippe,
> Why not use a gpointer for @d like in other patches?
Thank you for the feedback. I'll fix this to use a gpointer in the next
version of the series.
[-- Attachment #2: Type: text/html, Size: 241 bytes --]
^ permalink raw reply [flat|nested] 41+ messages in thread
end of thread, other threads:[~2025-04-26 6:39 UTC | newest]
Thread overview: 41+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-22 5:27 [PATCH v2 00/20] Enable QEMU TCI to run 32bit guests on browsers Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 01/20] hw/core/loader.c: Fix type conflict of GLib function pointers Kohei Tokunaga
2025-04-22 6:41 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 02/20] qom/object.c: " Kohei Tokunaga
2025-04-25 14:53 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 03/20] system/vl.c: " Kohei Tokunaga
2025-04-22 6:41 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 04/20] target/arm/helper.c: " Kohei Tokunaga
2025-04-25 14:53 ` Philippe Mathieu-Daudé
2025-04-26 6:38 ` Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 05/20] target/i386/cpu.c: " Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 06/20] contrib/plugins: " Kohei Tokunaga
2025-04-22 6:40 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 07/20] hw/net/can: " Kohei Tokunaga
2025-04-25 14:51 ` Philippe Mathieu-Daudé
2025-04-25 15:03 ` Francisco Iglesias
2025-04-22 5:27 ` [PATCH v2 08/20] target/ppc: " Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 09/20] target/s390x: " Kohei Tokunaga
2025-04-25 9:33 ` Thomas Huth
2025-04-22 5:27 ` [PATCH v2 10/20] include/glib-compat.h: Poison g_list_sort and g_slist_sort Kohei Tokunaga
2025-04-25 9:36 ` Thomas Huth
2025-04-26 6:36 ` Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 11/20] util/cacheflush.c: Update cache flushing mechanism for Emscripten Kohei Tokunaga
2025-04-22 6:43 ` Philippe Mathieu-Daudé
2025-04-22 6:48 ` Philippe Mathieu-Daudé
2025-04-23 6:01 ` Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 12/20] block: Add including of ioctl header for Emscripten build Kohei Tokunaga
2025-04-22 6:52 ` Philippe Mathieu-Daudé
2025-04-22 14:02 ` Stefan Hajnoczi
2025-04-22 5:27 ` [PATCH v2 13/20] block: Fix type confict of the copy_file_range stub Kohei Tokunaga
2025-04-22 6:43 ` Philippe Mathieu-Daudé
2025-04-22 14:01 ` Stefan Hajnoczi
2025-04-22 5:27 ` [PATCH v2 14/20] include/qemu/osdep.h: Add Emscripten-specific OS dependencies Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 15/20] Disable options unsupported on Emscripten Kohei Tokunaga
2025-04-22 6:53 ` Philippe Mathieu-Daudé
2025-04-22 5:27 ` [PATCH v2 16/20] util: exclude mmap-alloc.c from compilation target " Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 17/20] util: Add coroutine backend for emscripten Kohei Tokunaga
2025-04-22 13:59 ` Stefan Hajnoczi
2025-04-22 5:27 ` [PATCH v2 18/20] meson: Add wasm build in build scripts Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 19/20] tests: Add Dockerfile containing dependencies for Emscripten build Kohei Tokunaga
2025-04-22 5:27 ` [PATCH v2 20/20] gitlab: Enable CI for wasm build Kohei Tokunaga
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).