[英]Getting pointer from native syscall in Java
Having the following Java code具有以下 Java 代码
Object[] params = new Object[] {new Object(), null}
int ret = lib.getClass().getMethod("syscall", int.class, Object[].class).invoke(
lib, 116, params
);
where 116
is the code (on MacOS) for gettimofday
system function,其中116
是gettimofday
系统 function 的代码(在 MacOS 上),
how should I specify params correctly so that I can extract timeval
struct containing the result (as specified by https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/gettimeofday.2.html )我应该如何正确指定参数,以便我可以提取包含结果的timeval
结构(由https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/gettimeofday.2.html指定)
The function expects specific struct as a first parameter which it will populate: function 期望特定的结构作为第一个参数,它将填充:
@Structure.FieldOrder({"sec", "usec"})
public static class Timeval extends Structure {
/**
* Seconds.
*/
public long sec;
/**
* Microseconds.
*/
public long usec;
}
Supplying parameters as follows succeed the call:提供如下参数使调用成功:
final Timeval timeval = new Timeval();
final Object[] params = new Object[]{timeval, null};
lib.syscall(116, params)
Result can be retrieved from timeval.sec
and timeval.usec
.可以从timeval.sec
和timeval.usec
检索结果。
Thanks to @Mark Rotteveel for the hints.感谢@Mark Rotteveel的提示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.