-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix malloc & free in early constructors #2311
base: dev
Are you sure you want to change the base?
Conversation
97aa02c
to
b953392
Compare
I've switch to a model more like the one used by jemalloc. I retain a constructor with default priority, but add checks to all allocation paths that the allocator is initialized. I've also added a simple spin lock around initialization in case constructors manage to spawn threads that race the constructor. |
Hm, I also note that, unlike the dynamic library, these helpers only exist for one ABI. malloc_is_revoking makes sure to be purecap at least (technically it'll end up as benchmark ABI if you do a TARGET_ARCH=aarch64cb build but we don't do that so I guess that's ok, I'm sure other bugs like that exist), but this one doesn't, so it'll be hybrid in a hybrid world. It also means we're not testing it when statically linked, nor are we testing either for the benchmark ABI (though it would be hard to see how they'd break there), nor are we testing either for c18n. |
b953392
to
feee935
Compare
Now testing purecap and benchmark in static and dynamic configurations:
The Makefiles are arguably too clever for their own good, but it's doing the right thing. |
a704ba8
to
85c4acc
Compare
I think this is basically ready to land |
Prefer PATH_MAX which is in POSIX. Fixes: 5c59b01 cheribsdtest: infrastructure to spawn children
Being able to access more than the name provides extra flexibility.
85c4acc
to
b8cfa04
Compare
Add support for tests that look for a helper program with the cheribsdtest instance's suffix appended. This allows per-target helpers to test things that need to be tested with a range of compilation modes, but can't be tested directly in the cheribsdtest binary.
Add a check (predicted false) to all allocation paths that mrs has been initialized and add asserts to free paths. As with jemalloc, retain a constructor so that malloc is initialized before main() regardless. Previously, the constructor might not be called before another constructor called free() which lead to a NULL pointer dereference.
Protect against the possiblity of a constructor, etc creating a thread which races a call to mrs_init_impl and put a spinlock around the actual initialization.
Add a set of binaries with a simple constructor at priority 101 that calls malloc and free. Make sure they exit successfully.
b8cfa04
to
57ac576
Compare
Set a priority for the mrs constructer in the "system" range.
It's not clear to me what the right priority is. 100 works for this test, but it's seems easy to argue for something higher like 50.