119 lines
2.1 KiB
Plaintext
119 lines
2.1 KiB
Plaintext
OS_Linux_PROT = bits u32
|
|
{
|
|
read: u1,
|
|
write: u1,
|
|
execute: u1,
|
|
sem: u1,
|
|
_: u28,
|
|
}
|
|
|
|
OS_Linux_MAP_Type = enum u4
|
|
{
|
|
shared = 0x1,
|
|
private = 0x2,
|
|
shared_validate = 0x3,
|
|
}
|
|
|
|
OS_Linux_MAP = bits u32
|
|
{
|
|
type: OS_Linux_MAP_Type,
|
|
fixed: u1,
|
|
anonymous: u1,
|
|
bit_32: u1,
|
|
_: u1,
|
|
grows_down: u1,
|
|
_: u2,
|
|
deny_write: u1,
|
|
executable: u1,
|
|
locked: u1,
|
|
no_reserve: u1,
|
|
populate: u1,
|
|
non_block: u1,
|
|
stack: u1,
|
|
huge_tlb: u1,
|
|
sync: u1,
|
|
fixed_noreplace: u1,
|
|
_: u5,
|
|
uninitialized: u1,
|
|
_: u5,
|
|
}
|
|
|
|
[extern] mmap = fn [cc(c)] (address: u64, size: u64, protection: OS_Linux_PROT, map: OS_Linux_MAP, file_descriptor: s32, offset: s64) &u8;
|
|
|
|
OS_ProtectionFlags = bits
|
|
{
|
|
read: u1,
|
|
write: u1,
|
|
execute: u1,
|
|
}
|
|
|
|
OS_MapFlags = bits
|
|
{
|
|
private: u1,
|
|
anonymous: u1,
|
|
no_reserve: u1,
|
|
populate: u1,
|
|
}
|
|
|
|
os_linux_protection_flags = fn(map_flags: OS_ProtectionFlags) OS_Linux_PROT
|
|
{
|
|
return {
|
|
.read = map_flags.read,
|
|
.write = map_flags.write,
|
|
.execute = map_flags.execute,
|
|
zero,
|
|
};
|
|
}
|
|
|
|
os_linux_map_flags = fn(map_flags: OS_MapFlags) OS_Linux_MAP
|
|
{
|
|
return {
|
|
.type = #select(map_flags.private, .private, .shared),
|
|
.anonymous = map_flags.anonymous,
|
|
.no_reserve = map_flags.no_reserve,
|
|
.populate = map_flags.populate,
|
|
zero,
|
|
};
|
|
}
|
|
|
|
os_reserve = fn (base: u64, size: u64, protection: OS_ProtectionFlags, map: OS_MapFlags) &u8
|
|
{
|
|
>protection_flags = os_linux_protection_flags(protection);
|
|
>map_flags = os_linux_map_flags(map);
|
|
>address = mmap(base, size, protection_flags, map_flags, -1, 0);
|
|
if (#int_from_pointer(address) == #integer_max(u64))
|
|
{
|
|
unreachable;
|
|
}
|
|
else
|
|
{
|
|
}
|
|
}
|
|
|
|
Arena = struct
|
|
{
|
|
reserved_size: u64,
|
|
position: u64,
|
|
os_position: u64,
|
|
granularity: u64,
|
|
reserved: [32]u8,
|
|
}
|
|
|
|
minimum_position: u64 = #byte_size(Arena);
|
|
|
|
ArenaInitialization = struct
|
|
{
|
|
reserved_size: u64,
|
|
granularity: u64,
|
|
initial_size: u64,
|
|
}
|
|
|
|
arena_initialize = fn (initialization: ArenaInitialization) &Arena
|
|
{
|
|
}
|
|
|
|
[export] main = fn [cc(c)] () s32
|
|
{
|
|
return 0;
|
|
}
|