mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-22 23:08:01 +00:00
allow dynamic configuration of the heap memory (#287)
This PR changes the implementation of the emulated EVM heap memory: Instead of linking in a C implementation the code is emitted directly into the contract module. Which allows making it configurable via a compiler parameter (a follow up PR to this). --------- Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
@@ -5,34 +5,6 @@
|
||||
|
||||
// Missing builtins
|
||||
|
||||
#define EVM_WORD_SIZE 32
|
||||
#define ALIGN(size) ((size + EVM_WORD_SIZE - 1) & ~(EVM_WORD_SIZE - 1))
|
||||
#define MAX_MEMORY_SIZE (64 * 1024)
|
||||
char __memory[MAX_MEMORY_SIZE];
|
||||
uint32_t __memory_size = 0;
|
||||
|
||||
void * __sbrk_internal(uint32_t offset, uint32_t size) {
|
||||
if (offset >= MAX_MEMORY_SIZE || size > MAX_MEMORY_SIZE) {
|
||||
POLKAVM_TRAP();
|
||||
}
|
||||
|
||||
uint32_t new_size = ALIGN(offset + size);
|
||||
if (new_size > MAX_MEMORY_SIZE) {
|
||||
POLKAVM_TRAP();
|
||||
}
|
||||
if (new_size > __memory_size) {
|
||||
__memory_size = new_size;
|
||||
}
|
||||
|
||||
return (void *)&__memory[offset];
|
||||
}
|
||||
|
||||
void * memset(void *b, int c, size_t len) {
|
||||
uint8_t *dest = b;
|
||||
while (len-- > 0) *dest++ = c;
|
||||
return b;
|
||||
}
|
||||
|
||||
void * memcpy(void *dst, const void *_src, size_t len) {
|
||||
uint8_t *dest = dst;
|
||||
const uint8_t *src = _src;
|
||||
|
||||
@@ -2,14 +2,6 @@ use inkwell::{context::Context, memory_buffer::MemoryBuffer, module::Module, sup
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/polkavm_imports.rs"));
|
||||
|
||||
/// The emulated EVM heap memory global symbol.
|
||||
pub static MEMORY: &str = "__memory";
|
||||
|
||||
/// The emulated EVM heap memory size global symbol.
|
||||
pub static MEMORY_SIZE: &str = "__memory_size";
|
||||
|
||||
pub static SBRK: &str = "__sbrk_internal";
|
||||
|
||||
pub static ADDRESS: &str = "address";
|
||||
|
||||
pub static BALANCE: &str = "balance";
|
||||
@@ -78,8 +70,7 @@ pub static WEIGHT_TO_FEE: &str = "weight_to_fee";
|
||||
|
||||
/// All imported runtime API symbols.
|
||||
/// Useful for configuring common attributes and linkage.
|
||||
pub static IMPORTS: [&str; 34] = [
|
||||
SBRK,
|
||||
pub static IMPORTS: [&str; 33] = [
|
||||
ADDRESS,
|
||||
BALANCE,
|
||||
BALANCE_OF,
|
||||
|
||||
Reference in New Issue
Block a user