Describe the bug
When performing mmap of a 4KB page we expect that addresses from base + 0 through base + 4095 will be accessible, but addresses above that will no (assuming there are no valid mappings there).
In practice we can touch base + 4096, and an error is detected only when touching base + 4097 address.
This implies that either memory access check is not performed correctly or the region size during mapping was not calculated correctly. REV logs indicates the latter is likely the problem here - see full log at the bottom.
// riscv64-linux-gnu-gcc -march=rv64imafd munmap.c -o munmap.exe
#include "../../../common/syscalls/syscalls.h"
#include "unistd.h"
int main() {
char *addr;
addr = (char*)rev_mmap(0, 4096, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
addr[4096] = 0; // this should segfault, but it does not
addr[4097] = 0; // this segfaults, which implies off by one at the end of the memory region
return 0;
}
REV config:
#
# Copyright (C) 2017-2023 Tactical Computing Laboratories, LLC
# All Rights Reserved
# contact@tactcomplabs.com
#
# See LICENSE in the top level directory for licensing details
#
# rev-test-ex1.py
#
import os
import sst
# Define SST core options
sst.setProgramOption("timebase", "1ps")
# Tell SST what statistics handling we want
sst.setStatisticLoadLevel(8)
max_addr_gb = 1
# Define the simulation components
comp_cpu = sst.Component("cpu", "revcpu.RevCPU")
comp_cpu.addParams({
"verbose" : 10, # Verbosity
"numCores" : 1, # Number of cores
"clock" : "1.0GHz", # Clock
"memSize" : 1024*1024*1024, # Memory size in bytes
"machine" : "[0:RV64IMAFDC]", # Core:Config; RV64I for core 0
"startAddr" : "[0:0x00000000]", # Starting address for core 0
"memCost" : "[0:1:10]", # Memory loads required 1-10 cycles
"program" : "munmap.exe", # Target executable
"splash" : 1 # Display the splash message
})
# sst.setStatisticOutput("sst.statOutputCSV")
sst.enableAllStatisticsForAllComponents()
# EOF
REV VERSION: c4f21a7cb9066b
Expected behavior
Mapped region should have size of requested size, not requested size + 1.
Describe the bug When performing mmap of a 4KB page we expect that addresses from base + 0 through base + 4095 will be accessible, but addresses above that will no (assuming there are no valid mappings there). In practice we can touch base + 4096, and an error is detected only when touching base + 4097 address. This implies that either memory access check is not performed correctly or the region size during mapping was not calculated correctly. REV logs indicates the latter is likely the problem here - see full log at the bottom.
To Reproduce Compile the following program:
REV config:
REV VERSION: c4f21a7cb9066b
Expected behavior Mapped region should have size of requested size, not requested size + 1.
Trace