1 /* ``Licensed under the Apache License, Version 2.0 (the "License"); 2 * you may not use this file except in compliance with the License. 3 * You may obtain a copy of the License at 4 * 5 * http://www.apache.org/licenses/LICENSE-2.0 6 * 7 * Unless required by applicable law or agreed to in writing, software 8 * distributed under the License is distributed on an "AS IS" BASIS, 9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 * See the License for the specific language governing permissions and 11 * limitations under the License. 12 * 13 * The Initial Developer of the Original Code is Ericsson Utvecklings AB. 14 * Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings 15 * AB. All Rights Reserved.'' 16 * 17 * $Id$ 18 */ 19 20 #ifndef ALLOCATOR_TEST_H__ 21 #define ALLOCATOR_TEST_H__ 22 23 #if SIZEOF_VOID_P == SIZEOF_INT 24 typedef unsigned int Ulong; 25 #elif SIZEOF_VOID_P == SIZEOF_LONG 26 typedef unsigned long Ulong; 27 #elif SIZEOF_VOID_P == SIZEOF_LONG_LONG 28 typedef unsigned long long Ulong; 29 #else 30 # error No pointer sized integer type found ??? 31 #endif 32 33 #ifdef __WIN32__ 34 typedef Ulong erts_alc_test_Fn(Ulong, Ulong, Ulong, Ulong); 35 # define erts_alc_test ((erts_alc_test_Fn*)WinDynNifCallbacks.erts_alc_test) 36 #else 37 Ulong erts_alc_test(Ulong, Ulong, Ulong, Ulong); 38 #endif 39 40 #define UNDEF__ ~((Ulong) 0) 41 42 #define ALC_TEST0(OP) \ 43 erts_alc_test((Ulong) (OP), UNDEF__, UNDEF__, UNDEF__) 44 #define ALC_TEST1(OP, A1) \ 45 erts_alc_test((Ulong) (OP), (Ulong) (A1), UNDEF__, UNDEF__) 46 #define ALC_TEST2(OP, A1, A2) \ 47 erts_alc_test((Ulong) (OP), (Ulong) (A1), (Ulong) (A2), UNDEF__) 48 #define ALC_TEST3(OP, A1, A2, A3) \ 49 erts_alc_test((Ulong) (OP), (Ulong) (A1), (Ulong) (A2), (Ulong) (A3)) 50 51 typedef Ulong Block_t; 52 typedef Ulong Carrier_t; 53 typedef Ulong Allctr_t; 54 typedef Ulong RBT_t; 55 typedef Ulong RBTL_t; 56 typedef void* erts_thread; 57 typedef void* erts_mutex; 58 typedef void* erts_cond; 59 60 /* From erl_alloc_util.c */ 61 62 #define BLK_SZ(B) ((Ulong) ALC_TEST1(0x000, (B))) 63 #define UMEM_SZ(B) ((Ulong) ALC_TEST1(0x001, (B))) 64 #define IS_PREV_FREE_BLK(B) ((Ulong) ALC_TEST1(0x002, (B))) 65 #define IS_FREE_BLK(B) ((Ulong) ALC_TEST1(0x003, (B))) 66 #define IS_LAST_BLK(B) ((Ulong) ALC_TEST1(0x004, (B))) 67 #define UMEM2BLK(U) ((Block_t *) ALC_TEST1(0x005, (U))) 68 #define BLK2UMEM(B) ((void *) ALC_TEST1(0x006, (B))) 69 #define IS_SBC(C) ((Ulong) ALC_TEST1(0x007, (C))) 70 #define IS_SBC_BLK(B) ((Ulong) ALC_TEST1(0x008, (B))) 71 #define IS_MBC(C) ((Ulong) ALC_TEST1(0x009, (C))) 72 #define IS_MMAP_C(C) ((Ulong) ALC_TEST1(0x00a, (C))) 73 #define C_SZ(C) ((Ulong) ALC_TEST1(0x00b, (C))) 74 #define SBC2BLK(A, C) ((Block_t *) ALC_TEST2(0x00c, (A), (C))) 75 #define BLK_TO_SBC(A, B) ((Carrier_t *) ALC_TEST2(0x00d, (A), (B))) 76 #define MBC_TO_FIRST_BLK(A, C) ((Block_t *) ALC_TEST2(0x00e, (A), (C))) 77 #define FIRST_BLK_TO_MBC(A, B) ((Carrier_t *) ALC_TEST2(0x00f, (A), (B))) 78 #define FIRST_MBC(A) ((Carrier_t *) ALC_TEST1(0x010, (A))) 79 #define LAST_MBC(A) ((Carrier_t *) ALC_TEST1(0x011, (A))) 80 #define FIRST_SBC(A) ((Carrier_t *) ALC_TEST1(0x012, (A))) 81 #define LAST_SBC(A) ((Carrier_t *) ALC_TEST1(0x013, (A))) 82 #define NEXT_C(C) ((Carrier_t *) ALC_TEST1(0x014, (C))) 83 #define PREV_C(C) ((Carrier_t *) ALC_TEST1(0x015, (C))) 84 #define ABLK_HDR_SZ ((Ulong) ALC_TEST0(0x016)) 85 #define MIN_BLK_SZ(A) ((Ulong) ALC_TEST1(0x017, (A))) 86 #define NXT_BLK(B) ((Block_t *) ALC_TEST1(0x018, (B))) 87 #define PREV_BLK(B) ((Block_t *) ALC_TEST1(0x019, (B))) 88 #define IS_MBC_FIRST_BLK(A,B) ((Ulong) ALC_TEST2(0x01a, (A), (B))) 89 #define UNIT_SZ ((Ulong) ALC_TEST0(0x01b)) 90 #define BLK_TO_MBC(B) ((Carrier_t *) ALC_TEST1(0x01c, (B))) 91 #define ADD_MBC(A, C) ((void) ALC_TEST2(0x01d, (A), (C))) 92 #define REMOVE_MBC(A, C) ((void) ALC_TEST2(0x01e, (A), (C))) 93 #define ZERO_CRR_SIZE ((Ulong) ALC_TEST0(0x01f)) 94 #define ZERO_CRR_INIT(A,B) ((Carrier_t *) ALC_TEST2(0x020, (A), (B))) 95 #define CPOOL_INSERT(A,B) ((Carrier_t *) ALC_TEST2(0x021, (A), (B))) 96 #define CPOOL_DELETE(A,B) ((Carrier_t *) ALC_TEST2(0x022, (A), (B))) 97 #define CPOOL_IS_EMPTY(A) ((int) ALC_TEST1(0x023, (A))) 98 #define CPOOL_IS_IN_POOL(A,B) ((int) ALC_TEST2(0x024, (A), (B))) 99 #define UMEM2BLK_TEST(P) ((Block_t*) ALC_TEST1(0x025, (P))) 100 101 /* From erl_goodfit_alloc.c */ 102 #define BKT_IX(A, S) ((Ulong) ALC_TEST2(0x100, (A), (S))) 103 #define BKT_MIN_SZ(A, I) ((Ulong) ALC_TEST2(0x101, (A), (I))) 104 #define NO_OF_BKTS ((Ulong) ALC_TEST0(0x102)) 105 #define FIND_BKT(A, I) ((int) ALC_TEST2(0x103, (A), (I))) 106 107 /* From erl_bestfit_alloc.c and erl_ao_firstfit_alloc.c */ 108 #define IS_AOBF(A) ((Ulong) ALC_TEST1(RBT_OP(0), (A))) 109 #define RBT_ROOT(A,SZ) ((RBT_t *) ALC_TEST2(RBT_OP(1), (A), (SZ))) 110 #define RBT_PARENT(T) ((RBT_t *) ALC_TEST1(RBT_OP(2), (T))) 111 #define RBT_LEFT(T) ((RBT_t *) ALC_TEST1(RBT_OP(3), (T))) 112 #define RBT_RIGHT(T) ((RBT_t *) ALC_TEST1(RBT_OP(4), (T))) 113 #define RBT_NEXT(T) ((RBTL_t *) ALC_TEST1(RBT_OP(5), (T))) 114 #define RBT_IS_BLACK(T) ((Ulong) ALC_TEST1(RBT_OP(6), (T))) 115 #define RBT_IS_TREE(T) ((Ulong) ALC_TEST1(RBT_OP(7), (T))) 116 #define IS_BF_ALGO(A) ((Ulong) ALC_TEST1(RBT_OP(8), (A))) 117 #define RBT_MAX_SZ(T) ((Ulong) ALC_TEST1(RBT_OP(9), (T))) 118 #define IS_BF(A) ((Ulong) ALC_TEST1(RBT_OP(0xa), (A))) 119 #define RBT_PREV(T) ((RBTL_t *) ALC_TEST1(RBT_OP(0xb), (T))) 120 121 /* From erl_mseg.c */ 122 #define HAVE_MSEG() ((int) ALC_TEST0(0x400)) 123 #define MSEG_ALLOC(SP) ((void *) ALC_TEST1(0x401, (SP))) 124 #define MSEG_DEALLOC(P, S) ((void) ALC_TEST2(0x402, (P), (S))) 125 #define MSEG_REALLOC(P, OS, SP) ((void *) ALC_TEST3(0x403, (P), (OS), \ 126 (SP))) 127 #define MSEG_CLEAR_CACHE() ((void) ALC_TEST0(0x404)) 128 #define MSEG_NO() ((Ulong) ALC_TEST0(0x405)) 129 #define MSEG_CACHE_SIZE() ((Ulong) ALC_TEST0(0x406)) 130 131 /* From erl_alloc.c */ 132 133 #undef ALLOC 134 #undef REALLOC 135 #undef FREE 136 137 #define ALLOC(A, S) ((void *) ALC_TEST2(0xf00, (A), (S))) 138 #define REALLOC(A, P, S) ((void *) ALC_TEST3(0xf01, (A), (P), (S))) 139 #define FREE(A, P) ((void) ALC_TEST2(0xf02, (A), (P))) 140 #define START_ALC(N, T, A) ((Allctr_t *) ALC_TEST3(0xf03, (N), (T), (A))) 141 #define STOP_ALC(A) ((void) ALC_TEST1(0xf04, (A))) 142 #define IS_THREADS_ENABLED ((int) ALC_TEST0(0xf05)) 143 #define IS_ALLOC_THREAD_SAFE(A) ((int) ALC_TEST1(0xf06, (A))) 144 #define IS_ALLOC_FORK_SAFE(A) ((int) ALC_TEST1(0xf07, (A))) 145 #define THR_MTX_CREATE() ((erts_mutex) ALC_TEST0(0xf08)) 146 #define THR_MTX_DESTROY(M) ((void) ALC_TEST1(0xf09, (M))) 147 #define THR_MTX_LOCK(M) ((void) ALC_TEST1(0xf0a, (M))) 148 #define THR_MTX_UNLOCK(M) ((void) ALC_TEST1(0xf0b, (M))) 149 #define THR_COND_CREATE() ((erts_cond) ALC_TEST0(0xf0c)) 150 #define THR_COND_DESTROY(C) ((void) ALC_TEST1(0xf0d, (C))) 151 #define THR_COND_BCAST(C) ((void) ALC_TEST1(0xf0e, (C))) 152 #define THR_COND_WAIT(C, M) ((void) ALC_TEST2(0xf0f, (C), (M))) 153 #define THR_CREATE(F, A) ((erts_thread) ALC_TEST2(0xf10, (F), (A))) 154 #define THR_JOIN(T) ((void) ALC_TEST1(0xf11, (T))) 155 #define THR_EXIT(R) ((void) ALC_TEST1(0xf12, (R))) 156 #define IS_SMP_ENABLED ((int) ALC_TEST0(0xf13)) 157 #define ALLOC_TEST(S) ((void*) ALC_TEST1(0xf14, (S))) 158 #define FREE_TEST(P) ((void) ALC_TEST1(0xf15, (P))) 159 #define REALLOC_TEST(P,S) ((void*) ALC_TEST2(0xf16, (P), (S))) 160 #define SET_TEST_MBC_USER_HEADER(SZ,CMBC,DMBC) ((int)ALC_TEST3(0xf17, (SZ), (CMBC), (DMBC))) 161 #define GET_TEST_MBC_SIZE() ((int) ALC_TEST0(0xf18)) 162 163 #endif 164