aboutsummaryrefslogtreecommitdiff
path: root/tests/core/test_dlfcn_self.in
blob: 7094b97dc443946099ea40c4ec7bee6cac34555f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
#include <dlfcn.h>
#include <emscripten.h>

int EMSCRIPTEN_KEEPALIVE global = 123;

extern "C" EMSCRIPTEN_KEEPALIVE void foo(int x) {
        printf("%d\n", x);
}

extern "C" EMSCRIPTEN_KEEPALIVE void repeatable() {
        void* self = dlopen(NULL, RTLD_LAZY);
        int* global_ptr = (int*)dlsym(self, "global");
        void (*foo_ptr)(int) = (void (*)(int))dlsym(self, "foo");
        foo_ptr(*global_ptr);
        dlclose(self);
}

int main() {
        repeatable();
        repeatable();
        return 0;
}