Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #define JEMALLOC_MANGLE |
michael@0 | 2 | #include "jemalloc_test.h" |
michael@0 | 3 | |
michael@0 | 4 | #define NTHREADS 10 |
michael@0 | 5 | |
michael@0 | 6 | void * |
michael@0 | 7 | je_thread_start(void *arg) |
michael@0 | 8 | { |
michael@0 | 9 | unsigned main_arena_ind = *(unsigned *)arg; |
michael@0 | 10 | void *p; |
michael@0 | 11 | unsigned arena_ind; |
michael@0 | 12 | size_t size; |
michael@0 | 13 | int err; |
michael@0 | 14 | |
michael@0 | 15 | p = malloc(1); |
michael@0 | 16 | if (p == NULL) { |
michael@0 | 17 | malloc_printf("%s(): Error in malloc()\n", __func__); |
michael@0 | 18 | return (void *)1; |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | size = sizeof(arena_ind); |
michael@0 | 22 | if ((err = mallctl("thread.arena", &arena_ind, &size, &main_arena_ind, |
michael@0 | 23 | sizeof(main_arena_ind)))) { |
michael@0 | 24 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, |
michael@0 | 25 | strerror(err)); |
michael@0 | 26 | return (void *)1; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | size = sizeof(arena_ind); |
michael@0 | 30 | if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, |
michael@0 | 31 | 0))) { |
michael@0 | 32 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, |
michael@0 | 33 | strerror(err)); |
michael@0 | 34 | return (void *)1; |
michael@0 | 35 | } |
michael@0 | 36 | assert(arena_ind == main_arena_ind); |
michael@0 | 37 | |
michael@0 | 38 | return (NULL); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | int |
michael@0 | 42 | main(void) |
michael@0 | 43 | { |
michael@0 | 44 | int ret = 0; |
michael@0 | 45 | void *p; |
michael@0 | 46 | unsigned arena_ind; |
michael@0 | 47 | size_t size; |
michael@0 | 48 | int err; |
michael@0 | 49 | je_thread_t threads[NTHREADS]; |
michael@0 | 50 | unsigned i; |
michael@0 | 51 | |
michael@0 | 52 | malloc_printf("Test begin\n"); |
michael@0 | 53 | |
michael@0 | 54 | p = malloc(1); |
michael@0 | 55 | if (p == NULL) { |
michael@0 | 56 | malloc_printf("%s(): Error in malloc()\n", __func__); |
michael@0 | 57 | ret = 1; |
michael@0 | 58 | goto label_return; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | size = sizeof(arena_ind); |
michael@0 | 62 | if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, 0))) { |
michael@0 | 63 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, |
michael@0 | 64 | strerror(err)); |
michael@0 | 65 | ret = 1; |
michael@0 | 66 | goto label_return; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | for (i = 0; i < NTHREADS; i++) { |
michael@0 | 70 | je_thread_create(&threads[i], je_thread_start, |
michael@0 | 71 | (void *)&arena_ind); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | for (i = 0; i < NTHREADS; i++) |
michael@0 | 75 | je_thread_join(threads[i], (void *)&ret); |
michael@0 | 76 | |
michael@0 | 77 | label_return: |
michael@0 | 78 | malloc_printf("Test end\n"); |
michael@0 | 79 | return (ret); |
michael@0 | 80 | } |