Skip to content
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

NameTypeDirDescription
nameint-
namelenu_int-
oldvoid-
oldlenpsize_t-
newvoid-
newlensize_t-

Version history

XNU tagmacOS#
xnu-1456.1.26macOS 10.6 Snow Leopard202
xnu-1699.24.8macOS 10.7 Lion202
xnu-2050.18.24macOS 10.8 Mountain Lion202
xnu-2422.115.4macOS 10.9 Mavericks202
xnu-1486.2.11202
xnu-1504.15.3202
xnu-1504.3.12202
xnu-1504.7.4202
xnu-1504.9.17202
xnu-1504.9.26202
xnu-1504.9.37202
xnu-1699.22.73202
xnu-1699.22.81202
xnu-1699.24.23202
xnu-1699.26.8202
xnu-1699.32.7202
xnu-2050.22.13202
xnu-2050.24.15202
xnu-2050.48.11202
xnu-2050.7.9202
xnu-2050.9.2202
xnu-2422.1.72202
xnu-2422.100.13202
xnu-2422.110.17202
xnu-2422.90.20202

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