From 229d2c4a623d0d3c7f1d275942741dc768b33faa Mon Sep 17 00:00:00 2001 From: "mostang.com!davidm" Date: Tue, 3 May 2005 09:13:17 +0000 Subject: [PATCH] (atomic_read): New macro to read the value of a variable that can be updated atomically (for Linux kernel compat.). (unwi_full_mask): Rename from unwi_full_sigmask and change type to intrmask_t. (intrmask_t): New type. (define_lock): New macro. (lock_init): Likewise. (lock_acquire): Likewise. (lock_release): Likewise. (GET_MEMORY): Likewise. 2005/02/20 21:42:54-08:00 mostang.com!davidm (ALWAYS_INLINE): Include "inline" keyword for compatibility with Linux kernel. (ARRAY_SIZE): Rename from NELEMS for improved Linux-kernel compatibility. 2004/10/25 05:21:51-07:00 hp.com!davidm (Debug): Make a debug level of N imply that we're printing when UNW_DEBUG_LEVEL=N since that's more intuitive. (Logical change 1.290) --- include/internal.h | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/include/internal.h b/include/internal.h index 73a11916..452a0f32 100644 --- a/include/internal.h +++ b/include/internal.h @@ -1,5 +1,5 @@ /* libunwind - a platform-independent unwind library - Copyright (C) 2001-2004 Hewlett-Packard Co + Copyright (C) 2001-2005 Hewlett-Packard Co Contributed by David Mosberger-Tang This file is part of libunwind. @@ -65,7 +65,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ # define NORETURN __attribute__((noreturn)) # define ALIAS(name) __attribute__((alias (#name))) # if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ > 2) -# define ALWAYS_INLINE __attribute__((always_inline)) +# define ALWAYS_INLINE inline __attribute__((always_inline)) # define HIDDEN __attribute__((visibility ("hidden"))) # define PROTECTED __attribute__((visibility ("protected"))) # else @@ -97,7 +97,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ # define UNW_DEBUG 0 #endif -#define NELEMS(a) (sizeof (a) / sizeof ((a)[0])) +#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) /* Make it easy to write thread-safe code which may or may not be linked against libpthread. The macros below can be used @@ -157,13 +157,43 @@ cmpxchg_ptr (void *addr, void *old, void *new) # define HAVE_FETCH_AND_ADD1 # endif #endif +#define atomic_read(ptr) (*(ptr)) #define UNWI_OBJ(fn) UNW_PASTE(UNW_PREFIX,UNW_PASTE(I,fn)) #define UNWI_ARCH_OBJ(fn) UNW_PASTE(UNW_PASTE(UNW_PASTE(_UI,UNW_TARGET),_), fn) -#define unwi_full_sigmask UNWI_ARCH_OBJ(full_sigmask) +#define unwi_full_mask UNWI_ARCH_OBJ(full_mask) -extern sigset_t unwi_full_sigmask; +/* Type of a mask that can be used to inhibit preemption. At the + userlevel, preemption is caused by signals and hence sigset_t is + appropriate. In constrast, the Linux kernel uses "unsigned long" + to hold the processor "flags" instead. */ +typedef sigset_t intrmask_t; + +extern intrmask_t unwi_full_mask; + +#define define_lock(name) \ + pthread_mutex_t name = PTHREAD_MUTEX_INITIALIZER +#define lock_init(l) mutex_init (l) +#define lock_acquire(l,m) \ +do { \ + sigprocmask (SIG_SETMASK, &unwi_full_mask, &(m)); \ + mutex_lock (l); \ +} while (0) +#define lock_release(l,m) \ +do { \ + mutex_unlock (l); \ + sigprocmask (SIG_SETMASK, &(m), NULL); \ +} while (0) + +#define GET_MEMORY(mem, size_in_bytes) \ +do { \ + /* Hopefully, mmap() goes straight through to a system call stub... */ \ + mem = mmap (0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, \ + -1, 0); \ + if (mem == MAP_FAILED) \ + mem = NULL; \ +} while (0) #define unwi_find_dynamic_proc_info UNWI_OBJ(find_dynamic_proc_info) #define unwi_extract_dynamic_proc_info UNWI_OBJ(extract_dynamic_proc_info) @@ -208,7 +238,7 @@ extern long unwi_debug_level; # include # define Debug(level,format...) \ do { \ - if (unwi_debug_level > level) \ + if (unwi_debug_level >= level) \ { \ int _n = level; \ if (_n > 16) \ @@ -227,7 +257,7 @@ do { \ # define dprintf(format...) #endif -static inline ALWAYS_INLINE void +static ALWAYS_INLINE void print_error (const char *string) { write (2, string, strlen (string));