@@ -14,10 +14,14 @@ unsafe impl GlobalAlloc for KernelAllocator {
14
14
unsafe fn alloc ( & self , layout : Layout ) -> * mut u8 {
15
15
// `krealloc()` is used instead of `kmalloc()` because the latter is
16
16
// an inline function and cannot be bound to as a result.
17
+ // SAFETY: FFI call.
17
18
unsafe { bindings:: krealloc ( ptr:: null ( ) , layout. size ( ) , bindings:: GFP_KERNEL ) as * mut u8 }
18
19
}
19
20
20
21
unsafe fn dealloc ( & self , ptr : * mut u8 , _layout : Layout ) {
22
+ // SAFETY: the caller must guarantee that `ptr` and `layout` denote memory
23
+ // allocated by this allocator, so allocated with `kmalloc`.
24
+ // FFI call.
21
25
unsafe {
22
26
bindings:: kfree ( ptr as * const c_types:: c_void ) ;
23
27
}
@@ -32,16 +36,21 @@ static ALLOCATOR: KernelAllocator = KernelAllocator;
32
36
// let's generate them ourselves instead.
33
37
#[ no_mangle]
34
38
pub fn __rust_alloc ( size : usize , _align : usize ) -> * mut u8 {
39
+ // SAFETY: FFI call.
35
40
unsafe { bindings:: krealloc ( core:: ptr:: null ( ) , size, bindings:: GFP_KERNEL ) as * mut u8 }
36
41
}
37
42
38
43
#[ no_mangle]
39
44
pub fn __rust_dealloc ( ptr : * mut u8 , _size : usize , _align : usize ) {
45
+ // SAFETY: the caller must guarantee that `ptr` and `layout` denote memory
46
+ // allocated by this allocator, so allocated with `kmalloc`.
47
+ // FFI call.
40
48
unsafe { bindings:: kfree ( ptr as * const c_types:: c_void ) } ;
41
49
}
42
50
43
51
#[ no_mangle]
44
52
pub fn __rust_realloc ( ptr : * mut u8 , _old_size : usize , _align : usize , new_size : usize ) -> * mut u8 {
53
+ // SAFETY: FFI call.
45
54
unsafe {
46
55
bindings:: krealloc (
47
56
ptr as * const c_types:: c_void ,
@@ -53,6 +62,7 @@ pub fn __rust_realloc(ptr: *mut u8, _old_size: usize, _align: usize, new_size: u
53
62
54
63
#[ no_mangle]
55
64
pub fn __rust_alloc_zeroed ( size : usize , _align : usize ) -> * mut u8 {
65
+ // SAFETY: FFI call.
56
66
unsafe {
57
67
bindings:: krealloc (
58
68
core:: ptr:: null ( ) ,
0 commit comments