Initialize mparams */
| 3181 | |
| 3182 | /* Initialize mparams */ |
| 3183 | static int init_mparams(void) { |
| 3184 | #ifdef NEED_GLOBAL_LOCK_INIT |
| 3185 | if (malloc_global_mutex_status <= 0) |
| 3186 | init_malloc_global_mutex(); |
| 3187 | #endif |
| 3188 | |
| 3189 | ACQUIRE_MALLOC_GLOBAL_LOCK(); |
| 3190 | if (mparams.magic == 0) { |
| 3191 | size_t magic; |
| 3192 | size_t psize; |
| 3193 | size_t gsize; |
| 3194 | |
| 3195 | #ifndef WIN32 |
| 3196 | psize = malloc_getpagesize; |
| 3197 | gsize = ((DEFAULT_GRANULARITY != 0)? DEFAULT_GRANULARITY : psize); |
| 3198 | #else /* WIN32 */ |
| 3199 | { |
| 3200 | SYSTEM_INFO system_info; |
| 3201 | GetSystemInfo(&system_info); |
| 3202 | psize = system_info.dwPageSize; |
| 3203 | gsize = ((DEFAULT_GRANULARITY != 0)? |
| 3204 | DEFAULT_GRANULARITY : system_info.dwAllocationGranularity); |
| 3205 | } |
| 3206 | #endif /* WIN32 */ |
| 3207 | |
| 3208 | /* Sanity-check configuration: |
| 3209 | size_t must be unsigned and as wide as pointer type. |
| 3210 | ints must be at least 4 bytes. |
| 3211 | alignment must be at least 8. |
| 3212 | Alignment, min chunk size, and page size must all be powers of 2. |
| 3213 | */ |
| 3214 | if ((sizeof(size_t) != sizeof(char*)) || |
| 3215 | (MAX_SIZE_T < MIN_CHUNK_SIZE) || |
| 3216 | (sizeof(int) < 4) || |
| 3217 | (MALLOC_ALIGNMENT < (size_t)8U) || |
| 3218 | ((MALLOC_ALIGNMENT & (MALLOC_ALIGNMENT-SIZE_T_ONE)) != 0) || |
| 3219 | ((MCHUNK_SIZE & (MCHUNK_SIZE-SIZE_T_ONE)) != 0) || |
| 3220 | ((gsize & (gsize-SIZE_T_ONE)) != 0) || |
| 3221 | ((psize & (psize-SIZE_T_ONE)) != 0)) |
| 3222 | ABORT; |
| 3223 | mparams.granularity = gsize; |
| 3224 | mparams.page_size = psize; |
| 3225 | mparams.mmap_threshold = DEFAULT_MMAP_THRESHOLD; |
| 3226 | mparams.trim_threshold = DEFAULT_TRIM_THRESHOLD; |
| 3227 | #if MORECORE_CONTIGUOUS |
| 3228 | mparams.default_mflags = USE_LOCK_BIT|USE_MMAP_BIT; |
| 3229 | #else /* MORECORE_CONTIGUOUS */ |
| 3230 | mparams.default_mflags = USE_LOCK_BIT|USE_MMAP_BIT|USE_NONCONTIGUOUS_BIT; |
| 3231 | #endif /* MORECORE_CONTIGUOUS */ |
| 3232 | |
| 3233 | #if !ONLY_MSPACES |
| 3234 | /* Set up lock for main malloc area */ |
| 3235 | gm->mflags = mparams.default_mflags; |
| 3236 | (void)INITIAL_LOCK(&gm->mutex); |
| 3237 | #endif |
| 3238 | #if LOCK_AT_FORK |
| 3239 | pthread_atfork(&pre_fork, &post_fork_parent, &post_fork_child); |
| 3240 | #endif |
nothing calls this directly
no test coverage detected