1 // Copyright 2024 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 #include "pw_allocator/last_fit_block_allocator.h" 16 17 #include "pw_malloc/config.h" 18 #include "pw_malloc/malloc.h" 19 20 namespace pw::malloc { 21 namespace { 22 23 using LastFitBlockAllocator = 24 ::pw::allocator::LastFitBlockAllocator<PW_MALLOC_BLOCK_OFFSET_TYPE, 25 PW_MALLOC_BLOCK_POISON_INTERVAL, 26 PW_MALLOC_BLOCK_ALIGNMENT>; 27 GetLastFitBlockAllocator()28LastFitBlockAllocator& GetLastFitBlockAllocator() { 29 static LastFitBlockAllocator allocator; 30 return allocator; 31 } 32 33 } // namespace 34 GetSystemAllocator()35Allocator* GetSystemAllocator() { 36 auto& system_allocator = GetLastFitBlockAllocator(); 37 return &system_allocator; 38 } 39 InitSystemAllocator(ByteSpan heap)40void InitSystemAllocator(ByteSpan heap) { 41 auto& system_allocator = GetLastFitBlockAllocator(); 42 system_allocator.Init(heap); 43 } 44 45 } // namespace pw::malloc 46