Skip to content

Commit

Permalink
Add 39-bit virtual memory scheme support for riscv64.
Browse files Browse the repository at this point in the history
Fixed 'context.c' test failure on riscv64. See issue Snaipe#44.

Only riscv64 arch is affected in this commit, but you can modify
memory_addr_bits variable to support other memory schemes.
  • Loading branch information
Sakura286 committed Aug 11, 2023
1 parent c91d718 commit 3702026
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ if cc.symbols_have_underscore_prefix()
mangling = 'leading-underscore'
endif

memory_addr_bits = 'undefined'

if arch == 'x86'
bitness = 32
elif arch == 'x86_64'
Expand All @@ -88,6 +90,9 @@ elif arch == 'aarch64'
bitness = 64
elif arch == 'riscv64'
bitness = 64
# 39 bit virtual address scheme(sv39) is widely used in riscv64 in 2023
# still need to find a stable method to detect address scheme in user mode
memory_addr_bits = '39'
else
error('Architecture "@0@" is not supported.'.format(arch))
endif
Expand Down Expand Up @@ -121,6 +126,10 @@ config.set('BXF_ARCH_@0@'.format(arch.to_upper()), 1)
config.set('BXF_MANGLING', mangling)
config.set('BXF_BITS', bitness)

if memory_addr_bits != 'undefined'
config.set('BXF_MEM_ADDR_BITS', memory_addr_bits)
endif

checks = [
{'fn': 'clock_gettime'},
{'fn': 'gettimeofday'},
Expand Down
8 changes: 8 additions & 0 deletions src/arena.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,19 @@ static void *mmap_max = (void *) 0x80000000;
static intptr_t mmap_off = (intptr_t) 1 << 16;
static intptr_t mmap_off_mask = 0x3fff;
#elif BXF_BITS == 64
# ifndef BXF_MEM_ADDR_BITS
/* On Linux it seems that you cannot map > 48-bit addresses */
static void *mmap_base = (void *) 0x200000000000;
static void *mmap_max = (void *) 0x7f0000000000;
static intptr_t mmap_off = (intptr_t) 1 << 24;
static intptr_t mmap_off_mask = 0x3fffff;
# elif BXF_MEM_ADDR_BITS == 39
/* 39-bit virtual memory scheme is used in some riscv64 or amd64 machines */
static void *mmap_base = (void *) 0x1000000000;
static void *mmap_max = (void *) 0x3f00000000;
static intptr_t mmap_off = (intptr_t) 1 << 20;
static intptr_t mmap_off_mask = 0x1ffff;
# endif
#else
# error Platform not supported
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#mesondefine BXF_MANGLING
#mesondefine BXF_OS_FAMILY

#mesondefine BXF_MEM_ADDR_BITS

# ifdef BXF_OS_FAMILY
# define BXF_OS_FAMILY_STR #BXF_OS_FAMILY
# endif
Expand Down

0 comments on commit 3702026

Please sign in to comment.