blob: 3e6ba96c8f39791c74b4eb2f4a0e5c8be34b3517 [file] [log] [blame]
Brian Silverman8751d482022-05-18 23:28:44 -07001#include <stdint.h>
2
3// This file has some exciting magic to get Rust code linking in a cc_binary.
4// The Rust compiler generates some similar symbol aliases when it links, so we
5// have to do it manually.
6//
7// It is intended to be used in rust_toolchain.allocator_library.
8//
9// https://github.com/rust-lang/rust/blob/master/library/alloc/src/alloc.rs
10// and https://github.com/rust-lang/rust/blob/master/library/std/src/alloc.rs
11// are the best source of docs I've found on these functions and variables.
12// https://doc.rust-lang.org/std/alloc/index.html talks about how this is
13// intended to be used.
14//
15// Also note
16// https://rust-lang.github.io/unsafe-code-guidelines/layout/scalars.html for
17// the sizes of the various integer types.
18//
19// This file strongly assumes that the default allocator is used. It will
20// not work with any other allocated switched in via `#[global_allocator]`.
21
22// New feature as of https://github.com/rust-lang/rust/pull/88098.
23uint8_t __rust_alloc_error_handler_should_panic = 0;
24
25uint8_t *__rdl_alloc(uintptr_t size, uintptr_t align);
26uint8_t *__rust_alloc(uintptr_t size, uintptr_t align) {
27 return __rdl_alloc(size, align);
28}
29void __rdl_dealloc(uint8_t *ptr, uintptr_t size, uintptr_t align);
30void __rust_dealloc(uint8_t *ptr, uintptr_t size, uintptr_t align) {
31 __rdl_dealloc(ptr, size, align);
32}
33uint8_t *__rdl_realloc(uint8_t *ptr, uintptr_t old_size, uintptr_t align,
34 uintptr_t new_size);
35uint8_t *__rust_realloc(uint8_t *ptr, uintptr_t old_size, uintptr_t align,
36 uintptr_t new_size) {
37 return __rdl_realloc(ptr, old_size, align, new_size);
38}
39uint8_t *__rdl_alloc_zeroed(uintptr_t size, uintptr_t align);
40uint8_t *__rust_alloc_zeroed(uintptr_t size, uintptr_t align) {
41 return __rdl_alloc_zeroed(size, align);
42}
43void __rdl_oom(uintptr_t size, uintptr_t align);
44void __rust_alloc_error_handler(uintptr_t size, uintptr_t align) {
45 __rdl_oom(size, align);
46}