Skip to content

Add proc_info structs and methods to macOS SystemB#1723

Open
dbwiddis wants to merge 1 commit into
java-native-access:masterfrom
dbwiddis:add-resource-usage-and-proc-info
Open

Add proc_info structs and methods to macOS SystemB#1723
dbwiddis wants to merge 1 commit into
java-native-access:masterfrom
dbwiddis:add-resource-usage-and-proc-info

Conversation

@dbwiddis
Copy link
Copy Markdown
Contributor

@dbwiddis dbwiddis commented May 11, 2026

Adds macOS process/socket information structs and methods to c.s.j.p.mac.SystemB.

Most mappings have been in use by OSHI since 2020, finally catching up on my upstream contributions. vm_deallocate (yes I had a memory leak for a decade) and statfs64 are recent additions.

Changes

c.s.j.p.mac.SystemB:

  • ProcFdInfo
  • InSockInfo
  • TcpSockInfo
  • proc_pidfdinfo(), statfs64(), vm_deallocate() methods
  • Constants: PROC_PIDLISTFDS, PROC_PIDFDSOCKETINFO, PROX_FDTYPE_SOCKET, SOCKINFO_IN, SOCKINFO_TCP, TSI_T_NTIMERS, AF_INET, AF_INET6

Reference headers

  • sys/proc_info.h: struct proc_fdinfo, struct in_sockinfo, struct tcp_sockinfo, PROC_PIDLISTFDS, PROC_PIDFDSOCKETINFO, PROX_FDTYPE_SOCKET, TSI_T_NTIMERS

- Add ProcFdInfo, InSockInfo, TcpSockInfo structs to c.s.j.p.mac.SystemB
- Add proc_pidfdinfo(), statfs64(), vm_deallocate() methods
- Add PROC_PIDLISTFDS, PROC_PIDFDSOCKETINFO, PROX_FDTYPE_SOCKET,
  SOCKINFO_IN, SOCKINFO_TCP, TSI_T_NTIMERS, AF_INET, AF_INET6 constants
- Add SystemBTest additions (testProcPidFdInfo, testStatfs64)

All struct mappings verified against Apple XNU headers:
- sys/proc_info.h (struct proc_fdinfo, struct in_sockinfo, struct tcp_sockinfo)
@dbwiddis dbwiddis force-pushed the add-resource-usage-and-proc-info branch from fd3e4e7 to 4cd4d97 Compare May 11, 2026 01:04
*/
@Structure.FieldOrder({ "insi_fport", "insi_lport", "insi_gencnt", "insi_flags", "insi_flow", "insi_vflag",
"insi_ip_ttl", "rfu_1", "insi_faddr", "insi_laddr", "insi_v4", "insi_v6" })
class InSockInfo extends Structure {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this: https://github.com/phracker/MacOSX-SDKs/blob/041600eda65c6a668f66cb7d56b7d1da3e8bcc93/MacOSX11.3.sdk/usr/include/sys/proc_info.h#L360-L388

The first members match. Are the latter members intentionally not mapped as struct but instead as byte arrays?

Comment on lines +380 to +388
int bufferSize = SystemB.INSTANCE.proc_pidinfo(pid, SystemB.PROC_PIDLISTFDS, 0, null, 0);
assertTrue(bufferSize > 0);

int numFds = bufferSize / new ProcFdInfo().size();
assertTrue(numFds > 0);

ProcFdInfo[] fdInfoArray = (ProcFdInfo[]) new ProcFdInfo().toArray(numFds);
int ret = SystemB.INSTANCE.proc_pidinfo(pid, SystemB.PROC_PIDLISTFDS, 0, fdInfoArray[0],
bufferSize);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is fishy here. I'd expect proc_pidfdinfo not proc_pidinfo to be called here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants