about summary refs log tree commit diff
path: root/library/alloc/src/alloc.rs
AgeCommit message (Collapse)AuthorLines
2023-03-28Remove ~const from allocJubilee Young-7/+1
2023-01-14Remove various double spaces in source comments.André Vennberg-2/+2
2023-01-03Rollup merge of #106045 - RalfJung:oom-nounwind-panic, r=AmanieuMichael Goulet-1/+14
default OOM handler: use non-unwinding panic, to match std handler The OOM handler in std will by default abort. This adjusts the default in liballoc to do the same, using the `can_unwind` flag on the panic info to indicate a non-unwinding panic. In practice this probably makes little difference since the liballoc default will only come into play in no-std situations where people write a custom panic handler, which most likely will not implement unwinding. But still, this seems more consistent. Cc `@rust-lang/wg-allocators,` https://github.com/rust-lang/rust/issues/66741
2023-01-02default OOM handler: use non-unwinding panic (unless -Zoom=panic is set), to ↵Ralf Jung-1/+14
match std handler
2022-12-30Replace libstd, libcore, liballoc in line comments.jonathanCogan-1/+1
2022-12-28Update bootstrap cfgPietro Albini-13/+0
2022-11-06cfg-step codeMark Rousskov-8/+4
2022-10-31Rewrite implementation of `#[alloc_error_handler]`Amanieu d'Antras-6/+5
The new implementation doesn't use weak lang items and instead changes `#[alloc_error_handler]` to an attribute macro just like `#[global_allocator]`. The attribute will generate the `__rg_oom` function which is called by the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom` function is defined in any crate then the compiler shim will call `__rdl_oom` in the alloc crate which will simply panic. This also fixes link errors with `-C link-dead-code` with `default_alloc_error_handler`: `__rg_oom` was previously defined in the alloc crate and would attempt to reference the `oom` lang item, even if it didn't exist. This worked as long as `__rg_oom` was excluded from linking since it was not called. This is a prerequisite for the stabilization of `default_alloc_error_handler` (#102318).
2022-10-11rename rustc_allocator_nounwind to rustc_nounwindRalf Jung-4/+8
2022-08-12Adjust cfgsMark Rousskov-3/+3
2022-07-26codegen: use new {re,de,}allocator annotations in llvmAugie Fackler-1/+4
This obviates the patch that teaches LLVM internals about _rust_{re,de}alloc functions by putting annotations directly in the IR for the optimizer. The sole test change is required to anchor FileCheck to the body of the `box_uninitialized` method, so it doesn't see the `allocalign` on `__rust_alloc` and get mad about the string `alloca` showing up. Since I was there anyway, I added some checks on the attributes to prove the right attributes got set. While we're here, we also emit allocator attributes on __rust_alloc_zeroed. This should allow LLVM to perform more optimizations for zeroed blocks, and probably fixes #90032. [This comment](https://github.com/rust-lang/rust/issues/24194#issuecomment-308791157) mentions "weird UB-like behaviour with bitvec iterators in rustc_data_structures" so we may need to back this change out if things go wrong. The new test cases require LLVM 15, so we copy them into LLVM 14-supporting versions, which we can delete when we drop LLVM 14.
2022-07-14add missing null ptr check in alloc exampleRalf Jung-1/+4
2022-05-19Auto merge of #97033 - nbdd0121:unwind3, r=Amanieubors-2/+2
Remove libstd's calls to `C-unwind` foreign functions Remove all libstd and its dependencies' usage of `extern "C-unwind"`. This is a prerequiste of a WIP PR which will forbid libraries calling `extern "C-unwind"` functions to be compiled in `-Cpanic=unwind` and linked against `panic_abort` (this restriction is necessary to address soundness bug #96926). Cargo will ensure all crates are compiled with the same `-Cpanic` but the std is only compiled `-Cpanic=unwind` but needs the ability to be linked into `-Cpanic=abort`. Currently there are two places where `C-unwind` is used in libstd: * `__rust_start_panic` is used for interfacing to the panic runtime. This could be `extern "Rust"` * `_{rdl,rg}_oom`: a shim `__rust_alloc_error_handler` will be generated by codegen to call into one of these; they can also be `extern "Rust"` (in fact, the generated shim is used as `extern "Rust"`, so I am not even sure why these are not, probably because they used to `extern "C"` and was changed to `extern "C-unwind"` when we allow alloc error hooks to unwind, but they really should just be using Rust ABI). For dependencies, there is only one `extern "C-unwind"` function call, in `unwind` crate. This can be expressed as a re-export. More dicussions can be seen in the Zulip thread: https://rust-lang.zulipchat.com/#narrow/stream/210922-project-ffi-unwind/topic/soundness.20in.20mixed.20panic.20mode `@rustbot` label: T-libs F-c_unwind
2022-05-14Rollup merge of #95365 - mkroening:hermit-alloc-error-handler, r=joshtriplettYuki Okushi-1/+1
Use default alloc_error_handler for hermit Hermit now properly separates kernel from userspace. Applications for hermit can now use Rust's default `alloc_error_handler` instead of calling the kernel's `__rg_oom`. CC: ``@stlankes``
2022-05-14Use Rust ABI for `__rust_start_panic` and `_{rdl,rg}_oom`Gary Guo-2/+2
2022-04-05trivial cfg(bootstrap) changesPietro Albini-5/+1
2022-03-27Use default alloc_error_handler for hermitMartin Kröning-1/+1
Hermit now properly separates kernel from userspace. Applications for hermit can now use Rust's default alloc_error_handler instead of calling the kernel's __rg_oom.
2022-03-21Rename `~const Drop` to `~const Destruct`Deadbeef-1/+7
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-1/+1
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-02-05Mark __rgl_oom and __rd_oom as "C-unwind"Amanieu d'Antras-2/+2
2022-02-05Allow handle_alloc_error to unwindAmanieu d'Antras-2/+0
2022-01-04Add tracking issues (`const_box`, `const_alloc_error`)woppopo-2/+2
2021-12-23Constify `Box<T, A>` methodswoppopo-5/+18
2021-10-30Add #[must_use] to alloc functions that would leak memoryJohn Kugelman-0/+3
2021-09-25Use Rvalue::ShallowInitBox for box expressionGary Guo-1/+0
2021-08-22Fix typos “a”→“an”Frank Steffahn-1/+1
2021-05-05alloc: Add unstable Cfg feature `no-global_oom_handling`John Ericson-4/+5
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-01-12move WriteCloneIntoRaw into alloc::allocJosh Stone-0/+23
2020-12-04 Rename `AllocRef` to `Allocator` and `(de)alloc` to `(de)allocate`Tim Diekmann-20/+20
2020-11-23Auto merge of #79172 - a1phyr:cold_abort, r=Mark-Simulacrumbors-0/+1
Add #[cold] attribute to `std::process::abort` and `alloc::alloc::handle_alloc_error`
2020-11-19Bump bootstrap compiler versionJake Goulding-17/+2
2020-11-18Add #[cold] to `abort` and `handle_alloc_error`Benoît du Garreau-0/+1
2020-11-15document that __rust_alloc is also magic to our LLVM forkRalf Jung-0/+2
2020-10-25Merge remote-tracking branch 'upstream/master' into box-allocTim Diekmann-1/+1
2020-10-24Rollup merge of #77610 - hermitcore:dtors, r=m-ou-seJonas Schievink-1/+1
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-16Merge branch 'master' into box-allocTim Diekmann-6/+15
2020-10-13minor changes to pass the format checkStefan Lankes-1/+1
2020-10-13move __rg_oom to the libos to avoid duplicated symbolsStefan Lankes-1/+1
2020-10-12Use intra-doc links for links to module-level docsCamelid-3/+3
2020-10-09rename __default_lib_allocator -> __default_alloc_error_handlerRalf Jung-1/+1
2020-10-09also extend global allocator commentRalf Jung-2/+3
2020-10-09fix __rust_alloc_error_handler commentRalf Jung-2/+10
2020-10-07Support custom allocators in `Box`Tim Diekmann-4/+15
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-02Implement Make `handle_alloc_error` default to panic (for no_std + liballoc)Harald Hoyer-0/+47
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-09-28Rename AllocErr to AllocErrorJacob Hughes-10/+10
2020-09-22a few more &mut self -> self changesblitzerr-4/+4
2020-09-22removing &mut self for other methods of AllocRefblitzerr-2/+2
2020-09-21Changing the alloc() to accept &self instead of &mut selfblitzerr-2/+2
2020-09-08Capitalize safety commentsFlying-Toast-1/+1
2020-08-26Auto merge of #75687 - TimDiekmann:realloc-align, r=Amanieubors-34/+55
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