Implement no copy memory

Ardika Rommy Sanjaya ardikars at gmail.com
Sun May 19 23:33:13 UTC 2019


Hi,

There is native function in libpcap library: typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *, const u_char *);
When I use jextract it generate code like below:

@NativeHeader(...)
public interface pcap_h {

    ...

    @NativeLocation(...)
    @NativeFunction("(u64:${pcap}i32u64:(u64:u8u64:${pcap_pkthdr}u64:u8)vu64:u8)i32")
    int pcap_loop(Pointer<pcap> p, int cnt, Callback<pcap_handler> callback, Pointer<Byte> usr);

    @FunctionalInterface
    @NativeCallback("(u64:u8u64:${pcap_pkthdr}u64:u8)v")
    interface pcap_handler {

        void fn(Pointer<Byte> buf, Pointer<pcap_pkthdr> pkthdr, Pointer<Byte> usr) throws IllegalAccessException;

    }

    ...

}

It looks like pamana copy value from 'u_char *' into 'Pointer<Byte> buf', correct or not? Because when I call buf.addr() it returns 0, what zero mean?
How I can do with no copy? Just returns the address of 'u_char *' like below in callback method?

void fn(long memoryAddressOf_u_char_ptr, Pointer<pcap_pkthdr> pkthdr, Pointer<Byte> usr) throws IllegalAccessException;

Thanks and Regards,
Ardika Rommy Sanjaya


More information about the panama-dev mailing list