diff options
author | Tony Luck <tony.luck@intel.com> | 2020-12-09 16:58:42 -0800 |
---|---|---|
committer | Tony Luck <tony.luck@intel.com> | 2020-12-09 16:58:42 -0800 |
commit | 44d5b35b4129115a9a5d6d02011daf438cec815d (patch) | |
tree | 8d4a6f0c8882daa15d7df859374289fc36e0f713 | |
parent | c7ad657475ea3d09d096ed6cd5f6b63e6ef3b6ec (diff) | |
download | ras-tools-44d5b35b4129115a9a5d6d02011daf438cec815d.tar.gz |
mca-recover: Make sure we consume poison at right point in code
It seems that modern compilers have become smart enough to not just
blindly read from "buf" at the point where the C code says "i = buf[0];"
Throw in a function call, and a volatile cast, to make sure the consumption
happens at the right point in code flow.
[Also fix one duplicated "0x" on output, and one missing "0x"]
Signed-off-by: Tony Luck <tony.luck@intel.com>
-rw-r--r-- | mca-recover.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/mca-recover.c b/mca-recover.c index ce2be29..f82ae4d 100644 --- a/mca-recover.c +++ b/mca-recover.c @@ -78,7 +78,7 @@ void recover(int sig, siginfo_t *si, void *v) tried_recovery = 1; printf("recover: sig=%d si=%p v=%p\n", sig, si, v); - printf("Platform memory error at 0x%p\n", si->si_addr); + printf("Platform memory error at %p\n", si->si_addr); printf("addr = %p lsb=%d\n", m->addr, m->lsb); newbuf = mmap(buf, pagesize, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); @@ -94,7 +94,7 @@ void recover(int sig, siginfo_t *si, void *v) memset(buf, '*', pagesize); phys = vtop((unsigned long long)buf); - printf("Recovery allocated new page at physical %llx\n", phys); + printf("Recovery allocated new page at physical 0x%llx\n", phys); } struct sigaction recover_act = { @@ -102,6 +102,11 @@ struct sigaction recover_act = { .sa_flags = SA_SIGINFO, }; +int consume_poison(void) +{ + return *(volatile char *)buf; +} + int main(int argc, char **argv) { int i; @@ -127,7 +132,7 @@ int main(int argc, char **argv) fgets(reply, sizeof reply, stdin); - i = buf[0]; + i = consume_poison(); if (tried_recovery == 0) { fprintf(stderr, "%s: didn't trigger error\n", argv[0]); |