Comments (6)
This won't work for the case of critical natives, though, unless we are able to make the JVM's dynamic lookup (via dlopen and dlsym) find the JIT-compiled code. This is because critical natives cannot be registered using RegisterNatives.
I was trying this a few days ago and initial testing looks promising. Sample implementation here. Used the following libraries:
- ELF-Hook on Linux.
- Mach-O-Hook on MacOS.
- MinHook on Windows.
Works on all three, but care must be taken when calling back to Java; anything that touches native code will deadlock the JVM.
from jffi.
jnr-ffi already does use jnr-x86asm to generate native stubs for some cases. We could expand that, certainly. What else?
from jffi.
I was thinking about using a simple stub code generator (much simpler than jnr-x86asm) to generate machine code stubs for other platforms. This should work, because the stubs have a very simple form:
mov %rdx,%rdi
mov %rcx,%rsi
mov %r8,%rdx
mov %r9,%rcx
mov 0x8(%rsp),%r8
mov 0x10(%rsp),%r9
mov 0x18(%rsp),%rax
mov %rax,0x8(%rsp)
mov 0x20(%rsp),%rax
mov %rax,0x10(%rsp)
mov 0x28(%rsp),%rax
mov %rax,0x18(%rsp)
movabs $0x1,%rax
jmpq 0x402e80
In other words, a series of mov
instructions in registers, followed by a series of mov
instructions relative to the stack pointer, followed by a jmp
. This can be generated with fairly simple code, especially if one knows the absolute address into which the code will be placed in memory.
from jffi.
@DemiMarie Would be good if it can be implemented since jnr-x86asm hasn't been updated in years.
from jffi.
@DemiMarie Well it sounds like you have some idea how this might be done. Care to assist?
from jffi.
I'd look into this, which uses DynASM to compile lua call stubs at runtime.
Alternatively, you could try a higher level library like gnu lightning to handle the code generation for you (although I'm not sure about windows calling convention support).
from jffi.
Related Issues (20)
- Update to JUnit5 and latest Maven Surefire Plugin HOT 2
- libjffi-1.2.so file is not present for s390x HOT 4
- Empty library archives? HOT 1
- Segmentation fault executing `Kernel.system("ls -lha")` inside Logstash HOT 5
- JVM crashes on setting callback for GTK3 signals HOT 2
- Issue with Apple Silicon Processor HOT 4
- JVM crash on Ubuntu 21 HOT 9
- Apple notarization failure HOT 12
- Update libffi to a newer version to support LoongArch HOT 2
- UnsatisfiedLinkError on Apple Silicon HOT 1
- s390x CI build not working, just falls back on x86_64 build
- Testsuite failures on 32-bit ARM arches HOT 2
- JFF crashes VM on invokeN0 on i386 and on armhf alltogether
- jffi9396993929588479283.so: /lib64/libc.so.6: version `GLIBC_2.27' not found HOT 55
- Clarify licensing? HOT 4
- fun address is the same after Multiple load In Ubuntu HOT 1
- MAC arm64 HOT 1
- jffi Reporting CVE-2017-1000376 HOT 3
- Automated builds failing in CI
- [Feature Request] Direct Mapping like JNA's? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jffi.