Implement no copy memory

Jorn Vernee jbvernee at xs4all.nl
Mon May 20 13:30:22 UTC 2019


Hi,

> It looks like pamana copy value from 'u_char *' into 'Pointer<Byte>
> buf', correct or not?

Pointer<Byte> is just a wrapper for the native pointer value. Only the 
value of the pointer itself is copied, not the contents of the memory it 
points to.

> Because when I call buf.addr() it returns 0,
> what zero mean?

Zero means NULL.

> How I can do with no copy? Just returns the address of 'u_char *' like
> below in callback method?

Pointer::addr returns the value of the pointer, to get the address of 
the pointer value itself, à la:

    uchar_t **bufRef = &buf;

This is currently not possible.

Can you explain a bit more about your use case? We might be able to 
offer some suggestions.

Cheers,
Jorn

Ardika Rommy Sanjaya schreef op 2019-05-20 01:33:
> 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