* [wasm] Include the pinvoke table into a separate file, so the generated declarations don't conflict with the ones in the header files included by driver.c.
Same as https://github.com/mono/mono/pull/19853.
* Update src/mono/wasm/runtime/pinvoke.c
Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
CONFIG?=Release
BINDIR?=$(TOP)/artifacts/bin
OBJDIR?=$(TOP)/artifacts/obj
-PINVOKE_TABLE?=$(TOP)/artifacts/obj/mono/Browser.wasm.$(CONFIG)/wasm/pinvoke-table.h
+PINVOKE_TABLE?=$(TOP)/artifacts/obj/wasm/pinvoke-table.h
MONO_BIN_DIR?=$(BINDIR)/mono/Browser.wasm.$(CONFIG)
SYS_NATIVE_DIR?=$(OBJDIR)/native/net5.0-Browser-$(CONFIG)-wasm/System.Native
BUILDS_BIN_DIR?=$(BINDIR)/native/net5.0-Browser-$(CONFIG)-wasm/wasm/runtimes
# If EMSDK_PATH is not set by the caller, download and setup a local emsdk install.
#
-EMSCRIPTEN_VERSION=1.39.11
+EMSCRIPTEN_VERSION=1.39.16
EMSDK_LOCAL_PATH=emsdk
EMCC=source $(CURDIR)/emsdk_env.sh && emcc
$(BUILDS_OBJ_DIR)/$(1)/:
mkdir -p $$@
-$(BUILDS_BIN_DIR)/$(1)/dotnet.js: $(BUILDS_OBJ_DIR)/$(1)/driver.o $(BUILDS_OBJ_DIR)/$(1)/corebindings.o runtime/library_mono.js runtime/binding_support.js runtime/dotnet_support.js $(5) | $(BUILDS_BIN_DIR)/$(1)/ emsdk_env.sh
- $(EMCC) $(EMCC_FLAGS) $(3) --js-library runtime/library_mono.js --js-library runtime/binding_support.js --js-library runtime/dotnet_support.js $(BUILDS_OBJ_DIR)/$(1)/driver.o $(BUILDS_OBJ_DIR)/$(1)/corebindings.o $(4) -o $(BUILDS_BIN_DIR)/$(1)/dotnet.js
+$(BUILDS_BIN_DIR)/$(1)/dotnet.js: $(BUILDS_OBJ_DIR)/$(1)/driver.o $(BUILDS_OBJ_DIR)/$(1)/pinvoke.o $(BUILDS_OBJ_DIR)/$(1)/corebindings.o runtime/library_mono.js runtime/binding_support.js runtime/dotnet_support.js $(5) | $(BUILDS_BIN_DIR)/$(1)/ emsdk_env.sh
+ $(EMCC) $(EMCC_FLAGS) $(3) --js-library runtime/library_mono.js --js-library runtime/binding_support.js --js-library runtime/dotnet_support.js $(BUILDS_OBJ_DIR)/$(1)/driver.o $(BUILDS_OBJ_DIR)/$(1)/pinvoke.o $(BUILDS_OBJ_DIR)/$(1)/corebindings.o $(4) -o $(BUILDS_BIN_DIR)/$(1)/dotnet.js
$(BUILDS_OBJ_DIR)/$(1)/pinvoke-table.h: $(PINVOKE_TABLE) | $(BUILDS_OBJ_DIR)/$(1)/
if cmp -s $(PINVOKE_TABLE) $$@ ; then : ; else cp $(PINVOKE_TABLE) $$@ ; fi
-$(BUILDS_OBJ_DIR)/$(1)/driver.o: runtime/driver.c runtime/corebindings.c $(BUILDS_OBJ_DIR)/$(1)/pinvoke-table.h $(5) | $(BUILDS_OBJ_DIR)/$(1)/ emsdk_env.sh
+$(BUILDS_OBJ_DIR)/$(1)/driver.o: runtime/driver.c runtime/corebindings.c $(5) | $(BUILDS_OBJ_DIR)/$(1)/ emsdk_env.sh
$(EMCC) $(EMCC_FLAGS) $(3) -Oz -DCORE_BINDINGS -I$(BUILDS_OBJ_DIR)/$(1) -I$(MONO_INCLUDE_DIR) runtime/driver.c -c -o $$@
+$(BUILDS_OBJ_DIR)/$(1)/pinvoke.o: runtime/pinvoke.c runtime/pinvoke.h $(BUILDS_OBJ_DIR)/$(1)/pinvoke-table.h $(5) | $(BUILDS_OBJ_DIR)/$(1)/ emsdk_env.sh
+ $(EMCC) $(EMCC_FLAGS) $(3) -Oz -DGEN_PINVOKE=1 -I$(BUILDS_OBJ_DIR)/$(1) -I$(MONO_INCLUDE_DIR) runtime/pinvoke.c -c -o $$@
+
$(BUILDS_OBJ_DIR)/$(1)/corebindings.o: runtime/corebindings.c | $(BUILDS_OBJ_DIR)/$(1)/ emsdk_env.sh
$(EMCC) $(3) -Oz -I$(MONO_INCLUDE_DIR) runtime/corebindings.c -c -o $$@
#include <mono/utils/mono-dl-fallback.h>
#include <mono/jit/jit.h>
-#include "pinvoke-table.h"
+#include "pinvoke.h"
#ifdef CORE_BINDINGS
void core_initialize_internals ();
static void*
wasm_dl_load (const char *name, int flags, char **err, void *user_data)
{
- for (int i = 0; i < sizeof (pinvoke_tables) / sizeof (void*); ++i) {
- if (!strcmp (name, pinvoke_names [i]))
- return pinvoke_tables [i];
- }
+ void* handle = wasm_dl_lookup_pinvoke_table (name);
+ if (handle)
+ return handle;
#ifdef ENABLE_NETCORE
if (!strcmp (name, "System.Globalization.Native"))
return NULL;
}
-static mono_bool
-wasm_dl_is_pinvoke_tables (void* handle)
-{
- for (int i = 0; i < sizeof (pinvoke_tables) / sizeof (void*); ++i) {
- if (pinvoke_tables [i] == handle) {
- return 1;
- }
- }
- return 0;
-}
-
static void*
wasm_dl_symbol (void *handle, const char *name, char **err, void *user_data)
{
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "pinvoke.h"
+
+#include <stdint.h>
+
+/*
+ * The table header contain autogenerated function declarations, so avoid including standard headers
+ * to avoid incompatible declarations.
+ */
+#define NULL ((void*)0)
+int strcmp (const char *s1, const char *s2);
+
+#ifdef GEN_PINVOKE
+#include "pinvoke-table.h"
+#else
+#include "pinvoke-tables-default.h"
+#endif
+
+void*
+wasm_dl_lookup_pinvoke_table (const char *name)
+{
+ for (int i = 0; i < sizeof (pinvoke_tables) / sizeof (void*); ++i) {
+ if (!strcmp (name, pinvoke_names [i]))
+ return pinvoke_tables [i];
+ }
+ return NULL;
+}
+
+int
+wasm_dl_is_pinvoke_table (void *handle)
+{
+ for (int i = 0; i < sizeof (pinvoke_tables) / sizeof (void*); ++i) {
+ if (pinvoke_tables [i] == handle) {
+ return 1;
+ }
+ }
+ return 0;
+}
--- /dev/null
+#ifndef __PINVOKE_H__
+#define __PINVOKE_H__
+
+typedef struct {
+ const char *name;
+ void *func;
+} PinvokeImport;
+
+void*
+wasm_dl_lookup_pinvoke_table (const char *name);
+
+int
+wasm_dl_is_pinvoke_table (void *handle);
+
+#endif
private void EmitPInvokeTable(StreamWriter w, Dictionary<string, string> modules, List<PInvoke> pinvokes)
{
w.WriteLine("// GENERATED FILE, DO NOT MODIFY");
- w.WriteLine("typedef struct {");
- w.WriteLine("const char *name;");
- w.WriteLine("void *func;");
- w.WriteLine("} PinvokeImport;");
w.WriteLine();
foreach (var pinvoke in pinvokes)