mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
[boot] Improve bootloader allocation accounting
The bootloader relied on the kernel to know which parts of memory to not allocate over. For the future shift of having the init process load other processes instead of the kernel, the bootloader needs a mechanism to just hand the kernel a list of allocations. This is now done through the new bootloader allocator, which all allocation goes through. Pool memory will not be tracked, and so can be overwritten - this means the args structure and its other structures like programs need to be handled right away, or copied by the kernel. - Add bootloader allocator - Implement a new linked-list based set of pages that act as allocation registers - Allow for operator new in the bootloader, which goes through the global allocator for pool memory - Split memory map and frame accouting code in the bootloader into separate memory_map.* files - Remove many includes that could be replaced by forward declaration in the bootloader - Add a new global template type, `counted`, which replaces the bootloader's `buffer` type, and updated kernel args structure to use it. - Move bootloader's pointer_manipulation.h to the global include dir - Make offset_iterator try to return references instead of pointers to make it more consistent with static array iteration - Implement a stub atexit() in the bootloader to satisfy clang
This commit is contained in:
57
src/boot/allocator.h
Normal file
57
src/boot/allocator.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
/// \file allocator.h
|
||||
/// Page allocator class definition
|
||||
|
||||
#include "kernel_args.h"
|
||||
|
||||
namespace uefi {
|
||||
class boot_services;
|
||||
}
|
||||
|
||||
namespace boot {
|
||||
namespace memory {
|
||||
|
||||
using alloc_type = kernel::init::allocation_type;
|
||||
|
||||
class allocator
|
||||
{
|
||||
public:
|
||||
using allocation_register = kernel::init::allocation_register;
|
||||
|
||||
allocator(uefi::boot_services &bs);
|
||||
|
||||
void * allocate(size_t size, bool zero = false);
|
||||
void free(void *p);
|
||||
|
||||
void * allocate_pages(size_t count, alloc_type type, bool zero = false);
|
||||
|
||||
void memset(void *start, size_t size, uint8_t value);
|
||||
void copy(void *to, void *from, size_t size);
|
||||
|
||||
inline void zero(void *start, size_t size) { memset(start, size, 0); }
|
||||
|
||||
allocation_register * get_register() { return m_register; }
|
||||
|
||||
private:
|
||||
void add_register();
|
||||
|
||||
uefi::boot_services &m_bs;
|
||||
|
||||
allocation_register *m_register;
|
||||
allocation_register *m_current;
|
||||
};
|
||||
|
||||
/// Initialize the global allocator
|
||||
void init_allocator(uefi::boot_services *bs);
|
||||
|
||||
} // namespace memory
|
||||
|
||||
extern memory::allocator &g_alloc;
|
||||
|
||||
} // namespace boot
|
||||
|
||||
void * operator new (size_t size, void *p);
|
||||
void * operator new(size_t size);
|
||||
void * operator new [] (size_t size);
|
||||
void operator delete (void *p) noexcept;
|
||||
void operator delete [] (void *p) noexcept;
|
||||
Reference in New Issue
Block a user