forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
42 lines (37 loc) · 1 KB
/
main.c
File metadata and controls
42 lines (37 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Copyright 2019 The Emscripten Authors. All rights reserved.
* Emscripten is available under two separate licenses, the MIT license and the
* University of Illinois/NCSA Open Source License. Both these licenses can be
* found in the LICENSE file.
*/
#include <stdio.h>
#include <dlfcn.h>
#include <emscripten.h>
int bar(void) {
return 42;
}
int foo(void) __attribute__((alias("bar")));
int main()
{
EM_ASM({
FS.mkdir('/working');
FS.mount(NODEFS, { root: '.' }, '/working');
});
void *handle = dlopen("/working/side.wasm", RTLD_NOW);
if (!handle) {
printf("dlopen failed: %s", dlerror());
return 1;
}
typedef int (*func_type)(void);
func_type exportedfn = (func_type)dlsym(handle, "callAlias");
if (!exportedfn) {
const char *err = dlerror();
printf("ERROR: dlsym failed: for callAlias: %s", err);
return 1;
}
if (exportedfn() != 42)
return 1;
dlclose(handle);
printf("success\n");
return 0;
}