void PrivPtr::dereference_ptr_write_ptr(priv_ptr ptr, priv_ptr value, int dereferences, mpz_t priv_cond, int threadID) { priv_ptr copy_ptr = create_ptr(0, ptr->type); priv_ptr ptr1 = create_ptr(0, ptr->type); set_ptr(copy_ptr, ptr, threadID); priv_ptr tmp_ptr; if(dereferences > 1) { reduce_dereferences(copy_ptr, dereferences, ptr1, threadID); tmp_ptr = ptr1; } else tmp_ptr = ptr; dlist list = tmp_ptr->list; listnode node = list->head->next; while(node != list->tail) { priv_ptr ptr2 = create_ptr(0, ptr->type); priv_ptr assign_ptr = node->u.ptr_location; set_ptr(ptr2, value, threadID); mpz_t cond; mpz_init(cond); if(priv_cond == NULL) { ss->modSub(cond, 1, node->priv_tag); update_list_attributes(assign_ptr->list, cond, -1, assign_ptr->size, threadID); update_list_attributes(ptr2->list, node->priv_tag, -1, ptr2->size, threadID); } else { mpz_t* op1 = (mpz_t*)malloc(sizeof(mpz_t)); mpz_t* op2 = (mpz_t*)malloc(sizeof(mpz_t)); mpz_t* R = (mpz_t*)malloc(sizeof(mpz_t)); mpz_init_set(op1[0], priv_cond); mpz_init_set(op2[0], node->priv_tag); mpz_init(R[0]); Mul->doOperation(R, op1, op2, 1, threadID); ss->modSub(cond, 1, R[0]); update_list_attributes(assign_ptr->list, cond, -1, assign_ptr->size, threadID); update_list_attributes(ptr2->list, R[0], -1, ptr2->size, threadID); mpz_clear(op1[0]); mpz_clear(op2[0]); mpz_clear(R[0]); free(op1); free(op2); free(R); } merge_and_shrink_ptr(assign_ptr, ptr2); destroy_ptr(&ptr2); node = node->next; } destroy_ptr(©_ptr); destroy_ptr(&ptr1); return; }
//dereference read for pointer to integer void PrivPtr::dereference_ptr_read_var(priv_ptr ptr, mpz_t result, int dereferences, int threadID) { if(ptr->type != 0) { printf("WRONG TYPE on the left operator...\n"); exit(1); } priv_ptr copy_ptr = create_ptr(0, 0); priv_ptr ptr1 = create_ptr(0, 0); priv_ptr tmp_ptr; set_ptr(copy_ptr, ptr, threadID); if(dereferences > 1) { reduce_dereferences(copy_ptr, dereferences, ptr1, threadID); tmp_ptr = ptr1; } else tmp_ptr = ptr; int size = tmp_ptr->size; int index = 0; listnode tmp = tmp_ptr->list->head->next; if(size == 1) { mpz_set(result, *(tmp->u.int_var_location)); return; } mpz_t* op1 = (mpz_t*)malloc(sizeof(mpz_t) * size); mpz_t* op2 = (mpz_t*)malloc(sizeof(mpz_t) * size); mpz_t* product = (mpz_t*)malloc(sizeof(mpz_t) * size); for(int i = 0; i < size; i++) { mpz_init(op1[i]); mpz_init(op2[i]); mpz_init(product[i]); } while(tmp != tmp_ptr->list->tail) { mpz_set(op1[index], *(tmp->u.int_var_location)); mpz_set(op2[index], tmp->priv_tag); mpz_set_ui(product[index], 0); index++; tmp = tmp->next; } Mul->doOperation(product, op1, op2, size, threadID); mpz_set_ui(result, 0); for(int i = 0; i < size; i++) ss->modAdd(result, result, product[i]); for(int i = 0; i < size; i++) { mpz_clear(op1[i]); mpz_clear(op2[i]); mpz_clear(product[i]); } free(op1); free(op2); free(product); destroy_ptr(©_ptr); destroy_ptr(&ptr1); }
static void add_kmalloc(const char *func, unsigned long long ptr, unsigned int req, int alloc) { struct func_descr *funcd; struct ptr_descr *ptrd; funcd = find_func(func); if (!funcd) funcd = create_func(func); funcd->total_alloc += alloc; funcd->total_req += req; funcd->current_alloc += alloc; funcd->current_req += req; if (funcd->current_alloc > funcd->max_alloc) funcd->max_alloc = funcd->current_alloc; if (funcd->current_req > funcd->max_req) funcd->max_req = funcd->current_req; ptrd = find_ptr(ptr); if (!ptrd) ptrd = create_ptr(ptr); ptrd->alloc = alloc; ptrd->req = req; ptrd->func = funcd; }
void PrivPtr::dereference_ptr_write(priv_ptr ptr, mpz_t* int_var_loc, mpz_t** float_var_loc, void* struct_var_loc, priv_ptr* ptr_loc, int dereferences, mpz_t priv_cond, int threadID) { priv_ptr tmp_ptr = create_ptr(0, ptr->type); set_ptr(tmp_ptr, int_var_loc, float_var_loc, struct_var_loc, ptr_loc, threadID); dereference_ptr_write_ptr(ptr, tmp_ptr, dereferences, priv_cond, threadID); destroy_ptr(&tmp_ptr); }
void PrivPtr::update_ptr(priv_ptr assign_ptr, priv_ptr right_ptr, mpz_t private_tag, int index, int threadID) { if(assign_ptr->size == 0) { copy_list(assign_ptr->list, right_ptr->list,right_ptr->level-1, assign_ptr->type); update_list_attributes(assign_ptr->list, private_tag, index, right_ptr->size, threadID); assign_ptr->size = right_ptr->size; return; } else { priv_ptr ptr = create_ptr(right_ptr->level, right_ptr->type); ptr->size = right_ptr->size; mpz_t priv_cond; mpz_init(priv_cond); ss->modSub(priv_cond, 1, private_tag); copy_list(ptr->list, right_ptr->list, right_ptr->level-1, assign_ptr->type); update_list_attributes(ptr->list, private_tag, index, ptr->size, threadID); update_list_attributes(assign_ptr->list, priv_cond, -1, assign_ptr->size, threadID); merge_and_shrink_ptr(assign_ptr, ptr); mpz_clear(priv_cond); destroy_ptr(&ptr); return; } }
priv_ptr* PrivPtr::create_ptr(int level, int type, int num) { priv_ptr* ptrs = (priv_ptr*)malloc(sizeof(priv_ptr) * num); for(int i = 0; i < num; i++) ptrs[i] = create_ptr(level, type); return ptrs; }
void PrivPtr::dereference_ptr_read_ptr(priv_ptr ptr, priv_ptr result, int dereferences, mpz_t priv_cond, int threadID) { priv_ptr copy_ptr = create_ptr(ptr->level, ptr->type); priv_ptr ptr1 = create_ptr(ptr->level, ptr->type); set_ptr(ptr1, ptr, threadID); priv_ptr tmp_ptr; if(dereferences > 1) { reduce_dereferences(ptr1, dereferences, copy_ptr, threadID); tmp_ptr = copy_ptr; } else tmp_ptr = ptr; read_write_helper(tmp_ptr, result, priv_cond, threadID); destroy_ptr(©_ptr); destroy_ptr(&ptr1); }
void PrivPtr::reduce_dereferences(priv_ptr ptr, int dereferences, priv_ptr result_ptr, int threadID) { priv_ptr runner = create_ptr(0, ptr->type); set_ptr(runner, ptr, threadID); while(dereferences > 1) { read_write_helper(runner, result_ptr, NULL, threadID); set_ptr(runner, result_ptr, threadID); dereferences--; } set_ptr(result_ptr, runner, threadID); destroy_ptr(&runner); return; }
// returns true if plugin was loaded successfully bool KDecorationPlugins::loadPlugin( QString nameStr ) { if( nameStr.isEmpty()) { KConfigGroup group( config, QString("Style") ); nameStr = group.readEntry("PluginLib", defaultPlugin ); } // make sure people can switch between HEAD and kwin_iii branch if( nameStr.startsWith( "kwin_" )) nameStr = "kwin3_" + nameStr.mid( 5 ); KLibrary *oldLibrary = library; KDecorationFactory* oldFactory = fact; QString path = KLibLoader::findLibrary(nameStr); kDebug(1212) << "kwin : path " << path << " for " << nameStr; // If the plugin was not found, try to find the default if (path.isEmpty()) { nameStr = defaultPlugin; path = KLibLoader::findLibrary(nameStr); } // If no library was found, exit kwin with an error message if (path.isEmpty()) { error( i18n("No window decoration plugin library was found." )); return false; } // Check if this library is not already loaded. if(pluginStr == nameStr) return true; // Try loading the requested plugin library = KLibLoader::self()->library(path); // If that fails, fall back to the default plugin if (!library) { kDebug(1212) << " could not load library, try default plugin again"; nameStr = defaultPlugin; if ( pluginStr == nameStr ) return true; path = KLibLoader::findLibrary(nameStr); if (!path.isEmpty()) library = KLibLoader::self()->library(path); } if (!library) { error( i18n("The default decoration plugin is corrupt " "and could not be loaded." )); return false; } create_ptr = NULL; KLibrary::void_function_ptr create_func = library->resolveFunction("create_factory"); if(create_func) create_ptr = (KDecorationFactory* (*)())create_func; if(!create_ptr) { error( i18n( "The library %1 is not a KWin plugin.", path )); library->unload(); return false; } fact = create_ptr(); fact->checkRequirements( this ); // let it check what is supported pluginStr = nameStr; // For clients in kdeartwork QString catalog = nameStr; catalog.replace( "kwin3_", "kwin_" ); KGlobal::locale()->insertCatalog( catalog ); // For KCommonDecoration based clients KGlobal::locale()->insertCatalog( "kwin_lib" ); // For clients in kdebase KGlobal::locale()->insertCatalog( "kwin_clients" ); // For clients in kdeartwork KGlobal::locale()->insertCatalog( "kwin_art_clients" ); old_library = oldLibrary; // save for delayed destroying old_fact = oldFactory; return true; }
// returns true if plugin was loaded successfully bool KDecorationPlugins::loadPlugin(QString nameStr) { KConfigGroup group(config, QString("Style")); if (nameStr.isEmpty()) { nameStr = group.readEntry("PluginLib", defaultPlugin); } // Check if this library is not already loaded. if (pluginStr == nameStr) return true; KLibrary *oldLibrary = library; KDecorationFactory* oldFactory = fact; if (!canLoad(nameStr, &library)) { // If that fails, fall back to the default plugin nameStr = defaultPlugin; if (!canLoad(nameStr, &library)) { // big time trouble! // -> exit kwin with an error message error(i18n("The default decoration plugin is corrupt and could not be loaded.")); return false; } } // guarded by "canLoad" KLibrary::void_function_ptr create_func = library->resolveFunction("create_factory"); if (create_func) create_ptr = (KDecorationFactory * (*)())create_func; if (!create_ptr) { // this means someone probably attempted to load "some" kwin plugin/lib as deco // and thus cheated on the "isLoaded" shortcut -> try the default and yell a warning if (nameStr != defaultPlugin) { kWarning(1212) << i18n("The library %1 was attempted to be loaded as a decoration plugin but it is NOT", nameStr); return loadPlugin(defaultPlugin); } else { // big time trouble! // -> exit kwin with an error message error(i18n("The default decoration plugin is corrupt and could not be loaded.")); return false; } } fact = create_ptr(); fact->checkRequirements(this); // let it check what is supported pluginStr = nameStr; // For clients in kdeartwork QString catalog = nameStr; catalog.replace("kwin3_", "kwin_"); KGlobal::locale()->insertCatalog(catalog); // For KCommonDecoration based clients KGlobal::locale()->insertCatalog("libkdecorations"); // For clients in kdebase KGlobal::locale()->insertCatalog("kwin_clients"); // For clients in kdeartwork KGlobal::locale()->insertCatalog("kwin_art_clients"); old_library = oldLibrary; // save for delayed destroying old_fact = oldFactory; return true; }
//dereference write to a pointer to int void PrivPtr::dereference_ptr_write_var(priv_ptr ptr, mpz_t value, int dereferences, mpz_t priv_cond, int threadID) { if(ptr->type != 0) { printf("WRONG TYPE on the left operator...\n"); exit(1); } priv_ptr tmp_ptr; priv_ptr copy_ptr = create_ptr(0, 0); priv_ptr ptr1 = create_ptr(0, 0); set_ptr(ptr1, ptr, threadID); if(dereferences > 1) { reduce_dereferences(ptr1, dereferences, copy_ptr, threadID); tmp_ptr = copy_ptr; } else tmp_ptr = ptr; int index = 0; int size = tmp_ptr->size; listnode tmp = tmp_ptr->list->head->next; mpz_t* op1 = (mpz_t*)malloc(sizeof(mpz_t) * size); mpz_t* op2 = (mpz_t*)malloc(sizeof(mpz_t) * size); mpz_t* op3 = (mpz_t*)malloc(sizeof(mpz_t) * size); mpz_t* op4 = (mpz_t*)malloc(sizeof(mpz_t) * size); for(int i = 0; i < size; i++) { mpz_init(op1[i]); mpz_init(op2[i]); mpz_init(op3[i]); mpz_init(op4[i]); } while(tmp != tmp_ptr->list->tail) { mpz_set(op1[index], *(tmp->u.int_var_location)); mpz_set(op2[index], tmp->priv_tag); if(priv_cond != NULL) mpz_set(op3[index], priv_cond); mpz_set(op4[index], value); index++; tmp = tmp->next; } /* compute (*location) + tag * priv_cond * (value-(*location)) */ ss->modSub(op4, op4, op1, size); if(priv_cond != NULL) Mul->doOperation(op4, op4, op3, size, threadID); if(size != 1) Mul->doOperation(op4, op4, op2, size, threadID); ss->modAdd(op4, op1, op4, size); /* update the values of nodes in the list (not update the tags) */ tmp = tmp_ptr->list->head->next; index = 0; while(tmp != tmp_ptr->list->tail) { mpz_set(*(tmp->u.int_var_location), op4[index++]); tmp = tmp->next; } for(int i = 0; i < size; i++) { mpz_clear(op1[i]); mpz_clear(op2[i]); mpz_clear(op3[i]); mpz_clear(op4[i]); } free(op1); free(op2); free(op3); free(op4); destroy_ptr(&ptr1); destroy_ptr(©_ptr); return; }
void PrivPtr::read_write_helper(priv_ptr ptr, priv_ptr result, mpz_t priv_cond, int threadID) { // compute the number of elements in the second layer of list of ptr int num = 0; dlist list = ptr->list; listnode node = list->head->next; while(node != list->tail) { num += compute_list_size(node->u.ptr_location->list); node = node->next; } mpz_t* op1 = (mpz_t*)malloc(sizeof(mpz_t) * num); mpz_t* op2 = (mpz_t*)malloc(sizeof(mpz_t) * num); mpz_t* op3 = (mpz_t*)malloc(sizeof(mpz_t) * num); mpz_t* R = (mpz_t*)malloc(sizeof(mpz_t) * num); for(int i = 0; i < num; i++) { mpz_init(op1[i]); mpz_init(op2[i]); mpz_init(op3[i]); mpz_init(R[i]); } //fill the values for op1 and op2 int index = 0; node = list->head->next; while(node != list->tail) { dlist child_list = node->u.ptr_location->list; listnode child_node = child_list->head->next; while(child_node != child_list->tail) { mpz_set(op1[index], node->priv_tag); mpz_set(op2[index], child_node->priv_tag); if(priv_cond != NULL) mpz_set(op3[index], priv_cond); index++; child_node = child_node->next; } node = node->next; } Mul->doOperation(R, op1, op2, num, threadID); if(priv_cond != NULL) { mpz_t cond; mpz_init(cond); ss->modSub(cond, 1, priv_cond); update_list_attributes(result->list, cond, -1, result->size, threadID); Mul->doOperation(R, R, op3, num, threadID); } else { clear_list(&(result->list)); result->size = 0; } result->level = ptr->level-1; priv_ptr tmp_ptr = create_ptr(ptr->level-1, ptr->type); copy_nested_ptr(tmp_ptr, ptr, R); merge_and_shrink_ptr(result, tmp_ptr); destroy_ptr(&tmp_ptr); for(int i = 0; i < num; i++) { mpz_clear(op1[i]); mpz_clear(op2[i]); mpz_clear(op3[i]); mpz_clear(R[i]); } free(op1); free(op2); free(op3); free(R); }