Skip to content

Commit 5640d3d

Browse files
committed
Allocate sequential memory as if virtual paged
This forces allocated objects to be on the same page
1 parent a3d6da4 commit 5640d3d

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

engine/src/script/script.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,9 @@ gaddr_t Script::guest_alloc(gaddr_t bytes)
532532
return machine().arena().malloc(bytes);
533533
}
534534

535-
gaddr_t Script::guest_alloc_sequential(gaddr_t bytes)
535+
gaddr_t Script::guest_alloc_sequential(gaddr_t bytes, bool flat_arena)
536536
{
537-
return machine().arena().seq_alloc_aligned(bytes, 8, machine().memory.initial_rodata_end() != 0x0);
537+
return machine().arena().seq_alloc_aligned(bytes, 8, flat_arena && machine().memory.initial_rodata_end() != 0x0);
538538
}
539539

540540
bool Script::guest_free(gaddr_t addr)

engine/src/script/script.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@ struct Script
240240
/// consecutive array of bytes, allowing it to be used with many (if not most)
241241
/// APIs that do not handle fragmented memory.
242242
/// @param bytes The number of sequentially allocated 8-byte aligned bytes.
243+
/// @param flat_arena If enabled, treat arena memory as sequential.
243244
/// @return The address of the sequentially allocated bytes.
244-
gaddr_t guest_alloc_sequential(gaddr_t bytes);
245+
gaddr_t guest_alloc_sequential(gaddr_t bytes, bool flat_arena = false);
245246
bool guest_free(gaddr_t addr);
246247

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

543544
template <typename T> inline GuestObjects<T> Script::guest_alloc(size_t n)
544545
{
545-
auto addr = this->guest_alloc_sequential(sizeof(T) * n);
546+
auto addr = this->guest_alloc_sequential(sizeof(T) * n, false);
546547
if (addr != 0x0)
547548
{
548549
// Gather single writable buffer, making sure memory is not copy-on-write

ext/libriscv

0 commit comments

Comments
 (0)