Skip to content

feat(c/os): restore common native OS APIs - #47

Draft
MeteorsLiu wants to merge 6 commits into
goplus:mainfrom
MeteorsLiu:codex/c-os-native-bindings
Draft

MeteorsLiu wants to merge 6 commits into
goplus:mainfrom
MeteorsLiu:codex/c-os-native-bindings

Conversation

@MeteorsLiu

@MeteorsLiu MeteorsLiu commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Restore common native OS APIs from unified libc generation.

The implementation includes:

  • Classify the macOS 14 and glibc 2.24 outputs into one generated Go file per target, including Linux arm64.
  • Reuse compatible existing names for generated declarations, including Close, Closedir, Dup, Dup2, Fcntl, and Syscall.
  • Keep public Go contracts that differ from the raw declarations and retain the existing platform implementations outside the three native targets.
  • Pass guarded pipe I/O, native layout, Mach-header, and UUID checks where applicable, with GC and nogc on all three targets.

Existing C symbol coverage and the shared root C API remain unchanged by the name cleanup.

@MeteorsLiu

MeteorsLiu commented Oct 19, 2026 •

Copy link
Copy Markdown
Member Author

Merge order: #45 → #51 → #48 → #49 → #44 → #47 → #46 → #50 → #52.

Each draft changes one folder only. This refresh regenerates native APIs without omitting functions merely to preserve handwritten entry points. Existing compatibility APIs remain available; colliding native names use the Native prefix.

The combined prerequisite snapshot passes llgo build and executed llgo test runs on macOS arm64, Linux amd64 and Linux arm64, both with GC and -tags=nogc (54 package test runs and 6 complete builds). Generation uses unmodified llcppg main da227ff4, macOS SDK 14.0 and Bootlin glibc 2.24 headers. The earlier Timeval receiver and Signal layout failures are resolved.

These PRs remain draft for review. Documented generator/ABI failures and previously approved va_list exclusions remain; there are zero handwritten-retention exclusions.

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review: native libc OS bindings

Reviewed the full diff across four dimensions (correctness/quality, performance, security, documentation). This PR adds llcppg-generated libc bindings for linux/amd64 and darwin/arm64 (plus shared Iovec, signal, sched_param, and dirent types).

Overall: looks solid. go build and go vet ./c/os/ pass on linux/amd64 (darwin/arm64 can't be cross-compiled here due to the cgo toolchain, so darwin was reasoned about statically). No duplicate- or missing-symbol conflicts between the generated files and the existing hand-written os.go / os_darwin.go / os_other.go on either platform — the shared ModeT/UidT/GidT/OffT/DevT/PidT types resolve per-platform and the generated files only reference them.

ABI layouts verified against glibc / macOS SDK and found correct:

  • Termios — linux [32]CcT + c.Uint flags; darwin [20]CcT + c.Ulong flags.
  • SigsetT — linux [16]c.Ulong (128B); darwin uint32.
  • Iovec, Statvfs, Rusage, siginfo_t, SchedParam, GlobT, Passwd/Group — layouts and integer widths match their targets.
  • Spot-checked ~50 linkname / llgo:link mappings; Go→C symbol names and platform-divergent signatures are correct.

No security concerns and no meaningful performance concerns (these are pure FFI declarations).

The findings below are all low-severity / nits on generated output — none block the PR. Several belong upstream in the llcppg generator rather than being hand-edited in these DO NOT EDIT files.

Not inline-anchored

  • Merged .pub manifests can't express per-platform type ownership. c/signal/llcppg.pub lists X__SigvalT / SiginfoT / Sigval (which exist only in the linux variant) and SigsetT, but omits the darwin-only intermediate aliases X__Uint32T and X__DarwinSigsetT exported by types_darwin_arm64.go. Similarly c/os/llcppg.pub mixes linux-only (__syscall_slong_t, …) and darwin-only (mach_port_t, _filesec, …) typedefs in one file. This is generator metadata (it doesn't affect the Go build, which passes), but worth confirming the single merged manifest is intentional vs. splitting per platform.
  • Missing Darwin fcntl/open flag constants. The orphaned comments flagged inline at libc_darwin_arm64.go indicate O_NONBLOCK (O_NDELAY) and F_GETFL / F_SETFL were dropped from the Darwin bindings during generation. Worth confirming the omission is intentional.

Findings without inline locations

  • c/iovec_linux_amd64.go:10: Nit: iov_len is size_t on both platforms, but it's typed SizeT here (linux) and Ulong in iovec_darwin_arm64.go. Both are 8-byte unsigned on LP64 so the ABI is correct, but using two alias names for the same semantic C type is a needless cross-platform inconsistency — prefer one (SizeT) on both for maintainability.
  • c/signal/types_darwin_arm64.go:13: Nit: The // [???] signal set placeholder is Apple's own [???] conformance marker faithfully extracted from sys/_types.h, so it's not wrong — but it reads as noise/an incomplete doc. If the generator can be configured to drop or translate these [???] markers, that would read cleaner on regeneration (same marker also appears at libc_darwin_arm64.go // [???] microseconds).

Comment thread c/os/mach_darwin_arm64.go Outdated

import "github.com/goplus/lib/c"

// Canonical Mach typedefs from the macOS 14.0 SDK.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit (low): Pinning a specific SDK version — macOS 14.0 SDK — in a DO NOT EDIT generated file is a staleness trap: mach_port_t/semaphore_t both resolve to natural_t (unsigned int) and have been ABI-stable across many macOS releases, so the version isn't what's actually version-sensitive, and the text won't update if the file is regenerated against a newer SDK. Consider dropping the version (or deriving it from the generator) so the comment can't drift.

Comment thread c/os/libc_darwin_arm64.go
const (
// no delay
// set append mode
O_APPEND = 8

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit (low): Orphaned/misattributed comments. // no delay and // set append mode are stacked above O_APPEND = 8; // no delay actually belongs to an omitted O_NONBLOCK/O_NDELAY = 4 constant, so it now reads as if it describes O_APPEND. Besides the misleading comment, this signals O_NONBLOCK is missing from the Darwin bindings. Generator artifact — fix belongs upstream in llcppg rather than hand-editing this file.

Comment thread c/os/libc_darwin_arm64.go
// get file status flags
// set file status flags
// get SIGIO/SIGURG proc/pgrp
F_GETOWN = 5

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit (low): Same orphaned-comment pattern — // get file status flags and // set file status flags sit above F_GETOWN = 5 but belong to omitted F_GETFL = 3 / F_SETFL = 4 constants. The comment is misleading and it signals F_GETFL/F_SETFL are missing from the Darwin bindings. Generator-level; worth confirming the omission is intentional.

@MeteorsLiu MeteorsLiu changed the title feat(c/os): add native libc OS bindings feat(c/os): generate common native OS bindings per platform Oct 19, 2026
@MeteorsLiu MeteorsLiu changed the title feat(c/os): generate common native OS bindings per platform feat(c/os): add classified native OS bindings Oct 19, 2026
@MeteorsLiu MeteorsLiu changed the title feat(c/os): add classified native OS bindings feat(c/os): restore common native OS APIs Oct 19, 2026
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.

1 participant