Class LinuxLibcFunctions
java.lang.Object
oshi.ffm.ForeignFunctions
oshi.ffm.linux.LinuxLibcFunctions
FFM bindings for Linux libc functions used by OSHI.
Covers: getpid, gettid, syscall, getloadavg, sysinfo, statvfs,
gethostname, getaddrinfo/freeaddrinfo/gai_strerror, and getrlimit.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StructLayoutstruct addrinfolayout (64-bit Linux).static final intstatic final shortutmpx entry type: session leader of a logged in user.static final StructLayoutstruct rlimitlayout: twounsigned longfields.static final intstatic final StructLayoutstruct statvfslayout (64-bit Linux, no_f_unusedpadding field).static final StructLayoutstruct sysinfolayout (64-bit Linux).static final shortutmpx entry type: normal process.static final StructLayoutstruct utmpxlayout (64-bit Linux).Fields inherited from class ForeignFunctions
CAPTURE_CALL_STATE, CAPTURED_STATE_LAYOUT, ERRNO_HANDLE, LIBRARY_ARENA, LINKER, NATIVE_LONG_SIZE, NATIVE_POINTER_SIZE, NATIVE_SIZE_T_SIZE, SYMBOL_LOOKUP -
Method Summary
Modifier and TypeMethodDescriptionstatic StringaddrinfoCanoname(MemorySegment resPtr, Arena arena) Readsai_canonnamefrom the first addrinfo result pointer.static voidCallsendutxent()to close the utmpx database.static voidCallsfreeaddrinfo(struct addrinfo *res).static StringgaiStrerror(int errcode, Arena arena) Callsgai_strerror(int errcode)and returns the error string.static intgetaddrinfo(MemorySegment node, MemorySegment service, MemorySegment hints, MemorySegment res) Callsgetaddrinfo(node, service, hints, res).static intgethostname(MemorySegment buf, long len) Callsgethostname(char *name, size_t len).static intgetloadavg(MemorySegment loadavg, int nelem) Callsgetloadavg(double[] loadavg, int nelem).static intgetpid()Callsgetpid().static intgetrlimit(int resource, MemorySegment rlim) Callsgetrlimit(int resource, struct rlimit *rlim).static intgettid()Callsgettid()directly.static MemorySegmentCallsgetutxent()to read the next entry from the utmpx database.static booleanReturns whethergettid()is directly available in libc.static longrlimitCur(MemorySegment rlim) Readsrlim_curfrom a rlimit segment.static longrlimitMax(MemorySegment rlim) Readsrlim_maxfrom a rlimit segment.static voidCallssetutxent()to rewind the utmpx database.static intstatvfs(MemorySegment path, MemorySegment buf) Callsstatvfs(const char *path, struct statvfs *buf).static longReadsf_bavailfrom a statvfs segment.static longReadsf_bfreefrom a statvfs segment.static longReadsf_blocksfrom a statvfs segment.static longReadsf_ffreefrom a statvfs segment.static longReadsf_filesfrom a statvfs segment.static longReadsf_frsizefrom a statvfs segment.static longCallssyscall(SYS_GETTID).static intsysinfo(MemorySegment info) Callssysinfo(struct sysinfo *info).static intsysinfoProcs(MemorySegment info) Reads theprocsfield from a sysinfo segment.static int[]Readsut_addr_v6from a utmpx segment as a 4-element int array.static StringReadsut_linefrom a utmpx segment.static longReads the login time from a utmpx segment as epoch milliseconds.static shortReadsut_typefrom a utmpx segment.static StringReadsut_userfrom a utmpx segment.Methods inherited from class ForeignFunctions
downcall, getByteArrayFromNativePointer, getErrno, getStringFromNativePointer, getStructFromNativePointer, lib, libraryLookup
-
Field Details
-
RLIMIT_NOFILE
public static final int RLIMIT_NOFILE- See Also:
-
AI_CANONNAME
public static final int AI_CANONNAME- See Also:
-
SYSINFO_LAYOUT
struct sysinfolayout (64-bit Linux).long uptime (8) long[3] loads (24) long totalram (8) long freeram (8) long sharedram (8) long bufferram (8) long totalswap (8) long freeswap (8) short procs (2) ... padding/high memory fields follow
-
STATVFS_LAYOUT
struct statvfslayout (64-bit Linux, no_f_unusedpadding field). -
RLIMIT_LAYOUT
struct rlimitlayout: twounsigned longfields. -
ADDRINFO_LAYOUT
struct addrinfolayout (64-bit Linux).int ai_flags (4) int ai_family (4) int ai_socktype (4) int ai_protocol (4) long ai_addrlen (8) -- socklen_t padded to 8 ptr ai_addr (8) ptr ai_canonname (8) -- offset 32 ptr ai_next (8)
-
LOGIN_PROCESS
public static final short LOGIN_PROCESSutmpx entry type: session leader of a logged in user.- See Also:
-
USER_PROCESS
public static final short USER_PROCESSutmpx entry type: normal process.- See Also:
-
UTMPX_LAYOUT
struct utmpxlayout (64-bit Linux).short ut_type (2) pad (2) int ut_pid (4) char ut_line[32] (32) char ut_id[4] (4) char ut_user[32] (32) char ut_host[256] (256) short[2] ut_exit (4) int ut_session (4) int tv_sec (4) int tv_usec (4) int[4] ut_addr_v6 (16) char[20] reserved (20) total = 384
-
-
Method Details
-
hasGettid
public static boolean hasGettid()Returns whethergettid()is directly available in libc.- Returns:
trueifgettidis available
-
setutxent
-
getutxent
Callsgetutxent()to read the next entry from the utmpx database.- Returns:
- a pointer to the utmpx structure, or
nullif no more entries - Throws:
Throwable- if the native call fails
-
endutxent
-
utmpxType
Readsut_typefrom a utmpx segment.- Parameters:
ut- segment populated bygetutxent()- Returns:
- the entry type
-
utmpxUser
Readsut_userfrom a utmpx segment.- Parameters:
ut- segment populated bygetutxent()- Returns:
- the username string
-
utmpxLine
Readsut_linefrom a utmpx segment.- Parameters:
ut- segment populated bygetutxent()- Returns:
- the device name string
-
utmpxAddrV6
Readsut_addr_v6from a utmpx segment as a 4-element int array.- Parameters:
ut- segment populated bygetutxent()- Returns:
- the IPv6/IPv4 address as 4 ints
-
utmpxLoginTime
Reads the login time from a utmpx segment as epoch milliseconds.- Parameters:
ut- segment populated bygetutxent()- Returns:
- login time in milliseconds since epoch
-
getpid
-
gettid
Callsgettid()directly. Only valid ifhasGettid()is true.- Returns:
- the thread ID of the calling thread
- Throws:
Throwable- if the native call fails
-
syscallGettid
-
getloadavg
Callsgetloadavg(double[] loadavg, int nelem).- Parameters:
loadavg- pre-allocated segment ofnelemdoublesnelem- number of load average values to retrieve (1–3)- Returns:
- number of samples set, or -1 on error
- Throws:
Throwable
-
sysinfo
Callssysinfo(struct sysinfo *info).- Parameters:
info- segment allocated withSYSINFO_LAYOUT- Returns:
- 0 on success, -1 on error
- Throws:
Throwable
-
sysinfoProcs
Reads theprocsfield from a sysinfo segment.- Parameters:
info- segment populated bysysinfo(MemorySegment)- Returns:
- number of current processes
-
statvfs
Callsstatvfs(const char *path, struct statvfs *buf).- Parameters:
path- path segment (null-terminated UTF-8)buf- segment allocated withSTATVFS_LAYOUT- Returns:
- 0 on success, -1 on error
- Throws:
Throwable
-
statvfsFrsize
Readsf_frsizefrom a statvfs segment.- Parameters:
buf- segment populated bystatvfs(MemorySegment, MemorySegment)- Returns:
- fragment size in bytes
-
statvfsBlocks
Readsf_blocksfrom a statvfs segment.- Parameters:
buf- segment populated bystatvfs(MemorySegment, MemorySegment)- Returns:
- total data blocks in filesystem
-
statvfsBfree
Readsf_bfreefrom a statvfs segment.- Parameters:
buf- segment populated bystatvfs(MemorySegment, MemorySegment)- Returns:
- free blocks in filesystem
-
statvfsBavail
Readsf_bavailfrom a statvfs segment.- Parameters:
buf- segment populated bystatvfs(MemorySegment, MemorySegment)- Returns:
- free blocks available to unprivileged users
-
statvfsFiles
Readsf_filesfrom a statvfs segment.- Parameters:
buf- segment populated bystatvfs(MemorySegment, MemorySegment)- Returns:
- total file nodes in filesystem
-
statvfsFfree
Readsf_ffreefrom a statvfs segment.- Parameters:
buf- segment populated bystatvfs(MemorySegment, MemorySegment)- Returns:
- free file nodes in filesystem
-
gethostname
Callsgethostname(char *name, size_t len).- Parameters:
buf- segment of at leastlenbyteslen- buffer length- Returns:
- 0 on success, -1 on error
- Throws:
Throwable
-
getaddrinfo
public static int getaddrinfo(MemorySegment node, MemorySegment service, MemorySegment hints, MemorySegment res) throws Throwable Callsgetaddrinfo(node, service, hints, res).- Parameters:
node- hostname segment (null-terminated UTF-8)service- NULL segment or service namehints- segment allocated withADDRINFO_LAYOUT, or NULLres- pointer-to-pointer output segment (ADDRESS-sized)- Returns:
- 0 on success, non-zero error code on failure
- Throws:
Throwable
-
freeaddrinfo
Callsfreeaddrinfo(struct addrinfo *res).- Parameters:
res- the addrinfo pointer returned bygetaddrinfo- Throws:
Throwable
-
gaiStrerror
-
addrinfoCanoname
Readsai_canonnamefrom the first addrinfo result pointer.- Parameters:
resPtr- the raw pointer value stored in the output segment aftergetaddrinfoarena- arena to scope the reinterpret- Returns:
- the canonical name string, or
nullif the pointer is NULL
-
getrlimit
Callsgetrlimit(int resource, struct rlimit *rlim).- Parameters:
resource- resource constant (e.g.RLIMIT_NOFILE)rlim- segment allocated withRLIMIT_LAYOUT- Returns:
- 0 on success, -1 on error
- Throws:
Throwable
-
rlimitCur
Readsrlim_curfrom a rlimit segment.- Parameters:
rlim- segment populated bygetrlimit(int, MemorySegment)- Returns:
- the soft resource limit
-
rlimitMax
Readsrlim_maxfrom a rlimit segment.- Parameters:
rlim- segment populated bygetrlimit(int, MemorySegment)- Returns:
- the hard resource limit
-