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

DLL Support? #102

Open
PAEz opened this issue Apr 5, 2023 · 1 comment
Open

DLL Support? #102

PAEz opened this issue Apr 5, 2023 · 1 comment

Comments

@PAEz
Copy link

PAEz commented Apr 5, 2023

Do you think you could ever add dll support to this? That would make it soooo more useful.
Something like was in jswin would be nice. Wish that had of kept on being updated.

@joaodasilva
Copy link
Contributor

It's an interesting idea and could be added. It shouldn't be a lot of work to add the jswin DLL loading code as an API to windowjs.

What kind of usage do you have in mind?

Making this work correctly in the Javascript environment is not trivial though. Some issues that come to mind:

  • Memory passed into and out of native functions. The Javascript VM and windowjs have no way to know if memory passed to a native function is retained internally or not by the native code, so proper GC for that becomes harder. It could make the assumption that native never retains memory, so the .js code MUST keep a reference if it needs to be kept in memory.

  • Structs. The .js code would have to pack the content of structs into ArrayBuffers. This depends a lot on the sizes of native types like size_t, int, etc and there's also issues of struct padding and alignment; getting all of that right may work in a given platform but not on others, or on other CPUs, or on other versions of the DLL.

  • Threading. The Javascript VM MUST execute in a single thread, but DLL code might take callbacks and invoke them in other threads.

  • Callbacks to native is another issue... we could always pass a trampoline function, but we have no way of knowing the parameters that have been passed and how to wrap that to Javascript properly.

  • Any mistakes in function signatures, etc in Javascript will seriously mess up the VM and the heap. At best you get a crash; in most cases you might just get wrong parameter values and corrupted heap memory.

So this could be implemented in a robust way for a limited range of native functions that could be invoked in the DLL, but some other usages would be much harder to get right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants