|
From: | Christian Franke |
Subject: | Re: [PATCH] Fix eisa_mmap evaluation, add memory existence check |
Date: | Sat, 10 Nov 2007 00:12:35 +0100 |
User-agent: | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4 |
Marco Gerards wrote:
...+static int +addr_is_valid (grub_addr_t addr) +{ + volatile unsigned char * p = (volatile unsigned char *)addr;Why volatile? I have the feeling it is not needed.+ unsigned char x, y; + x = *p; + *p = x ^ 0xcf; + y = *p; + *p = x; + return y == (x ^ 0xcf); +}
volatile is necessary here to tell the complier that the memory address might not behave like regular memory. Otherwise, the optimizer might legitimately remove memory accesses and then constant propagation detects an unchanged value.
gcc actually does a very good job here. Result with volatile removed: $ gcc -S -O -fomit-frame-pointer init.c && cat init.s ... addr_is_valid: movl $1, %eax ret ... aka: static int addr_is_valid (grub_addr_t addr) { return 1; }This is at least a proof that the original function returns the correct result when real memory is present :-)
Christian
[Prev in Thread] | Current Thread | [Next in Thread] |