rust-lang / rust-lang/rust

Global allocator re-entrancy guarantees missing tests

Open
#160,776 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

E-needs-test needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Thread::new tries to avoid invoking the global allocator for re-entrancy reasons (https://doc.rust-lang.org/nightly/std/alloc/trait.GlobalAlloc.html#re-entrance), but CString::new invoked indirectly here will reserve an extra byte of memory in the passed String using the Global, not System, allocator. I think we don't actually have a problem here because Thread::new isn't called with a name from thread::current(), but it's probably worth adding some comments for that.

Separately from those comments, I also noticed while poking at this that the PR adding those guarantees (https://github.com/rust-lang/rust/pull/144465) didn't add tests confirming that the functions in question didn't invoke the global allocator when called. I don't recall seeing a subsequent PR with tests but cutting this to track adding some. I think we wouldn't be able to easily write a unit test since those run concurrently, but it seems doable to put together a UI test or run-make test (we may need to use a C / raw pthread spawned thread, not sure).

cc @orlp

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in library/std/src/thread/thread.rs around the Thread::new call and review the linked GlobalAlloc re-entrancy guarantee and PR #144465. Determine whether a UI test or run-make test can exercise the functions from a separately spawned thread without invoking the global allocator, and add comments covering the CString::new concern. Done means the relevant no-allocation guarantees are tested.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.