On Linux 32: sizeof(long)=32 == sizeof(void *)=32 on Linux 64: sizeof(long)=64 == sizeof(void *)=64 on Windows 64: sizeof(long)=32 != sizeof(void *)=64
Showing the changes to lib (1 of 6 files). Show all
Unified · Split
| @@ -69,15 +69,15 @@ · 68 unmodified lines | |||
| 69 | #define INVALID_SIZE 0 | 69 | #define INVALID_SIZE 0 |
| 70 | 70 | ||
| 71 | typedef struct BoundEntry { | 71 | typedef struct BoundEntry { |
| 72 | unsigned long start; | 72 | size_t start; |
| 73 | unsigned long size; | 73 | size_t size; |
| 74 | struct BoundEntry *next; | 74 | struct BoundEntry *next; |
| 75 | unsigned long is_invalid; /* true if pointers outside region are invalid */ | 75 | size_t is_invalid; /* true if pointers outside region are invalid */ |
| 76 | } BoundEntry; | 76 | } BoundEntry; |
| 77 | 77 | ||
| 78 | /* external interface */ | 78 | /* external interface */ |
| 79 | void __bound_init(void); | 79 | void __bound_init(void); |
| 80 | void __bound_new_region(void *p, unsigned long size); | 80 | void __bound_new_region(void *p, size_t size); |
| 81 | int __bound_delete_region(void *p); | 81 | int __bound_delete_region(void *p); |
| 82 | 82 | ||
| 83 | #define FASTCALL __attribute__((regparm(3))) | 83 | #define FASTCALL __attribute__((regparm(3))) |
| @@ -104,7 +104,7 @@ extern char __bounds_start; /* start of static bounds table */ · 20 unmodified lines | |||
| 104 | const char *__bound_error_msg; | 104 | const char *__bound_error_msg; |
| 105 | 105 | ||
| 106 | /* runtime error output */ | 106 | /* runtime error output */ |
| 107 | extern void rt_error(unsigned long pc, const char *fmt, ...); | 107 | extern void rt_error(size_t pc, const char *fmt, ...); |
| 108 | 108 | ||
| 109 | #ifdef BOUND_STATIC | 109 | #ifdef BOUND_STATIC |
| 110 | static BoundEntry *__bound_t1[BOUND_T1_SIZE]; /* page table */ | 110 | static BoundEntry *__bound_t1[BOUND_T1_SIZE]; /* page table */ |
| @@ -116,12 +116,12 @@ static BoundEntry *__bound_invalid_t2; /* invalid page, for invalid pointers */ · 5 unmodified lines | |||
| 116 | 116 | ||
| 117 | static BoundEntry *__bound_find_region(BoundEntry *e1, void *p) | 117 | static BoundEntry *__bound_find_region(BoundEntry *e1, void *p) |
| 118 | { | 118 | { |
| 119 | unsigned long addr, tmp; | 119 | size_t addr, tmp; |
| 120 | BoundEntry *e; | 120 | BoundEntry *e; |
| 121 | 121 | ||
| 122 | e = e1; | 122 | e = e1; |
| 123 | while (e != NULL) { | 123 | while (e != NULL) { |
| 124 | addr = (unsigned long)p; | 124 | addr = (size_t)p; |
| 125 | addr -= e->start; | 125 | addr -= e->start; |
| 126 | if (addr <= e->size) { | 126 | if (addr <= e->size) { |
| 127 | /* put region at the head */ | 127 | /* put region at the head */ |
| @@ -156,9 +156,9 @@ static void bound_alloc_error(void) · 28 unmodified lines | |||
| 156 | 156 | ||
| 157 | /* return '(p + offset)' for pointer arithmetic (a pointer can reach | 157 | /* return '(p + offset)' for pointer arithmetic (a pointer can reach |
| 158 | the end of a region in this case */ | 158 | the end of a region in this case */ |
| 159 | void * FASTCALL __bound_ptr_add(void *p, int offset) | 159 | void * FASTCALL __bound_ptr_add(void *p, size_t offset) |
| 160 | { | 160 | { |
| 161 | unsigned long addr = (unsigned long)p; | 161 | size_t addr = (size_t)p; |
| 162 | BoundEntry *e; | 162 | BoundEntry *e; |
| 163 | #if defined(BOUND_DEBUG) | 163 | #if defined(BOUND_DEBUG) |
| 164 | printf("add: 0x%x %d\n", (int)p, offset); | 164 | printf("add: 0x%x %d\n", (int)p, offset); |
| @@ -171,7 +171,7 @@ void * FASTCALL __bound_ptr_add(void *p, int offset) · 6 unmodified lines | |||
| 171 | addr -= e->start; | 171 | addr -= e->start; |
| 172 | if (addr > e->size) { | 172 | if (addr > e->size) { |
| 173 | e = __bound_find_region(e, p); | 173 | e = __bound_find_region(e, p); |
| 174 | addr = (unsigned long)p - e->start; | 174 | addr = (size_t)p - e->start; |
| 175 | } | 175 | } |
| 176 | addr += offset; | 176 | addr += offset; |
| 177 | if (addr > e->size) | 177 | if (addr > e->size) |
| @@ -184,7 +184,7 @@ void * FASTCALL __bound_ptr_add(void *p, int offset) · 6 unmodified lines | |||
| 184 | #define BOUND_PTR_INDIR(dsize) \ | 184 | #define BOUND_PTR_INDIR(dsize) \ |
| 185 | void * FASTCALL __bound_ptr_indir ## dsize (void *p, int offset) \ | 185 | void * FASTCALL __bound_ptr_indir ## dsize (void *p, int offset) \ |
| 186 | { \ | 186 | { \ |
| 187 | unsigned long addr = (unsigned long)p; \ | 187 | size_t addr = (size_t)p; \ |
| 188 | BoundEntry *e; \ | 188 | BoundEntry *e; \ |
| 189 | \ | 189 | \ |
| 190 | e = __bound_t1[addr >> (BOUND_T2_BITS + BOUND_T3_BITS)]; \ | 190 | e = __bound_t1[addr >> (BOUND_T2_BITS + BOUND_T3_BITS)]; \ |
| @@ -194,7 +194,7 @@ void * FASTCALL __bound_ptr_indir ## dsize (void *p, int offset) \ · 3 unmodified lines | |||
| 194 | addr -= e->start; \ | 194 | addr -= e->start; \ |
| 195 | if (addr > e->size) { \ | 195 | if (addr > e->size) { \ |
| 196 | e = __bound_find_region(e, p); \ | 196 | e = __bound_find_region(e, p); \ |
| 197 | addr = (unsigned long)p - e->start; \ | 197 | addr = (size_t)p - e->start; \ |
| 198 | } \ | 198 | } \ |
| 199 | addr += offset + dsize; \ | 199 | addr += offset + dsize; \ |
| 200 | if (addr > e->size) \ | 200 | if (addr > e->size) \ |
| @@ -212,13 +212,13 @@ BOUND_PTR_INDIR(16) · 11 unmodified lines | |||
| 212 | /* return the frame pointer of the caller */ | 212 | /* return the frame pointer of the caller */ |
| 213 | #define GET_CALLER_FP(fp)\ | 213 | #define GET_CALLER_FP(fp)\ |
| 214 | {\ | 214 | {\ |
| 215 | fp = (unsigned long)__builtin_frame_address(1);\ | 215 | fp = (size_t)__builtin_frame_address(1);\ |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | /* called when entering a function to add all the local regions */ | 218 | /* called when entering a function to add all the local regions */ |
| 219 | void FASTCALL __bound_local_new(void *p1) | 219 | void FASTCALL __bound_local_new(void *p1) |
| 220 | { | 220 | { |
| 221 | unsigned long addr, size, fp, *p = p1; | 221 | size_t addr, size, fp, *p = p1; |
| 222 | GET_CALLER_FP(fp); | 222 | GET_CALLER_FP(fp); |
| 223 | for(;;) { | 223 | for(;;) { |
| 224 | addr = p[0]; | 224 | addr = p[0]; |
| @@ -234,7 +234,7 @@ void FASTCALL __bound_local_new(void *p1) · 9 unmodified lines | |||
| 234 | /* called when leaving a function to delete all the local regions */ | 234 | /* called when leaving a function to delete all the local regions */ |
| 235 | void FASTCALL __bound_local_delete(void *p1) | 235 | void FASTCALL __bound_local_delete(void *p1) |
| 236 | { | 236 | { |
| 237 | unsigned long addr, fp, *p = p1; | 237 | size_t addr, fp, *p = p1; |
| 238 | GET_CALLER_FP(fp); | 238 | GET_CALLER_FP(fp); |
| 239 | for(;;) { | 239 | for(;;) { |
| 240 | addr = p[0]; | 240 | addr = p[0]; |
| @@ -290,11 +290,11 @@ static inline BoundEntry *get_page(int index) · 49 unmodified lines | |||
| 290 | } | 290 | } |
| 291 | 291 | ||
| 292 | /* mark a region as being invalid (can only be used during init) */ | 292 | /* mark a region as being invalid (can only be used during init) */ |
| 293 | static void mark_invalid(unsigned long addr, unsigned long size) | 293 | static void mark_invalid(size_t addr, size_t size) |
| 294 | { | 294 | { |
| 295 | unsigned long start, end; | 295 | size_t start, end; |
| 296 | BoundEntry *page; | 296 | BoundEntry *page; |
| 297 | int t1_start, t1_end, i, j, t2_start, t2_end; | 297 | size_t t1_start, t1_end, i, j, t2_start, t2_end; |
| 298 | 298 | ||
| 299 | start = addr; | 299 | start = addr; |
| 300 | end = addr + size; | 300 | end = addr + size; |
| @@ -347,7 +347,7 @@ void __bound_init(void) · 46 unmodified lines | |||
| 347 | { | 347 | { |
| 348 | int i; | 348 | int i; |
| 349 | BoundEntry *page; | 349 | BoundEntry *page; |
| 350 | unsigned long start, size; | 350 | size_t start, size; |
| 351 | 351 | ||
| 352 | /* int *p; */ | 352 | /* int *p; */ |
| 353 | __PTRDIFF_TYPE__ *p; /* 32 or 64 bit integer */ | 353 | __PTRDIFF_TYPE__ *p; /* 32 or 64 bit integer */ |
| @@ -376,7 +376,7 @@ void __bound_init(void) · 22 unmodified lines | |||
| 376 | __bound_invalid_t2 = page; | 376 | __bound_invalid_t2 = page; |
| 377 | 377 | ||
| 378 | /* invalid pointer zone */ | 378 | /* invalid pointer zone */ |
| 379 | start = (unsigned long)INVALID_POINTER & ~(BOUND_T23_SIZE - 1); | 379 | start = (size_t)INVALID_POINTER & ~(BOUND_T23_SIZE - 1); |
| 380 | size = BOUND_T23_SIZE; | 380 | size = BOUND_T23_SIZE; |
| 381 | mark_invalid(start, size); | 381 | mark_invalid(start, size); |
| 382 | 382 | ||
| @@ -407,7 +407,7 @@ void __bound_init(void) · 24 unmodified lines | |||
| 407 | * (b) on Linux >= v3.3, the alternative is to read | 407 | * (b) on Linux >= v3.3, the alternative is to read |
| 408 | * start_brk from /proc/self/stat | 408 | * start_brk from /proc/self/stat |
| 409 | */ | 409 | */ |
| 410 | start = (unsigned long)sbrk(0); | 410 | start = (size_t)sbrk(0); |
| 411 | size = 128 * 0x100000; | 411 | size = 128 * 0x100000; |
| 412 | mark_invalid(start, size); | 412 | mark_invalid(start, size); |
| 413 | #endif | 413 | #endif |
| @@ -433,7 +433,7 @@ void __bound_exit(void) · 19 unmodified lines | |||
| 433 | } | 433 | } |
| 434 | 434 | ||
| 435 | static inline void add_region(BoundEntry *e, | 435 | static inline void add_region(BoundEntry *e, |
| 436 | unsigned long start, unsigned long size) | 436 | size_t start, size_t size) |
| 437 | { | 437 | { |
| 438 | BoundEntry *e1; | 438 | BoundEntry *e1; |
| 439 | if (e->start == 0) { | 439 | if (e->start == 0) { |
| @@ -453,13 +453,13 @@ static inline void add_region(BoundEntry *e, · 13 unmodified lines | |||
| 453 | } | 453 | } |
| 454 | 454 | ||
| 455 | /* create a new region. It should not already exist in the region list */ | 455 | /* create a new region. It should not already exist in the region list */ |
| 456 | void __bound_new_region(void *p, unsigned long size) | 456 | void __bound_new_region(void *p, size_t size) |
| 457 | { | 457 | { |
| 458 | unsigned long start, end; | 458 | size_t start, end; |
| 459 | BoundEntry *page, *e, *e2; | 459 | BoundEntry *page, *e, *e2; |
| 460 | int t1_start, t1_end, i, t2_start, t2_end; | 460 | size_t t1_start, t1_end, i, t2_start, t2_end; |
| 461 | 461 | ||
| 462 | start = (unsigned long)p; | 462 | start = (size_t)p; |
| 463 | end = start + size; | 463 | end = start + size; |
| 464 | t1_start = start >> (BOUND_T2_BITS + BOUND_T3_BITS); | 464 | t1_start = start >> (BOUND_T2_BITS + BOUND_T3_BITS); |
| 465 | t1_end = end >> (BOUND_T2_BITS + BOUND_T3_BITS); | 465 | t1_end = end >> (BOUND_T2_BITS + BOUND_T3_BITS); |
| @@ -519,12 +519,12 @@ void __bound_new_region(void *p, unsigned long size) · 53 unmodified lines | |||
| 519 | 519 | ||
| 520 | /* delete a region */ | 520 | /* delete a region */ |
| 521 | static inline void delete_region(BoundEntry *e, | 521 | static inline void delete_region(BoundEntry *e, |
| 522 | void *p, unsigned long empty_size) | 522 | void *p, size_t empty_size) |
| 523 | { | 523 | { |
| 524 | unsigned long addr; | 524 | size_t addr; |
| 525 | BoundEntry *e1; | 525 | BoundEntry *e1; |
| 526 | 526 | ||
| 527 | addr = (unsigned long)p; | 527 | addr = (size_t)p; |
| 528 | addr -= e->start; | 528 | addr -= e->start; |
| 529 | if (addr <= e->size) { | 529 | if (addr <= e->size) { |
| 530 | /* region found is first one */ | 530 | /* region found is first one */ |
| @@ -548,7 +548,7 @@ static inline void delete_region(BoundEntry *e, · 17 unmodified lines | |||
| 548 | /* region not found: do nothing */ | 548 | /* region not found: do nothing */ |
| 549 | if (e == NULL) | 549 | if (e == NULL) |
| 550 | break; | 550 | break; |
| 551 | addr = (unsigned long)p - e->start; | 551 | addr = (size_t)p - e->start; |
| 552 | if (addr <= e->size) { | 552 | if (addr <= e->size) { |
| 553 | /* found: remove entry */ | 553 | /* found: remove entry */ |
| 554 | e1->next = e->next; | 554 | e1->next = e->next; |
| @@ -563,11 +563,11 @@ static inline void delete_region(BoundEntry *e, · 8 unmodified lines | |||
| 563 | /* return non zero if error */ | 563 | /* return non zero if error */ |
| 564 | int __bound_delete_region(void *p) | 564 | int __bound_delete_region(void *p) |
| 565 | { | 565 | { |
| 566 | unsigned long start, end, addr, size, empty_size; | 566 | size_t start, end, addr, size, empty_size; |
| 567 | BoundEntry *page, *e, *e2; | 567 | BoundEntry *page, *e, *e2; |
| 568 | int t1_start, t1_end, t2_start, t2_end, i; | 568 | size_t t1_start, t1_end, t2_start, t2_end, i; |
| 569 | 569 | ||
| 570 | start = (unsigned long)p; | 570 | start = (size_t)p; |
| 571 | t1_start = start >> (BOUND_T2_BITS + BOUND_T3_BITS); | 571 | t1_start = start >> (BOUND_T2_BITS + BOUND_T3_BITS); |
| 572 | t2_start = (start >> (BOUND_T3_BITS - BOUND_E_BITS)) & | 572 | t2_start = (start >> (BOUND_T3_BITS - BOUND_E_BITS)) & |
| 573 | ((BOUND_T2_SIZE - 1) << BOUND_E_BITS); | 573 | ((BOUND_T2_SIZE - 1) << BOUND_E_BITS); |
| @@ -579,7 +579,7 @@ int __bound_delete_region(void *p) · 5 unmodified lines | |||
| 579 | if (addr > e->size) | 579 | if (addr > e->size) |
| 580 | e = __bound_find_region(e, p); | 580 | e = __bound_find_region(e, p); |
| 581 | /* test if invalid region */ | 581 | /* test if invalid region */ |
| 582 | if (e->size == EMPTY_SIZE || (unsigned long)p != e->start) | 582 | if (e->size == EMPTY_SIZE || (size_t)p != e->start) |
| 583 | return -1; | 583 | return -1; |
| 584 | /* compute the size we put in invalid regions */ | 584 | /* compute the size we put in invalid regions */ |
| 585 | if (e->is_invalid) | 585 | if (e->is_invalid) |
| @@ -638,9 +638,9 @@ int __bound_delete_region(void *p) · 52 unmodified lines | |||
| 638 | 638 | ||
| 639 | /* return the size of the region starting at p, or EMPTY_SIZE if non | 639 | /* return the size of the region starting at p, or EMPTY_SIZE if non |
| 640 | existent region. */ | 640 | existent region. */ |
| 641 | static unsigned long get_region_size(void *p) | 641 | static size_t get_region_size(void *p) |
| 642 | { | 642 | { |
| 643 | unsigned long addr = (unsigned long)p; | 643 | size_t addr = (size_t)p; |
| 644 | BoundEntry *e; | 644 | BoundEntry *e; |
| 645 | 645 | ||
| 646 | e = __bound_t1[addr >> (BOUND_T2_BITS + BOUND_T3_BITS)]; | 646 | e = __bound_t1[addr >> (BOUND_T2_BITS + BOUND_T3_BITS)]; |
| @@ -650,7 +650,7 @@ static unsigned long get_region_size(void *p) · 3 unmodified lines | |||
| 650 | addr -= e->start; | 650 | addr -= e->start; |
| 651 | if (addr > e->size) | 651 | if (addr > e->size) |
| 652 | e = __bound_find_region(e, p); | 652 | e = __bound_find_region(e, p); |
| 653 | if (e->start != (unsigned long)p) | 653 | if (e->start != (size_t)p) |
| 654 | return EMPTY_SIZE; | 654 | return EMPTY_SIZE; |
| 655 | return e->size; | 655 | return e->size; |
| 656 | } | 656 | } |
| @@ -764,7 +764,7 @@ void __bound_free(void *ptr, const void *caller) · 107 unmodified lines | |||
| 764 | void *__bound_realloc(void *ptr, size_t size, const void *caller) | 764 | void *__bound_realloc(void *ptr, size_t size, const void *caller) |
| 765 | { | 765 | { |
| 766 | void *ptr1; | 766 | void *ptr1; |
| 767 | int old_size; | 767 | size_t old_size; |
| 768 | 768 | ||
| 769 | if (size == 0) { | 769 | if (size == 0) { |
| 770 | __bound_free(ptr, caller); | 770 | __bound_free(ptr, caller); |