BSD syscall#202
svc · unix #202
__sysctl
Raw entry point for the BSD sysctl tree: reads or writes a kernel state variable identified by an integer-OID path.
Prototype
int __sysctl(int *name, u_int namelen, void *old, size_t *oldlenp, void *new, size_t newlen);Returns: int
Arguments
| Name | Type | Dir | Description |
|---|---|---|---|
| name | int | - | |
| namelen | u_int | - | |
| old | void | - | |
| oldlenp | size_t | - | |
| new | void | - | |
| newlen | size_t | - |
Version history
| XNU tag | macOS | # |
|---|---|---|
| xnu-1456.1.26 | macOS 10.6 Snow Leopard | 202 |
| xnu-1699.24.8 | macOS 10.7 Lion | 202 |
| xnu-2050.18.24 | macOS 10.8 Mountain Lion | 202 |
| xnu-2422.115.4 | macOS 10.9 Mavericks | 202 |
| xnu-1486.2.11 | — | 202 |
| xnu-1504.15.3 | — | 202 |
| xnu-1504.3.12 | — | 202 |
| xnu-1504.7.4 | — | 202 |
| xnu-1504.9.17 | — | 202 |
| xnu-1504.9.26 | — | 202 |
| xnu-1504.9.37 | — | 202 |
| xnu-1699.22.73 | — | 202 |
| xnu-1699.22.81 | — | 202 |
| xnu-1699.24.23 | — | 202 |
| xnu-1699.26.8 | — | 202 |
| xnu-1699.32.7 | — | 202 |
| xnu-2050.22.13 | — | 202 |
| xnu-2050.24.15 | — | 202 |
| xnu-2050.48.11 | — | 202 |
| xnu-2050.7.9 | — | 202 |
| xnu-2050.9.2 | — | 202 |
| xnu-2422.1.72 | — | 202 |
| xnu-2422.100.13 | — | 202 |
| xnu-2422.110.17 | — | 202 |
| xnu-2422.90.20 | — | 202 |
Examples
C — read kern.osrelease
int mib[2] = { CTL_KERN, KERN_OSRELEASE };
char buf[64];
size_t len = sizeof(buf);
sysctl(mib, 2, buf, &len, NULL, 0);Notes
Backs the libc sysctl(3), sysctlbyname(3) and sysctlnametomib(3) wrappers. The userland sysctl(8) command, hw.* / kern.* queries, and most of the system-info gathering done by tools like ps, top, vm_stat and ioreg ultimately funnel through this one syscall. Some MIBs (notably kern.proc) honour per-entitlement filtering on hardened binaries.
Detection
Endpoint Security does not surface __sysctl directly, but its NOTIFY_PROC_CHECK event covers proc-listing sysctls. DTrace's syscall::__sysctl:entry probe decodes the OID array and is the standard way to audit who is reading kern.proc.
Related APIs
sysctlsysctlbynamesysctlnametomibproc_infokdebug_trace