Enable QEMU TCI to run 32bit guests on browsers
Subsystems (2)
v2 cover Enable QEMU TCI to run 32bit guests on browsers
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-interpreteremmake 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/[email protected]/
- 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
Signature · 1 line
2.25.1
PATCH v2 1/20 hw/core/loader.c: Fix type conflict of GLib function pointers
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.
--- 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.
hw/core/loader.c +2 -2
@@ -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;
Signature · 1 line
2.25.1
PATCH v2 2/20 qom/object.c: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaOn 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.
--- 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.
qom/object.c +4 -3
@@ -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)
Signature · 1 line
2.25.1
PATCH v2 3/20 system/vl.c: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaOn 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.
--- 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.
system/vl.c +2 -2
@@ -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) {
Signature · 1 line
2.25.1
PATCH v2 4/20 target/arm/helper.c: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaOn 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.
--- 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.
target/arm/helper.c +2 -2
@@ -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 ;
Signature · 1 line
2.25.1
PATCH v2 5/20 target/i386/cpu.c: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaOn 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.
--- 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.
target/i386/cpu.c +8 -3
@@ -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);
Signature · 1 line
2.25.1
PATCH v2 6/20 contrib/plugins: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaOn 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.
--- 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.
contrib/plugins/cache.c +6 -6
@@ -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) {
contrib/plugins/cflow.c +5 -5
@@ -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;
contrib/plugins/hotblocks.c +2 -2
@@ -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" );
contrib/plugins/hotpages.c +2 -2
@@ -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;
contrib/plugins/howvec.c +2 -2
@@ -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)) {
contrib/plugins/hwprofile.c +4 -4
@@ -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);
tests/tcg/plugins/mem.c +2 -2
@@ -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" );
tests/tcg/plugins/syscall.c +2 -2
@@ -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 );
Signature · 1 line
2.25.1
PATCH v2 7/20 hw/net/can: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaOn 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.
--- 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.
hw/net/can/xlnx-versal-canfd.c +2 -2
@@ -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 ;
Signature · 1 line
2.25.1
PATCH v2 8/20 target/ppc: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaOn 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.
--- 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.
target/ppc/cpu_init.c +2 -2
@@ -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);
Signature · 1 line
2.25.1
PATCH v2 9/20 target/s390x: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaOn 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.
--- 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.
target/s390x/cpu_models.c +2 -2
@@ -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);
Signature · 1 line
2.25.1
PATCH v2 10/20 include/glib-compat.h: Poison g_list_sort and g_slist_sort
In reply to Kohei TokunagaOn 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.
--- 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.
include/glib-compat.h +6 -0
@@ -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
Signature · 1 line
2.25.1
PATCH v2 11/20 util/cacheflush.c: Update cache flushing mechanism for Emscripten
In reply to Kohei TokunagaAlthough __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.
Quoted 1 line
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.
--- 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.
include/qemu/cacheflush.h +7 -0
@@ -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);
util/cacheflush.c +4 -0
@@ -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
Signature · 1 line
2.25.1
PATCH v2 12/20 block: Add including of ioctl header for Emscripten build
In reply to Kohei TokunagaIncluding <sys/ioctl.h> is still required on Emscripten, just like on other platforms, to make the ioctl function available.
--- 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.
block/file-posix.c +4 -0
@@ -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
Signature · 1 line
2.25.1
PATCH v2 13/20 block: Fix type confict of the copy_file_range stub
In reply to Kohei TokunagaEmscripten 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.
--- 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.
block/file-posix.c +2 -2
@@ -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,
Signature · 1 line
2.25.1
PATCH v2 14/20 include/qemu/osdep.h: Add Emscripten-specific OS dependencies
In reply to Kohei TokunagaOn 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.
--- 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.
MAINTAINERS +6 -0
@@ -619,6 +619,12 @@ F: .gitlab-ci.d/cirrus/macos-* F: */*.m F: scripts/entitlement.sh +WebAssembly +M: Kohei Tokunaga <[email protected]> +S: Maintained +F: include/system/os-wasm.h +F: os-wasm.c + Alpha Machines -------------- M: Richard Henderson <[email protected]>
include/qemu/osdep.h +6 -2
@@ -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 __cplusplusextern "C" {#endif
include/system/os-wasm.h new file +104 -0
104 lines not on this page · raw message
os-wasm.c new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 15/20 Disable options unsupported on Emscripten
In reply to Kohei TokunagaDaemonizing and run-with aren't supported on Emscripten so disable these flags.
--- 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.
qemu-options.hx +2 -2
@@ -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"
system/vl.c +2 -2
@@ -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 ;
Signature · 1 line
2.25.1
PATCH v2 16/20 util: exclude mmap-alloc.c from compilation target on Emscripten
In reply to Kohei TokunagaEmscripten 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.
--- 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.
backends/meson.build +4 -2
@@ -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'))
system/memory.c +1 -1
@@ -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,
system/physmem.c +5 -4
@@ -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);
util/meson.build +3 -1
@@ -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
util/oslib-posix.c +28 -0
@@ -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;
Signature · 1 line
2.25.1
PATCH v2 17/20 util: Add coroutine backend for emscripten
In reply to Kohei TokunagaEmscripten 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.
--- 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.
MAINTAINERS +1 -0
@@ -624,6 +624,7 @@ M: Kohei Tokunaga <[email protected]> S: Maintained F: include/system/os-wasm.h F: os-wasm.c +F: util/coroutine-wasm.c Alpha Machines --------------
util/coroutine-wasm.c new file +127 -0
127 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 18/20 meson: Add wasm build in build scripts
In reply to Kohei Tokunagahas_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).
--- 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.
MAINTAINERS +1 -0
@@ -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 --------------
configs/meson/emscripten.txt new file +8 -0
@@ -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']
configure +7 -0
@@ -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" && {
meson.build +24 -5
@@ -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
meson_options.txt +1 -1
@@ -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
scripts/meson-buildoptions.sh +1 -1
@@ -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'
Signature · 1 line
2.25.1
PATCH v2 19/20 tests: Add Dockerfile containing dependencies for Emscripten build
In reply to Kohei TokunagaThe 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.
--- 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.
MAINTAINERS +1 -0
@@ -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 --------------
tests/docker/dockerfiles/emsdk-wasm32-cross.docker new file +145 -0
145 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 20/20 gitlab: Enable CI for wasm build
In reply to Kohei TokunagaAdd GitLab CI job that builds QEMU using emscripten. The build runs in the container defined in tests/docker/dockerfiles/emsdk-wasm32-cross.docker.
--- .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.
.gitlab-ci.d/buildtest-template.yml +27 -0
@@ -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
.gitlab-ci.d/buildtest.yml +9 -0
@@ -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
.gitlab-ci.d/container-cross.yml +5 -0
@@ -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
Signature · 1 line
2.25.1
Re: [PATCH v2 06/20] contrib/plugins: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaQuoted 8 lines · Kohei Tokunaga
On Emscripten, function pointer casts can result in runtime failures due to strict function signature checks. This affects the use of
g_list_sortandg_slist_sort, which internally perform function pointer casts that are not supported by Emscripten. To avoid these issues,g_list_sort_with_dataandg_slist_sort_with_datashould be used instead, as they do not rely on function pointer casting.Signed-off-by Kohei Tokunaga <[email protected]>
Quoted 10 lines
--- 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(-)
Re: [PATCH v2 03/20] system/vl.c: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaQuoted 11 lines · Kohei Tokunaga
On Emscripten, function pointer casts can result in runtime failures due to strict function signature checks. This affects the use of
g_list_sortandg_slist_sort, which internally perform function pointer casts that are not supported by Emscripten. To avoid these issues,g_list_sort_with_dataandg_slist_sort_with_datashould be used instead, as they do not rely on function pointer casting.Signed-off-by Kohei Tokunaga <[email protected]>--- system/vl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Re: [PATCH v2 01/20] hw/core/loader.c: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaQuoted 11 lines · Kohei Tokunaga
On Emscripten, function pointer casts can result in runtime failures due to strict function signature checks. This affects the use of
g_list_sortandg_slist_sort, which internally perform function pointer casts that are not supported by Emscripten. To avoid these issues,g_list_sort_with_dataandg_slist_sort_with_datashould be used instead, as they do not rely on function pointer casting.Signed-off-by Kohei Tokunaga <[email protected]>--- hw/core/loader.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Re: [PATCH v2 11/20] util/cacheflush.c: Update cache flushing mechanism for Emscripten
In reply to Kohei TokunagaQuoted 10 lines · Kohei Tokunaga
Although
__builtin___clear_cacheis 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.Quoted 1 line
fatal error: error in backend: llvm.clear_cache is not supported on wasm
To resolve this, this commit removes the call to
__builtin___clear_cachefor Emscripten build.
Quoted 7 lines
Signed-off-by Kohei Tokunaga <[email protected]>--- include/qemu/cacheflush.h | 7 +++++++ util/cacheflush.c | 4 ++++ 2 files changed, 11 insertions(+)
Re: [PATCH v2 13/20] block: Fix type confict of the copy_file_range stub
In reply to Kohei TokunagaQuoted 6 lines · Kohei Tokunaga
Emscripten doesn't provide
copy_file_rangeimplementation but it declares this function in its headers. Meson correctly detects the missing implementation and unsetsHAVE_COPY_FILE_RANGE. However, the stub defined infile-posix.ccauses a type conflict with the declaration from Emscripten during compilation.
Quoted 8 lines
To fix this error, this commit updates the stub implementation in
file-posix.cto exactly match the declaration in Emscripten's headers. The manpage also aligns with this signature.Signed-off-by Kohei Tokunaga <[email protected]>--- block/file-posix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Re: [PATCH v2 11/20] util/cacheflush.c: Update cache flushing mechanism for Emscripten
In reply to Kohei TokunagaQuoted 6 lines · Kohei Tokunaga
Although
__builtin___clear_cacheis 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.Quoted 1 line
fatal error: error in backend: llvm.clear_cache is not supported on wasm
Note, you mix LLVM error ...
Quoted 5 lines
To resolve this, this commit removes the call to
__builtin___clear_cachefor Emscripten build.
... 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.
Quoted 6 lines
Signed-off-by Kohei Tokunaga <[email protected]>--- include/qemu/cacheflush.h | 7 +++++++ util/cacheflush.c | 4 ++++ 2 files changed, 11 insertions(+)
Re: [PATCH v2 12/20] block: Add including of ioctl header for Emscripten build
In reply to Kohei TokunagaQuoted 7 lines · Kohei Tokunaga
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 <[email protected]>--- block/file-posix.c | 4 ++++ 1 file changed, 4 insertions(+)
Re: [PATCH v2 15/20] Disable options unsupported on Emscripten
In reply to Kohei TokunagaQuoted 8 lines · Kohei Tokunaga
Daemonizing and run-with aren't supported on Emscripten so disable these flags.
Signed-off-by Kohei Tokunaga <[email protected]>--- qemu-options.hx | 4 ++-- system/vl.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
Re: [PATCH v2 17/20] util: Add coroutine backend for emscripten
In reply to Kohei TokunagaQuoted 12 lines · Kohei Tokunaga
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 <[email protected]>--- MAINTAINERS | 1 + util/coroutine-wasm.c | 127 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 util/coroutine-wasm.c
Quoted 3 lines
V2:
- Split theMAINTAINERSfile change that addscoroutine-wasm.cfrom the previous 19th patch into this commit.
Re: [PATCH v2 13/20] block: Fix type confict of the copy_file_range stub
In reply to Kohei TokunagaQuoted 15 lines · Kohei Tokunaga
Emscripten doesn't provide
copy_file_rangeimplementation but it declares this function in its headers. Meson correctly detects the missing implementation and unsetsHAVE_COPY_FILE_RANGE. However, the stub defined infile-posix.ccauses a type conflict with the declaration from Emscripten during compilation.To fix this error, this commit updates the stub implementation in
file-posix.cto exactly match the declaration in Emscripten's headers. The manpage also aligns with this signature.Signed-off-by Kohei Tokunaga <[email protected]>--- block/file-posix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 5 lines
V2:
- Removed the Emscripten-specific stub ofcopy_file_rangeinstubs/emscripten.c. Instead, updated the type of the existingcopy_file_rangestub inblock/file-posix.cto match the declaration in the Emscripten headers and avoid a compilation error.
Re: [PATCH v2 12/20] block: Add including of ioctl header for Emscripten build
In reply to Kohei TokunagaQuoted 11 lines · Kohei Tokunaga
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 <[email protected]>--- 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.
Re: [PATCH v2 11/20] util/cacheflush.c: Update cache flushing mechanism for Emscripten
In reply to Philippe Mathieu-DaudéHi Philippe,
Quoted 2 lines · Kohei Tokunaga
Quoted 1 line
Although
__builtin___clear_cacheis used to flush the instruction cache
for
Quoted 1 line
Quoted 1 line
a specified memory region[1], this operation doesn't apply to wasm, as
its
Quoted 1 line
Quoted 1 line
memory isn't executable. Moreover, Emscripten does not support this
builtin
Quoted 8 lines
Quoted 3 lines
and fails to compile it with the following error.
Quoted 1 line
fatal error: error in backend: llvm.clear_cache is not supported on wasm
Note, you mix LLVM error ...
Quoted 2 lines
To resolve this, this commit removes the call to
__builtin___clear_cache
for
Quoted 3 lines
Quoted 3 lines
Emscripten build.
[1]
Quoted 8 lines
... with this GCC documentation:
If the target does not require instruction cache flushes,
__builtin___clear_cachehas 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.
Re: [PATCH v2 09/20] target/s390x: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaQuoted 11 lines · Kohei Tokunaga
On Emscripten, function pointer casts can result in runtime failures due to strict function signature checks. This affects the use of
g_list_sortandg_slist_sort, which internally perform function pointer casts that are not supported by Emscripten. To avoid these issues,g_list_sort_with_dataandg_slist_sort_with_datashould be used instead, as they do not rely on function pointer casting.Signed-off-by Kohei Tokunaga <[email protected]>--- target/s390x/cpu_models.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Re: [PATCH v2 10/20] include/glib-compat.h: Poison g_list_sort and g_slist_sort
In reply to Kohei TokunagaQuoted 22 lines · Kohei Tokunaga
On Emscripten, function pointer casts can result in runtime failures due to strict function signature checks. This affects the use of
g_list_sortandg_slist_sort, which internally perform function pointer casts that are not supported by Emscripten. To avoid these issues,g_list_sort_with_dataandg_slist_sort_with_datashould be used instead, as they do not rely on function pointer casting.Signed-off-by Kohei Tokunaga <[email protected]>--- 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.include/glib-compat.h +0
-0
include/glib-compat.h line 39
Quoted 4 lines
include/glib-compat.h +1
-0@@ -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.
include/glib-compat.h line 47
Quoted 8 lines
include/glib-compat.h +5
-0+* 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:
Re: [PATCH v2 07/20] hw/net/can: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaQuoted 11 lines · Kohei Tokunaga
On Emscripten, function pointer casts can result in runtime failures due to strict function signature checks. This affects the use of
g_list_sortandg_slist_sort, which internally perform function pointer casts that are not supported by Emscripten. To avoid these issues,g_list_sort_with_dataandg_slist_sort_with_datashould be used instead, as they do not rely on function pointer casting.Signed-off-by Kohei Tokunaga <[email protected]>--- hw/net/can/xlnx-versal-canfd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Re: [PATCH v2 04/20] target/arm/helper.c: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaHi Kohei,
Quoted 21 lines · Kohei Tokunaga
On Emscripten, function pointer casts can result in runtime failures due to strict function signature checks. This affects the use of
g_list_sortandg_slist_sort, which internally perform function pointer casts that are not supported by Emscripten. To avoid these issues,g_list_sort_with_dataandg_slist_sort_with_datashould be used instead, as they do not rely on function pointer casting.Signed-off-by Kohei Tokunaga <[email protected]>--- 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.target/arm/helper.c +0
-0
target/arm/helper.c static void count_cpreg(gpointer key, gpointer opaque) · line 223
Quoted 5 lines
target/arm/helper.c +1
-1@@ -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?
Quoted 12 lines
target/arm/helper.c +1
-1{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 ;
Re: [PATCH v2 02/20] qom/object.c: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaQuoted 11 lines · Kohei Tokunaga
On Emscripten, function pointer casts can result in runtime failures due to strict function signature checks. This affects the use of
g_list_sortandg_slist_sort, which internally perform function pointer casts that are not supported by Emscripten. To avoid these issues,g_list_sort_with_dataandg_slist_sort_with_datashould be used instead, as they do not rely on function pointer casting.Signed-off-by Kohei Tokunaga <[email protected]>--- qom/object.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Re: [PATCH v2 07/20] hw/net/can: Fix type conflict of GLib function pointers
In reply to Kohei TokunagaQuoted 8 lines · Kohei Tokunaga
On Emscripten, function pointer casts can result in runtime failures due to strict function signature checks. This affects the use of
g_list_sortandg_slist_sort, which internally perform function pointer casts that are not supported by Emscripten. To avoid these issues,g_list_sort_with_dataandg_slist_sort_with_datashould be used instead, as they do not rely on function pointer casting.Signed-off-by Kohei Tokunaga <[email protected]>
Quoted 33 lines
--- 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.hw/net/can/xlnx-versal-canfd.c +2
-2@@ -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 ;Signature · 1 line
2.25.1
Re: [PATCH v2 10/20] include/glib-compat.h: Poison g_list_sort and g_slist_sort
In reply to Thomas HuthHi Thomas,
Quoted 1 line
Cosmetic nit: Multiline comments in QEMU should start with "/*" on their
own
Quoted 1 line
line.
Thank you for the feedback. I'll fix this in the next version of the series.
Re: [PATCH v2 04/20] target/arm/helper.c: Fix type conflict of GLib function pointers
In reply to Philippe Mathieu-DaudéHi Philippe,
Quoted 1 line
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.