Skip to content

Commit a07c190

Browse files
authored
Merge pull request #1995 from arrv-sc/arrv-sc/fix-store-segfault
fix: log store only if it actually happened
2 parents 14cad99 + 7d43d38 commit a07c190

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

ci-tests/atomics.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdio.h>
2+
#include <stdatomic.h>
3+
4+
atomic_int acnt = 0;
5+
atomic_int bcnt = 0;
6+
7+
int foo() {
8+
for(int n = 0; n < 1000; ++n) {
9+
++acnt;
10+
if(acnt % 10 == 0)
11+
++bcnt;
12+
}
13+
return acnt;
14+
}
15+
16+
int main(void) {
17+
int acnt = foo();
18+
printf("First atomic counter is %u, second is %u\n", acnt, bcnt);
19+
return 0;
20+
}

ci-tests/create-ci-binary-tarball

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@ mkdir -p build/dummycsr && cd "$_"
2020
riscv64-unknown-elf-gcc -O2 -o customcsr `git rev-parse --show-toplevel`/ci-tests/customcsr.c
2121
cd -
2222

23+
mkdir -p build/atomics && cd "$_"
24+
riscv64-unknown-elf-gcc -O2 -o atomics `git rev-parse --show-toplevel`/ci-tests/atomics.c
25+
cd -
26+
27+
2328
mv build/pk/pk .
2429
mv build/hello/hello .
2530
mv build/dummy-slliuw/dummy-slliuw .
2631
mv build/dummycsr/customcsr .
27-
tar -cf spike-ci.tar pk hello dummy-slliuw customcsr
32+
mv build/atomics/atomics .
33+
tar -cf spike-ci.tar pk hello dummy-slliuw customcsr atomics
2834

29-
rm pk hello dummy-slliuw customcsr
35+
rm pk hello dummy-slliuw customcsr atomics

ci-tests/test-spike

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ cd run
1111
wget https://github.com/riscv-software-src/riscv-isa-sim/releases/download/dummy-tag-for-ci-storage/spike-ci.tar
1212
tar xf spike-ci.tar
1313
time ../install/bin/spike --isa=rv64gc pk hello | grep "Hello, world! Pi is approximately 3.141588."
14+
../install/bin/spike --log-commits --isa=rv64gc pk atomics | grep "First atomic counter is 1000, second is 100"
1415

1516
# check that including sim.h in an external project works
1617
g++ -std=c++2a -I../install/include -L../install/lib $DIR/testlib.cc -lriscv -o test-libriscv

riscv/mmu.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ void mmu_t::store_slow_path(reg_t original_addr, reg_t len, const uint8_t* bytes
369369
store_slow_path_intrapage(len, bytes, access_info, actually_store);
370370
}
371371

372-
if (proc && unlikely(proc->get_log_commits_enabled()))
372+
if (actually_store && proc && unlikely(proc->get_log_commits_enabled()))
373373
proc->state.log_mem_write.push_back(std::make_tuple(original_addr, reg_from_bytes(len, bytes), len));
374374
}
375375

0 commit comments

Comments
 (0)