mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-23 00:18:01 +00:00
disable sbrk and emulate EVM linear memory internally (#76)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com> Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
@@ -3,9 +3,34 @@
|
||||
|
||||
#include "polkavm_guest.h"
|
||||
|
||||
|
||||
// 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)
|
||||
static char __memory[MAX_MEMORY_SIZE];
|
||||
static uint32_t __memory_size = 0;
|
||||
|
||||
void * __sbrk_internal(uint32_t offset, uint32_t size) {
|
||||
if (offset >= MAX_MEMORY_SIZE || size > MAX_MEMORY_SIZE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t new_size = ALIGN(offset + size);
|
||||
if (new_size > MAX_MEMORY_SIZE) {
|
||||
return NULL;
|
||||
}
|
||||
if (new_size > __memory_size) {
|
||||
__memory_size = new_size;
|
||||
}
|
||||
|
||||
return (void *)&__memory[__memory_size];
|
||||
}
|
||||
|
||||
uint32_t __msize() {
|
||||
return __memory_size;
|
||||
}
|
||||
|
||||
void * memset(void *b, int c, size_t len) {
|
||||
uint8_t *dest = b;
|
||||
while (len-- > 0) *dest++ = c;
|
||||
@@ -37,18 +62,6 @@ void * memmove(void *dst, const void *src, size_t n) {
|
||||
return dst;
|
||||
}
|
||||
|
||||
void * __sbrk(uint32_t size) {
|
||||
uint32_t address;
|
||||
__asm__ __volatile__(
|
||||
".insn r 0xb, 1, 0, %[dst], %[sz], zero"
|
||||
: [dst] "=r" (address)
|
||||
: [sz] "ir" (size)
|
||||
:
|
||||
);
|
||||
return (void *)address;
|
||||
}
|
||||
|
||||
|
||||
// Imports
|
||||
|
||||
POLKAVM_IMPORT(void, input, uint32_t, uint32_t)
|
||||
|
||||
Reference in New Issue
Block a user