void map_physics_tick(struct map * map, struct gamedata * gamedata) { assert(map != NULL); assert(gamedata == NULL || gamedata->map == map); if(map->level_start_anim_on) { map_level_start_animation_tick(map); } else { if(map->game_paused == false) { map->game_timer++; if(map->game_timer >= map->game_speed) { map->game_timer = 0; /* The girl is special, she moves first. */ if(map->girl->mob->alive == true) { if(map->player_movement != NULL) { if(map->player_movement(map, gamedata) == false) map = NULL; } } else if(map->is_intermission == true) { /* The girl has died, too bad, but if this is intermission level, then she will get to the next level. * Our copy of map may no longer be valid after player_next_level(), so it's set to NULL. */ if(map->player_next_level != NULL) { map->player_next_level(gamedata); map = NULL; } } /* Then process the rest of the map. */ if(map != NULL) process_map(map, gamedata); } } } }
int main(int argc, char *argv[]) { FILE *fh; if (argc < 2) { fprintf(stderr, "route <file>\n"); return 1; } fh = fopen(argv[1], "rb"); load_data(fh); fclose(fh); if (!type_map) { return 2; } build_route_map(); process_map(); return 0; }
int main(int argc, char *argv[]) { const char *errstr; char errbuf[_POSIX2_LINE_MAX], *kmem = NULL, *kernel = NULL; struct kinfo_proc *kproc; struct sum total_sum; int many, ch, rc; kvm_t *kd; pid_t pid = -1; gid_t gid; while ((ch = getopt(argc, argv, "AaD:dlmM:N:p:Prsvx")) != -1) { switch (ch) { case 'A': print_amap = 1; break; case 'a': print_all = 1; break; case 'd': print_ddb = 1; break; case 'D': debug = strtonum(optarg, 0, 0xf, &errstr); if (errstr) errx(1, "invalid debug mask"); break; case 'l': print_maps = 1; break; case 'm': print_map = 1; break; case 'M': kmem = optarg; break; case 'N': kernel = optarg; break; case 'p': pid = strtopid(optarg); break; case 'P': pid = getpid(); break; case 's': print_solaris = 1; break; case 'v': verbose = 1; break; case 'r': case 'x': errx(1, "-%c option not implemented, sorry", ch); /*NOTREACHED*/ default: usage(); } } /* * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. */ gid = getgid(); if (kernel != NULL || kmem != NULL) if (setresgid(gid, gid, gid) == -1) err(1, "setresgid"); argc -= optind; argv += optind; /* more than one "process" to dump? */ many = (argc > 1 - (pid == -1 ? 0 : 1)) ? 1 : 0; /* apply default */ if (print_all + print_map + print_maps + print_solaris + print_ddb == 0) print_solaris = 1; /* start by opening libkvm */ kd = kvm_openfiles(kernel, kmem, NULL, O_RDONLY, errbuf); if (kernel == NULL && kmem == NULL) if (setresgid(gid, gid, gid) == -1) err(1, "setresgid"); if (kd == NULL) errx(1, "%s", errbuf); /* get "bootstrap" addresses from kernel */ load_symbols(kd); memset(&total_sum, 0, sizeof(total_sum)); do { struct sum sum; memset(&sum, 0, sizeof(sum)); if (pid == -1) { if (argc == 0) pid = getppid(); else { pid = strtopid(argv[0]); argv++; argc--; } } /* find the process id */ if (pid == 0) kproc = NULL; else { kproc = kvm_getprocs(kd, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &rc); if (kproc == NULL || rc == 0) { warnc(ESRCH, "%d", pid); pid = -1; continue; } } /* dump it */ if (many) { if (kproc) printf("process %d:\n", pid); else printf("kernel:\n"); } process_map(kd, pid, kproc, &sum); if (print_amap) print_sum(&sum, &total_sum); pid = -1; } while (argc > 0); if (print_amap) print_sum(&total_sum, NULL); /* done. go away. */ rc = kvm_close(kd); if (rc == -1) err(1, "kvm_close"); return (0); }
int main() { char* args[] = { "200", "100", "8" }; allocateMap(3, args); process_map(); }
void BaseBot::process_diplomacy_message( char *message, int message_length ) { Token *message_tokens; // The tokens in the incoming message TokenMessage incoming_message; // The incoming message Token lead_token; // The first token of the message message_tokens = (Token *)( message ); if ( message_tokens[ 0 ] == TOKEN_COMMAND_PRN ) { process_prn_message( message_tokens, message_length ); } else { incoming_message.set_message( message_tokens, message_length / 2 ); log_tcpip_comms( true, incoming_message ); // If the first subtoken is a single message if ( incoming_message.submessage_is_single_token( 0 ) ) { // Act on that token lead_token = incoming_message.get_token( 0 ); // Messages that BaseBot handles initially if ( lead_token == TOKEN_COMMAND_HLO ) { process_hlo( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_MAP ) { process_map( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_MDF ) { process_mdf( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_NOW ) { process_now( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_ORD ) { process_ord( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_SCO ) { process_sco( incoming_message ); } // Messages which are broken down further before being passed on else if ( lead_token == TOKEN_COMMAND_NOT ) { process_not( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_REJ ) { process_rej( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_YES ) { process_yes( incoming_message ); } // Messages to be handled by Bot immediately else if ( lead_token == TOKEN_COMMAND_CCD ) { process_ccd( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_DRW ) { process_drw( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_FRM ) { process_frm_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_HUH ) { process_huh_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_LOD ) { process_lod_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_MIS ) { process_mis_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_OFF ) { process_off_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_OUT ) { process_out( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_SLO ) { process_slo( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_SMR ) { process_smr_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_SVE ) { process_sve_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_THX ) { process_thx_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_TME ) { process_tme_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_ADM ) { process_adm_message( incoming_message ); } /* ADDED BY ME */ else if ( lead_token == TOKEN_PRESS_PRP ) { process_prp_message( incoming_message ); } else { log_error("Unexpected first token in message : %s", incoming_message.get_message_as_text().c_str() ); } } else { log_error("Illegal message received"); } } }
int main (int argc, char** argv) { int ret, c; int i, repeat = 5; int cpu = 2; static int errortype = 1; static int verbose = 1; static int disableHuge = 0; static int madvisePoison = 0; static int poll_exit=0; static long length; struct bitmask *nodes, *gnodes; int gpolicy; unsigned long error_opt; void *vaddrmin = (void *)-1UL, *vaddrmax = NULL; static size_t pdcount=0; unsigned long mattr, addrend, pages, count, nodeid, paddr = 0; unsigned long addr_start=0, nodeid_start=-1, mattr_start=-1; unsigned int pagesize = getpagesize(); char pte_str[20]; struct dlook_get_map_info req; static page_desc_t *pdbegin=NULL; page_desc_t *pd, *pdend; length = memsize("100k"); nodes = numa_allocate_nodemask(); gnodes = numa_allocate_nodemask(); progname = argv[0]; while (1) { static struct option long_options[] = { {"verbose", no_argument, &verbose, 1}, {"delay", no_argument, &delay, 1}, {"disableHuge", no_argument, &disableHuge, 1}, {"poll", no_argument, &poll_exit, 1}, {"madvisePoison", no_argument, &madvisePoison, 1}, {"manual", no_argument, &manual, 1}, {"cpu", required_argument, 0, 'c'}, {"errortype", required_argument, 0, 'e'}, {"help", no_argument, 0, 'h'}, {"length", required_argument, 0, 'l'} }; /* getopt_long stores the option index here. */ int option_index = 0; c = getopt_long (argc, argv, "hc:e:l:", long_options, &option_index); /* Detect the end of the options. */ if (c == -1) break; switch (c) { case 'c': cpu = atoi(optarg); break; case 'e': errortype = atoi(optarg); break; case 'h': help(); case 'l': /* Not exposed */ printf ("option -l with value `%s'\n", optarg); length = memsize("optarg"); break; case '?': /* getopt_long already printed an error message. */ exit(-1); } } cpu_process_setaffinity(getpid(), cpu); error_opt = get_etype(errortype); buf = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); if (mbind((void *)buf, length, MPOL_DEFAULT, nodes->maskp, nodes->size, 0) < 0){ perror("mbind error\n"); } /* Disable Hugepages */ if (disableHuge) madvise((void *)buf, length, MADV_NOHUGEPAGE); if (madvisePoison) madvise((void *)buf, length,MADV_HWPOISON ); gpolicy = -1; if (get_mempolicy(&gpolicy, gnodes->maskp, gnodes->size, (void *)buf, MPOL_F_ADDR) < 0) perror("get_mempolicy"); if (!numa_bitmask_equal(gnodes, nodes)) { printf("nodes differ %lx, %lx!\n", gnodes->maskp[0], nodes->maskp[0]); } strcpy(pte_str, ""); addrend = ((unsigned long)buf)+length; pages = (addrend-((unsigned long)buf))/pagesize; if (pages > pdcount) { pdbegin = realloc(pdbegin, sizeof(page_desc_t)*pages); pdcount = pages; } req.pid = getpid(); req.start_vaddr = (unsigned long)buf; req.end_vaddr = addrend; req.pd = pdbegin; sigaction(SIGBUS, &recover_act, NULL); /*Fault in Pages */ if(!poll_exit) hog((void *)buf, length); /* Get mmap phys_addrs */ if ((fd = open(UVMCE_DEVICE, O_RDWR)) < 0) { printf("Failed to open: %s\n", UVMCE_DEVICE); exit (1); } if (ioctl(fd, UVMCE_DLOOK, &req ) < 0){ printf("Failed to INJECT_UCE\n"); exit(1); } process_map(pd,pdbegin, pdend, pages, buf, addrend, pagesize, mattr, nodeid, paddr, pte_str, nodeid_start, mattr_start, addr_start); printf("\n\tstart_vaddr\t 0x%016lx length\t 0x%x\n\tend_vaddr\t 0x%016lx pages\t %ld\n", buf , length, addrend, pages); uv_inject(pd,pdbegin, pdend, pages, (unsigned long)buf, addrend, pagesize, mattr, nodeid, paddr, pte_str, nodeid_start, mattr_start, addr_start, error_opt); if (delay){ printf("Enter char to consume bad memory.."); getchar(); } if (error_opt != UVMCE_PATROL_SCRUB_UCE){ consume_it((void *)buf, length); } out: close(fd); return 0; }