Add proc_info structs and methods to macOS SystemB#1723
Conversation
fd3e4e7 to
4cd4d97
Compare
| */ | ||
| @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 { |
There was a problem hiding this comment.
The first members match. Are the latter members intentionally not mapped as struct but instead as byte arrays?
There was a problem hiding this comment.
int arrays to be precise.
I knew there was a reason I hadn't contributed these upstream for years... since I didn't really need them in my project I just made sure the byte counts matched as creating a union I would never need was annoying.
So this is four 32-bit IP addresses, the larger member of the first and second unions (thus int[4])
struct in4in6_addr {
u_int32_t i46a_pad32[3];
struct in_addr i46a_addr4;
};
struct in_addr {
in_addr_t s_addr;
};
typedef __uint32_t in_addr_t; /* base type for internet address */
Similarly with the last insi_v6 structure.
Not sure I want to go to the trouble of mapping them. I can just close this PR. (I guess it's not that hard. I'm just lazy.)
| 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); |
There was a problem hiding this comment.
Something is fishy here. I'd expect proc_pidfdinfo not proc_pidinfo to be called here.
There was a problem hiding this comment.
This is correct for proc_pidinfo
https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/proc_info.h#L736-L738
But as you call out I'm missing a test for proc_pidfdinfo which I need for socket info:
https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/proc_info.h#L839-L848
4cd4d97 to
4ba2dc0
Compare
Add In4In6Addr, In6Addr, InsiAddr union for proper address mapping in InSockInfo. Add ProcFileInfo, SockbufInfo, SocketInfo, Pri union, and SocketFdInfo structures for proc_pidfdinfo support. InSockInfo.read() and SocketInfo.read() automatically select the correct union type based on insi_vflag and soi_kind respectively. Add testProcPidFdSocketInfo test exercising proc_pidfdinfo with PROC_PIDFDSOCKETINFO.
4ba2dc0 to
70db423
Compare
|
Properly mapped the unions. Made identical changes here: https://github.com/dbwiddis/oshi/tree/jna-union-mapping And got sane socket info: |
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) andstatfs64are recent additions.Changes
c.s.j.p.mac.SystemB:ProcFdInfoInSockInfoTcpSockInfoproc_pidfdinfo(),statfs64(),vm_deallocate()methodsPROC_PIDLISTFDS,PROC_PIDFDSOCKETINFO,PROX_FDTYPE_SOCKET,SOCKINFO_IN,SOCKINFO_TCP,TSI_T_NTIMERS,AF_INET,AF_INET6Reference headers
sys/proc_info.h:struct proc_fdinfo,struct in_sockinfo,struct tcp_sockinfo,PROC_PIDLISTFDS,PROC_PIDFDSOCKETINFO,PROX_FDTYPE_SOCKET,TSI_T_NTIMERS