Version
Provides generation of invocation plumbing for a defined native library interface. Also provides various utilities for native operations.
getTypeMapper(java.lang.Class<?>)
and getStructureAlignment(java.lang.Class<?>)
are provided to avoid having to explicitly pass these parameters to Structure
s, which would require every Structure
which requires custom mapping or alignment to define a constructor and pass parameters to the superclass. To avoid lots of boilerplate, the base Structure
constructor figures out these properties based on its enclosing interface.
When JNA classes are loaded, the native shared library (jnidispatch) is loaded as well. An attempt is made to load it from the any paths defined in jna.boot.library.path
(if defined), then the system library path using System.loadLibrary(java.lang.String)
, unless jna.nosys=true
. If not found, the appropriate library will be extracted from the class path (into a temporary directory if found within a jar file) and loaded from there, unless jna.noclasspath=true
. If your system has additional security constraints regarding execution or load of files (SELinux, for example), you should probably install the native library in an accessible location and configure your system accordingly, rather than relying on JNA to extract the library from its own jar file.
To avoid the automatic unpacking (in situations where you want to force a failure if the JNA native library is not properly installed on the system), set the system property jna.nounpack=true
.
While this class and its corresponding native library are loaded, the system property jna.loaded
will be set. The property will be cleared when native support has been unloaded (i.e. the Native class and its underlying native support has been GC'd).
NOTE: all native functions are provided within this class to ensure that all other JNA-provided classes and objects are GC'd and/or finalized/disposed before this class is disposed and/or removed from memory (most notably Memory and any other class which by default frees its resources in a finalizer).
Native Library LoadingNative libraries loaded via
load(Class)
may be found in
several locations.
Verschachtelte Klassen
Felder
static final int
Size of a native bool
type (C99 and later), in bytes.
(Package privat) static final int
Indicates whether the callback has an initializer.
(Package privat) static final int
Use direct mapping for callback.
(Package privat) static final int
Return a DLL-resident fucntion pointer.
static final boolean
static final boolean
(Package privat) static final String
(Package privat) static String
static final int
Size of a native long double
type (C99 and later), in bytes.
static final int
Size of a native long
type, in bytes.
(Package privat) static final int
(Package privat) static final int
static final int
The size of a native pointer (void*
) on the current platform, in bytes.
static final int
Size of a native size_t
type, in bytes.
static final int
Size of a native wchar_t
type, in bytes.
(Package privat) static void
Close the given native library.
(Package privat) static long
Create a native trampoline to delegate execution to the Java callback.
(Package privat) static boolean
Remove any automatically unpacked native library.
static void
Indicate whether the JVM should detach the current native thread when the current Java code finishes execution.
Attempt to extract a native library from the current resource path, using the current thread context class loader.
Attempt to extract a native library from the resource path using the given class loader.
static void
ffi_call(long cif, long fptr, long resp, long args)
Make an FFI function call.
static void
static long
ffi_prep_cif(int abi, int nargs, long ffi_return_type, long ffi_types)
Create a new cif structure.
static long
(Package privat) static Class<?>
Find the nearest enclosing class with native methods.
(Package privat) static Class<?>
Find the library interface corresponding to the given class.
(Package privat) static long
static void
Call the real native free
(Package privat) static void
Free the given callback trampoline.
(Package privat) static byte
(Package privat) static byte[]
(Package privat) static byte[]
(Package privat) static byte[]
(Package privat) static Class<?>
(Package privat) static char
static long
Utility method to get the native window ID for a heavyweight Java
Component
as a
long
value.
Utility method to get the native window pointer for a heavyweight Java
Component
as a
Pointer
value.
(Package privat) static double
(Package privat) static float
(Package privat) static int
static int
Retrieve last error set by the OS.
Return the preferred native library configuration options for the given class.
(Package privat) static long
Get the
NativeLibrary
instance to which the given "registered" class is bound.
static int
Returns the native size for a given Java class.
static int
(Package privat) static short
(Package privat) static String
(Package privat) static String
(Package privat) static String
(Package privat) static byte[]
static int
(Package privat) static File
Obtain a directory suitable for writing JNA-specific temporary files.
Return the preferred
TypeMapper
for the given native interface.
If running web start, determine the location of a given native library.
(Package privat) static String
(Package privat) static long
static long
Utility method to get the native window ID for a Java
Window
as a
long
value.
Utility method to get the native window pointer for a Java
Window
as a
Pointer
value.
(Package privat) static long
(Package privat) static int
Returns the size (calculated by libffi) of the given type.
(Package privat) static double
Call the native function.
(Package privat) static float
Call the native function.
(Package privat) static int
Call the native function.
(Package privat) static long
Call the native function.
(Package privat) static Object
Call the native function, returning a Java Object
.
(Package privat) static long
Call the native function.
Call the native function, returning a struct by value.
(Package privat) static void
Call the native function.
(Package privat) static boolean
Version string must have the structure . . a bugfix change in the native code increments revision, the minor is incremented for backwards compatible changes and the major version is changed for backwards incompatbile changes.
static boolean
Returns whether protection is enabled.
static boolean
(Package privat) static boolean
Identify temporary files unpacked from classpath jar files.
Map a library interface to the current process, providing the explicit interface class.
Map a library interface to the current process, providing the explicit interface class.
Map a library interface to the given shared library, providing the explicit interface class.
Load a library interface from the given shared library, providing the explicit interface class and a map of options for the library.
static <T> T
static <T> T
static <T> T
static <T> T
static void
Prints JNA library details to the console.
static long
Call the real native malloc
(Package privat) static void
Perform cleanup of automatically unpacked native shared library.
(Package privat) static long
Open the requested native library with default options.
(Package privat) static long
Open the requested native library with the specified platform-specific otions.
(Package privat) static void
read(Pointer pointer, long baseaddr, long offset, byte[] buf, int index, int length)
(Package privat) static void
read(Pointer pointer, long baseaddr, long offset, char[] buf, int index, int length)
(Package privat) static void
read(Pointer pointer, long baseaddr, long offset, double[] buf, int index, int length)
(Package privat) static void
read(Pointer pointer, long baseaddr, long offset, float[] buf, int index, int length)
(Package privat) static void
read(Pointer pointer, long baseaddr, long offset, int[] buf, int index, int length)
(Package privat) static void
read(Pointer pointer, long baseaddr, long offset, long[] buf, int index, int length)
(Package privat) static void
read(Pointer pointer, long baseaddr, long offset, short[] buf, int index, int length)
static void
When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.
static void
When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.
static void
When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.
static void
When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.
static boolean
(Package privat) static void
Remove all marked temporary files in the given directory.
(Package privat) static String
(Package privat) static void
static void
Set the default handler invoked when a callback throws an uncaught exception.
static void
Set a thread initializer for the given callback.
(Package privat) static void
(Package privat) static void
(Package privat) static void
(Package privat) static void
static void
Set the OS last error code.
(Package privat) static void
(Package privat) static void
(Package privat) static void
static void
Set whether native memory accesses are protected from invalid accesses.
(Package privat) static void
(Package privat) static void
Returns a synchronized (thread-safe) library backed by the specified library.
static byte[]
static byte[]
static byte[]
static char[]
Obtain a Java String from the given native byte array.
Obtain a Java String from the given native byte array, using the given encoding.
Obtain a Java String from the given native byte array, using the given encoding.
Obtain a Java String from the given native wchar_t array.
Converts a "list" of strings each null terminated into a
List
of
String
values.
Converts a "list" of strings each null terminated into a
List
of
String
values.
static void
Remove all native mappings for the calling class.
static void
Remove all native mappings for the given class.
(Package privat) static void
write(Pointer pointer, long baseaddr, long offset, byte[] buf, int index, int length)
(Package privat) static void
write(Pointer pointer, long baseaddr, long offset, char[] buf, int index, int length)
(Package privat) static void
write(Pointer pointer, long baseaddr, long offset, double[] buf, int index, int length)
(Package privat) static void
write(Pointer pointer, long baseaddr, long offset, float[] buf, int index, int length)
(Package privat) static void
write(Pointer pointer, long baseaddr, long offset, int[] buf, int index, int length)
(Package privat) static void
write(Pointer pointer, long baseaddr, long offset, long[] buf, int index, int length)
(Package privat) static void
write(Pointer pointer, long baseaddr, long offset, short[] buf, int index, int length)
Von Klasse geerbte Methoden java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static final boolean DEBUG_LOAD
public static final boolean DEBUG_JNA_LOAD
public static final int POINTER_SIZE
The size of a native pointer (void*
) on the current platform, in bytes.
public static final int LONG_SIZE
Size of a native long
type, in bytes.
public static final int WCHAR_SIZE
Size of a native wchar_t
type, in bytes.
public static final int SIZE_T_SIZE
Size of a native size_t
type, in bytes.
public static final int BOOL_SIZE
Size of a native bool
type (C99 and later), in bytes.
public static final int LONG_DOUBLE_SIZE
Size of a native long double
type (C99 and later), in bytes.
static final int MAX_ALIGNMENT
static final int MAX_PADDING
static final int CB_HAS_INITIALIZER
Indicates whether the callback has an initializer.
static final int CB_OPTION_DIRECT
Use direct mapping for callback.
static final int CB_OPTION_IN_DLL
Return a DLL-resident fucntion pointer.
Version string must have the structure . . a bugfix change in the native code increments revision, the minor is incremented for backwards compatible changes and the major version is changed for backwards incompatbile changes.
expectedVersion
-
nativeVersion
-
Remove any automatically unpacked native library. This will fail on windows, which disallows removal of any file that is still in use, so an alternative is required in that case. Mark the file that could not be deleted, and attempt to delete any temporaries on next startup. Do NOT force the class loader to unload the native library, since that introduces issues with cleaning up any extant JNA bits (e.g. Memory) which may still need use of the library before shutdown.
public static void setProtected(boolean enable)
Set whether native memory accesses are protected from invalid accesses. This should only be set true when testing or debugging, and should not be considered reliable or robust for applications where JNA native calls are occurring on multiple threads. Protected mode will be automatically set if the system property
jna.protected
has a value of "true" when the JNA library is first loaded.
If not supported by the underlying platform, this setting will have no effect.
NOTE: On platforms which support signals (non-Windows), JNA uses signals to trap errors. This may interfere with the JVM's own use of signals. When protected mode is enabled, you should make use of the jsig library, if available (see Signal Chaining). In short, set the environment variable LD_PRELOAD
to the path to libjsig.so
in your JRE lib directory (usually ${java.home}/lib/${os.arch}/libjsig.so) before launching your Java application.
public static boolean isProtected()
Returns whether protection is enabled. Check the result of this method after calling
setProtected(true)
to determine if this platform supports protecting memory accesses.
Utility method to get the native window ID for a Java
Window
as a
long
value. This method is primarily for X11-based systems, which use an opaque
XID
(usually
long int
) to identify windows.
HeadlessException
- if the current VM is running headless
Utility method to get the native window ID for a heavyweight Java
Component
as a
long
value. This method is primarily for X11-based systems, which use an opaque
XID
(usually
long int
) to identify windows.
HeadlessException
- if the current VM is running headless
Utility method to get the native window pointer for a Java
Window
as a
Pointer
value. This method is primarily for w32, which uses the
HANDLE
type (actually
void *
) to identify windows.
HeadlessException
- if the current VM is running headless
Utility method to get the native window pointer for a heavyweight Java
Component
as a
Pointer
value. This method is primarily for w32, which uses the
HWND
type (actually
void *
) to identify windows.
HeadlessException
- if the current VM is running headless
IllegalArgumentException
- if the buffer is not direct.
Obtain a Java String from the given native byte array. If there is no NUL terminator, the String will comprise the entire array. The encoding is obtained from
getDefaultStringEncoding()
.
buf
- The buffer containing the encoded bytes
Usage note: This function assumes, that buf
holds a char
array. This means only single-byte encodings are supported.
buf
- The buffer containing the encoded bytes. Must not be null
.
encoding
- The encoding name - if null
then the platform default encoding will be used
Usage note: This function assumes, that buf
holds a char
array. This means only single-byte encodings are supported.
buf
- The buffer containing the encoded bytes. Must not be null
.
charset
- The charset to decode buf
. Must not be null
.
Obtain a Java String from the given native wchar_t array. If there is no NUL terminator, the String will comprise the entire array.
buf
- The buffer containing the characters
Converts a "list" of strings each null terminated into a
List
of
String
values. The end of the list is signaled by an extra NULL value at the end or by the end of the buffer.
buf
- The buffer containing the strings
List
of all the strings in the buffer
Converts a "list" of strings each null terminated into a
List
of
String
values. The end of the list is signaled by an extra NULL value at the end or by the end of the data.
buf
- The buffer containing the strings
offset
- Offset to start parsing
len
- The total characters to parse
List
of all the strings in the buffer
Map a library interface to the current process, providing the explicit interface class. Native libraries loaded via this method may be found in
several locations.
T
- Type of expected wrapper
interfaceClass
- The implementation wrapper interface
UnsatisfiedLinkError
- if the library cannot be found or dependent libraries are missing.
Map a library interface to the current process, providing the explicit interface class. Any options provided for the library are cached and associated with the library and any of its defined structures and/or functions. Native libraries loaded via this method may be found in
several locations.
T
- Type of expected wrapper
interfaceClass
- The implementation wrapper interface
options
- Map of library options
UnsatisfiedLinkError
- if the library cannot be found or dependent libraries are missing.
Map a library interface to the given shared library, providing the explicit interface class. If
name
is null, attempts to map onto the current process. Native libraries loaded via this method may be found in
several locations.
T
- Type of expected wrapper
name
- Library base name
interfaceClass
- The implementation wrapper interface
UnsatisfiedLinkError
- if the library cannot be found or dependent libraries are missing.
Load a library interface from the given shared library, providing the explicit interface class and a map of options for the library. If no library options are detected the map is interpreted as a map of Java method names to native function names.
If name
is null, attempts to map onto the current process. Native libraries loaded via this method may be found in several locations.
T
- Type of expected wrapper
name
- Library base name
interfaceClass
- The implementation wrapper interface
options
- Map of library options
UnsatisfiedLinkError
- if the library cannot be found or dependent libraries are missing.
Veraltet.
Provided for improved compatibility between JNA 4.X and 5.X
Veraltet.
Provided for improved compatibility between JNA 4.X and 5.X
Veraltet.
Provided for improved compatibility between JNA 4.X and 5.X
Veraltet.
Provided for improved compatibility between JNA 4.X and 5.X
Find the library interface corresponding to the given class. Checks all ancestor classes and interfaces for a declaring class which implements
Library
.
cls
- The given class
Return the preferred native library configuration options for the given class. First attempts to load any field of the interface type within the interface mapping, then checks the cache for any specified library options. If none found, a set of library options will be generated from the fields (by order of precedence)
OPTIONS
(a
Map
),
TYPE_MAPPER
(a
TypeMapper
),
STRUCTURE_ALIGNMENT
(an
Integer
), and
STRING_ENCODING
(a
String
).
type
- The type class
cls
- The native interface type
getDefaultStringEncoding()
.
()
jna.encoding
or DEFAULT_ENCODING
.
cls
- The native interface type
s
- The input string
getDefaultStringEncoding()
.
s
- The string. Must not be null
.
encoding
- The encoding - if null
then the default platform encoding is used
s
- The string. Must not be null
.
charset
- The charset used to encode s
. Must not be null
.
s
- The string
getDefaultStringEncoding()
.
s
- The string. Must not be null
.
encoding
- The encoding - if null
then the default platform encoding is used
s
- The string. Must not be null
.
charset
- The charset used to encode s
. Must not be null
.
s
- The string
Identify temporary files unpacked from classpath jar files.
public static int getLastError()
Retrieve last error set by the OS. This corresponds to
GetLastError()
on Windows, and
errno
on most other platforms. The value is preserved per-thread, but whether the original value is per-thread depends on the underlying OS.
An alternative method of obtaining the last error result is to declare your mapped method to throw LastErrorException
instead. If a method's signature includes a throw of LastErrorException
, the last error will be set to zero before the native call and a LastErrorException
will be raised if the last error value is non-zero after the call, regardless of the actual returned value from the native function.
public static void setLastError(int code)
Set the OS last error code. The value will be saved on a per-thread basis.
Returns a synchronized (thread-safe) library backed by the specified library. This wrapping will prevent simultaneous invocations of any functions mapped to a given
NativeLibrary
. Note that the native library may still be sensitive to being called from different threads.
library
- the library to be "wrapped" in a synchronized library.
If running web start, determine the location of a given native library. This value may be used to properly set
jna.library.path
so that JNA can load libraries identified by the <nativelib> tag in the JNLP configuration file. Returns
null
if the Web Start native library cache location can not be determined. Note that the path returned may be different for any given library name.
Use System.getProperty("javawebstart.version")
to detect whether your code is running under Web Start.
UnsatisfiedLinkError
- if the library can't be found by the Web Start class loader, which usually means it wasn't included as a <nativelib>
resource in the JNLP file.
Perform cleanup of automatically unpacked native shared library.
Obtain a directory suitable for writing JNA-specific temporary files. Override with jna.tmpdir
IOException
Remove all marked temporary files in the given directory.
IOException
type
- The Java class for which the native size is to be determined
value
- an instance of said class (if available)
Returns the native size for a given Java class. Structures are assumed to be
struct
pointers unless they implement
Structure.ByValue
.
cls
- The Java class
cls
- The Java class
true
whether the given class is supported as a native argument type.
Set the default handler invoked when a callback throws an uncaught exception. If the given handler is null
, the default handler will be reinstated.
eh
- The default handler
When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.
libName
- library name to which functions should be bound
When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.
lib
- native library to which functions should be bound
Find the nearest enclosing class with native methods.
()
Set a thread initializer for the given callback.
cb
- The callback to invoke
initializer
- The thread initializer indicates desired thread configuration when the given Callback is invoked on a native thread not yet attached to the VM.
public static void unregister()
Remove all native mappings for the calling class. Should only be called if the class is no longer referenced and about to be garbage collected.
Remove all native mappings for the given class. Should only be called if the class is no longer referenced and about to be garbage collected.
cls
- The type Class
When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface. Uses the class loader of the given class to search for the native library in the resource path if it is not found in the system library load path or jna.library.path
.
cls
- Class with native methods to register
libName
- name of or path to native library to which functions should be bound
When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.
cls
- Class with native methods to register
lib
- library to which functions should be bound
library
- the Library
interface instance, which was created by the Native.load()
method
NativeLibrary
instance
Get the
NativeLibrary
instance to which the given "registered" class is bound.
cls
- the "registered" class, which was previously registered via the register()
method
NativeLibrary
instance to which the "registered" class is bound
public static long ffi_prep_cif(int abi, int nargs, long ffi_return_type, long ffi_types)
Create a new cif structure.
public static void ffi_call(long cif, long fptr, long resp, long args)
Make an FFI function call.
public static void ffi_free_closure(long closure)
static int initialize_ffi_type(long type_info)
Returns the size (calculated by libffi) of the given type.
Prints JNA library details to the console.
static void freeNativeCallback(long ptr)
Free the given callback trampoline.
Create a native trampoline to delegate execution to the Java callback.
Call the native function.
function
- Present to prevent the GC to collect the Function object prematurely
fp
- function pointer
callFlags
- calling convention to be used
args
- Arguments to pass to the native function
Call the native function.
function
- Present to prevent the GC to collect the Function object prematurely
fp
- function pointer
callFlags
- calling convention to be used
args
- Arguments to pass to the native function
Call the native function.
function
- Present to prevent the GC to collect the Function object prematurely
fp
- function pointer
callFlags
- calling convention to be used
args
- Arguments to pass to the native function
Call the native function.
function
- Present to prevent the GC to collect the Function object prematurely
fp
- function pointer
callFlags
- calling convention to be used
args
- Arguments to pass to the native function
Call the native function.
function
- Present to prevent the GC to collect the Function object prematurely
fp
- function pointer
callFlags
- calling convention to be used
args
- Arguments to pass to the native function
Call the native function.
function
- Present to prevent the GC to collect the Function object prematurely
fp
- function pointer
callFlags
- calling convention to be used
args
- Arguments to pass to the native function
Call the native function, returning a struct by value.
function
- Present to prevent the GC to collect the Function object prematurely
fp
- function pointer
callFlags
- calling convention to be used
args
- Arguments to pass to the native function
Call the native function, returning a Java Object
.
function
- Present to prevent the GC to collect the Function object prematurely
fp
- function pointer
callFlags
- calling convention to be used
args
- Arguments to pass to the native function
Object
Open the requested native library with default options.
Open the requested native library with the specified platform-specific otions.
static void close(long handle)
Close the given native library.
public static long malloc(long size)
Call the real native malloc
size
- size of the memory to be allocated
public static void free(long ptr)
Call the real native free
ptr
- native address to be freed; a value of zero has no effect, passing an already-freed pointer will cause pain.
public static void detach(boolean detach)
Indicate whether the JVM should detach the current native thread when the current Java code finishes execution. Generally this is used to avoid detaching native threads when it is known that a given thread will be relatively long-lived and call back to Java code frequently.
This call is lightweight; it only results in an additional JNI crossing if the desired state changes from its last setting.
IllegalStateException
- if detach(true)
is called on a thread created by the JVM.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4