mirror of
https://github.com/justinian/jsix.git
synced 2025-12-11 00:44:31 -08:00
This commit makes several fundamental changes to memory handling:
- the frame allocator is now only an allocator for free frames, and does
not track used frames.
- the frame allocator now stores its free list inside the free frames
themselves, as a hybrid stack/span model.
- This has the implication that all frames must currently fit within
the offset area.
- kutil has a new allocator interface, which is the only allowed way for
any code outside of src/kernel to allocate. Code under src/kernel
_may_ use new/delete, but should prefer the allocator interface.
- the heap manager has become heap_allocator, which is merely an
implementation of kutil::allocator which doles out sections of a given
address range.
- the heap manager now only writes block headers when necessary,
avoiding page faults until they're actually needed
- page_manager now has a page fault handler, which checks with the
address_manager to see if the address is known, and provides a frame
mapping if it is, allowing heap manager to work with its entire
address size from the start. (Currently 32GiB.)
36 lines
738 B
C++
36 lines
738 B
C++
#include "kutil/memory.h"
|
|
|
|
namespace std {
|
|
enum class __attribute__ ((__type_visibility("default"))) align_val_t : size_t { };
|
|
}
|
|
|
|
namespace kutil {
|
|
|
|
void *
|
|
memset(void *s, uint8_t v, size_t n)
|
|
{
|
|
uint8_t *p = reinterpret_cast<uint8_t *>(s);
|
|
for (size_t i = 0; i < n; ++i) p[i] = v;
|
|
return s;
|
|
}
|
|
|
|
void *
|
|
memcpy(void *dest, const void *src, size_t n)
|
|
{
|
|
const uint8_t *s = reinterpret_cast<const uint8_t *>(src);
|
|
uint8_t *d = reinterpret_cast<uint8_t *>(dest);
|
|
for (size_t i = 0; i < n; ++i) d[i] = s[i];
|
|
return d;
|
|
}
|
|
|
|
uint8_t
|
|
checksum(const void *p, size_t len, size_t off)
|
|
{
|
|
uint8_t sum = 0;
|
|
const uint8_t *c = reinterpret_cast<const uint8_t *>(p);
|
|
for (int i = off; i < len; ++i) sum += c[i];
|
|
return sum;
|
|
}
|
|
|
|
} // namespace kutil
|