translate-all: wrapped map_exec() in #ifdef
PATCH 1/1 translate-all: wrapped map_exec() in #ifdef
Moved map_exec() and wrapped it in #ifdef to avoid "-Wunused-function" on clang 3.4 or later.
--- translate-all.c | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-)
translate-all.c +27 -25
@@ -269,31 +269,6 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t retaddr)return false; } -#ifdef _WIN32 -static inline void map_exec (void *addr,long size) -{ -DWORD old_protect; -VirtualProtect (addr, size, -PAGE_EXECUTE_READWRITE , &old_protect); -} -#else -static inline void map_exec (void *addr,long size) -{ -unsigned long start, end, page_size; - - page_size =getpagesize (); - start = (unsigned long )addr; - start &= ~(page_size -1 ); - - end = (unsigned long )addr + size; - end += page_size -1 ; - end &= ~(page_size -1 ); - -mprotect ((void *)start, end - start, -PROT_READ |PROT_WRITE |PROT_EXEC ); -} -#endif -void page_size_init (void ) {/* NOTE: we can always suppose that qemu_host_page_size >=
@@ -536,6 +511,33 @@ static inline void *split_cross_256mb(void *buf1, size_t size1) }#endif +#ifndef USE_MMAP +# ifdef _WIN32 +static inline void map_exec (void *addr,long size) +{ +DWORD old_protect; +VirtualProtect (addr, size, +PAGE_EXECUTE_READWRITE , &old_protect); +} +# else +static inline void map_exec (void *addr,long size) +{ +unsigned long start, end, page_size; + + page_size =getpagesize (); + start = (unsigned long )addr; + start &= ~(page_size -1 ); + + end = (unsigned long )addr + size; + end += page_size -1 ; + end &= ~(page_size -1 ); + +mprotect ((void *)start, end - start, +PROT_READ |PROT_WRITE |PROT_EXEC ); +} +# endif +#endif +#ifdef USE_STATIC_CODE_GEN_BUFFER static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE] __attribute__((aligned(CODE_GEN_ALIGN)));
Signature · 1 line
2.1.0
Quoted 3 lines · SeokYeon Hwang
Moved
map_exec()and wrapped it in #ifdef to avoid "-Wunused-function" on clang 3.4 or later.Signed-off-by SeokYeon Hwang <[email protected]>
I had this kind of on my todo list too, but I didn't much like the nested ifdefs which are really only because of what the different implementations of alloc_code_gen_buffer() happen to do. I think it would be more robust to just mark the functions with the 'unused' attribute instead of relying on 'inline' to implicitly do this for us:
translate-all.c +2 -2
@@ -270,14 +270,14 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t retaddr) }#ifdef _WIN32 -static inline void map_exec (void *addr,long size) +static __attribute__((unused))void map_exec (void *addr,long size) {DWORD old_protect;VirtualProtect (addr, size,PAGE_EXECUTE_READWRITE , &old_protect); }#else -static inline void map_exec (void *addr,long size) +static __attribute__((unused))void map_exec (void *addr,long size) {unsigned long start, end, page_size;
thanks
-- PMM
I posted a new patch which your suggestion is applied.
Thanks.
Quoted 39 lines
-----Original Message-----
From: Peter Maydell [mailto:[email protected]]
Sent: Saturday, November 01, 2014 3:30 AM
To: SeokYeon Hwang
Cc: QEMU Developers
Subject: Re: [Qemu-devel] [PATCH] translate-all: wrappedmap_exec()in #ifdefQuoted 1 line · SeokYeon Hwang
Moved
map_exec()and wrapped it in #ifdef to avoid "-Wunused-function"on clang 3.4 or later.
Quoted 2 lines
Signed-off-by SeokYeon Hwang <[email protected]>I had this kind of on my todo list too, but I didn't much like the nested ifdefs which are really only because of what the different implementations of
alloc_code_gen_buffer()happen to do. I think it would be more robust to just mark the functions with the 'unused' attribute instead of relying on 'inline' to implicitly do this for us:translate-all.c +2
-1@@ -270,14 +270,14 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t retaddr) }#ifdef _WIN32 -static inline void map_exec (void *addr,long size) +static __attribute__((unused))void map_exec (void *addr,long size) {DWORD old_protect;VirtualProtect (addr, size, PAGE_EXECUTE_READWRITE, &old_protect); } #else -staticinline void map_exec (void *addr,long size) +static __attribute__((unused)) void map_exec(void *addr, long size) {unsigned long start, end, page_size;thanks
-- PMM
Quoted 25 lines · SeokYeon Hwang
Quoted 25 lines
-----Original Message-----
From: Peter Maydell [mailto:[email protected]]
Sent: Saturday, November 01, 2014 3:30 AM
To: SeokYeon Hwang
Cc: QEMU Developers
Subject: Re: [Qemu-devel] [PATCH] translate-all: wrappedmap_exec()in #ifdefQuoted 1 line · SeokYeon Hwang
Moved
map_exec()and wrapped it in #ifdef to avoid "-Wunused-function"on clang 3.4 or later.
Quoted 2 lines
Signed-off-by SeokYeon Hwang <[email protected]>I had this kind of on my todo list too, but I didn't much like the nested ifdefs which are really only because of what the different implementations of
alloc_code_gen_buffer()happen to do. I think it would be more robust to just mark the functions with the 'unused' attribute instead of relying on 'inline' to implicitly do this for us:translate-all.c +0
-0@@ -270,14 +270,14 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t retaddr) }
Quoted 7 lines
translate-all.c bool cpu_restore_state(CPUState *cpu, uintptr_t · line 277
Quoted 7 lines
translate-all.c +1
-1#ifdef _WIN32 -static inline void map_exec (void *addr,long size) +static __attribute__((unused))void map_exec (void *addr,long size) {DWORD old_protect;VirtualProtect (addr, size,PAGE_EXECUTE_READWRITE , &old_protect); }
In which case this function isn't used on windows? I mean, is it really necessary to mark it as unused for win32 case?
Quoted 5 lines
translate-all.c bool cpu_restore_state(CPUState *cpu, uintptr_t · line 281
Quoted 5 lines
translate-all.c +1
-1#else -static inline void map_exec (void *addr,long size) +static __attribute__((unused))void map_exec (void *addr,long size) {unsigned long start, end, page_size;
How about this instead:
translate-all.c +1 -1
@@ -276,7 +276,7 @@ static inline void map_exec(void *addr, long size)VirtualProtect (addr, size, PAGE_EXECUTE_READWRITE, &old_protect); } -#else +#elif !defined(USE_MMAP)static inline void map_exec (void *addr,long size) {unsigned long start, end, page_size;
? (Untested, but just to show an idea)... ;)
Thanks,
/mjt
Quoted 6 lines · Michael Tokarev
Quoted 5 lines · SeokYeon Hwang
Quoted 5 lines
translate-all.c +0
-0@@ -270,14 +270,14 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t retaddr) }
Quoted 10 lines
Quoted 7 lines
translate-all.c bool cpu_restore_state(CPUState *cpu, uintptr_t · line 277
Quoted 7 lines
translate-all.c +1
-1#ifdef _WIN32 -static inline void map_exec (void *addr,long size) +static __attribute__((unused))void map_exec (void *addr,long size) {DWORD old_protect;VirtualProtect (addr, size,PAGE_EXECUTE_READWRITE , &old_protect); }In which case this function isn't used on windows? I mean, is it really necessary to mark it as unused for win32 case?
It's not necessary, but it means we're consistent between windows and not-windows. It avoids unnecessary coupling between how the calling function happens to be implemented and what defines we put around this utility function.
Quoted 20 lines
Quoted 5 lines
translate-all.c bool cpu_restore_state(CPUState *cpu, uintptr_t · line 281
Quoted 5 lines
translate-all.c +1
-1#else -static inline void map_exec (void *addr,long size) +static __attribute__((unused))void map_exec (void *addr,long size) {unsigned long start, end, page_size;How about this instead:
translate-all.c +1
-1@@ -276,7 +276,7 @@ static inline void map_exec(void *addr, long size)VirtualProtect (addr, size, PAGE_EXECUTE_READWRITE, &old_protect); } -#else +#elif !defined(USE_MMAP)static inline void map_exec (void *addr,long size) {unsigned long start, end, page_size;
Quoted 1 line
? (Untested, but just to show an idea)... ;)
This breaks for linux-user, where we will define both USE_STATIC_CODE_GEN_BUFFER and USE_MMAP, and your change won't define map_exec() but the later ifdef ladder will pick a version of alloc_code_gen_buffer() that calls it.
-- PMM
Quoted 18 lines · Peter Maydell
Quoted 6 lines · Michael Tokarev
Quoted 5 lines · SeokYeon Hwang
Quoted 5 lines
translate-all.c +0
-0@@ -270,14 +270,14 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t retaddr) }Quoted 10 lines
Quoted 7 lines
translate-all.c bool cpu_restore_state(CPUState *cpu, uintptr_t · line 277
Quoted 7 lines
translate-all.c +1
-1#ifdef _WIN32 -static inline void map_exec (void *addr,long size) +static __attribute__((unused))void map_exec (void *addr,long size) {DWORD old_protect;VirtualProtect (addr, size,PAGE_EXECUTE_READWRITE , &old_protect); }In which case this function isn't used on windows? I mean, is it really necessary to mark it as unused for win32 case?
Quoted 4 lines
It's not necessary, but it means we're consistent between windows and not-windows. It avoids unnecessary coupling between how the calling function happens to be implemented and what defines we put around this utility function.
I usually reluctant to add these unused attributes and shut up other warnings by force, because with time this cruft does not help, and more and more code becomes "forgotten". If it is not needed for windows, why add it?
Quoted 20 lines
Quoted 20 lines
Quoted 5 lines
translate-all.c bool cpu_restore_state(CPUState *cpu, uintptr_t · line 281
Quoted 5 lines
translate-all.c +1
-1#else -static inline void map_exec (void *addr,long size) +static __attribute__((unused))void map_exec (void *addr,long size) {unsigned long start, end, page_size;How about this instead:
translate-all.c +1
-1@@ -276,7 +276,7 @@ static inline void map_exec(void *addr, long size)VirtualProtect (addr, size, PAGE_EXECUTE_READWRITE, &old_protect); } -#else +#elif !defined(USE_MMAP)static inline void map_exec (void *addr,long size) {unsigned long start, end, page_size;
Quoted 6 lines
Quoted 1 line
? (Untested, but just to show an idea)... ;)
This breaks for linux-user, where we will define both
USE_STATIC_CODE_GEN_BUFFERandUSE_MMAP, and your change won't definemap_exec()but the later ifdef ladder will pick a version ofalloc_code_gen_buffer()that calls it.
Hence the "untested" warning by me... So the test can be rewritten like this:
#elif defined(USE_STATIC_CODE_GEN_BUFFER) || !defined(USE_MMAP)
(untested again! ;) and everything should be well without adding extra attributes... Which one is better is, well, a matter of personal taste really.. :)
(Not that all this is hugely important, we already spent too much time discussing various trivial/unimportant things and had much less time to do the real work, but... ;)
Thanks,
/mjt
Quoted 4 lines · Michael Tokarev
I usually reluctant to add these unused attributes and shut up other warnings by force, because with time this cruft does not help, and more and more code becomes "forgotten". If it is not needed for windows, why add it?
You could equally ask why we've marked the function "inline" for both, when it's currently only required for non-win32 and only needed because it silences the warning on gcc.
Quoted 8 lines
Hence the "untested" warning by me... So the test can be rewritten like this:
#elif
defined(USE_STATIC_CODE_GEN_BUFFER)|| !defined(USE_MMAP)(untested again! ;) and everything should be well without adding extra attributes... Which one is better is, well, a matter of personal taste really.. :)
Yeah, that's the "close coupling between warning-suppressing and the implementation of a different bit of the code" approach. As you say, personal taste; I've applied my r-by tag to the other one ;-)
-- PMM