Skip to content

Commit

Permalink
Add 32 bit address allocation on 64 bits systems.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlixANNERAUD committed Nov 15, 2024
1 parent eb8ebf1 commit 39688d9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions Modules/ABI/include/Xila.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ extern const Xila_memory_protection_type Xila_memory_protection_execute;
extern const Xila_memory_flag_type Xila_memory_flag_anonymous;
extern const Xila_memory_flag_type Xila_memory_flag_private;
extern const Xila_memory_flag_type Xila_memory_flag_fixed;
extern const Xila_memory_flag_type Xila_memory_flag_address_32_bits;

void *Rust_function Xila_memory_allocate_custom(void *Pointer, size_t Size, uint8_t Alignment, Xila_memory_protection_type Protection, Xila_memory_flag_type Flags);
void Rust_function Xila_memory_deallocate_custom(void *Pointer, size_t Size);
Expand Down
2 changes: 2 additions & 0 deletions Modules/ABI/src/Memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ pub static Xila_memory_flag_anonymous: u8 = Flags_type::Anonymous_bit;
pub static Xila_memory_flag_fixed: u8 = Flags_type::Fixed_bit;
#[no_mangle]
pub static Xila_memory_flag_private: u8 = Flags_type::Private_bit;
#[no_mangle]
pub static Xila_memory_flag_address_32_bits: u8 = Flags_type::Address_32_bits;

/// This function is used to allocate a memory region.
///
Expand Down
4 changes: 0 additions & 4 deletions Modules/Memory/src/Espressif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ impl Memory_allocator_trait for Memory_allocator_type {
MALLOC_CAP_8BIT
};

#[cfg(esp_idf_comp_esp_psram_enabled)]
let _Caps = esp_idf_sys::MALLOC_CAP_SPIRAM;

let Address =
Expand Down Expand Up @@ -58,10 +57,8 @@ impl Memory_allocator_trait for Memory_allocator_type {
}
}

#[cfg(esp_idf_comp_esp_psram_enabled)]
static Mutex: std::sync::Mutex<()> = std::sync::Mutex::new(());

#[cfg(esp_idf_comp_esp_psram_enabled)]
extern "C" {
fn Cache_WriteBack_All();
fn Cache_Disable_ICache() -> u32;
Expand All @@ -70,7 +67,6 @@ extern "C" {

#[link_section = ".iram1"]
pub fn Flush_data_cache() {
#[cfg(esp_idf_comp_esp_psram_enabled)]
{
let _Guard = Mutex
.lock()
Expand Down
10 changes: 10 additions & 0 deletions Modules/Memory/src/Flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ impl Debug for Flags_type {
.field("Anonymous", &self.Get_anonymous())
.field("Fixed", &self.Get_fixed())
.field("Private", &self.Get_private())
.field("Address_32_bits", &self.Get_address_32_bits())
.finish()
}
}
Expand All @@ -19,6 +20,7 @@ impl Flags_type {
pub const Anonymous_bit: u8 = 1 << 0;
pub const Fixed_bit: u8 = 1 << 1;
pub const Private_bit: u8 = 1 << 2;
pub const Address_32_bits: u8 = 1 << 3;

pub fn New(Anonymous: bool, Fixed: bool) -> Self {
let mut Flags = Self(0);
Expand Down Expand Up @@ -57,6 +59,10 @@ impl Flags_type {
self.Set_bits(Self::Private_bit, Value)
}

pub fn Set_address_32_bits(&mut self, Value: bool) -> &mut Self {
self.Set_bits(Self::Address_32_bits, Value)
}

pub const fn Get_anonymous(&self) -> bool {
self.Get_bits(Self::Anonymous_bit)
}
Expand All @@ -68,6 +74,10 @@ impl Flags_type {
pub const fn Get_private(&self) -> bool {
self.Get_bits(Self::Private_bit)
}

pub const fn Get_address_32_bits(&self) -> bool {
self.Get_bits(Self::Address_32_bits)
}
}

impl From<Flags_type> for u8 {
Expand Down
8 changes: 6 additions & 2 deletions Modules/Memory/src/Native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use core::ptr::NonNull;
use std::os::raw::c_void;

use libc::{
mmap, mprotect, munmap, sysconf, MAP_ANONYMOUS, MAP_FAILED, MAP_FIXED, MAP_PRIVATE, PROT_EXEC,
PROT_NONE, PROT_READ, PROT_WRITE, _SC_PAGE_SIZE,
mmap, mprotect, munmap, sysconf, MAP_32BIT, MAP_ANONYMOUS, MAP_FAILED, MAP_FIXED, MAP_PRIVATE,
PROT_EXEC, PROT_NONE, PROT_READ, PROT_WRITE, _SC_PAGE_SIZE,
};

use crate::{Flags_type, Layout_type, Memory_allocator_trait, Protection_type};
Expand Down Expand Up @@ -40,6 +40,10 @@ impl Memory_allocator_trait for Memory_allocator_type {
Libc_flags |= MAP_FIXED;
}

if Flags.Get_address_32_bits() {
Libc_flags |= MAP_32BIT;
}

// TODO : Add MAP_JIT flag for macOS, iOS and ARM64

let Protection = Get_libc_protection(Protection);
Expand Down
3 changes: 3 additions & 0 deletions Modules/Virtual_machine/WAMR/src/Core.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ Xila_memory_flag_type To_xila_memory_flags(int flags)
if (flags & MMAP_MAP_FIXED)
Xila_flags |= Xila_memory_flag_fixed;

if (flags & MMAP_MAP_32BIT)
Xila_flags |= Xila_memory_flag_address_32_bits;

return Xila_flags;
}

Expand Down

0 comments on commit 39688d9

Please sign in to comment.