Skip to content

audit(platform-cfg): full platform-gate inventory; fix android signal-table legs (kill/trap) - #492

Merged
caomengxuan666 merged 1 commit into
masterfrom
audit/cfg-platform-gates
Oct 10, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
audit/cfg-platform-gates

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

背景

#487(login shell)初版把平台门写成 target_os = "linux"、漏掉 release matrix 的 macOS 两腿。本 PR 是对 src/ 全部平台 cfg 门的平台门审计:全量盘点 + 分类判定,只提交无争议修复。

结论先行:没有发现 #487 同类的「漏 macOS 腿」问题。 所有 target_os = "linux" 独用门都是真 Linux 专属(内核/libc API 或编号契约),macOS 要么有显式 macos 腿、要么被 unix 全家门覆盖;#468(procsub fd)全程 cfg(unix),macOS 正确。真正发现的同类问题是 android 腿被 kill/trap 信号表排除——#456 修了 sa_restorer 的门,但漏了信号编号表本体。已修。

修复(本次提交,b 类无争议)

kill -l 17 在 android(CI cross-target)上当前打印空、trap -l 列出 bionic 不用的 BSD 名(7=EMT, 20=CHLD)。原因:kill 表的 Linux 腿 target_os = "linux" 不含 android,trap 表把所有非 Linux unix 送进 BSD 位置表。libc 0.2.186 android 模块实证 bionic 1..31 与 Linux 内核编号逐值一致(SIGBUS=7、SIGUSR1=10、SIGSTKFLT=16、SIGPWR=30、SIGSYS=31…):

  • kill.rs:12 个 1..31 槽位门 target_os = "linux" → any(target_os = "linux", target_os = "android")。RT 字面量块(34..64)保持 Linux 专属——glibc 契约 SIGRTMIN=34,bionic __libc_current_sigrtmin()=32,字面量在 android 上会是错的。
  • trap.rs:android 新增 64 槽表(1..31 Linux 名,RT 槽留空),BSD 表门收窄为 not(any(linux, android))。空 RT 槽让越段数字 spec 静默接受(Linux 32/33 洞的形状),而不是宣传错误的 RTMIN 基数。现有 positional_slots_match_libc / trap_table_agrees_with_kill_table 交叉测试在 android 测试运行器下自动钉住新表。

全量盘点表

统计口径:src/ 下含平台键的 cfg 共 511 处;target_os 族(排除 windows 专用)92 处、集中于 8 个文件;其余为 unix / windows / not(windows) / cfg! 运行时宏。

判定为 a 类(真 Linux 专属 / 平台设计正确,保留)

位置 当前门 理由
kill.rs:188-248(RT 块 31 项) target_os = "linux" glibc 34..64 字面量契约;bionic RT base=32、Darwin/BSD 无 RT;linux 测试运行时钉住
kill.rs:1597 sa_restorer any(linux, android) Darwin libc 的 sigaction 无该字段;#456 引入,写法正确
kill.rs macos/freebsd 交替腿 + :2015 测试 any(macos, freebsd) BSD 编号槽位(EMT/INFO/STOP 族序),与 libc 常量对齐
trap.rs Linux 表(含 RT 名) target_os = "linux" 同 RT 契约;trap -l 与 GNU signames 一致
trap.rs:684 SIGRTMIN 种子 any(not(unix), target_os = "linux") WSL wire 契约;GNU bash on Darwin 无 SIGRTMIN(注释有据);android 无 RT 名,被排除一致
trap.rs macos/freebsd 表 + :980 测试 all(unix, not(...)) BSD 位置表,测试逐槽钉 libc
ulimit.rs:106 Linux LIMITS 表 target_os = "linux" oracle(WSL bash 5.3.0 ulimit -a)逐行核对的 glibc 资源集(RTTIME/NICE/MSGQUEUE 等)
ulimit.rs:259/262 RlimitResource typedef target_env = "gnu" / 非 gnu glibc __rlimit_resource_t vs musl/OHOS c_int 的编译正确性;OHOS(target_os="linux", target_env="ohos")天然被 linux 腿覆盖
ulimit.rs:302/311 rlimit_get 分型 linux / 其余 unix 与上面 typedef 配套
uname.rs:385-463(两处测试) linux / macos / not(any(linux, macos)) 测试期望值的平台分支,与 identity.rs 实现一一对应;android 落 "other unix"=unknown 腿,与实现一致
test.rs:827 AT_EACCESS target_os = "android" bionic 头文件有 AT_EACCESS 但 libc crate 不导出,注释明确的 workaround
identity.rs:91/254/262/288/302(运行时 cfg!) macos / linux coreutils persona 仿真(uname -p 的 APPLE arm、GNU/Linux -o 等),平台差异均有 GNU 源码行号注释;macOS 腿显式存在
identity.rs:61/93 target_env = "gnu" 运行时 OSTYPE/MACHTYPE configure triple 仿真
identity.rs / locale.rs / test.rs 各 cfg(unix) 面 unix uname(2)、setlocale、faccessat(AT_EACCESS) 等 POSIX 全家语义,macOS 天然覆盖
path.rs:595/603/619 confstr all(unix, not(android)) / all(unix, android) bionic 无 confstr(3),走 STANDARD_UTILS_PATH fallback;#456 引入,正确
fd/unix.rs:150-157 pipe2/pipe+fcntl target_os = "linux" / not(...) pipe2 是 glibc/musl API、Darwin 只有 pipe+fcntl(注释有据);两腿产物语义等价(CLOEXEC 管道)
console_readline / fd/mod / script_driver / proc_vfs / locale / posix_errors 等 windows↔unix/not(windows) 分离(约 419 处) windows / unix / not(windows) 结构性双肢,不存在漏腿;proc_vfs unix 侧的空 stub(list_pids 等)是刻意的保守降级而非门错分

判定为 b 类(门写窄了,已修)

位置 原门 修复 证据
kill.rs 12 个 1..31 槽位(BUS/USR1/USR2/STKFLT/CHLD/CONT/STOP/TSTP/URG/IO/PWR/SYS) target_os = "linux" any(target_os = "linux", target_os = "android") libc 0.2.186 src/unix/linux_like/android/mod.rs:950-969 逐值核对
trap.rs SIGNALS 表 android 落 all(unix, not(linux)) BSD 表 新增 all(unix, target_os = "android") 64 槽表;BSD 门收窄 同上;RT 留空的理由见 commit message

近期 PR 复核(owner 点名的六条)

PR 新增 cfg 门 macOS 腿
#455 SIGPIPE 无(注释 + 平台中立错误处理) 不受影响
#456 android any(linux, android)(sa_restorer)、all(unix, not(android))(confstr)、test.rs AT_EACCESS 不受影响;但漏了信号表本体 → 本 PR 补
#458 输入规范化 无(C0 字节规范化平台中立) 不受影响
#467 ERR trap 无 不受影响
#468 procsub fd 全部 cfg(unix) 正确覆盖 macOS
#486 opener checkpoint 无 不受影响

存疑表(d 类,不动代码,需真机 oracle)

  1. ulimit 保守表在 android 的行集:bionic 实际定义 RLIMIT_NICE/RTPRIO/RTTIME/MSGQUEUE/MEMLOCK/AS/LOCKS(asm-generic),android 腿可以扩充行集;但需要真机 bash ulimit -a oracle 核对描述文案,维持保守集无害。
  2. fd/unix.rs pipe2 微优化:bionic 有 pipe2,not(linux) 腿可收窄为 not(any(linux, android)) 省两次 fcntl;纯性能、语义等价,不动。
  3. trap android RT 名:若未来要在 android 暴露 RT 名,需按 __libc_current_sigrtmin()=32 运行时生成(const 表做不到,glibc 是函数、bionic 同),需真机验证。
  4. uname -p/-i 在 android 的取值:当前 "other unix" → unknown;android 生态用 toybox 而非 coreutils,其行为需真机核对。

验证

  • cargo check(x86_64-pc-windows-msvc):通过
  • cargo check --target aarch64-linux-android / armv7-linux-androideabi:通过(修复的 compile-level 证明)
  • cargo check --target aarch64-apple-darwin:本机 rustup 拉取该 target std 失败(网络),待 CI cross-target check 腿;本次改动未触碰任何 macos/freebsd/unix 通用臂(diff 只在 linux/android 门与新 android 表),darwin 编译不受影响
  • cargo test --lib:636 passed / 2 failed,与基线 a7cce03 完全一致(2 个失败为预存环境问题:pwd::logical_mode_reports_posix_drive_pwd_by_default、path::virtual_system_root_operand_resolution_keeps_option_b_and_legacy_verbatim,stash 后基线复跑同样失败)
  • cargo fmt --check:通过

Windows / macOS / linux-gnu 语义零变化:所有改动臂在这些 target 上编译排除。

…or android too

The kill(1) number table gated its Linux legs on target_os = linux and
trap's SIGNALS table sent every non-Linux unix target to the BSD-family
positional table, so an aarch64-linux-android build (a CI cross-target)
resolved neither: kill -l 17 printed nothing on bionic and trap -l listed
the BSD names (7=EMT, 20=CHLD) that bionic does not use.

Bionic resolves the Linux kernel numbering for signals 1..31 (libc's
android module pins SIGBUS=7, SIGUSR1=10, SIGSTKFLT=16, SIGPWR=30,
SIGSYS=31, ...), so:

- kill.rs: extend the twelve 1..31 Linux-leg cfg attrs to
  any(target_os = linux, target_os = android). The 34..64 RT
  literal block stays Linux-only: glibc's SIGRTMIN contract is 34, while
  bionic's __libc_current_sigrtmin() is 32, so the literal numbering
  would be wrong there.
- trap.rs: give android its own 64-slot table (1..31 Linux names, RT
  slots empty) instead of the BSD table; the BSD gate narrows to
  not(any(linux, android)). Empty RT slots keep in-range numeric
  specifiers silently accepted (the Linux 32/33-hole shape) instead of
  advertising a wrong RTMIN base, and the existing cross-checks
  (positional_slots_match_libc, trap_table_agrees_with_kill_table) pin
  the table on any future android test runner.

No Windows/macOS/linux-gnu behavior change: every touched arm compiles
out on those targets (cargo test --lib: same 636 passed / 2 pre-existing
environmental failures before and after). aarch64-apple-darwin and
linux-gnu are untouched by construction; android arms verified with
cargo check on aarch64-linux-android and armv7-linux-androideabi.
@caomengxuan666
caomengxuan666 merged commit 94fbad2 into master Oct 10, 2026
7 of 8 checks passed
@caomengxuan666
caomengxuan666 deleted the audit/cfg-platform-gates branch October 10, 2026 05:57
caomengxuan666 added a commit that referenced this pull request Oct 10, 2026
#499)

Non-cfg-layer Windows-hardcode audit (sister of the cfg-gate audit #492).

b-class fixes (wrong on non-Windows builds):
- tilde.rs home_value(): the USERPROFILE fallback (env_vars lookup +
  process env) ran un-gated, so a stray USERPROFILE exported by
  cross-platform tooling would hijack `~` on unix once HOME is unset.
  Now cfg(windows)-gated; unix keeps the empty default it always had.
- main.rs identity disclosure/report: on non-Windows builds the persona
  is always native, but --help/--identity still advertised "unset
  RUBASH_IDENTITY to return to msys". Platform-split so unix prints an
  n/a switch line instead of an impossible instruction.

c-class fixes (stale/dangling copy):
- build_info.rs --version note pointed to docs/platform-support.md,
  which does not exist; repointed to the README identity section
  (both anchoring assertions updated).
- README.md/README.zh-CN.md Quick Start still claimed "full
  functionality requires Windows today", contradicting the Platform
  status section (Linux native runs, macOS CI-green).
- README.md identity section now states non-Windows builds always
  report the honest-native identity.

Windows behavior is byte-identical (all edits are unix-arm additions or
cfg(windows)-scoped text). Verified: cargo check --lib + cargo test
--lib (642 passed; 2 pre-existing environment-dependent failures also
failing on pristine origin/master) + cargo check --lib
--target x86_64-unknown-linux-gnu.
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