mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[project] Lose the battle between tabs & spaces
I'm a tabs guy. I like tabs, it's an elegant way to represent indentation instead of brute-forcing it. But I have to admit that the world seems to be going towards spaces, and tooling tends not to play nice with tabs. So here we go, changing the whole repo to spaces since I'm getting tired of all the inconsistent formatting.
This commit is contained in:
committed by
Justin C. Miller
parent
d36b2d8057
commit
8f529046a9
@@ -24,139 +24,139 @@ static_assert(sizeof(allocation_register) == page_size);
|
||||
|
||||
void
|
||||
allocator::init(
|
||||
allocation_register *&allocs,
|
||||
modules_page *&modules,
|
||||
uefi::boot_services *bs)
|
||||
allocation_register *&allocs,
|
||||
modules_page *&modules,
|
||||
uefi::boot_services *bs)
|
||||
{
|
||||
new (&g_alloc) allocator(*bs);
|
||||
allocs = g_alloc.m_register;
|
||||
modules = g_alloc.m_modules;
|
||||
new (&g_alloc) allocator(*bs);
|
||||
allocs = g_alloc.m_register;
|
||||
modules = g_alloc.m_modules;
|
||||
}
|
||||
|
||||
|
||||
allocator::allocator(uefi::boot_services &bs) :
|
||||
m_bs(bs),
|
||||
m_register(nullptr),
|
||||
m_modules(nullptr)
|
||||
m_bs(bs),
|
||||
m_register(nullptr),
|
||||
m_modules(nullptr)
|
||||
{
|
||||
add_register();
|
||||
add_modules();
|
||||
add_register();
|
||||
add_modules();
|
||||
}
|
||||
|
||||
void
|
||||
allocator::add_register()
|
||||
{
|
||||
allocation_register *reg = nullptr;
|
||||
allocation_register *reg = nullptr;
|
||||
|
||||
try_or_raise(
|
||||
m_bs.allocate_pages(uefi::allocate_type::any_pages,
|
||||
uefi::memory_type::loader_data, 1, reinterpret_cast<void**>(®)),
|
||||
L"Failed allocating allocation register page");
|
||||
try_or_raise(
|
||||
m_bs.allocate_pages(uefi::allocate_type::any_pages,
|
||||
uefi::memory_type::loader_data, 1, reinterpret_cast<void**>(®)),
|
||||
L"Failed allocating allocation register page");
|
||||
|
||||
m_bs.set_mem(reg, sizeof(allocation_register), 0);
|
||||
m_bs.set_mem(reg, sizeof(allocation_register), 0);
|
||||
|
||||
if (m_register)
|
||||
m_register->next = reg;
|
||||
if (m_register)
|
||||
m_register->next = reg;
|
||||
|
||||
m_register = reg;
|
||||
return;
|
||||
m_register = reg;
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
allocator::add_modules()
|
||||
{
|
||||
modules_page *mods = reinterpret_cast<modules_page*>(
|
||||
allocate_pages(1, alloc_type::init_args, true));
|
||||
modules_page *mods = reinterpret_cast<modules_page*>(
|
||||
allocate_pages(1, alloc_type::init_args, true));
|
||||
|
||||
if (m_modules)
|
||||
m_modules->next = reinterpret_cast<uintptr_t>(mods);
|
||||
if (m_modules)
|
||||
m_modules->next = reinterpret_cast<uintptr_t>(mods);
|
||||
|
||||
mods->modules = reinterpret_cast<module*>(mods + 1);
|
||||
m_modules = mods;
|
||||
m_next_mod = mods->modules;
|
||||
return;
|
||||
mods->modules = reinterpret_cast<module*>(mods + 1);
|
||||
m_modules = mods;
|
||||
m_next_mod = mods->modules;
|
||||
return;
|
||||
}
|
||||
|
||||
void *
|
||||
allocator::allocate_pages(size_t count, alloc_type type, bool zero)
|
||||
{
|
||||
if (count & ~0xffffffffull) {
|
||||
error::raise(uefi::status::unsupported,
|
||||
L"Cannot allocate more than 16TiB in pages at once.",
|
||||
__LINE__);
|
||||
}
|
||||
if (count & ~0xffffffffull) {
|
||||
error::raise(uefi::status::unsupported,
|
||||
L"Cannot allocate more than 16TiB in pages at once.",
|
||||
__LINE__);
|
||||
}
|
||||
|
||||
if (!m_register || m_register->count == 0xff)
|
||||
add_register();
|
||||
if (!m_register || m_register->count == 0xff)
|
||||
add_register();
|
||||
|
||||
void *pages = nullptr;
|
||||
void *pages = nullptr;
|
||||
|
||||
try_or_raise(
|
||||
m_bs.allocate_pages(uefi::allocate_type::any_pages,
|
||||
uefi::memory_type::loader_data, count, &pages),
|
||||
L"Failed allocating usable pages");
|
||||
try_or_raise(
|
||||
m_bs.allocate_pages(uefi::allocate_type::any_pages,
|
||||
uefi::memory_type::loader_data, count, &pages),
|
||||
L"Failed allocating usable pages");
|
||||
|
||||
page_allocation &ent = m_register->entries[m_register->count++];
|
||||
ent.address = reinterpret_cast<uintptr_t>(pages);
|
||||
ent.count = count;
|
||||
ent.type = type;
|
||||
page_allocation &ent = m_register->entries[m_register->count++];
|
||||
ent.address = reinterpret_cast<uintptr_t>(pages);
|
||||
ent.count = count;
|
||||
ent.type = type;
|
||||
|
||||
if (zero)
|
||||
m_bs.set_mem(pages, count * page_size, 0);
|
||||
if (zero)
|
||||
m_bs.set_mem(pages, count * page_size, 0);
|
||||
|
||||
return pages;
|
||||
return pages;
|
||||
}
|
||||
|
||||
module *
|
||||
allocator::allocate_module_untyped(size_t size)
|
||||
{
|
||||
size_t remaining =
|
||||
reinterpret_cast<uintptr_t>(m_modules) + page_size
|
||||
- reinterpret_cast<uintptr_t>(m_next_mod);
|
||||
size_t remaining =
|
||||
reinterpret_cast<uintptr_t>(m_modules) + page_size
|
||||
- reinterpret_cast<uintptr_t>(m_next_mod);
|
||||
|
||||
if (size > remaining)
|
||||
add_modules();
|
||||
if (size > remaining)
|
||||
add_modules();
|
||||
|
||||
++m_modules->count;
|
||||
module *m = m_next_mod;
|
||||
m_next_mod = offset_ptr<module>(m_next_mod, size);
|
||||
++m_modules->count;
|
||||
module *m = m_next_mod;
|
||||
m_next_mod = offset_ptr<module>(m_next_mod, size);
|
||||
|
||||
m->mod_length = size;
|
||||
return m;
|
||||
m->mod_length = size;
|
||||
return m;
|
||||
}
|
||||
|
||||
void *
|
||||
allocator::allocate(size_t size, bool zero)
|
||||
{
|
||||
void *p = nullptr;
|
||||
try_or_raise(
|
||||
m_bs.allocate_pool(uefi::memory_type::loader_data, size, &p),
|
||||
L"Could not allocate pool memory");
|
||||
void *p = nullptr;
|
||||
try_or_raise(
|
||||
m_bs.allocate_pool(uefi::memory_type::loader_data, size, &p),
|
||||
L"Could not allocate pool memory");
|
||||
|
||||
if (zero)
|
||||
m_bs.set_mem(p, size, 0);
|
||||
if (zero)
|
||||
m_bs.set_mem(p, size, 0);
|
||||
|
||||
return p;
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
allocator::free(void *p)
|
||||
{
|
||||
try_or_raise(
|
||||
m_bs.free_pool(p),
|
||||
L"Freeing pool memory");
|
||||
try_or_raise(
|
||||
m_bs.free_pool(p),
|
||||
L"Freeing pool memory");
|
||||
}
|
||||
|
||||
void
|
||||
allocator::memset(void *start, size_t size, uint8_t value)
|
||||
{
|
||||
m_bs.set_mem(start, size, value);
|
||||
m_bs.set_mem(start, size, value);
|
||||
}
|
||||
|
||||
void
|
||||
allocator::copy(void *to, void *from, size_t size)
|
||||
{
|
||||
m_bs.copy_mem(to, from, size);
|
||||
m_bs.copy_mem(to, from, size);
|
||||
}
|
||||
|
||||
} // namespace memory
|
||||
|
||||
Reference in New Issue
Block a user