xref: /haiku/src/system/boot/platform/efi/heap.cpp (revision 8bacd281ba5156920f4b8cfa1da7520122beab78)
1 /*
2  * Copyright 2016-2024, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <boot/platform.h>
8 #include <kernel/kernel.h>
9 
10 #include "efi_platform.h"
11 
12 
13 extern "C" ssize_t
14 platform_allocate_heap_region(size_t _size, void** _base)
15 {
16 	size_t pages = HOWMANY(_size, B_PAGE_SIZE);
17 	efi_physical_addr base;
18 	if (kBootServices->AllocatePages(AllocateAnyPages, EfiLoaderData, pages, &base) != EFI_SUCCESS)
19 		return B_NO_MEMORY;
20 
21 	*_base = (void*)base;
22 	return pages * B_PAGE_SIZE;
23 }
24 
25 
26 extern "C" void
27 platform_free_heap_region(void* base, size_t size)
28 {
29 	kBootServices->FreePages((efi_physical_addr)base, size / B_PAGE_SIZE);
30 }
31