Googler | 75c7ad0 | 2022-05-23 13:27:49 -0700 | [diff] [blame] | 1 | // Part of the Crubit project, under the Apache License v2.0 with LLVM |
| 2 | // Exceptions. See /LICENSE for license information. |
| 3 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | |
| 5 | #include <stddef.h> |
| 6 | #include <stdlib.h> |
| 7 | |
| 8 | // Our temporary, local solution to |
| 9 | // https://github.com/rust-lang/rust/issues/73632. |
| 10 | |
| 11 | void *__rdl_alloc(size_t, size_t); |
| 12 | void __rdl_dealloc(void *); |
| 13 | void *__rdl_realloc(void *, size_t, size_t, size_t); |
| 14 | void *__rdl_alloc_zeroed(size_t, size_t); |
| 15 | |
| 16 | // https://stdrs.dev/nightly/x86_64-unknown-linux-gnu/alloc/alloc/index.html |
| 17 | |
| 18 | __attribute__((weak)) |
| 19 | void *__rust_alloc(size_t size, size_t align) { |
| 20 | return __rdl_alloc(size, align); |
| 21 | } |
| 22 | |
| 23 | __attribute__((weak)) |
| 24 | void __rust_dealloc(void *ptr) { |
| 25 | __rdl_dealloc(ptr); |
| 26 | } |
| 27 | |
| 28 | __attribute__((weak)) |
| 29 | void *__rust_realloc(void *ptr, size_t old_size, size_t align, |
| 30 | size_t new_size) { |
| 31 | return __rdl_realloc(ptr, old_size, align, new_size); |
| 32 | } |
| 33 | |
| 34 | __attribute__((weak)) |
| 35 | void *__rust_alloc_zeroed(size_t size, size_t align) { |
| 36 | return __rdl_alloc_zeroed(size, align); |
| 37 | } |
| 38 | |
| 39 | __attribute__((weak)) |
| 40 | void *__rust_alloc_error_handler(size_t size, size_t align) { |
| 41 | (void)size; |
| 42 | (void)align; |
| 43 | |
| 44 | abort(); |
| 45 | } |
Marcel Hlopko | 9ad0396 | 2022-06-03 02:23:13 -0700 | [diff] [blame] | 46 | |
| 47 | // This symbol is normally emitted by rustc. 0 means OOMs should abort, 1 means OOMs should panic. |
| 48 | unsigned char __attribute__((weak)) __rust_alloc_error_handler_should_panic = 1; |
Jing Lu | d476b75 | 2023-07-27 09:25:47 -0700 | [diff] [blame] | 49 | |
| 50 | // See https://github.com/rust-lang/rust/issues/73632#issuecomment-1563462239 |
| 51 | unsigned char __attribute__((weak)) __rust_no_alloc_shim_is_unstable = 0; |