Skip to content

ours-sys ​

libs/sys — a workspace crate with unsafe: the system calls that neither rustix nor socket2 offers. It has its own [lints] without forbid (see unsafe). Only the calls themselves are unsafe; what the kernel wrote — addresses, control messages, option values — is read by safe code over bytes.

  • setsockopt(fd, level, name, &[u8]), getsockopt(fd, level, name, &mut [u8]) — options by number with the value in the bytes the kernel takes: TCP_FASTOPEN[_CONNECT], IP_BIND_ADDRESS_NO_PORT, SO_RCVLOWAT, IP[V6]_RECVORIGDSTADDR, IP_PKTINFO, IPV6_RECVPKTINFO, UDP_GRO, SO_ZEROCOPY, TCP_BRUTAL_PARAMS.
  • recvmsg(fd, buf, &mut Control<N>, flags) — one datagram with its control messages; Message holds the length, the source, the filled part of the control buffer and the flags (MSG_TRUNC, MSG_CTRUNC).
  • recvmmsg(fd, bufs, controls, out, flags) — up to MAX_BATCH (64) datagrams. The headers, the source addresses and the iovecs are on the stack and are built anew on every call, so a short address or control length of one call does not carry over to the next; nothing is allocated.
  • Control<N> — a control buffer aligned as cmsghdr is (the kernel writes headers in place); the caller keeps it and reuses it.
  • socket_addr(bytes) — sockaddr_in/sockaddr_in6 from bytes (a source, IP[V6]_ORIGDSTADDR).
  • thread_cpu_time(tid) — clock_gettime on another thread's CPU clock, as glibc's pthread_getcpuclockid builds it (/proc/<tid>/schedstat is missing on kernels without CONFIG_SCHED_INFO, WSL among them).

Control messages themselves are parsed and built in ours-net-sys (cmsg.rs), in safe code. Sending with a control message is socket2's safe sendmsg.

GPL-3.0-or-later