/* * Called when the last reference to the mm * is dropped: either by a lazy thread or by * mmput. Free the page directory and the mm. */ void __mmdrop(struct mm_struct *mm) { BUG_ON(mm == &init_mm); mm_free_pgd(mm); destroy_context(mm); mmu_notifier_mm_destroy(mm); #ifdef CONFIG_TRANSPARENT_HUGEPAGE VM_BUG_ON(mm->pmd_huge_pte); #endif free_mm(mm); }
/* * Steal a context from a task that has one at the moment. * This is only used on 8xx and 4xx and we presently assume that * they don't do SMP. If they do then this will have to check * whether the MM we steal is in use. * We also assume that this is only used on systems that don't * use an MMU hash table - this is true for 8xx and 4xx. * This isn't an LRU system, it just frees up each context in * turn (sort-of pseudo-random replacement :). This would be the * place to implement an LRU scheme if anyone was motivated to do it. * -- paulus */ void steal_context(void) { struct mm_struct *mm; /* free up context `next_mmu_context' */ /* if we shouldn't free context 0, don't... */ if (next_mmu_context < FIRST_CONTEXT) next_mmu_context = FIRST_CONTEXT; mm = context_mm[next_mmu_context]; flush_tlb_mm(mm); destroy_context(mm); }
int main(int argc, char **argv) { int ret; context_t context; if (zero_context(&context) < 0) { return EXIT_FAILURE; } ret = make_sock(&context.socks[CTL_SOCK], SERVER_IP, CTL_PORT); if (ret < 0) { destroy_context(&context); return EXIT_FAILURE; } proc_ebs(&context); destroy_context(&context); return EXIT_SUCCESS; }
void test_context (void) { CUZMEM_CONTEXT context; // create_context(); context = get_context(); printf ("plan_name[] : %s\n", context->plan_name); printf ("start_time : %lu\n", context->start_time); printf ("best_time : %lu\n", context->best_time); destroy_context (); }
static inline void __exit_mm(struct task_struct * tsk) { struct mm_struct * mm = tsk->mm; /* Set us up to use the kernel mm state */ if (mm != &init_mm) { flush_cache_mm(mm); flush_tlb_mm(mm); destroy_context(mm); tsk->mm = &init_mm; tsk->swappable = 0; SET_PAGE_DIR(tsk, swapper_pg_dir); mm_release(); mmput(mm); } }
void msls_destroy_connection(SERVER_STATE *state, uint32_t client_id) { if (!state) { return; } CLIENT_CONTEXT *connection = NULL; for (int i=0; i<MAX_CONNECTIONS; i++) { connection = state->connections[i]; if (connection && connection->connection_id == client_id) { destroy_context(connection); state->connections[i] = NULL; } } }
static void audio_converter_cleanup(gavl_audio_converter_t* cnv) { gavl_audio_convert_context_t * ctx; ctx = cnv->contexts; while(ctx) { ctx = cnv->contexts->next; if(ctx && cnv->contexts->output_frame) gavl_audio_frame_destroy(cnv->contexts->output_frame); destroy_context(cnv->contexts); cnv->contexts = ctx; } cnv->num_conversions = 0; cnv->contexts = NULL; cnv->last_context = NULL; }
void ShellWin32::run() { create_window(); create_context(); resize_swapchain(settings_.initial_width, settings_.initial_height); Win32Timer timer; double current_time = timer.get(); while (true) { bool quit = false; assert(settings_.animate); // process all messages MSG msg; while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { quit = true; break; } TranslateMessage(&msg); DispatchMessage(&msg); } if (quit) break; acquire_back_buffer(); double t = timer.get(); add_game_time(static_cast<float>(t - current_time)); present_back_buffer(); current_time = t; } destroy_context(); DestroyWindow(hwnd_); }
void ShellXcb::run() { create_window(); xcb_map_window(c_, win_); xcb_flush(c_); create_context(); resize_swapchain(settings_.initial_width, settings_.initial_height); quit_ = false; if (settings_.animate) loop_poll(); else loop_wait(); destroy_context(); xcb_destroy_window(c_, win_); xcb_flush(c_); }
virtual int run_tcp_server(int argc, char_t **argv, char_t **env) { int err = 0; talas::protocol::tls::openssl::server_context context; talas::protocol::tls::openssl::server server(context); if ((create_context(context))) { if ((server.create())) { if ((network::os::sockets::startup())) { if ((ep_.attach(accept_port_))) { if ((sk_.open(tp_))) { if ((sk_.listen(ep_))) { network::os::socket sk; io::socket::tcp::reader rsock(sk); io::socket::tcp::writer wsock(sk); talas::protocol::tls::openssl::connection connection(rsock, wsock); if ((sk_.accept(sk, ep_))) { if ((server.accept(connection))) { respond(connection); } sk.close(); } } sk_.close(); } ep_.detach(); } network::os::sockets::cleanup(); } server.destroy(); } destroy_context(context); } return err; }
void ShellAndroid::on_app_cmd(int32_t cmd) { switch (cmd) { case APP_CMD_INIT_WINDOW: create_context(); resize_swapchain(0, 0); break; case APP_CMD_TERM_WINDOW: destroy_context(); break; case APP_CMD_WINDOW_RESIZED: resize_swapchain(0, 0); break; case APP_CMD_STOP: ANativeActivity_finish(app_.activity); break; default: break; } }
/* * Flush the entrie MM for userland. The fastest way is to move to Next ASID */ noinline void local_flush_tlb_mm(struct mm_struct *mm) { /* * Small optimisation courtesy IA64 * flush_mm called during fork,exit,munmap etc, multiple times as well. * Only for fork( ) do we need to move parent to a new MMU ctxt, * all other cases are NOPs, hence this check. */ if (atomic_read(&mm->mm_users) == 0) return; /* * - Move to a new ASID, but only if the mm is still wired in * (Android Binder ended up calling this for vma->mm != tsk->mm, * causing h/w - s/w ASID to get out of sync) * - Also get_new_mmu_context() new implementation allocates a new * ASID only if it is not allocated already - so unallocate first */ destroy_context(mm); if (current->mm == mm) get_new_mmu_context(mm); }
void run_server() { zctx_t *ctx; void *socket; int i, n, nclient; char buf[256]; char data[256]; char client[256]; ctx = new_context(); socket = new_socket(ctx, ZMQ_ROUTER); // socket = new_socket(ctx, ZMQ_REP); assert_result(socket_bind(socket, host), 0); // assert_result(zmq_bind(socket, host), 0); log_printf(0, "my identity=%s\n", zsocket_identity(socket)); i = 0; for (;;) { log_printf(0, "Waiting %d\n", i); nclient = zmq_recv(socket, client, sizeof(client), 0); client[nclient] = 0; log_printf(0, "From %s [%d]\n", client, nclient); n = zmq_recv(socket, buf, sizeof(buf), 0); buf[n] = 0; if (n != 0) log_printf(0, "Missing EMPTY frame! buf=%s\n", buf); n = zmq_recv(socket, buf, sizeof(buf), 0); buf[n] = 0; log_printf(0, "Got %s\n", buf); zmq_send(socket, client, nclient, ZMQ_SNDMORE); zmq_send(socket, NULL, 0, ZMQ_SNDMORE); snprintf(data, sizeof(buf), "(%s) World %d", buf, i); zmq_send(socket, data, strlen(data)+1, 0); i++; } destroy_context(ctx); }
virtual int run_tcp_client(int argc, char_t **argv, char_t **env) { int err = 0; talas::protocol::tls::openssl::client_context context; talas::protocol::tls::openssl::client client(context); io::socket::tcp::reader rsock(sk_); io::socket::tcp::writer wsock(sk_); talas::protocol::tls::openssl::connection connection(rsock, wsock); if ((create_context(context))) { if ((client.create())) { if ((network::os::sockets::startup())) { if ((ep_.attach(host_, port_))) { if ((sk_.open(tp_))) { if ((sk_.connect(ep_))) { if ((client.connect(connection))) { request(connection); } } sk_.close(); } ep_.detach(); } network::os::sockets::cleanup(); } client.destroy(); } destroy_context(context); } return err; }
void run_client() { zctx_t *ctx; void *socket; int i, n; char buf[256]; char *me; ctx = new_context(); socket = new_socket(ctx, ZMQ_REQ); socket_connect(socket, host); // zmq_connect(socket, host); me = zsocket_identity(socket); log_printf(0, "my identity=%s\n", me); i = 0; for (;;) { log_printf(0, "Sending %d\n", i); // zmq_send(socket, host, strlen(host), ZMQ_SNDMORE); // zmq_send(socket, me, strlen(me), ZMQ_SNDMORE); snprintf(buf, sizeof(buf), "Hello %d", i); zmq_send(socket, buf, strlen(buf)+1, 0); // zmq_recv(socket, buf, sizeof(buf), 0); // log_printf(0, "From %s\n", buf); n = zmq_recv(socket, buf, sizeof(buf), 0); buf[n] = 0; log_printf(0, "Got %s\n", buf); sleep(1); i++; } destroy_context(ctx); }
static boolean title_key(context *ctx, int *key) { const struct config_info *conf = get_config(); struct game_context *title = (struct game_context *)ctx; struct world *mzx_world = ctx->world; // NOTE: disabled due to joystick support. See IKEY_RETURN and IKEY_ESCAPE. //int key_status = get_key_status(keycode_internal_wrt_numlock, *key); boolean exit_status = get_exit_status(); boolean reload_curr_file_in_editor = true; boolean confirm_exit = false; switch(*key) { #ifdef CONFIG_HELPSYS case IKEY_h: { // Help system alternate binding. *key = IKEY_F1; break; } #endif case IKEY_s: { // Configure alternate binding. *key = IKEY_F2; break; } case IKEY_F3: case IKEY_l: { if(conf->standalone_mode) return true; load_world_title_selection(title); return true; } case IKEY_F4: { // ALT+F4 - do nothing. if(get_alt_status(keycode_internal)) break; } /* fallthrough */ case IKEY_r: { // Restore saved game if(conf->standalone_mode && !get_counter(mzx_world, "LOAD_MENU", 0)) return true; if(load_savegame_selection(title)) { play_game(ctx, &(title->fade_in)); title->need_reload = true; } return true; } case IKEY_F5: case IKEY_p: { // Play game if(mzx_world->active) { if(mzx_world->only_from_swap) { error("You can only play this game via a swap from another game", ERROR_T_WARNING, ERROR_OPT_OK, 0x3101); return true; } if(load_world_gameplay(title, curr_file)) { play_game(ctx, NULL); title->need_reload = true; } } return true; } case IKEY_F7: case IKEY_u: { if(check_for_updates) { // FIXME this is garbage int current_music_vol = audio_get_music_volume(); int current_pcs_vol = audio_get_pcs_volume(); audio_set_music_volume(0); audio_set_pcs_volume(0); if(mzx_world->active) audio_set_module_volume(0); check_for_updates(ctx, false); audio_set_pcs_volume(current_pcs_vol); audio_set_music_volume(current_music_vol); if(mzx_world->active) audio_set_module_volume(mzx_world->current_board->volume); } return true; } case IKEY_F8: case IKEY_n: { reload_curr_file_in_editor = false; } /* fallthrough */ case IKEY_F9: case IKEY_e: { if(edit_world) { // Editor sfx_clear_queue(); vquick_fadeout(); title->need_reload = true; title->fade_in = true; edit_world(ctx, reload_curr_file_in_editor); } return true; } // Quickload saved game case IKEY_F10: { struct stat file_info; if(conf->standalone_mode && !get_counter(mzx_world, "LOAD_MENU", 0)) return true; if(!stat(curr_sav, &file_info) && load_savegame(title, curr_sav)) { play_game(ctx, &(title->fade_in)); title->need_reload = true; } return true; } case IKEY_RETURN: // Enter { // Ignore if this isn't a fresh press // NOTE: disabled because it breaks the joystick actions. //if(key_status != 1) //return true; if(!conf->standalone_mode || get_counter(mzx_world, "ENTER_MENU", 0)) main_menu(ctx); return true; } case IKEY_ESCAPE: { // Ignore if this isn't a fresh press // NOTE: disabled because it breaks the joystick actions. //if(key_status != 1) //return true; // ESCAPE_MENU (2.90+) only works on the title screen if the // standalone_mode config option is set if(mzx_world->version < V290 || !conf->standalone_mode || get_counter(mzx_world, "ESCAPE_MENU", 0)) confirm_exit = true; break; } } // Quit if(exit_status || confirm_exit) { // Special behaviour in standalone- only escape exits // ask for confirmation. Exit events instead terminate MegaZeux. if(conf->standalone_mode && !confirm_exit) { core_full_exit(ctx); } else { if(!confirm(mzx_world, "Exit MegaZeux - Are you sure?")) destroy_context(ctx); } return true; } return false; }
static boolean game_key(context *ctx, int *key) { struct game_context *game = (struct game_context *)ctx; struct config_info *conf = get_config(); struct world *mzx_world = ctx->world; struct board *cur_board = mzx_world->current_board; char keylbl[] = "KEY?"; int key_status = get_key_status(keycode_internal_wrt_numlock, *key); boolean exit_status = get_exit_status(); boolean confirm_exit = false; if(*key && !exit_status) { // Get the char for the KEY? labels. If there is no relevant unicode // keypress, we want to use the regular code instead. int key_unicode = get_key(keycode_unicode); int key_char = *key; if(key_unicode > 0 && key_unicode < 256) key_char = key_unicode; if(key_char) { if(key_char < 256) { // Send the KEY? label. // Values over 256 have no meaning here. keylbl[3] = key_char; send_robot_all_def(mzx_world, keylbl); } // In pre-port MZX versions key was a board counter if(mzx_world->version < VERSION_PORT) { char keych = toupper(key_char); // <2.60 it only supported 1-9 and A-Z // This is difficult to version check, so apply it to <2.62 if(mzx_world->version >= V262 || (keych >= 'A' && keych <= 'Z') || (keych >= '1' && keych <= '9')) { cur_board->last_key = keych; } } } switch(*key) { case IKEY_F3: { // Save game if(!mzx_world->dead && player_can_save(mzx_world)) { char save_game[MAX_PATH]; strcpy(save_game, curr_sav); if(!new_file(mzx_world, save_ext, ".sav", save_game, "Save game", 1)) { strcpy(curr_sav, save_game); save_world(mzx_world, curr_sav, true, MZX_VERSION); } } return true; } case IKEY_F4: { // ALT+F4 - do nothing. if(get_alt_status(keycode_internal)) break; // Restore saved game if(mzx_world->version < V282 || get_counter(mzx_world, "LOAD_MENU", 0)) { load_savegame_selection(game); } return true; } case IKEY_F5: case IKEY_INSERT: { // Change bomb type if(!mzx_world->dead) player_switch_bomb_type(mzx_world); return true; } // Toggle debug mode case IKEY_F6: { if(edit_world && mzx_world->editing) mzx_world->debug_mode = !(mzx_world->debug_mode); return true; } // Cheat case IKEY_F7: { if(game->allow_cheats || mzx_world->editing) player_cheat_give_all(mzx_world); return true; } // Cheat More case IKEY_F8: { if(game->allow_cheats || mzx_world->editing) player_cheat_zap(mzx_world); return true; } // Quick save case IKEY_F9: { if(!mzx_world->dead) { if(player_can_save(mzx_world)) save_world(mzx_world, curr_sav, true, MZX_VERSION); } return true; } // Quick load saved game case IKEY_F10: { if(mzx_world->version < V282 || get_counter(mzx_world, "LOAD_MENU", 0)) { struct stat file_info; if(!stat(curr_sav, &file_info)) load_savegame(game, curr_sav); } return true; } case IKEY_F11: { if(mzx_world->editing) { // Breakpoint editor if(get_alt_status(keycode_internal)) { if(debug_robot_config) debug_robot_config(mzx_world); } // Counter debugger else { if(debug_counters) debug_counters(ctx); } } return true; } case IKEY_RETURN: { send_robot_all_def(mzx_world, "KeyEnter"); // Ignore if this isn't a fresh press if(key_status != 1) return true; if(mzx_world->version < V260 || get_counter(mzx_world, "ENTER_MENU", 0)) game_menu(ctx); return true; } case IKEY_ESCAPE: { // Ignore if this isn't a fresh press // NOTE: disabled because it breaks the joystick action. //if(key_status != 1) //return true; // ESCAPE_MENU (2.90+) if(mzx_world->version < V290 || get_counter(mzx_world, "ESCAPE_MENU", 0)) confirm_exit = true; break; } } } // Quit if(exit_status || confirm_exit) { // Special behaviour in standalone- only escape exits // ask for confirmation. Exit events instead terminate MegaZeux. if(conf->standalone_mode && !confirm_exit) { core_full_exit(ctx); } else { if(!confirm(mzx_world, "Quit playing- Are you sure?")) destroy_context(ctx); } return true; } return false; }
static boolean game_idle(context *ctx) { struct game_context *game = (struct game_context *)ctx; struct config_info *conf = get_config(); struct world *mzx_world = ctx->world; if(!mzx_world->active) return false; if(game->fade_in) { vquick_fadein(); game->fade_in = false; } switch(mzx_world->change_game_state) { case CHANGE_STATE_NONE: break; case CHANGE_STATE_SWAP_WORLD: { // The SWAP WORLD command was used by a robot. // TODO: the game has already been loaded at this point, but maybe // should be loaded here instead of in run_robot.c? // Load the new board's mod load_board_module(mzx_world); // Send both JUSTLOADED and JUSTENTERED; the JUSTENTERED label will take // priority if a robot defines it (instead of JUSTLOADED like on the title // screen). send_robot_def(mzx_world, 0, LABEL_JUSTLOADED); send_robot_def(mzx_world, 0, LABEL_JUSTENTERED); return true; } case CHANGE_STATE_LOAD_GAME_ROBOTIC: { // The LOAD_GAME counter was used by a robot. // TODO: the game has already been loaded at this point, but maybe // should be loaded here instead of in counter.c? // real_mod_playing was set during the savegame load but the mod hasn't // started playing yet. load_game_module(mzx_world, mzx_world->real_mod_playing, false); // Only send JUSTLOADED for savegames. send_robot_def(mzx_world, 0, LABEL_JUSTLOADED); return true; } case CHANGE_STATE_PLAY_GAME_ROBOTIC: { if(!game->is_title) break; if(load_world_gameplay(game, curr_file)) { play_game(ctx, NULL); game->need_reload = true; return true; } break; } case CHANGE_STATE_EXIT_GAME_ROBOTIC: { // The EXIT_GAME counter was used by a robot. This works during gameplay, // but also on the titlescreen if standalone mode is active. if(!game->is_title || conf->standalone_mode) { destroy_context(ctx); return true; } break; } case CHANGE_STATE_REQUEST_EXIT: { // The user halted the program while a robot was executing. destroy_context(ctx); return true; } } // A board change or other form of teleport may need to occur. // This may require a fade in the next time this function is run (next cycle). if(update_resolve_target(mzx_world, &(game->fade_in))) return true; // The SAVE_GAME counter might have been used this cycle. if(!game->is_title && mzx_world->robotic_save_type == SAVE_GAME) { save_world(mzx_world, mzx_world->robotic_save_path, true, MZX_VERSION); mzx_world->robotic_save_type = SAVE_NONE; } return false; }
CLContext::~CLContext () { destroy_context (); XCAM_LOG_DEBUG ("CLContext destructed"); }
int main(int argc, char const* argv[]) { corefungi::init(argc, argv); create_context(); __info() << "vendor: " << gtulu::api::get_string(gtulu::cst::vendor); __info() << "renderer: " << gtulu::api::get_string(gtulu::cst::renderer); __info() << "version: " << gtulu::api::get_string(gtulu::cst::version); __info() << "shading_language_version: " << gtulu::api::get_string(gtulu::cst::shading_language_version); std::vector< int32_t > count; gtulu::api::get(gtulu::cst::max_combined_texture_image_units, count); __debug() << "maximum combined textures: " << count; auto const& messages = gtulu::api::get_debug_message_log(); for (auto const& message : messages) { std::clog << std::get< 4 >(message) << std::endl; } gtulu::api::active_texture(0); gtulu::api::attach_shader(1, 2); std::vector< gtulu::vec3< float > > const uniform_data = { { { 1, 2, 3 } }, { { 2, 3, 4 } }, { { 3, 4, 5 } } }; gtulu::api::uniform(0, uniform_data); gtulu::api::compressed_tex_image(gtulu::cst::texture_1d, 0, gtulu::cst::rgb8, gtulu::vec1< gtulu::size > { { 16 } }, 0, 128, gtulu::buffer_ref(0)); gtulu::vertex_double vdouble1 = 1; gtulu::vertex_double vdouble2 = 1.0f; gtulu::vertex_double vdouble3 = 1.0; gtulu::vertex_attrib attrib1 = 1; gtulu::vertex_attrib attrib2 = 1.0f; gtulu::vertex_attrib attrib3 = 1.0; gtulu::vertex_attrib attrib4 = vdouble2; gtulu::vertex_float float1 = 1; gtulu::vertex_float float2 = 1.0f; gtulu::vertex_float float3 = 1.0; // gtulu::vertex_float float4 = vdouble1; // compile error as expected gtulu::vertex_float float5 = attrib1; gtulu::vertex_integer integer1 = 1; gtulu::vertex_integer integer2 = 1.0f; gtulu::vertex_integer integer3 = 1.0; // gtulu::vertex_integer integer4 = vdouble1; // compile error as expected gtulu::vertex_integer integer5 = attrib1; // gtulu::api::vertex_attrib(vdouble1, gtulu::vec3< int >{1,2,3}); // compile error as expected // gtulu::api::vertex_attrib(vdouble2, gtulu::vec3< float >{1.0f,2.0f,3.0f}); // compile error as expected gtulu::api::vertex_attrib(vdouble3, gtulu::vec3< double > { 1.0, 2.0, 3.0 }); // gtulu::api::vertex_attrib(attrib1, gtulu::vec4< int32_t >{1,2,3,4}); // ambiguous gtulu::api::vertex_attrib(float1, gtulu::vec3< int16_t > { 1, 2, 3 }); gtulu::api::vertex_attrib(float2, gtulu::vec3< float > { 1.0f, 2.0f, 3.0f }); gtulu::api::vertex_attrib(float3, gtulu::vec3< double > { 1.0, 2.0, 3.0 }); gtulu::api::vertex_attrib(integer1, gtulu::vec3< int32_t > { 1, 2, 3 }); // gtulu::api::vertex_attrib(integer2, gtulu::vec3< float >{1.0f,2.0f,3.0f}); // compile error as expected // gtulu::api::vertex_attrib(integer3, gtulu::vec3< double >{1.0,2.0,3.0}); // compile error as expected destroy_context(); return 0; } // main
int wasm_gen_file(WasmSource* source, int multi_module, WasmParserTypeCheck type_check) { Context ctx = {}; WasmParserCallbacks callbacks = {}; callbacks.user_data = &ctx; callbacks.error = error; callbacks.before_module = before_module; callbacks.after_module = after_module; callbacks.before_function = before_function; callbacks.after_function = after_function; callbacks.before_block = before_block; callbacks.after_block = after_block; callbacks.before_binary = before_binary; callbacks.before_break = before_break; callbacks.after_break = after_break; callbacks.before_call = before_call; callbacks.before_call_import = before_call_import; callbacks.before_compare = before_compare; callbacks.after_const = after_const; callbacks.before_convert = before_convert; callbacks.after_get_local = after_get_local; callbacks.before_if = before_if; callbacks.after_if = after_if; callbacks.before_label = before_label; callbacks.after_label = after_label; callbacks.before_load = before_load; callbacks.after_load_global = after_load_global; callbacks.before_loop = before_loop; callbacks.after_loop = after_loop; callbacks.after_memory_size = after_memory_size; callbacks.after_nop = after_nop; callbacks.after_page_size = after_page_size; callbacks.before_resize_memory = before_resize_memory; callbacks.before_return = before_return; callbacks.before_set_local = before_set_local; callbacks.before_store = before_store; callbacks.before_store_global = before_store_global; callbacks.before_unary = before_unary; callbacks.assert_invalid_error = assert_invalid_error; int result; if (multi_module) { if (g_outfile) { callbacks.before_module = before_module_multi; callbacks.after_module = after_module_multi; callbacks.before_assert_return = before_assert_return; callbacks.after_assert_return = after_assert_return; callbacks.before_assert_return_nan = before_assert_return_nan; callbacks.after_assert_return_nan = after_assert_return_nan; callbacks.before_assert_trap = before_assert_trap; callbacks.after_assert_trap = after_assert_trap; callbacks.before_invoke = before_invoke; callbacks.after_invoke = after_invoke; init_output_buffer(&ctx.js_buf, INITIAL_OUTPUT_BUFFER_CAPACITY); } result = wasm_parse_file(source, &callbacks, type_check); if (g_outfile) { finish_module(&ctx); write_output_buffer(&ctx.js_buf, g_outfile); } } else { result = wasm_parse_module(source, &callbacks, type_check); if (result == 0 && g_outfile) write_output_buffer(&ctx.buf, g_outfile); } destroy_context(&ctx); return result; }
int main(int argc, char **argv) { if(verbose) fprintf(stdout, "Benvingut a l'intèrpret de FastGameScript!\n\n"); char c; while((c = getopt(argc, argv, "vgsdt")) != -1) { if(test) fprintf(stdout, "Found option %c\n", c); switch(c) { case 'v': verbose = 1; break; case 'g': bisonverbose = 1; break; case 's': stackverbose = 1; break; case 'd': debug = 1; break; case 't': test = 1; break; case '?': printf("Unknown option %c.", c); exit(3); break; default: printf("This shouldn't happen?"); exit(99); break; } } fgs_state *FGS; FGS = fgs_start_context(); if(test) printf("--------------\n"); /* Test */ fgs_load_script(FGS, "test/prova_condicional_else.fgs"); testFunction(FGS, "prova_condicional_else"); /* Test */ fgs_load_script(FGS, "test/prova_condicional_if.fgs"); testFunction(FGS, "prova_condicional_if"); /* Test */ fgs_load_script(FGS, "test/prova_aritmetica_sum.fgs"); testFunction(FGS, "prova_aritmetica_sum"); /* Test */ fgs_load_script(FGS, "test/prova_aritmetica_sum_parenth.fgs"); testFunction(FGS, "prova_aritmetica_sum_parenth"); /* Test */ fgs_load_script(FGS, "test/prova_aritmetica_strings.fgs"); testFunctionS(FGS, "prova_aritmetica_strings", "hola!"); /* Test */ fgs_load_script(FGS, "test/prova_fibonacci.fgs"); push_valueI(FGS, 30); testFunctionI(FGS, "prova_fibonacci", 514229); push_valueF(FGS, 30.0f); testFunctionI(FGS, "prova_fibonacci", 514229); /* Test */ push_valueI(FGS, 1); fgs_load_script(FGS, "test/prova_tipus_nou.fgs"); testFunctionI(FGS, "prova_tipus_nou", 1); /* Test */ fgs_load_script(FGS, "test/prova_aritmetica_parametres.fgs"); push_valueI(FGS, 10); push_valueI(FGS, 10); testFunctionI(FGS, "suma", 20); /* Test: */ fgs_load_script(FGS, "test/prova_aritmetica_return.fgs"); push_valueI(FGS, 10); push_valueI(FGS, 10); testFunctionI(FGS, "suma", 20); /* Test: */ fgs_load_script(FGS, "test/prova_funcions_repetides.fgs"); push_valueI(FGS, 10); push_valueI(FGS, 10); testFunctionI(FGS, "resta", 0); /* Test */ fgs_load_script(FGS, "test/prova_aritmetica_mul.fgs"); testFunction(FGS, "prova_aritmetica_mul"); /* test: */ /*fgs_load_script(FGS, "test/prova_aritmetica_areatriangle.fgs"); push_valueI(FGS, 10); push_valueI(FGS, 10); testFunctionI(FGS, "prova_aritmetica_areatriangle", 50);*/ fgs_load_script(FGS, "test/prova_lexic_c.fgs"); push_valueI(FGS, 1); testFunctionI(FGS, "prova_codi_c", 1); /* /* Test: * fgs_load_script(FGS, "test/.fgs"); testFunction(FGS, ""); */ destroy_context(FGS); return 0; }
/* Uaaahahahh, ich will dir einloggen! PAM authentication entry point. */ PAM_EXTERN int pam_sm_authenticate (pam_handle_t *pam_handle, int flags, int argc, const char **argv) { const void *conv_void; gpg_error_t err; poldi_ctx_t ctx; conv_t conv; scd_context_t scd_ctx; int ret; const char *pam_username; struct auth_method_parse_cookie method_parse_cookie = { NULL, NULL }; simpleparse_handle_t method_parse; struct getpin_cb_data getpin_cb_data; pam_username = NULL; scd_ctx = NULL; conv = NULL; ctx = NULL; method_parse = NULL; err = 0; /*** Basic initialization. ***/ bindtextdomain (PACKAGE, LOCALEDIR); /* Initialize Libgcrypt. Disable secure memory for now; because of the implicit priviledge dropping, having secure memory enabled causes the following error: su: Authentication service cannot retrieve authentication info. */ gcry_control (GCRYCTL_DISABLE_SECMEM); /*** Setup main context. ***/ err = create_context (&ctx, pam_handle); if (err) goto out; /* Setup logging prefix. */ log_set_flags (ctx->loghandle, LOG_FLAG_WITH_PREFIX | LOG_FLAG_WITH_TIME | LOG_FLAG_WITH_PID); log_set_prefix (ctx->loghandle, "Poldi"); log_set_backend_syslog (ctx->loghandle); /*** Parse auth-method independent options. ***/ /* ... from configuration file: */ err = simpleparse_parse_file (ctx->parsehandle, 0, POLDI_CONF_FILE); if (err) { log_msg_error (ctx->loghandle, _("failed to parse configuration file '%s': %s"), POLDI_CONF_FILE, gpg_strerror (err)); goto out; } /* ... and from argument vector provided by PAM: */ if (argc) { err = simpleparse_parse (ctx->parsehandle, 0, argc, argv, NULL); if (err) { log_msg_error (ctx->loghandle, _("failed to parse PAM argument vector: %s"), gpg_strerror (err)); goto out; } } /*** Initialize logging. ***/ /* In case `logfile' has been set in the configuration file, initialize jnlib-logging the traditional file, loggin to the file (or socket special file) specified in the configuration file; in case `logfile' has NOT been set in the configuration file, log through Syslog. */ if (ctx->logfile) { gpg_error_t rc; rc = log_set_backend_file (ctx->loghandle, ctx->logfile); if (rc != 0) /* Last try... */ log_set_backend_syslog (ctx->loghandle); } /*** Sanity checks. ***/ /* Authentication method to use must be specified. */ if (ctx->auth_method < 0) { log_msg_error (ctx->loghandle, _("no authentication method specified")); err = GPG_ERR_CONFIGURATION; goto out; } /* Authentication methods must provide a parser callback in case they have specific a configuration file. */ assert ((!auth_methods[ctx->auth_method].method->config) || (auth_methods[ctx->auth_method].method->parsecb && auth_methods[ctx->auth_method].method->opt_specs)); if (ctx->debug) { log_msg_debug (ctx->loghandle, _("using authentication method `%s'"), auth_methods[ctx->auth_method].name); } /*** Init authentication method. ***/ if (auth_methods[ctx->auth_method].method->func_init) { err = (*auth_methods[ctx->auth_method].method->func_init) (&ctx->cookie); if (err) { log_msg_error (ctx->loghandle, _("failed to initialize authentication method %i: %s"), -1, gpg_strerror (err)); goto out; } } if (auth_methods[ctx->auth_method].method->config) { /* Do auth-method specific parsing. */ err = simpleparse_create (&method_parse); if (err) { log_msg_error (ctx->loghandle, _("failed to initialize parsing of configuration file for authentication method %s: %s"), auth_methods[ctx->auth_method].name, gpg_strerror (err)); goto out_parsing; } method_parse_cookie.poldi_ctx = ctx; method_parse_cookie.method_ctx = ctx->cookie; simpleparse_set_loghandle (method_parse, ctx->loghandle); simpleparse_set_parse_cb (method_parse, auth_methods[ctx->auth_method].method->parsecb, &method_parse_cookie); simpleparse_set_i18n_cb (method_parse, i18n_cb, NULL); simpleparse_set_specs (method_parse, auth_methods[ctx->auth_method].method->opt_specs); err = simpleparse_parse_file (method_parse, 0, auth_methods[ctx->auth_method].method->config); if (err) { log_msg_error (ctx->loghandle, _("failed to parse configuration for authentication method %i: %s"), auth_methods[ctx->auth_method].name, gpg_strerror (err)); goto out_parsing; } out_parsing: simpleparse_destroy (method_parse); if (err) goto out; } /*** Prepare PAM interaction. ***/ /* Ask PAM for conv structure. */ ret = pam_get_item (ctx->pam_handle, PAM_CONV, &conv_void); if (ret != PAM_SUCCESS) { log_msg_error (ctx->loghandle, _("failed to retrieve PAM conversation structure")); err = GPG_ERR_INTERNAL; goto out; } /* Init conv subsystem by creating a conv_t object. */ err = conv_create (&conv, conv_void); if (err) goto out; ctx->conv = conv; /*** Retrieve username from PAM. ***/ err = retrieve_username_from_pam (ctx->pam_handle, &pam_username); if (err) { log_msg_error (ctx->loghandle, _("failed to retrieve username from PAM: %s"), gpg_strerror (err)); } /*** Connect to Scdaemon. ***/ err = scd_connect (&scd_ctx, NULL, getenv ("GPG_AGENT_INFO"), ctx->scdaemon_program, ctx->scdaemon_options, 0, ctx->loghandle); if (err) goto out; ctx->scd = scd_ctx; /* Install PIN retrival callback. */ getpin_cb_data.poldi_ctx = ctx; scd_set_pincb (ctx->scd, getpin_cb, &getpin_cb_data); /*** Wait for card insertion. ***/ if (pam_username) { if (ctx->debug) log_msg_debug (ctx->loghandle, _("Waiting for card for user `%s'..."), pam_username); if (!ctx->quiet) conv_tell (ctx->conv, _("Insert authentication card for user `%s'"), pam_username); } else { if (ctx->debug) log_msg_debug (ctx->loghandle, _("Waiting for card...")); if (!ctx->quiet) conv_tell (ctx->conv, _("Insert authentication card")); } err = wait_for_card (ctx->scd, 0); if (err) { log_msg_error (ctx->loghandle, _("failed to wait for card insertion: %s"), gpg_strerror (err)); goto out; } /*** Receive card info. ***/ err = scd_learn (ctx->scd, &ctx->cardinfo); if (err) goto out; if (ctx->debug) log_msg_debug (ctx->loghandle, _("connected to card; serial number is: %s"), ctx->cardinfo.serialno); /*** Authenticate. ***/ if (pam_username) { /* Try to authenticate user as PAM_USERNAME. */ if (!(*auth_methods[ctx->auth_method].method->func_auth_as) (ctx, ctx->cookie, pam_username)) /* Authentication failed. */ err = GPG_ERR_GENERAL; } else { /* Try to authenticate user, choosing an identity is up to the user. */ char *username_authenticated = NULL; if (!(*auth_methods[ctx->auth_method].method->func_auth) (ctx, ctx->cookie, &username_authenticated)) /* Authentication failed. */ err = GPG_ERR_GENERAL; else { /* Send username received during authentication process back to PAM. */ err = send_username_to_pam (ctx->pam_handle, username_authenticated); xfree (username_authenticated); } } out: /* Log result. */ if (err) log_msg_error (ctx->loghandle, _("authentication failed: %s"), gpg_strerror (err)); else { if (ctx->debug) log_msg_debug (ctx->loghandle, _("authentication succeeded")); if (ctx->modify_environment) modify_environment (pam_handle, ctx); } /* Call authentication method's deinit callback. */ if ((ctx->auth_method >= 0) && auth_methods[ctx->auth_method].method->func_deinit) (*auth_methods[ctx->auth_method].method->func_deinit) (ctx->cookie); /* FIXME, cosmetics? */ conv_destroy (conv); destroy_context (ctx); /* Return to PAM. */ return err ? PAM_AUTH_ERR : PAM_SUCCESS; }
HybridAnalyzer::~HybridAnalyzer () { destroy_context (); }
extern void glXDestroyContext(Display *dpy, GLXContext ctx) { GH_GET_PTR_GL(glXDestroyContext); GH_glXDestroyContext(dpy, ctx); destroy_context(ctx); }
int LWSClient::_handle_cb(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) { Ref<LWSPeer> peer = static_cast<Ref<LWSPeer> >(_peer); LWSPeer::PeerData *peer_data = (LWSPeer::PeerData *)user; switch (reason) { #if defined(LWS_OPENSSL_SUPPORT) case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS: { PoolByteArray arr = StreamPeerSSL::get_project_cert_array(); if (arr.size() > 0) SSL_CTX_add_client_CA((SSL_CTX *)user, d2i_X509(NULL, &arr.read()[0], arr.size())); else if (verify_ssl) WARN_PRINTS("No CA cert specified in project settings, SSL will not work"); } break; #endif case LWS_CALLBACK_CLIENT_ESTABLISHED: peer->set_wsi(wsi, _in_buf_size, _in_pkt_size, _out_buf_size, _out_pkt_size); peer_data->peer_id = 0; peer_data->force_close = false; peer_data->clean_close = false; _on_connect(lws_get_protocol(wsi)->name); break; case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: _on_error(); destroy_context(); return -1; // We should close the connection (would probably happen anyway) case LWS_CALLBACK_WS_PEER_INITIATED_CLOSE: { int code; String reason2 = peer->get_close_reason(in, len, code); peer_data->clean_close = true; _on_close_request(code, reason2); return 0; } case LWS_CALLBACK_CLIENT_CLOSED: peer->close(); destroy_context(); _on_disconnect(peer_data->clean_close); return 0; // We can end here case LWS_CALLBACK_CLIENT_RECEIVE: peer->read_wsi(in, len); if (peer->get_available_packet_count() > 0) _on_peer_packet(); break; case LWS_CALLBACK_CLIENT_WRITEABLE: if (peer_data->force_close) { peer->send_close_status(wsi); return -1; } peer->write_wsi(); break; default: break; } return 0; }
extern void glXFreeContextEXT(Display *dpy, GLXContext ctx) { GH_GET_PTR_GL(glXFreeContextEXT); GH_glXFreeContextEXT(dpy, ctx); destroy_context(ctx); }
static EGLBoolean egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx) { struct egl_g3d_context *gctx = egl_g3d_context(ctx); struct egl_g3d_surface *gdraw = egl_g3d_surface(draw); struct egl_g3d_surface *gread = egl_g3d_surface(read); struct egl_g3d_context *old_gctx; _EGLContext *old_ctx; _EGLSurface *old_draw, *old_read; EGLBoolean ok = EGL_TRUE; /* make new bindings */ if (!_eglBindContext(ctx, draw, read, &old_ctx, &old_draw, &old_read)) return EGL_FALSE; old_gctx = egl_g3d_context(old_ctx); if (old_gctx) { /* flush old context */ old_gctx->stctxi->flush(old_gctx->stctxi, ST_FLUSH_FRONT, NULL); } if (gctx) { ok = gctx->stapi->make_current(gctx->stapi, gctx->stctxi, (gdraw) ? gdraw->stfbi : NULL, (gread) ? gread->stfbi : NULL); if (ok) { if (gdraw) { if (gdraw->base.Type == EGL_WINDOW_BIT) { gctx->base.WindowRenderBuffer = (gdraw->stvis.render_buffer == ST_ATTACHMENT_FRONT_LEFT) ? EGL_SINGLE_BUFFER : EGL_BACK_BUFFER; } } } } else if (old_gctx) { ok = old_gctx->stapi->make_current(old_gctx->stapi, NULL, NULL, NULL); if (ok) old_gctx->base.WindowRenderBuffer = EGL_NONE; } if (ok) { if (_eglPutContext(old_ctx)) destroy_context(dpy, old_ctx); if (_eglPutSurface(old_draw)) destroy_surface(dpy, old_draw); if (_eglPutSurface(old_read)) destroy_surface(dpy, old_read); } else { /* undo the previous _eglBindContext */ _eglBindContext(old_ctx, old_draw, old_read, &ctx, &draw, &read); assert(&gctx->base == ctx && &gdraw->base == draw && &gread->base == read); _eglPutSurface(draw); _eglPutSurface(read); _eglPutContext(ctx); _eglPutSurface(old_draw); _eglPutSurface(old_read); _eglPutContext(old_ctx); } return ok; }