Skip to content

Commit

Permalink
Allocate sequential memory as if virtual paged
Browse files Browse the repository at this point in the history
This forces allocated objects to be on the same page
  • Loading branch information
fwsGonzo committed Dec 19, 2024
1 parent a3d6da4 commit 5640d3d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions engine/src/script/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,9 @@ gaddr_t Script::guest_alloc(gaddr_t bytes)
return machine().arena().malloc(bytes);
}

gaddr_t Script::guest_alloc_sequential(gaddr_t bytes)
gaddr_t Script::guest_alloc_sequential(gaddr_t bytes, bool flat_arena)
{
return machine().arena().seq_alloc_aligned(bytes, 8, machine().memory.initial_rodata_end() != 0x0);
return machine().arena().seq_alloc_aligned(bytes, 8, flat_arena && machine().memory.initial_rodata_end() != 0x0);
}

bool Script::guest_free(gaddr_t addr)
Expand Down
5 changes: 3 additions & 2 deletions engine/src/script/script.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ struct Script
/// consecutive array of bytes, allowing it to be used with many (if not most)
/// APIs that do not handle fragmented memory.
/// @param bytes The number of sequentially allocated 8-byte aligned bytes.
/// @param flat_arena If enabled, treat arena memory as sequential.
/// @return The address of the sequentially allocated bytes.
gaddr_t guest_alloc_sequential(gaddr_t bytes);
gaddr_t guest_alloc_sequential(gaddr_t bytes, bool flat_arena = false);
bool guest_free(gaddr_t addr);

/// @brief Create a wrapper object that manages an allocation of n objects of type T
Expand Down Expand Up @@ -542,7 +543,7 @@ template <typename T> struct GuestObjects

template <typename T> inline GuestObjects<T> Script::guest_alloc(size_t n)
{
auto addr = this->guest_alloc_sequential(sizeof(T) * n);
auto addr = this->guest_alloc_sequential(sizeof(T) * n, false);
if (addr != 0x0)
{
// Gather single writable buffer, making sure memory is not copy-on-write
Expand Down
2 changes: 1 addition & 1 deletion ext/libriscv

0 comments on commit 5640d3d

Please sign in to comment.