/* * pmalloc_construct -- allocates a new block of memory with a constructor * * The block offset is written persistently into the off variable, but only * after the constructor function has been called. * * If successful function returns zero. Otherwise an error number is returned. */ int pmalloc_construct(PMEMobjpool *pop, uint64_t *off, size_t size, void (*constructor)(PMEMobjpool *pop, void *ptr, size_t usable_size, void *arg), void *arg, uint64_t data_off) { int err; struct lane_section *lane; lane_hold(pop, &lane, LANE_SECTION_ALLOCATOR); size_t sizeh = size + sizeof (struct allocation_header); struct bucket *b = heap_get_best_bucket(pop, sizeh); struct memory_block m = {0, 0, 0, 0}; m.size_idx = b->calc_units(b, sizeh); err = heap_get_bestfit_block(pop, b, &m); if (err == ENOMEM && b->type == BUCKET_HUGE) goto out; /* there's only one huge bucket */ if (err == ENOMEM) { /* * There's no more available memory in the common heap and in * this lane cache, fallback to the auxiliary (shared) bucket. */ b = heap_get_auxiliary_bucket(pop, sizeh); err = heap_get_bestfit_block(pop, b, &m); } if (err == ENOMEM) { /* * The auxiliary bucket cannot satisfy our request, borrow * memory from other caches. */ heap_drain_to_auxiliary(pop, b, m.size_idx); err = heap_get_bestfit_block(pop, b, &m); } if (err == ENOMEM) { /* we are completely out of memory */ goto out; } /* * Now that the memory is reserved we can go ahead with making the * allocation persistent. */ uint64_t real_size = b->unit_size * m.size_idx; persist_alloc(pop, lane, m, real_size, off, constructor, arg, data_off); err = 0; out: lane_release(pop); return err; }
int php_init_config(char *php_ini_path_override) { char *env_location, *php_ini_search_path; int safe_mode_state; char *open_basedir; int free_ini_search_path=0; zend_file_handle fh; PLS_FETCH(); if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1)==FAILURE) { return FAILURE; } zend_llist_init(&extension_lists.engine, sizeof(zval), (llist_dtor_func_t) free_estring, 1); zend_llist_init(&extension_lists.functions, sizeof(zval), (llist_dtor_func_t) ZVAL_DESTRUCTOR, 1); safe_mode_state = PG(safe_mode); open_basedir = PG(open_basedir); env_location = getenv("PHPRC"); if (!env_location) { env_location=""; } if (php_ini_path_override) { php_ini_search_path = php_ini_path_override; free_ini_search_path = 0; } else { char *default_location; int free_default_location; #ifdef PHP_WIN32 default_location = (char *) emalloc(512); if (!GetWindowsDirectory(default_location,255)) { default_location[0]=0; } free_default_location=1; #else default_location = PHP_CONFIG_FILE_PATH; free_default_location=0; #endif php_ini_search_path = (char *) emalloc(sizeof(".")+strlen(env_location)+strlen(default_location)+2+1); free_ini_search_path = 1; if(env_location && env_location[0]) { sprintf(php_ini_search_path, ".%c%s%c%s", ZEND_PATHS_SEPARATOR, env_location, ZEND_PATHS_SEPARATOR, default_location); } else { sprintf(php_ini_search_path, ".%c%s", ZEND_PATHS_SEPARATOR, default_location); } if (free_default_location) { efree(default_location); } } PG(safe_mode) = 0; PG(open_basedir) = NULL; fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path); if (free_ini_search_path) { efree(php_ini_search_path); } PG(safe_mode) = safe_mode_state; PG(open_basedir) = open_basedir; if (!fh.handle.fp) { return SUCCESS; /* having no configuration file is ok */ } fh.type = ZEND_HANDLE_FP; fh.filename = php_ini_opened_path; zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists); if (php_ini_opened_path) { zval tmp; tmp.value.str.len = strlen(php_ini_opened_path); tmp.value.str.val = zend_strndup(php_ini_opened_path, tmp.value.str.len); tmp.type = IS_STRING; zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"),(void *) &tmp,sizeof(zval), NULL); persist_alloc(php_ini_opened_path); } return SUCCESS; }