From e43606c2b13ad7fc1af2bbe4a61cf8480ee3a532 Mon Sep 17 00:00:00 2001 From: Bruce Cran Date: Mon, 20 Feb 2012 09:34:24 +0100 Subject: [PATCH] Fix assumption that pointers fits in a 'long' Windows uses LLP64 model so [u]intptr_t is more correct. Signed-off-by: Jens Axboe --- backend.c | 7 ++++--- hash.h | 2 +- memalign.c | 5 +++-- rbtree.h | 7 ++++--- smalloc.c | 5 +++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/backend.c b/backend.c index 6e0e4424..eaa6ea77 100644 --- a/backend.c +++ b/backend.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -67,7 +68,7 @@ int temp_stall_ts; unsigned long done_secs = 0; #define PAGE_ALIGN(buf) \ - (char *) (((unsigned long) (buf) + page_mask) & ~page_mask) + (char *) (((uintptr_t) (buf) + page_mask) & ~page_mask) #define JOB_START_TIMEOUT (5 * 1000) @@ -1179,7 +1180,7 @@ err: write_iolog_close(td); td_set_runstate(td, TD_EXITED); - return (void *) (unsigned long) td->error; + return (void *) (uintptr_t) td->error; } @@ -1210,7 +1211,7 @@ static int fork_main(int shmid, int offset) td = data + offset * sizeof(struct thread_data); ret = thread_main(td); shmdt(data); - return (int) (unsigned long) ret; + return (int) (uintptr_t) ret; } /* diff --git a/hash.h b/hash.h index 0c3cdda7..4b8c6bf0 100644 --- a/hash.h +++ b/hash.h @@ -58,7 +58,7 @@ static inline unsigned long hash_long(unsigned long val, unsigned int bits) static inline unsigned long hash_ptr(void *ptr, unsigned int bits) { - return hash_long((unsigned long)ptr, bits); + return hash_long((uintptr_t)ptr, bits); } /* diff --git a/memalign.c b/memalign.c index 87667b42..7a04ffd8 100644 --- a/memalign.c +++ b/memalign.c @@ -1,5 +1,6 @@ #include #include +#include #include "memalign.h" @@ -8,7 +9,7 @@ struct align_footer { }; #define PTR_ALIGN(ptr, mask) \ - (char *) (((unsigned long) ((ptr) + (mask)) & ~(mask))) + (char *) (((uintptr_t) ((ptr) + (mask)) & ~(mask))) void *fio_memalign(size_t alignment, size_t size) { @@ -21,7 +22,7 @@ void *fio_memalign(size_t alignment, size_t size) if (ptr) { ret = PTR_ALIGN(ptr, alignment); f = ret + size; - f->offset = (unsigned long) ret - (unsigned long) ptr; + f->offset = (uintptr_t) ret - (uintptr_t) ptr; } return ret; diff --git a/rbtree.h b/rbtree.h index 20306ff1..7563725e 100644 --- a/rbtree.h +++ b/rbtree.h @@ -95,10 +95,11 @@ static inline struct page * rb_insert_page_cache(struct inode * inode, #define _LINUX_RBTREE_H #include +#include struct rb_node { - unsigned long rb_parent_color; + intptr_t rb_parent_color; #define RB_RED 0 #define RB_BLACK 1 struct rb_node *rb_right; @@ -121,7 +122,7 @@ struct rb_root static inline void rb_set_parent(struct rb_node *rb, struct rb_node *p) { - rb->rb_parent_color = (rb->rb_parent_color & 3) | (unsigned long)p; + rb->rb_parent_color = (rb->rb_parent_color & 3) | (uintptr_t)p; } static inline void rb_set_color(struct rb_node *rb, int color) { @@ -144,7 +145,7 @@ extern struct rb_node *rb_first(struct rb_root *); static inline void rb_link_node(struct rb_node * node, struct rb_node * parent, struct rb_node ** rb_link) { - node->rb_parent_color = (unsigned long )parent; + node->rb_parent_color = (uintptr_t)parent; node->rb_left = node->rb_right = NULL; *rb_link = node; diff --git a/smalloc.c b/smalloc.c index 0c7c6df7..5ba20047 100644 --- a/smalloc.c +++ b/smalloc.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -253,9 +254,9 @@ void scleanup(void) #ifdef SMALLOC_REDZONE static void *postred_ptr(struct block_hdr *hdr) { - unsigned long ptr; + uintptr_t ptr; - ptr = (unsigned long) hdr + hdr->size - sizeof(unsigned int); + ptr = (uintptr_t) hdr + hdr->size - sizeof(unsigned int); ptr = (ptr + int_mask) & ~int_mask; return (void *) ptr; -- 2.25.1