Giter Club home page Giter Club logo

Comments (6)

Spasi avatar Spasi commented on July 23, 2024

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:

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.

headius avatar headius commented on July 23, 2024

jnr-ffi already does use jnr-x86asm to generate native stubs for some cases. We could expand that, certainly. What else?

from jffi.

DemiMarie avatar DemiMarie commented on July 23, 2024

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.

 avatar commented on July 23, 2024

@DemiMarie Would be good if it can be implemented since jnr-x86asm hasn't been updated in years.

from jffi.

headius avatar headius commented on July 23, 2024

@DemiMarie Well it sounds like you have some idea how this might be done. Care to assist?

from jffi.

Techcable avatar Techcable commented on July 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.