Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use it in emscripten? #8

Open
bumagh opened this issue Dec 15, 2022 · 13 comments
Open

How to use it in emscripten? #8

bumagh opened this issue Dec 15, 2022 · 13 comments
Labels
question Further information is requested

Comments

@bumagh
Copy link

bumagh commented Dec 15, 2022

I want to use it in emscripten

@nomi-san
Copy link
Collaborator

In theory, LLVM/Clang's C compiler can compile those examples fine, so there is no problem to compile them in Emscripten.
But I'm not sure about they can run correctly, in machine code level.

You should use C++ instead.

@bumagh
Copy link
Author

bumagh commented Dec 22, 2022

But in the obj.h it can not support the platform,

@nomi-san
Copy link
Collaborator

Did you get compilation errors in this header?

@nomi-san nomi-san reopened this Dec 22, 2022
@nomi-san nomi-san added the question Further information is requested label Dec 22, 2022
@bumagh
Copy link
Author

bumagh commented Dec 22, 2022

no compilation errors , just show not support

@bumagh
Copy link
Author

bumagh commented Dec 22, 2022

#endif
#define __OBJ_ACTIV(ptr, size)
(VirtualProtect(ptr, size, PAGE_EXECUTE_READWRITE, &((unsigned long){ 0 })) != 0)
#else
#error "This OS is not supported!"
#endif

#if defined(x86_64) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
#define __OBJ_X64 1
#elif defined(__i386) || defined(i386) || defined(_M_IX86)
#define __OBJ_X86 1
#else
#error This architecture is not supported!
#endif
VirtualProtect this function I can not find

@bumagh
Copy link
Author

bumagh commented Dec 22, 2022

PAGE_SHIFT undefine

@nomi-san
Copy link
Collaborator

no compilation errors , just show not support

cc: error "This OS is not supported!"
cc: error "This architecture is not supported!"

If you got errors of the header checks, you can disable these #error code.

obj.h/obj.h

Lines 66 to 76 in c9f00cf

#else
#error "This OS is not supported!"
#endif
#if defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
#define __OBJ_X64 1
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
#define __OBJ_X86 1
#else
#error This architecture is not supported!
#endif

In CPU arch checking, you should define one.
For example, your web browser runtime is 64-bit (x86-64):

#define __OBJ_X64

Remember this library still does not support ARM64 (includes Apple M1/M2 Sillicon).

@nomi-san
Copy link
Collaborator

VirtualProtect this function I can not find

This is a win32 API, in Emscripten you should use mprotect() instead.

PAGE_SHIFT undefine

This value usually is 12, you can find it in compiler's include files.

@bumagh
Copy link
Author

bumagh commented Dec 22, 2022

./obj.h:101:71: error: use of undeclared identifier '__OBJ_CLOFNNUM'
...if (*(size_t *)((uintptr_t)prototype + offset) == (size_t)__OBJ_CLOFNNUM)

                                                           ^

./obj.h:142:30: error: use of undeclared identifier 'asmc'; did you mean 'asin'

ihsize = offset + sizeof(asmc);
                         ^~~~
                         asin

D:\cenv\emsdk\upstream\emscripten\cache\sysroot/include\math.h:143:13: note:
'asin' declared here
double asin(double);
^
In file included from ./player.c:2:
In file included from ./skillButton.h:4:
In file included from ./textTexture.h:3:
./obj.h:145:10: error: use of undeclared identifier 'PAGE_SHIFT'; did you mean
'KMOD_SHIFT'?
if (!__OBJ_ACTIV(code, ihsize)) {
^
./obj.h:49:40: note: expanded from macro '__OBJ_ACTIV'
(mprotect((void *)(((size_t)ptr >> PAGE_SHIFT) << PAGE_SHIFT), size...
^
D:\cenv\emsdk\upstream\emscripten\cache\sysroot\include\SDL2/SDL_keycode.h:344:
: note:
'KMOD_SHIFT' declared here
KMOD_SHIFT = KMOD_LSHIFT | KMOD_RSHIFT,
^
In file included from ./player.c:2:
In file included from ./skillButton.h:4:
In file included from ./textTexture.h:3:
./obj.h:145:10: error: use of undeclared identifier 'PAGE_SHIFT'; did you mean
'KMOD_SHIFT'?
if (!__OBJ_ACTIV(code, ihsize)) {
^
./obj.h:49:55: note: expanded from macro '__OBJ_ACTIV'
(mprotect((void *)(((size_t)ptr >> PAGE_SHIFT) << PAGE_SHIFT), size...
^
D:\cenv\emsdk\upstream\emscripten\cache\sysroot\include\SDL2/SDL_keycode.h:344:
: note:
'KMOD_SHIFT' declared here
KMOD_SHIFT = KMOD_LSHIFT | KMOD_RSHIFT,
^
In file included from ./player.c:2:
In file included from ./skillButton.h:4:
In file included from ./textTexture.h:3:
./obj.h:157:5: error: use of undeclared identifier 'asmc'
asmc.data = (uintptr_t)data;
^
./obj.h:159:41: error: use of undeclared identifier 'asmc'; did you mean 'asin'

memcpy(code + offset, &asmc, sizeof(asmc));
                                    ^~~~
                                    asin

D:\cenv\emsdk\upstream\emscripten\cache\sysroot/include\math.h:143:13: note:
'asin' declared here
double asin(double);
^
In file included from ./player.c:2:
In file included from ./skillButton.h:4:
In file included from ./textTexture.h:3:
./obj.h:159:28: error: use of undeclared identifier 'asmc'; did you mean 'asin'

memcpy(code + offset, &asmc, sizeof(asmc));
                       ^~~~

@bumagh bumagh closed this as completed Dec 22, 2022
@bumagh
Copy link
Author

bumagh commented Dec 22, 2022

index.js:2333 could't find closure declaration at prototype function (0x25)!could't find closure declaration at prototype function (0x26)!could't find closure declaration at prototype function (0x27)!could't find closure declaration at prototype function (0x28)!could't find closure declaration at prototype function (0x29)![obj.h] error: could't implement the method 'show'!
put_char @ index.js:2333
index.js:2333 could't find closure declaration at prototype function (0x1b)!could't find closure declaration at prototype function (0x1c)!could't find closure declaration at prototype function (0x1d)!could't find closure declaration at prototype function (0x1e)!could't find closure declaration at prototype function (0x1f)![obj.h] error: could't implement the method 'show'!

when i run it

@nomi-san
Copy link
Collaborator

nomi-san commented Dec 22, 2022

These errors related to CPU arch and function ABI, also wasm code when Emscripten compiles.
I'll test them soon.

Leave your system information here, about CPU, OS, web browser name and Emscripten version.

@bumagh
Copy link
Author

bumagh commented Dec 22, 2022

These errors related to CPU arch and function ABI, also wasm code when Emscripten compiles. I'll test them soon.

Leave your system information here, about CPU, OS, web browser name and Emscripten version.

windows7 x64
Intel core i5 2467m [email protected]
chrome 108.0.5359.125 (64 位)
emscripten version 3.1.7
Thank you

@bumagh
Copy link
Author

bumagh commented Jan 3, 2023

Anything new? @nomi-san

@nomi-san nomi-san reopened this Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

No branches or pull requests

2 participants