Skip to content

feat(c/signal): restore native APIs and signal layouts - #48

Draft
MeteorsLiu wants to merge 8 commits into
goplus:mainfrom
MeteorsLiu:codex/c-signal-native-types
Draft

MeteorsLiu wants to merge 8 commits into
goplus:mainfrom
MeteorsLiu:codex/c-signal-native-types

Conversation

@MeteorsLiu

@MeteorsLiu MeteorsLiu commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Verify every retained native signal symbol and exercise real handler delivery while preserving the existing Signal contract.

The implementation includes:

  • Generate native signal records and APIs from macOS 14 and Bootlin glibc 2.24 for macOS arm64 and Linux amd64/arm64 using unmodified llcppg.
  • Keep Signal returning the Sigaction installation status and NativeSignal returning C signal's previous handler; use generated records and union accessors without changing existing public function signatures.
  • Remove private C implementation entry points and the private macOS wrapper source, and exclude Linux SysSiglist with explicit approval because current glibc provides no default sys_siglist export.
  • Cover every retained C function with a symbol-address and native-prototype check, and check all public type layouts, constants, native globals and generated union accessors; recognize _xgo_union storage as a C union while retaining all size/alignment assertions.
  • Exercise guarded sigaction output, signal-set operations, handler installation/restoration, real Raise delivery, Kill(self, 0), and the complete Linux non-notifying timer lifecycle. TimerCreate keeps its link check and uses an approved static signature/ABI check to avoid the dependency's reflection-wrapper limitation.

Executed LLGo v1.0.8 (c171abfa130108bc6451e01fcf15a8a3474eb0a7) GC and nogc tests pass on all three targets. Validation includes #45's root c files at 99ddac92c7335a53a1c996174e1753bcd72c5050 and #51's c/time files at 855f0c294499b32a0d3380d1d608592255155e89; merge #45, then #51, before this draft. Standalone build CI currently reports undefined: lltime.TimerT because #51 is not merged. The existing c/time full-signature reflection limitation remains documented and unchanged. This PR changes only c/signal and makes missing symbol coverage and native layout regressions visible.

@MeteorsLiu

MeteorsLiu commented Oct 19, 2026 •

Copy link
Copy Markdown
Member Author

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

This draft changes only c/signal. Its validation snapshot includes #45's root c files at 99ddac92c7335a53a1c996174e1753bcd72c5050 and #51's c/time at 855f0c294499b32a0d3380d1d608592255155e89. Linux signal bindings require the timer types from #51, so that prerequisite must merge first.

All retained native signal functions have link-address and native-prototype coverage; public types, constants, globals and generated union accessors also have complete source-inventory coverage. Executed tests pass on macOS arm64, Linux amd64 and Linux arm64 with GC and -tags=nogc, using LLGo v1.0.8 (c171abfa). Runtime tests include real signal delivery to the installed handler and the unchanged Linux timer lifecycle assertions.

Private C entry points and their private macOS wrapper are removed. Linux SysSiglist is excluded with explicit approval, while macOS keeps its native globals. Signal and NativeSignal retain their distinct status-return and previous-handler-return contracts. The approved static TimerCreate prototype test preserves its full link and lifecycle checks without modifying c/time or llcppg. The PR remains draft.

Standalone build CI currently stops at c/signal/libc_linux_amd64.go:655:81: undefined: lltime.TimerT, because #51 has not merged. The six passing signal runs include the documented prerequisite snapshots.

@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 — c/signal native types

Ran code-quality, performance, security, and documentation passes over the four generated files.

Verified correct — no action needed

  • Struct layouts match the glibc amd64 ABI, confirmed with a size/offset probe: SiginfoT = 128 bytes (__SI_MAX_SIZE) with _sifields at offset 16, Sigval = 8 bytes, SigsetT = 128 bytes ([16]c.Ulong). Darwin SigsetT resolves to a 4-byte uint32, matching __darwin_sigset_t.
  • Every XGof_ref_* accessor casts strictly within its backing union — no out-of-bounds reads — and they are zero-cost unsafe.Pointer reinterpretations (no copies/allocations).
  • Package builds for linux/amd64 and darwin/arm64; all files are gofmt-clean.

Findings (non-blocking)
These are llcppg-generated files, so fixes most likely belong in the generator/config rather than hand edits.

  • Platform-coverage gap on the published type surface — see inline on llcppg.pub.
  • [???] doc placeholder — see inline on types_darwin_arm64.go.

Minor nits

  • _llcppg_anon_34 (_sigsys, libc_linux_amd64.go:113) is the only _sifields union member without the category doc comment its siblings carry (glibc labels it /* SIGSYS. */).
  • Darwin maps __uint32_t to c.Uint (types_darwin_arm64.go:9) while the linux file uses c.Uint32T for the analogous 32-bit field — same width today, purely a cross-file consistency nit.

Comment thread c/signal/llcppg.pub
@@ -0,0 +1,5 @@
D github.com/goplus/lib/c
T __sigval_t X__SigvalT
T siginfo_t SiginfoT

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

llcppg.pub publishes SiginfoT, Sigval, and X__SigvalT as package types, but they are defined only for linux && amd64 (libc_linux_amd64.go). On darwin/arm64 only SigsetT exists, and on other platforms none of these do — so any consumer that references signal.SiginfoT or signal.Sigval will fail to build outside linux/amd64. If this is an intended incremental first step, no change needed; otherwise consider generating the darwin (and other-platform) definitions so the published surface matches what is actually available.

Comment thread c/signal/types_darwin_arm64.go Outdated

type SigsetT = X__DarwinSigsetT

// [???] signal set

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The doc comment // [???] signal set carries a [???] placeholder artifact that surfaces in godoc. __darwin_sigset_t is simply __uint32_t, so this should read something like // signal set. Worth fixing at the generator so the placeholder is not emitted.

@MeteorsLiu MeteorsLiu changed the title feat(c/signal): add native signal support types feat(c/signal): generate native signal types per platform Oct 19, 2026
@MeteorsLiu MeteorsLiu changed the title feat(c/signal): generate native signal types per platform feat(c/signal): add native signal types for libc bindings Oct 19, 2026
@MeteorsLiu MeteorsLiu changed the title feat(c/signal): add native signal types for libc bindings feat(c/signal): add native signal and timer declarations Oct 19, 2026
@MeteorsLiu MeteorsLiu changed the title feat(c/signal): add native signal and timer declarations feat(c/signal): restore native APIs and signal layouts Oct 20, 2026
@MeteorsLiu
MeteorsLiu force-pushed the codex/c-signal-native-types branch from 931115b to 45790ae Compare October 22, 2026 05:48
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