libunwind-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Libunwind-devel] [PATCH 19/19] Rename and share `ALIGN' macro from _UCD


From: Tommi Rantala
Subject: [Libunwind-devel] [PATCH 19/19] Rename and share `ALIGN' macro from _UCD_internal.h
Date: Wed, 5 Sep 2012 14:50:27 +0300

Rename the `ALIGN' macro to `UNW_ALIGN', and move it from
`_UCD_internal.h' to `libunwind_i.h' so that we can share it with the
mempool code. `ALIGN' was clashing with system headers on FreeBSD:

In file included from src/coredump/_UCD_access_reg_freebsd.c:26:
src/coredump/_UCD_internal.h:102:1: warning: "ALIGN" redefined
In file included from /usr/include/sys/param.h:115,
                 from src/coredump/_UCD_lib.h:52,
                 from src/coredump/_UCD_access_reg_freebsd.c:24:
/usr/include/machine/param.h:79:1: warning: this is the location of the 
previous definition
---
 include/libunwind_i.h        |    2 ++
 src/coredump/_UCD_create.c   |    4 ++--
 src/coredump/_UCD_internal.h |    1 -
 src/mi/mempool.c             |   10 +++++-----
 4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/include/libunwind_i.h b/include/libunwind_i.h
index bdd3f46..91439b1 100644
--- a/include/libunwind_i.h
+++ b/include/libunwind_i.h
@@ -352,4 +352,6 @@ static inline void invalidate_edi (struct elf_dyn_info *edi)
 # define tdep_get_func_addr(as,addr,v)         (*(v) = addr, 0)
 #endif
 
+#define UNW_ALIGN(x,a) (((x)+(a)-1UL)&~((a)-1UL))
+
 #endif /* libunwind_i_h */
diff --git a/src/coredump/_UCD_create.c b/src/coredump/_UCD_create.c
index 73cd28a..f22664b 100644
--- a/src/coredump/_UCD_create.c
+++ b/src/coredump/_UCD_create.c
@@ -66,8 +66,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.  */
 #include "_UCD_lib.h"
 #include "_UCD_internal.h"
 
-#define NOTE_DATA(_hdr) STRUCT_MEMBER_P((_hdr), sizeof (Elf32_Nhdr) + 
ALIGN((_hdr)->n_namesz, 4))
-#define NOTE_SIZE(_hdr) (sizeof (Elf32_Nhdr) + ALIGN((_hdr)->n_namesz, 4) + 
(_hdr)->n_descsz)
+#define NOTE_DATA(_hdr) STRUCT_MEMBER_P((_hdr), sizeof (Elf32_Nhdr) + 
UNW_ALIGN((_hdr)->n_namesz, 4))
+#define NOTE_SIZE(_hdr) (sizeof (Elf32_Nhdr) + UNW_ALIGN((_hdr)->n_namesz, 4) 
+ (_hdr)->n_descsz)
 #define NOTE_NEXT(_hdr) STRUCT_MEMBER_P((_hdr), NOTE_SIZE(_hdr))
 #define NOTE_FITS_IN(_hdr, _size) ((_size) >= sizeof (Elf32_Nhdr) && (_size) 
>= NOTE_SIZE (_hdr))
 #define NOTE_FITS(_hdr, _end) NOTE_FITS_IN((_hdr), (unsigned long)((char 
*)(_end) - (char *)(_hdr)))
diff --git a/src/coredump/_UCD_internal.h b/src/coredump/_UCD_internal.h
index 5e92777..3c95a2a 100644
--- a/src/coredump/_UCD_internal.h
+++ b/src/coredump/_UCD_internal.h
@@ -99,7 +99,6 @@ struct UCD_info
 
 extern coredump_phdr_t * _UCD_get_elf_image(struct UCD_info *ui, unw_word_t 
ip);
 
-#define ALIGN(x,a) (((x)+(a)-1UL)&~((a)-1UL))
 #define STRUCT_MEMBER_P(struct_p, struct_offset) ((void *) ((char*) (struct_p) 
+ (long) (struct_offset)))
 #define STRUCT_MEMBER(member_type, struct_p, struct_offset) (*(member_type*) 
STRUCT_MEMBER_P ((struct_p), (struct_offset)))
 
diff --git a/src/mi/mempool.c b/src/mi/mempool.c
index ef891bf..6fb5afe 100644
--- a/src/mi/mempool.c
+++ b/src/mi/mempool.c
@@ -39,14 +39,14 @@ sos_alloc (size_t size)
 #ifdef HAVE_CMPXCHG
   char *old_mem;
 
-  size = (size + MAX_ALIGN - 1) & -MAX_ALIGN;
+  size = UNW_ALIGN(size, MAX_ALIGN);
   if (!sos_memp)
     cmpxchg_ptr (&sos_memp, 0, sos_memory);
   do
     {
       old_mem = sos_memp;
 
-      mem = (char *) (((unsigned long) old_mem + MAX_ALIGN - 1) & -MAX_ALIGN);
+      mem = (char *) UNW_ALIGN((unsigned long) old_mem, MAX_ALIGN);
       mem += size;
       assert (mem < sos_memory + sizeof (sos_memory));
     }
@@ -55,14 +55,14 @@ sos_alloc (size_t size)
   static define_lock (sos_lock);
   intrmask_t saved_mask;
 
-  size = (size + MAX_ALIGN - 1) & -MAX_ALIGN;
+  size = UNW_ALIGN(size, MAX_ALIGN);
 
   lock_acquire (&sos_lock, saved_mask);
   {
     if (!sos_memp)
       sos_memp = sos_memory;
 
-    mem = (char *) (((unsigned long) sos_memp + MAX_ALIGN - 1) & -MAX_ALIGN);
+    mem = (char *) UNW_ALIGN((unsigned long) sos_memp, MAX_ALIGN);
     mem += size;
     assert (mem < sos_memory + sizeof (sos_memory));
     sos_memp = mem;
@@ -126,7 +126,7 @@ mempool_init (struct mempool *pool, size_t obj_size, size_t 
reserve)
   lock_init (&pool->lock);
 
   /* round object-size up to integer multiple of MAX_ALIGN */
-  obj_size = (obj_size + MAX_ALIGN - 1) & -MAX_ALIGN;
+  obj_size = UNW_ALIGN(obj_size, MAX_ALIGN);
 
   if (!reserve)
     {
-- 
1.7.9.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]