Commit Graph

35 Commits

Author SHA1 Message Date
Frank Steffahn bf88b113ea Fix typos “a”→“an” 2021-08-22 15:35:11 +02:00
John Ericson 19be438cda alloc: Add unstable Cfg feature no-global_oom_handling
For certain sorts of systems, programming, it's deemed essential that
all allocation failures be explicitly handled where they occur. For
example, see Linus Torvald's opinion in [1]. Merely not calling global
panic handlers, or always `try_reserving` first (for vectors), is not
deemed good enough, because the mere presence of the global OOM handlers
is burdens static analysis.

One option for these projects to use rust would just be to skip `alloc`,
rolling their own allocation abstractions.  But this would, in my
opinion be a real shame. `alloc` has a few `try_*` methods already, and
we could easily have more. Features like custom allocator support also
demonstrate and existing to support diverse use-cases with the same
abstractions.

A natural way to add such a feature flag would a Cargo feature, but
there are currently uncertainties around how std library crate's Cargo
features may or not be stable, so to avoid any risk of stabilizing by
mistake we are going with a more low-level "raw cfg" token, which
cannot be interacted with via Cargo alone.

Note also that since there is no notion of "default cfg tokens" outside
of Cargo features, we have to invert the condition from
`global_oom_handling` to to `not(no_global_oom_handling)`. This breaks
the monotonicity that would be important for a Cargo feature (i.e.
turning on more features should never break compatibility), but it
doesn't matter for raw cfg tokens which are not intended to be
"constraint solved" by Cargo or anything else.

To support this use-case we create a new feature, "global-oom-handling",
on by default, and put the global OOM handler infra and everything else
it that depends on it behind it. By default, nothing is changed, but
users concerned about global handling can make sure it is disabled, and
be confident that all OOM handling is local and explicit.

For this first iteration, non-flat collections are outright disabled.
`Vec` and `String` don't yet have `try_*` allocation methods, but are
kept anyways since they can be oom-safely created "from parts", and we
hope to add those `try_` methods in the future.

[1]: https://lore.kernel.org/lkml/CAHk-=wh_sNLoz84AUUzuqXEsYH35u=8HV3vK-jbRbJ_B-JjGrg@mail.gmail.com/
2021-05-05 16:49:04 -04:00
Josh Stone 1f1a3b4857 move WriteCloneIntoRaw into alloc::alloc 2021-01-12 12:24:28 -08:00
Tim Diekmann 9274b37d99 Rename AllocRef to Allocator and (de)alloc to (de)allocate 2020-12-04 14:47:15 +01:00
bors f32459c7ba Auto merge of #79172 - a1phyr:cold_abort, r=Mark-Simulacrum
Add #[cold] attribute to `std::process::abort` and `alloc::alloc::handle_alloc_error`
2020-11-23 02:25:13 +00:00
Jake Goulding dcef5ff372 Bump bootstrap compiler version 2020-11-19 19:23:36 -05:00
Benoît du Garreau b4c91f9a52 Add #[cold] to abort and handle_alloc_error 2020-11-18 18:15:03 +01:00
Ralf Jung af869c2f8d document that __rust_alloc is also magic to our LLVM fork 2020-11-15 18:40:49 +01:00
Tim Diekmann 06e4497a04 Merge remote-tracking branch 'upstream/master' into box-alloc 2020-10-25 16:32:28 +01:00
Jonas Schievink e34263d86a Rollup merge of #77610 - hermitcore:dtors, r=m-ou-se
revise Hermit's mutex interface to support the behaviour of StaticMutex

rust-lang/rust#77147 simplifies things by splitting this Mutex type into two types matching the two use cases: StaticMutex and MovableMutex. To support the new behavior of StaticMutex, we move part of the mutex implementation into libstd.

The interface to the OS changed. Consequently, I removed a few functions, which aren't longer needed.
2020-10-24 22:39:44 +02:00
Tim Diekmann 955b37b305 Merge branch 'master' into box-alloc 2020-10-16 08:54:38 +02:00
Stefan Lankes 77d98316f4 minor changes to pass the format check 2020-10-13 12:22:18 +02:00
Stefan Lankes bc6b2ac449 move __rg_oom to the libos to avoid duplicated symbols 2020-10-13 12:06:48 +02:00
Camelid 95221b4eb5 Use intra-doc links for links to module-level docs 2020-10-12 19:22:47 -07:00
Ralf Jung b6bedc80c9 rename __default_lib_allocator -> __default_alloc_error_handler 2020-10-09 11:39:28 +02:00
Ralf Jung 1911d21866 also extend global allocator comment 2020-10-09 11:36:20 +02:00
Ralf Jung 6cd9b88a25 fix __rust_alloc_error_handler comment 2020-10-09 11:36:13 +02:00
Tim Diekmann f288cd2e17 Support custom allocators in Box
Remove `Box::leak_with_alloc`


Add leak-test for box with allocator


Rename `AllocErr` to `AllocError` in leak-test


Add `Box::alloc` and adjust examples to use the new API
2020-10-07 03:07:02 +02:00
Harald Hoyer cadd12b5f0 Implement Make handle_alloc_error default to panic (for no_std + liballoc)
Related: https://github.com/rust-lang/rust/issues/66741

Guarded with `#![feature(default_alloc_error_handler)]` a default
`alloc_error_handler` is called, if a custom allocator is used and no
other custom `#[alloc_error_handler]` is defined.

The panic message does not contain the size anymore, because it would
pull in the fmt machinery, which would blow up the code size
significantly.
2020-10-02 09:00:29 +02:00
Jacob Hughes 5829560a68 Rename AllocErr to AllocError 2020-09-28 14:51:03 -04:00
blitzerr 2b19b14cec a few more &mut self -> self changes 2020-09-22 21:04:31 -07:00
blitzerr 3ffd403c6b removing &mut self for other methods of AllocRef 2020-09-22 06:22:02 -07:00
blitzerr d9d02fa168 Changing the alloc() to accept &self instead of &mut self 2020-09-21 16:43:36 -07:00
Flying-Toast 2799aec6ab Capitalize safety comments 2020-09-08 22:37:18 -04:00
bors ffd59bf9c6 Auto merge of #75687 - TimDiekmann:realloc-align, r=Amanieu
Allow reallocation to different alignment in `AllocRef`

The allocator-wg [has decided](https://github.com/rust-lang/wg-allocators/issues/5#issuecomment-672591112) to support reallocating to a different alignment in `AllocRef`. For more details please see the linked issue.

r? @Amanieu

closes https://github.com/rust-lang/wg-allocators/issues/5
2020-08-26 10:44:28 +00:00
LeSeulArtichaut 1ababd8794 Use intra-doc-links in alloc 2020-08-21 00:25:25 +02:00
Tim Diekmann 438c40efa1 Allow reallocation to different alignment 2020-08-19 06:46:47 +02:00
Tim Diekmann 63d241a7b7 Make grow_impl unsafe 2020-08-18 15:22:10 +02:00
Tim Diekmann a9fe0ca47a Clean up AllocRef implementation and documentation 2020-08-18 09:53:22 +02:00
Tim Diekmann c48f784418 Fix typo in comment 2020-08-17 15:05:19 +02:00
Tim Diekmann c619b36975 Remove fast path in reallocation for same layout sizes 2020-08-17 13:23:38 +02:00
Tim Diekmann ab9362ad9a Replace Memoryblock with NonNull<[u8]> 2020-08-04 18:03:34 +02:00
Tim Diekmann b01fbc437e Simplify implementations of AllocRef for Global and System 2020-07-29 11:41:36 +02:00
Tim Diekmann 076ef66ba2 Remove in-place allocation and revert to separate methods for zeroed allocations
Fix docs
2020-07-28 12:41:18 +02:00
mark 2c31b45ae8 mv std libs to library/ 2020-07-27 19:51:13 -05:00