Skip to content

builtins(ulimit): normalize Darwin RLIM_INFINITY and print macOS -l/-m/-v rows - #3707

Merged
caomengxuan666 merged 2 commits into
masterfrom
devin/ulimit-darwin-infinity
Nov 16, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
devin/ulimit-darwin-infinity

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

ulimit -a on macOS printed 9007199254740991 for the unlimited rows (and ulimit -Hn printed the raw infinity integer), and non-root ulimit -f unlimited failed Operation not permitted where GNU returns 0.

  • Root cause: rubash's internal UNLIMITED sentinel is u64::MAX, but Darwin's RLIM_INFINITY is (1<<63)-1 — getrlimit values never matched the sentinel, so printone (third_party/bash/builtins/ulimit.def:754-777, curlim == RLIM_INFINITY → unlimited) divided by the block factor; symmetrically, setrlimit wrote u64::MAX, which the kernel treats as a hard-limit raise above the real maximum → EPERM for the ulimit.def:623-626 no-op case.
  • Fix: rlimit_get normalizes >= libc::RLIM_INFINITY to UNLIMITED; all write paths map UNLIMITED back to libc::RLIM_INFINITY. Linux is unaffected (its RLIM_INFINITY already equals u64::MAX).
  • macOS table: LIMITS/resource() gain -l/MEMLOCK, -m/RSS and -v/VIRTMEM (RLIMIT_AS) under cfg(target_os = "macos"), so ulimit -a prints the full eleven rows like print_all_limits over the compiled-in limits[] (ulimit.def:734-749, 239-298). Other non-Linux unix keeps the conservative table.

Refs #3605

Verification

  • Byte-identical vs GNU Bash 5.3.20 on macOS arm64: ulimit -a, ulimit -Hn/-Sn, ulimit -f unlimited (rc=0, no diagnostic), ulimit -v/-m/-l, ulimit -n unlimited EPERM edge, -Hs value.
  • New tests/issue3605_ulimit_infinity_rows.rs: 3 tests green on macOS.
  • Gate run-builtins: ulimit diff eliminated; the remaining diff is the separate help builtin-table divergence (niu lists env; GNU has no env builtin) — recorded on macOS: GNU upstream gate 48/86 — catalog of remaining divergences #3605.
  • Known env-bound residual (pre-existing, unchanged): Darwin rejects lowering RLIMIT_STACK below the already-established stack region in this runtime → issue2636_subshell_ulimit_isolation::subshell_ulimit_other_resource_does_not_leak fails locally; GNU's shallower main stack does not trip it.

…s (Refs #3605)

run-builtins `ulimit -a` printed `9007199254740991` (unlimited/1024) for
the -d/-f/-t rows and `ulimit -f unlimited` failed EPERM for non-root:
rubash's internal UNLIMITED sentinel is u64::MAX while Darwin's
RLIM_INFINITY is (1<<63)-1, so printone (ulimit.def:754-777 —
`curlim == RLIM_INFINITY` prints `unlimited`) never matched and the
setrlimit write counted as a hard-limit raise.

- rlimit_get normalizes values >= libc::RLIM_INFINITY to UNLIMITED;
  writes map UNLIMITED back to libc::RLIM_INFINITY (set_limit
  ulimit.def:578-638 / non-root softening ulimit.def:623-626).
- macOS LIMITS table and resource() gain -l/MEMLOCK, -m/RSS and
  -v/VIRTMEM (Darwin's RLIMIT_AS) so `ulimit -a` prints all eleven rows
  like print_all_limits over the compiled-in limits[]
  (ulimit.def:734-749, table ulimit.def:239-298).

Byte-verified against GNU Bash 5.3.20 on macOS arm64: `ulimit -a`,
`ulimit -Hn/-Sn`, `ulimit -f unlimited`, `ulimit -v/-m/-l`, and the
non-root EPERM matrix all match. Known env-bound residual: Darwin
rejects lowering RLIMIT_STACK below the already-established stack
region for this runtime (issue2636 other-resource cell), GNU's
shallower main stack does not trip it.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3707 第1轮 — 建议:PASS
head: 3b8d490(审计 4b610b8 + 本 lane fmt 修复 1 commit)base(merge-base): 96802ca 文件: 2 个 +169/-13
关联 issue: #3605(状态:open,我核过的时间:2026-11-16 本地)——注意:#3605 是 38-suite 的 macOS gate 追踪目录,本 PR 只修其中 ulimit 一格,不合入后关单,保持 Refs。

机制核查:

  • norm_in/to_rlim_t 归一化方向与 GNU 一致:printone 在 curlim == RLIM_INFINITY 时打印 unlimited(third_party/bash/builtins/ulimit.def:754-777);非 root 写 unlimited 走 limit.rlim_max no-op(ulimit.def:623-626);-v 行对应 RLIMIT_VIRTMEM(ulimit.def:287-289 HAVE_RESOURCE);-l/-m 行对应 limits[] 表的 MEMLOCK/RSS(ulimit.def:239-298)。Darwin RLIM_INFINITY=(1<<63)-1 下 >= 归一化覆盖 RLIM_SAVED_MAX/CUR 同值哨兵;Linux 上 RLIM_INFINITY==u64::MAX,>= 退化为 ==,行为逐位不变;Windows 由独立 #[cfg(windows)] mod plat 承载,未触碰。
  • diff 无可疑/无关改动;无桥接层/半成品修法。

腿:

  • 钉自跑:issue3605_ulimit_infinity_rows 编译通过;Windows 上 0 passed/0 failed(全部 #[cfg(unix)]/cfg(macos),本平台只证编译)。
  • fail-first:VOID(环境受限)——钉在 unix 下才有断言体,Windows base/head 均 0 测试,无法在本机区分;macOS CI 腿是其真实执行环境。
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state}(1350 passed/1 failed/4 ignored)/ base 失败名集 {同上}(1350/1/4)/ 差集 {} —— 该失败为 env-bound 基线(NIU_/WINUXCMD_ 主机环境影响),与本 PR 无关(PR 只改 cfg(unix) 代码,Windows 编译期即不生效)。
  • -D warnings:lib+bins 0 警告;PR 自身测试 target 0 警告。--all-targets 下唯一红是 tests/d11_pipeline_squote_carrier_regressions.rs:32 dead_code(PR 未触碰文件,基线已有)。
  • 卫生:marker-lint OK(117 registry consts / 268 allowlisted sites);utf8-boundary-hygiene clean;fmt 原 head 有 1 处数组折行违规,已由本 lane commit 修复(见续作记录)。
  • CI:红任务 4 个,逐个归因——Rust tests(Linux)/Rust tests (macOS)/GNU regression goldens and canaries 各仅红 issue2875_input_procsub_child_runs_as_rubash_shell = 已知基线;niubash builds against this tree 红在 check-api-ledger MISSING rubash::api::Session::cwd,与 master 基线 run 43779513466 逐格一致 = 基线。无 PR 自身红。
  • GNU 对照:WSL GNU bash 5.3.20(1)-release,脚本 target/s4-probes/ulimit-probe.sh(ulimit -f/-d/-t/-Hf/-n)→ GNU 输出 unlimited×4 + 10240;本 PR head 的 rubash.exe 同脚本输出逐字节一致。Darwin 专属形状(RLIM_INFINITY≠u64::MAX、-l/-m/-v 行、EPERM no-op)Windows 无法触发——待队长 macOS/Linux oracle 复核;PR 正文声称已在 macOS arm64 与 GNU 5.3.20 逐字节核对。

F 点:无

续作记录(本 lane 动过代码):

未跑/VOID 的腿:

  • fail-first:环境受限(钉为 unix-only),见上。
  • Darwin 行为验证:本机无 macOS,按规程标注待 oracle 复核。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 16, 2026 06:09
@caomengxuan666
caomengxuan666 merged commit 0c95350 into master Nov 16, 2026
8 of 11 checks passed
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