blob: fbf4de47df9f8311af7a6c7b5d1e2c101e4db529 [file] [log] [blame]
Googler75c7ad02022-05-23 13:27:49 -07001// 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
11void *__rdl_alloc(size_t, size_t);
12void __rdl_dealloc(void *);
13void *__rdl_realloc(void *, size_t, size_t, size_t);
14void *__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))
19void *__rust_alloc(size_t size, size_t align) {
20 return __rdl_alloc(size, align);
21}
22
23__attribute__((weak))
24void __rust_dealloc(void *ptr) {
25 __rdl_dealloc(ptr);
26}
27
28__attribute__((weak))
29void *__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))
35void *__rust_alloc_zeroed(size_t size, size_t align) {
36 return __rdl_alloc_zeroed(size, align);
37}
38
39__attribute__((weak))
40void *__rust_alloc_error_handler(size_t size, size_t align) {
41 (void)size;
42 (void)align;
43
44 abort();
45}
Marcel Hlopko9ad03962022-06-03 02:23:13 -070046
47// This symbol is normally emitted by rustc. 0 means OOMs should abort, 1 means OOMs should panic.
48unsigned char __attribute__((weak)) __rust_alloc_error_handler_should_panic = 1;
Jing Lud476b752023-07-27 09:25:47 -070049
50// See https://github.com/rust-lang/rust/issues/73632#issuecomment-1563462239
51unsigned char __attribute__((weak)) __rust_no_alloc_shim_is_unstable = 0;