qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 12/19] block: Update block to compile with Emscripten


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH 12/19] block: Update block to compile with Emscripten
Date: Wed, 16 Apr 2025 11:33:08 +0200
User-agent: Mozilla Thunderbird

On 16/4/25 11:00, Philippe Mathieu-Daudé wrote:
On 16/4/25 10:14, Kohei Tokunaga wrote:
emscripten exposes copy_file_range declaration but doesn't provide the
implementation in the final link. Define the emscripten-specific stub
function to avoid type conflict with the emscripten's header.

Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
  block/file-posix.c |  6 ++++++
  stubs/emscripten.c | 13 +++++++++++++
  2 files changed, 19 insertions(+)
  create mode 100644 stubs/emscripten.c

diff --git a/block/file-posix.c b/block/file-posix.c
index 56d1972d15..22e0ed5069 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
@@ -2010,6 +2014,7 @@ static int handle_aiocb_write_zeroes_unmap(void *opaque)
      return handle_aiocb_write_zeroes(aiocb);
  }
+#ifndef EMSCRIPTEN
  #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) @@ -2023,6 +2028,7 @@ static off_t copy_file_range(int in_fd, off_t *in_off, int out_fd,
  #endif
  }
  #endif
+#endif
  /*
   * parse_zone - Fill a zone descriptor
diff --git a/stubs/emscripten.c b/stubs/emscripten.c
new file mode 100644
index 0000000000..2157d6349b
--- /dev/null
+++ b/stubs/emscripten.c
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "qemu/osdep.h"
+/*
+ * emscripten exposes copy_file_range declaration but doesn't provide the
+ * implementation in the final link. Define the stub here but avoid type
+ * conflict with the emscripten's header.
+ */
+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)
+{
+    errno = ENOSYS;
+    return -1;
+}

I'd include in this patch this hunk from patch 17:

-- >8 --
diff --git a/stubs/meson.build b/stubs/meson.build
index 63392f5e78..4fd4d362f9 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -89,3 +89,7 @@ if have_system or have_user
    stub_ss.add(files('hotplug-stubs.c'))
    stub_ss.add(files('sysbus.c'))
  endif
+
+if host_os == 'emscripten'
+  stub_ss.add(files('emscripten.c'))
+endif
---

Actually what about checking the symbol presence in meson?
Something like (untested):

-- >8 --
diff --git a/meson.build b/meson.build
index b18c46d16a2..33185fdf315 100644
--- a/meson.build
+++ b/meson.build
@@ -2654,3 +2654,2 @@ config_host_data.set('CONFIG_TIMERFD', cc.has_function('timerfd_create'))
 config_host_data.set('CONFIG_GETLOADAVG', cc.has_function('getloadavg'))
-config_host_data.set('HAVE_COPY_FILE_RANGE', cc.has_function('copy_file_range'))
 config_host_data.set('HAVE_GETIFADDRS', cc.has_function('getifaddrs'))
@@ -2756,2 +2755,6 @@ config_host_data.set('HAVE_UTMPX',

+config_host_data.set('HAVE_COPY_FILE_RANGE', cc.links(gnu_source_prefix + '''
+  #include <unistd.h>
+  int main(void) { return copy_file_range(-1, NULL, -1, NULL, 0, 0); }'''))
 config_host_data.set('CONFIG_EVENTFD', cc.links('''
---



reply via email to

[Prev in Thread] Current Thread [Next in Thread]