File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,10 @@ impl<const ORDER: usize> FrameAllocator<ORDER> {
61
61
} else {
62
62
32
63
63
} ;
64
- let size = min ( lowbit, prev_power_of_two ( end - current_start) ) ;
64
+ let size = min (
65
+ min ( lowbit, prev_power_of_two ( end - current_start) ) ,
66
+ 1 << ( ORDER - 1 ) ,
67
+ ) ;
65
68
total += size;
66
69
67
70
self . free_list [ size. trailing_zeros ( ) as usize ] . insert ( current_start) ;
Original file line number Diff line number Diff line change @@ -122,11 +122,20 @@ fn test_frame_allocator_add() {
122
122
}
123
123
124
124
#[ test]
125
- #[ should_panic]
126
- fn test_frame_allocator_add_large_size_panics ( ) {
125
+ fn test_frame_allocator_allocate_large ( ) {
126
+ let mut frame = FrameAllocator :: < 32 > :: new ( ) ;
127
+ assert_eq ! ( frame. alloc( 10_000_000_000 ) , None ) ;
128
+ }
129
+
130
+ #[ test]
131
+ fn test_frame_allocator_add_large_size_split ( ) {
127
132
let mut frame = FrameAllocator :: < 32 > :: new ( ) ;
128
133
129
134
frame. insert ( 0 ..10_000_000_000 ) ;
135
+
136
+ assert_eq ! ( frame. alloc( 0x8000_0001 ) , None ) ;
137
+ assert_eq ! ( frame. alloc( 0x8000_0000 ) , Some ( 0x8000_0000 ) ) ;
138
+ assert_eq ! ( frame. alloc( 0x8000_0000 ) , Some ( 0x1_0000_0000 ) ) ;
130
139
}
131
140
132
141
#[ test]
You can’t perform that action at this time.
0 commit comments