int main (void) { set_global (1); set_global (2); return 0; }
void _handle_special_chatter(creature_t* creature) { std::string name = creature->name; if (name.find("Harmund") != std::string::npos) { if (!global_is_set("necromancer_killed")) { append_msg_log("%s grunts, \"Greetings to ye, adventurer. Lately our quiet town has been terrorized by an evil necromancer.", capitalize(creature->get_full_name()).c_str()); append_msg_log("Ye would offer us a great service if ye could find and deal with him... Ye can find his hideout in the caverns to the east of here...\""); } else if (get_global("necromancer_killed") == "true" && !global_is_set("harmund_granted_item")) { append_msg_log("%s smiles at you, \"Ah, adventurer. I have heard the good news! The necromancer is dead and we can all rejoice, for now.", capitalize(creature->get_full_name()).c_str()); append_msg_log("Please take this as a token of our appreciation.\""); set_global("harmund_granted_item", "true"); } else { append_msg_log("%s smiles at you, \"Greetings once again, adventurer...\"", capitalize(creature->get_full_name()).c_str()); } } }
int SdaccelSgd::setup_kernel() { set_global(GLOBAL_WORK_GROUP_SIZE); //sets global work group size set_local(LOCAL_WORK_GROUP_SIZE); //sets local work group size // Execute the kernel over the entire range of our 1d input data set // using the maximum number of work group items for this device return EXIT_SUCCESS; }
/** * \brief Constructor. */ bear::mouse_over_manager::mouse_over_manager() : m_sample(NULL) { set_global(true); set_artificial(true); set_phantom(true); } // mouse_over_manager::mouse_over_manager()
void su_setglobal(su_state *s, const char *name) { value_t v; unsigned size = strlen(name); v.type = SU_STRING; v.obj.gc_object = string_from_cache(s, name, size); set_global(s, name, hash_value(&v), size, STK(-1)); su_pop(s, 1); }
bool set_channel(std::vector<uint8_t> data) { int num = decode_be(data); if (num <= NCHANNELS) { if (debug_) printf("set channel number=%d\n", num); if (num == 0) { flag_global = true; chan = num; set_global(); } else { flag_global = false; chan = num - 1; if (!isChannelIncluded(packets[pnum], num)) new_channel(chan); } return true; } if (debug_) printf("failed to set channel number=%d\n", num); return false; }
bool update(const char * field, std::vector<uint8_t> data) { if (!strcmp(field, "dlpkt")) { return delete_packet(data); } else if (!strcmp(field, "dlcha")) { return delete_channel(data); } else if (!strcmp(field, "pnum")) { return set_pnumber(data); } else if (!strcmp(field, "chan")) { return set_channel(data); } else if (!strcmp(field, "pol")) { set_poll(data); } else if (!strcmp(field, "dir")) { const char * dirStr = byteVec2cstr(data); if (!strcmp(dirStr, "pos")) set_direction(DIR_POS); else if (!strcmp(dirStr, "neg")) set_direction(DIR_NEG); else return false; } else if (!strcmp(field, "data")) { return set_current(data); } else if (!strcmp(field, "wait")) { set_delay(data); } else if (!strcmp(field, "send")) { flag_return = true; send_packets(); } else if (!strcmp(field, "reset")) { send_global_reset(); } else if (!strcmp(field, "glob")) { set_global(); } else if (!strcmp(field, "conn")) { flag_return = true; return connect_serial(); } else if (!strcmp(field, "exit")) { return exit(); } else if (!strcmp(field, "clrpks")) { clear_packets(); } else if (!strcmp(field, "prev")) { if (debug_) preview_packets(); preview_packet_bytes(); flag_return = true; } else { return false; } return true; }
void select_processor(char *name) { struct px *found = NULL; if (state.cmd_line.processor == 1) { gpwarning(GPW_CMDLINE_PROC, NULL); } else { found = gp_find_processor(name); if (found) { if (state.processor == none) { state.processor = found->tag; state.processor_info = found; set_global(found->defined_as, 1, PERMANENT, gvt_constant); } else if (state.processor != found->tag ) { gpwarning(GPW_REDEFINING_PROC, NULL); gperror(GPE_EXTRA_PROC, NULL); } } else { if (state.pass) { gperror(GPE_UNKNOWN_PROC, NULL); } else { printf("Didn't find any processor named: %s\nHere are the supported processors:\n",name); gp_dump_processor_list(); exit(1); } } /* load the instruction sets if necessary */ if ((state.processor_chosen == 0) && (state.processor != no_processor)) { opcode_init(1); /* General directives */ /* seperate the directives from the opcodes */ state.stBuiltin = push_symbol_table(state.stBuiltin, 1); opcode_init(2); /* Processor-specific */ if (!_16bit_core && !_17cxx_core) { opcode_init(3); /* Special pseudo ops for 12 and 14 bit devices */ } state.processor_chosen = 1; } } }
/* * set_M30620FCAFP(OAKS16)用のベクトルを設定する */ static void set_M30620FCAFP(FILE* pfo, int no, int m) { #ifdef OAKS16_JSP13 struct VEC *v; int x; #endif /* OAKS16_JSP13 */ int i; #ifdef OAKS16_JSP13 if(no == 2){ set_global(pfo, in_portid); set_global(pfo, out_portid); fputs(lf, pfo); fputs(func01, pfo); fputs(lf, pfo); fputs("_", pfo); fputs(in_portid, pfo); fputs(":", pfo); fputs(lf, pfo); fputs(func02, pfo); fputs(lf, pfo); fputs("_", pfo); fputs(out_portid, pfo); fputs(":", pfo); fputs(lf, pfo); fputs(func02, pfo); fputs(lf, pfo); fputs(lf, pfo); v = &vec_table[0][0]; for(i = x = 0 ; i < num_vec[0] ; i++, v++){ if(v->no >= 17 && v->no < 21){ x = 1; break; } } if(x){ fputs(func03, pfo); fputs(lf, pfo); v = &vec_table[0][0]; for(i = x = 0 ; i < num_vec[0] ; i++, v++){ if(v->no == 17 || v->no == 19){ fputs(out_handler, pfo); fputs("1:", pfo); fputs(lf, pfo); fputs("\tmov.w\t#1, _", pfo); fputs(out_portid, pfo); fputs(lf, pfo); fputs("\tjmp\t_", pfo); fputs(v->no_label, pfo); fputs(lf, pfo); fputs(out_handler, pfo); fputs("2:", pfo); fputs(lf, pfo); fputs("\tmov.w\t#2, _", pfo); fputs(out_portid, pfo); fputs(lf, pfo); fputs("\tjmp\t_", pfo); fputs(v->no_label, pfo); fputs(lf, pfo); break; } } v = &vec_table[0][0]; for(i = x = 0 ; i < num_vec[0] ; i++, v++){ if(v->no == 18 || v->no == 20){ fputs(in_handler, pfo); fputs("1:", pfo); fputs(lf, pfo); fputs("\tmov.w\t#1, _", pfo); fputs(in_portid, pfo); fputs(lf, pfo); fputs("\tjmp\t_", pfo); fputs(v->no_label, pfo); fputs(lf, pfo); fputs(in_handler, pfo); fputs("2:", pfo); fputs(lf, pfo); fputs("\tmov.w\t#2, _", pfo); fputs(in_portid, pfo); fputs(lf, pfo); fputs("\tjmp\t_", pfo); fputs(v->no_label, pfo); fputs(lf, pfo); break; } } } } #endif /* OAKS16_JSP13 */ set_comment(pfo, int_vec); fputs("\t.section\tvvector", pfo); fputs(lf, pfo); set_org(pfo, "VECTOR_ADR"); for(i = 0 ; i < MAX_INT ; i++){ if(no == 2){ if(i >= 17 && i < 21) set_vector2(pfo, INT_STATE, i); else set_vector(pfo, INT_STATE, i); } else set_vector(pfo, INT_STATE, i); } }
int main(int argc, char* argv[]) { FILE* pfi; FILE* pfo; FILE* pfw; char buf[BUF_SIZE]; struct VEC *v; int i, j, k; bool cnv, dec; char* s; char* p; char* q; char c; strcpy(input_file, default_input_file); strcpy(output_file, default_output_file); strcpy(unused_vec[0], default_unused_int); strcpy(unused_vec[1], default_unused_int); strcpy(fvector,default_fvector); for(i = 1 ; i < argc ; i++){ s = argv[i]; if(*s++ == '-'){ c = *s++; skip_space(&s); switch(c){ case 'I': // インクルードファイルの設定 case 'i': if(num_include < MAX_INCLUDE){ strcpy(include_file[num_include], s); num_include++; } break; case 'F': // フィックスベクタの定義 case 'f': strcpy(fvector, s); break; case 'O': // アウトプットファイルの設定 case 'o': strcpy(output_file, s); break; case 'R': // インプットファイルの設定 case 'r': strcpy(input_file, s); break; case 'M': // ボードモード case 'm': board_mode = atoi(s); break; default: printf("m16cvec -R<input_file> -O<output_file> -I<include_file> -M<mode> -F<fixvector>\n"); break; } } } printf("version = %s\n", version); printf("input file = %s\n", input_file); printf("output file = %s\n", output_file); printf("Fix Vector = %s\n", fvector); printf("board mode = %d : ", board_mode); if(board_mode == 1) printf("M30262F8FG(OAKS16 MINI)\n"); else printf("M30620FCAFP(OAKS16)\n"); if((pfi = fopen(input_file, "r")) == NULL){ fprintf(stderr, "can't open input file !"); exit(1); } if((pfo = fopen(output_file, "w")) == NULL){ fclose(pfi); fprintf(stderr, "can't open output file !"); exit(1); } for(i = 0 ; i < num_include ; i++){ printf("include file = %s\n", include_file[i]); } for(;;){ if((fgets(buf, BUF_SIZE, pfi)) == NULL) break; s = buf; switch(vec_state){ case INT_STATE: case EXC_STATE: if(test_string(&s, ";")) vec_state = NORMAL_STATE; else if(test_string(&s, "{")){ v = &vec_table[vec_state][num_vec[vec_state]]; p = &v->no_name[0]; if(skip_space(&s)) continue; dec = true; while(*s != ','){ if(*s == 0) continue; if(*s == '(' || *s == ')' || *s <= ' '){ s++; continue; } if(*s < '0' || *s > '9') dec = false; *p++ = *s++; } s++; *p++ = 0; if(dec) v->no = atoi(v->no_name); else{ v->no = -1; num_nodec++; } p = &v->no_label[0]; if(skip_char(&s, ',')) continue; test_string(&s, "INT_ENTRY("); test_string(&s, "EXC_ENTRY("); test_string(&s, "CFG_INT_ENTRY("); test_string(&s, "CFG_EXC_ENTRY("); test_string(&s, "(FP)"); if(skip_space(&s)) continue; while(*s != ')' && *s != ',' && *s > ' '){ *p++ = *s++; } *p++ = 0; num_vec[vec_state]++; } else continue; break; default: if(!test_string(&s, "const")) continue; if(test_string(&s, "INHINIB")) vec_state = INT_STATE; else if(test_string(&s, "EXCINIB")) vec_state = EXC_STATE; break; } } do{ cnv = false; for(i = 0 ; i < num_include ; i++){ if((pfw = fopen(include_file[i], "r")) != NULL){ for(;;){ if((fgets(buf, BUF_SIZE, pfw)) == NULL) break; s = buf; if(!test_string(&s, "#define")) continue; if(skip_space(&s)) continue; for(k = 0 ; k < 2 ; k++){ for(j = 0 ; j < num_vec[k] ; j++){ v = &vec_table[k][j]; if(v->no < 0){ p = s; dec = true; if(test_string(&p, v->no_name)){ q = &v->no_name[0]; if(!skip_space(&p)){ while(*p > ' '){ if(*p == '(' || *p == ')'){ p++; continue; } if(*p < '0' || *p > '9') dec = false; *q++ = *p++; } } *q++ = 0; } else dec = false; if(dec){ v->no = atoi(v->no_name); num_nodec--; } } } } } fclose(pfw); } else printf("open error %s !!\n", include_file[i]); } }while(cnv); for(i = 0 ; i < num_vec[EXC_STATE] ; i++){ v = &vec_table[EXC_STATE][i]; if(v->no >= 32 && v->no < MAX_INT){ vec_table[INT_STATE][num_vec[INT_STATE]] = vec_table[EXC_STATE][i]; num_vec[INT_STATE]++; for(j = i ; j < (num_vec[EXC_STATE]-1) ; j++) vec_table[EXC_STATE][j] = vec_table[EXC_STATE][j+1]; num_vec[EXC_STATE]--; } } for(j = 0 ; j < num_vec[INT_STATE] ; j++){ v = &vec_table[INT_STATE][j]; if(v->no >= MAX_INT) strcpy(unused_vec[INT_STATE], v->no_label); else if(max_int < v->no) max_int = v->no; printf("int %d:%d,%s,%s\n", j, v->no, v->no_name, v->no_label); } for(j = 0 ; j < num_vec[EXC_STATE] ; j++){ v = &vec_table[EXC_STATE][j]; if((v->no >= MAX_EXC && v->no < 32) || v->no >= MAX_INT) strcpy(unused_vec[EXC_STATE], v->no_label); printf("exc %d:%d,%s,%s\n", j, v->no, v->no_name, v->no_label); } if(num_nodec > 0) printf("%dのエクセプション番号を特定できません!\n", num_nodec); else{ fputs(lf, pfo); for(i = 0 ; i < 2 ; i++){ for(j = 0 ; j < num_vec[i] ; j++) set_global(pfo, vec_table[i][j].no_label); } if(!strcmp(default_unused_int, unused_vec[0])) set_global(pfo, unused_vec[0]); else if(!strcmp(default_unused_int, unused_vec[1])) set_global(pfo, unused_vec[1]); switch(board_mode){ case 1: // M30262F8FG(OAKS16 MINI) set_M30262F8FG(pfo, board_mode, max_int); break; default: // M30620FCAFP(OAKS16) set_M30620FCAFP(pfo, board_mode, max_int); break; } set_comment(pfo, exc_vec); fputs("\t.section\tfvector", pfo); fputs(lf, pfo); set_org(pfo, fvector); for(i = 0 ; i < (MAX_EXC-1) ; i++) set_vector(pfo, EXC_STATE, i); fputs("\t.lword\t_hardware_start\t\t\t; RESET", pfo); fputs(lf, pfo); } fclose(pfi); fclose(pfo); return 0; }
int main(int argc, const char * argv[]) { FILE *text_input; FILE *pcap_out = NULL; // Command-line arguments if(argc != 3){ // Check for more than two arguments, error. system("clear"); fprintf(stderr, "Error running %s: %s\n", argv[0], strerror(errno)); usage_error (*argv); return 7; // Argument List too Long. } // Open files as a data stream text_input = fopen(argv[1], "rb"); pcap_out = fopen(argv[2], "w+b"); // Writeable so we can use it if good. if(argc == 3){ // Check both files to validate they are there and accessable. if (!text_input){ printf("Error! No text file at '%s'.\n", argv[1]); usage_error (*argv); exit_clean(pcap_out, text_input); } else if (!pcap_out){ printf("Error! No destination PCAP file at '%s'\n", argv[2]); usage_error (*argv); exit_clean(pcap_out, text_input); } } printf("DEBUG: Your two file locations are good.\nWho knows if they are the correct types of files. Here...We....GO...\n\n"); struct global global; struct packet packet; struct ethernet ethernet; struct IPv4 IPv4; struct UDP UDP; set_global(&global); set_packet(&packet); set_ethernet(ðernet); set_IPv4(&IPv4); set_udp(&UDP); // Could not get this working. Supposed to loop the writing. // void *structures[5] = { &global, &packet, ðernet, &IPv4, &UDP }; // for (int i = 0; i < 6; i++){ // fwrite(structures[i], sizeof(*structures[i]), 1, pcap_out); // } fwrite(&global, sizeof(global), 1, pcap_out); fwrite(&packet, sizeof(packet), 1, pcap_out); fwrite(ðernet, sizeof(ethernet), 1, pcap_out); fwrite(&IPv4, sizeof(IPv4), 1, pcap_out); fwrite(&UDP, sizeof(UDP), 1, pcap_out); // union type_seq_ver med_tsv; struct med_head med_head; struct status status; struct cmnd cmnd; // READ AND PROCESS the given text file. // 0 is the mead_head. This will tell find_word what the next task is int next_section; next_section = 0; int next_word = 0; // int section = -3; while(!feof(text_input)){ // start with med_head find_word(&next_section, &next_word, text_input); check_set_value(&next_section, &next_word, text_input, pcap_out, argv, &med_head, &status, &cmnd); // Get values for med_head. // 0-5 are for Type, Version, Sequence, From, and To respectively } fclose(pcap_out); fclose(text_input); return 0; }
static int tk_archive_write_mtree_header(struct archive_write *a, struct archive_entry *entry) { struct mtree_writer *mtree= a->format_data; struct archive_string *str; const char *path; mtree->entry = tk_archive_entry_clone(entry); path = tk_archive_entry_pathname(mtree->entry); if (mtree->first) { mtree->first = 0; tk_archive_strcat(&mtree->buf, "#mtree\n"); } if (mtree->set.output) set_global(mtree, entry); tk_archive_string_empty(&mtree->ebuf); str = (mtree->indent)? &mtree->ebuf : &mtree->buf; if (!mtree->dironly || tk_archive_entry_filetype(entry) == AE_IFDIR) mtree_quote(str, path); mtree->entry_bytes_remaining = tk_archive_entry_size(entry); if ((mtree->keys & F_CKSUM) != 0 && tk_archive_entry_filetype(entry) == AE_IFREG) { mtree->compute_sum |= F_CKSUM; mtree->crc = 0; mtree->crc_len = 0; } else mtree->compute_sum &= ~F_CKSUM; #ifdef ARCHIVE_HAS_MD5 if ((mtree->keys & F_MD5) != 0 && tk_archive_entry_filetype(entry) == AE_IFREG) { mtree->compute_sum |= F_MD5; tk_archive_md5_init(&mtree->md5ctx); } else mtree->compute_sum &= ~F_MD5; #endif #ifdef ARCHIVE_HAS_RMD160 if ((mtree->keys & F_RMD160) != 0 && tk_archive_entry_filetype(entry) == AE_IFREG) { mtree->compute_sum |= F_RMD160; tk_archive_rmd160_init(&mtree->rmd160ctx); } else mtree->compute_sum &= ~F_RMD160; #endif #ifdef ARCHIVE_HAS_SHA1 if ((mtree->keys & F_SHA1) != 0 && tk_archive_entry_filetype(entry) == AE_IFREG) { mtree->compute_sum |= F_SHA1; tk_archive_sha1_init(&mtree->sha1ctx); } else mtree->compute_sum &= ~F_SHA1; #endif #ifdef ARCHIVE_HAS_SHA256 if ((mtree->keys & F_SHA256) != 0 && tk_archive_entry_filetype(entry) == AE_IFREG) { mtree->compute_sum |= F_SHA256; tk_archive_sha256_init(&mtree->sha256ctx); } else mtree->compute_sum &= ~F_SHA256; #endif #ifdef ARCHIVE_HAS_SHA384 if ((mtree->keys & F_SHA384) != 0 && tk_archive_entry_filetype(entry) == AE_IFREG) { mtree->compute_sum |= F_SHA384; tk_archive_sha384_init(&mtree->sha384ctx); } else mtree->compute_sum &= ~F_SHA384; #endif #ifdef ARCHIVE_HAS_SHA512 if ((mtree->keys & F_SHA512) != 0 && tk_archive_entry_filetype(entry) == AE_IFREG) { mtree->compute_sum |= F_SHA512; tk_archive_sha512_init(&mtree->sha512ctx); } else mtree->compute_sum &= ~F_SHA512; #endif return (ARCHIVE_OK); }
/*ARGSUSED*/ error_t cvt_to_metal(menu_t *mp, char *osroot, char *menu_root) { const char *fcn = "cvt_to_metal()"; line_t *lp; entry_t *ent; size_t len, zfslen; char *delim = ","; char *newstr; char *osdev; char *title = NULL; char *findroot = NULL; char *bootfs = NULL; char *kernel = NULL; char *module = NULL; char *barchive_path = DIRECT_BOOT_ARCHIVE; char *kern_path = NULL; int curdef, newdef; int emit_bflag = 1; int ret = BAM_ERROR; assert(osroot); BAM_DPRINTF((D_FUNC_ENTRY2, fcn, osroot, "")); /* * First just check to verify osroot is a sane directory. */ if ((osdev = get_special(osroot)) == NULL) { bam_error(CANT_FIND_SPECIAL, osroot); return (BAM_ERROR); } free(osdev); /* * Found the GRUB signature on the target partitions, so now get the * default GRUB boot entry number from the menu.lst file */ curdef = atoi(mp->curdefault->arg); /* look for the first line of the matching boot entry */ for (ent = mp->entries; ((ent != NULL) && (ent->entryNum != curdef)); ent = ent->next) ; /* couldn't find it, so error out */ if (ent == NULL) { bam_error(CANT_FIND_DEFAULT, curdef); goto abort; } /* * Now process the entry itself. */ for (lp = ent->start; lp != NULL; lp = lp->next) { /* * Process important lines from menu.lst boot entry. */ if (lp->flags == BAM_TITLE) { title = alloca(strlen(lp->arg) + 1); (void) strcpy(title, lp->arg); } else if (strcmp(lp->cmd, "findroot") == 0) { findroot = alloca(strlen(lp->arg) + 1); (void) strcpy(findroot, lp->arg); } else if (strcmp(lp->cmd, "bootfs") == 0) { bootfs = alloca(strlen(lp->arg) + 1); (void) strcpy(bootfs, lp->arg); } else if (strcmp(lp->cmd, menu_cmds[MODULE_DOLLAR_CMD]) == 0) { if (strstr(lp->arg, "boot_archive") == NULL) { module = alloca(strlen(lp->arg) + 1); (void) strcpy(module, lp->arg); cvt_hyper_module(module, &kern_path); } else { barchive_path = alloca(strlen(lp->arg) + 1); (void) strcpy(barchive_path, lp->arg); } } else if ((strcmp(lp->cmd, menu_cmds[KERNEL_DOLLAR_CMD]) == 0) && (cvt_hyper_kernel(lp->arg) < 0)) { ret = BAM_NOCHANGE; goto abort; } if (lp == ent->end) break; } /* * If findroot, module or kern_path are NULL, the boot entry is * malformed. */ if (findroot == NULL) { bam_error(FINDROOT_NOT_FOUND, curdef); goto abort; } if (module == NULL) { bam_error(MODULE_NOT_PARSEABLE, curdef); goto abort; } if (kern_path == NULL) { bam_error(KERNEL_NOT_FOUND, curdef); goto abort; } /* * Assemble new kernel and module arguments from parsed values. * * First, change the kernel directory from the hypervisor version to * that needed for a metal kernel. */ newstr = modify_path(kern_path, HYPER_KERNEL_DIR, METAL_KERNEL_DIR); free(kern_path); kern_path = newstr; /* allocate initial space for the kernel path */ len = strlen(kern_path) + 1; zfslen = (zfs_boot ? (WHITESPC(1) + strlen(ZFS_BOOT)) : 0); if ((kernel = malloc(len + zfslen)) == NULL) { free(kern_path); bam_error(NO_MEM, len + zfslen); bam_exit(1); } (void) snprintf(kernel, len, "%s", kern_path); free(kern_path); if (zfs_boot) { char *zfsstr = alloca(zfslen + 1); (void) snprintf(zfsstr, zfslen + 1, " %s", ZFS_BOOT); (void) strcat(kernel, zfsstr); emit_bflag = 0; } /* * Process the bootenv.rc file to look for boot options that would be * the same as what the hypervisor had manually set, as we need not set * those explicitly. * * If there's no bootenv.rc, it's not an issue. */ parse_bootenvrc(osroot); /* * Don't emit a console setting if it's the same as what would be * set by bootenv.rc. */ if ((console_dev != NULL) && (bootenv_rc_console == NULL || (strcmp(console_dev, bootenv_rc_console) != 0))) { if (emit_bflag) { newstr = append_str(kernel, BFLAG, " "); free(kernel); kernel = append_str(newstr, "console=", " "); free(newstr); newstr = append_str(kernel, console_dev, ""); free(kernel); kernel = newstr; emit_bflag = 0; } else { newstr = append_str(kernel, "console=", ","); free(kernel); kernel = append_str(newstr, console_dev, ""); free(newstr); } } /* * We have to do some strange processing here because the hypervisor's * serial ports default to "9600,8,n,1,-" if "comX=auto" is specified, * or to "auto" if nothing is specified. * * This could result in a serial mode setting string being added when * it would otherwise not be needed, but it's better to play it safe. */ if (emit_bflag) { newstr = append_str(kernel, BFLAG, " "); free(kernel); kernel = newstr; delim = " "; emit_bflag = 0; } if ((serial_config[0] != NULL) && (bootenv_rc_serial[0] == NULL || (strcmp(serial_config[0], bootenv_rc_serial[0]) != 0))) { newstr = append_str(kernel, "ttya-mode='", delim); free(kernel); /* * Pass the serial configuration as the delimiter to * append_str() as it will be inserted between the current * string and the string we're appending, in this case the * closing single quote. */ kernel = append_str(newstr, "'", serial_config[0]); free(newstr); delim = ","; } if ((serial_config[1] != NULL) && (bootenv_rc_serial[1] == NULL || (strcmp(serial_config[1], bootenv_rc_serial[1]) != 0))) { newstr = append_str(kernel, "ttyb-mode='", delim); free(kernel); /* * Pass the serial configuration as the delimiter to * append_str() as it will be inserted between the current * string and the string we're appending, in this case the * closing single quote. */ kernel = append_str(newstr, "'", serial_config[1]); free(newstr); delim = ","; } /* shut off warning messages from the entry line parser */ if (ent->flags & BAM_ENTRY_BOOTADM) ent->flags &= ~BAM_ENTRY_BOOTADM; BAM_DPRINTF((D_CVT_CMD_KERN_DOLLAR, fcn, kernel)); BAM_DPRINTF((D_CVT_CMD_MOD_DOLLAR, fcn, module)); if ((newdef = add_boot_entry(mp, title, findroot, kernel, NULL, barchive_path, bootfs)) == BAM_ERROR) { free(kernel); return (newdef); } /* * Now try to delete the current default entry from the menu and add * the new hypervisor entry with the parameters we've setup. */ if (delete_boot_entry(mp, curdef, DBE_QUIET) == BAM_SUCCESS) newdef--; else bam_print(NEW_BOOT_ENTRY, title); free(kernel); /* * If we successfully created the new entry, set the default boot * entry to that entry and let the caller know the new menu should * be written out. */ return (set_global(mp, menu_cmds[DEFAULT_CMD], newdef)); abort: if (ret != BAM_NOCHANGE) bam_error(METAL_ABORT, osroot); return (ret); }
error_t cvt_to_hyper(menu_t *mp, char *osroot, char *extra_args) { const char *fcn = "cvt_to_hyper()"; line_t *lp; entry_t *ent; size_t len, zfslen; char *newstr; char *osdev; char *title = NULL; char *findroot = NULL; char *bootfs = NULL; char *kernel = NULL; char *mod_kernel = NULL; char *module = NULL; char *kern_path = NULL; char *kern_bargs = NULL; int curdef, newdef; int kp_allocated = 0; int ret = BAM_ERROR; assert(osroot); BAM_DPRINTF((D_FUNC_ENTRY2, fcn, osroot, extra_args)); /* * First just check to verify osroot is a sane directory. */ if ((osdev = get_special(osroot)) == NULL) { bam_error(CANT_FIND_SPECIAL, osroot); return (BAM_ERROR); } free(osdev); /* * While the effect is purely cosmetic, if osroot is "/" don't * bother prepending it to any paths as they are constructed to * begin with "/" anyway. */ if (strcmp(osroot, "/") == 0) osroot = ""; /* * Found the GRUB signature on the target partitions, so now get the * default GRUB boot entry number from the menu.lst file */ curdef = atoi(mp->curdefault->arg); /* look for the first line of the matching boot entry */ for (ent = mp->entries; ((ent != NULL) && (ent->entryNum != curdef)); ent = ent->next) ; /* couldn't find it, so error out */ if (ent == NULL) { bam_error(CANT_FIND_DEFAULT, curdef); goto abort; } /* * We found the proper menu entry, so first we need to process the * bootenv.rc file to look for boot options the hypervisor might need * passed as kernel start options such as the console device and serial * port parameters. * * If there's no bootenv.rc, it's not an issue. */ parse_bootenvrc(osroot); if (bootenv_rc_console != NULL) console_metal_to_hyper(bootenv_rc_console); if (bootenv_rc_serial[0] != NULL) (void) serial_metal_to_hyper("ttya-mode", bootenv_rc_serial[0]); if (bootenv_rc_serial[1] != NULL) (void) serial_metal_to_hyper("ttyb-mode", bootenv_rc_serial[1]); /* * Now process the entry itself. */ for (lp = ent->start; lp != NULL; lp = lp->next) { /* * Process important lines from menu.lst boot entry. */ if (lp->flags == BAM_TITLE) { title = alloca(strlen(lp->arg) + 1); (void) strcpy(title, lp->arg); } else if (strcmp(lp->cmd, "findroot") == 0) { findroot = alloca(strlen(lp->arg) + 1); (void) strcpy(findroot, lp->arg); } else if (strcmp(lp->cmd, "bootfs") == 0) { bootfs = alloca(strlen(lp->arg) + 1); (void) strcpy(bootfs, lp->arg); } else if (strcmp(lp->cmd, menu_cmds[MODULE_DOLLAR_CMD]) == 0) { module = alloca(strlen(lp->arg) + 1); (void) strcpy(module, lp->arg); } else if ((strcmp(lp->cmd, menu_cmds[KERNEL_DOLLAR_CMD]) == 0) && (ret = cvt_metal_kernel(lp->arg, &kern_path)) != 0) { if (ret < 0) { ret = BAM_ERROR; bam_error(KERNEL_NOT_PARSEABLE, curdef); } else ret = BAM_NOCHANGE; goto abort; } if (lp == ent->end) break; } /* * If findroot, module or kern_path are NULL, the boot entry is * malformed. */ if (findroot == NULL) { bam_error(FINDROOT_NOT_FOUND, curdef); goto abort; } if (module == NULL) { bam_error(MODULE_NOT_PARSEABLE, curdef); goto abort; } if (kern_path == NULL) { bam_error(KERNEL_NOT_FOUND, curdef); goto abort; } /* assemble new kernel and module arguments from parsed values */ if (console_dev != NULL) { kern_bargs = s_strdup(console_dev); if (serial_config[0] != NULL) { newstr = append_str(kern_bargs, serial_config[0], " "); free(kern_bargs); kern_bargs = newstr; } if (serial_config[1] != NULL) { newstr = append_str(kern_bargs, serial_config[1], " "); free(kern_bargs); kern_bargs = newstr; } } if ((extra_args != NULL) && (*extra_args != NULL)) { newstr = append_str(kern_bargs, extra_args, " "); free(kern_bargs); kern_bargs = newstr; } len = strlen(osroot) + strlen(XEN_MENU) + strlen(kern_bargs) + WHITESPC(1) + 1; kernel = alloca(len); if (kern_bargs != NULL) { if (*kern_bargs != NULL) (void) snprintf(kernel, len, "%s%s %s", osroot, XEN_MENU, kern_bargs); free(kern_bargs); } else { (void) snprintf(kernel, len, "%s%s", osroot, XEN_MENU); } /* * Change the kernel directory from the metal version to that needed for * the hypervisor. Convert either "direct boot" path to the default * path. */ if ((strcmp(kern_path, DIRECT_BOOT_32) == 0) || (strcmp(kern_path, DIRECT_BOOT_64) == 0)) { kern_path = HYPERVISOR_KERNEL; } else { newstr = modify_path(kern_path, METAL_KERNEL_DIR, HYPER_KERNEL_DIR); free(kern_path); kern_path = newstr; kp_allocated = 1; } /* * We need to allocate space for the kernel path (twice) plus an * intervening space, possibly the ZFS boot string, and NULL, * of course. */ len = (strlen(kern_path) * 2) + WHITESPC(1) + 1; zfslen = (zfs_boot ? (WHITESPC(1) + strlen(ZFS_BOOT)) : 0); mod_kernel = alloca(len + zfslen); (void) snprintf(mod_kernel, len, "%s %s", kern_path, kern_path); if (kp_allocated) free(kern_path); if (zfs_boot) { char *zfsstr = alloca(zfslen + 1); (void) snprintf(zfsstr, zfslen + 1, " %s", ZFS_BOOT); (void) strcat(mod_kernel, zfsstr); } /* shut off warning messages from the entry line parser */ if (ent->flags & BAM_ENTRY_BOOTADM) ent->flags &= ~BAM_ENTRY_BOOTADM; BAM_DPRINTF((D_CVT_CMD_KERN_DOLLAR, fcn, kernel)); BAM_DPRINTF((D_CVT_CMD_MOD_DOLLAR, fcn, mod_kernel)); if ((newdef = add_boot_entry(mp, title, findroot, kernel, mod_kernel, module, bootfs)) == BAM_ERROR) return (newdef); /* * Now try to delete the current default entry from the menu and add * the new hypervisor entry with the parameters we've setup. */ if (delete_boot_entry(mp, curdef, DBE_QUIET) == BAM_SUCCESS) newdef--; else bam_print(NEW_BOOT_ENTRY, title); /* * If we successfully created the new entry, set the default boot * entry to that entry and let the caller know the new menu should * be written out. */ return (set_global(mp, menu_cmds[DEFAULT_CMD], newdef)); abort: if (ret != BAM_NOCHANGE) bam_error(HYPER_ABORT, ((*osroot == NULL) ? "/" : osroot)); return (ret); }
template<typename T> void set_global(T &&name, value_t value) { return set_global(symbol_cast(std::forward<T>(name)), value); }
/* Called when a command is invoked */ TEE_Result TA_InvokeCommandEntryPoint(void *pSessionContext, uint32_t nCommandID, uint32_t nParamTypes, TEE_Param pParams[4]) { static bool use_fptr = false; (void)pSessionContext; switch (nCommandID) { case TA_CRYPT_CMD_SHA224: use_fptr = !use_fptr; if (use_fptr) return ta_cmd_entries[nCommandID](nParamTypes, pParams); else return ta_entry_sha224(nParamTypes, pParams); case TA_CRYPT_CMD_SHA256: use_fptr = !use_fptr; if (use_fptr) return ta_cmd_entries[nCommandID](nParamTypes, pParams); else return ta_entry_sha256(nParamTypes, pParams); case TA_CRYPT_CMD_AES256ECB_ENC: return ta_entry_aes256ecb_encrypt(nParamTypes, pParams); case TA_CRYPT_CMD_AES256ECB_DEC: return ta_entry_aes256ecb_decrypt(nParamTypes, pParams); case TA_CRYPT_CMD_ALLOCATE_OPERATION: return ta_entry_allocate_operation(nParamTypes, pParams); case TA_CRYPT_CMD_FREE_OPERATION: return ta_entry_free_operation(nParamTypes, pParams); case TA_CRYPT_CMD_GET_OPERATION_INFO: return ta_entry_get_operation_info(nParamTypes, pParams); case TA_CRYPT_CMD_RESET_OPERATION: return ta_entry_reset_operation(nParamTypes, pParams); case TA_CRYPT_CMD_SET_OPERATION_KEY: return ta_entry_set_operation_key(nParamTypes, pParams); case TA_CRYPT_CMD_SET_OPERATION_KEY2: return ta_entry_set_operation_key2(nParamTypes, pParams); case TA_CRYPT_CMD_COPY_OPERATION: return ta_entry_copy_operation(nParamTypes, pParams); case TA_CRYPT_CMD_DIGEST_UPDATE: return ta_entry_digest_update(nParamTypes, pParams); case TA_CRYPT_CMD_DIGEST_DO_FINAL: return ta_entry_digest_do_final(nParamTypes, pParams); case TA_CRYPT_CMD_CIPHER_INIT: return ta_entry_cipher_init(nParamTypes, pParams); case TA_CRYPT_CMD_CIPHER_UPDATE: return ta_entry_cipher_update(nParamTypes, pParams); case TA_CRYPT_CMD_CIPHER_DO_FINAL: return ta_entry_cipher_do_final(nParamTypes, pParams); case TA_CRYPT_CMD_MAC_INIT: return ta_entry_mac_init(nParamTypes, pParams); case TA_CRYPT_CMD_MAC_UPDATE: return ta_entry_mac_update(nParamTypes, pParams); case TA_CRYPT_CMD_MAC_FINAL_COMPUTE: return ta_entry_mac_final_compute(nParamTypes, pParams); case TA_CRYPT_CMD_MAC_FINAL_COMPARE: return ta_entry_mac_final_compare(nParamTypes, pParams); case TA_CRYPT_CMD_ALLOCATE_TRANSIENT_OBJECT: return ta_entry_allocate_transient_object(nParamTypes, pParams); case TA_CRYPT_CMD_FREE_TRANSIENT_OBJECT: return ta_entry_free_transient_object(nParamTypes, pParams); case TA_CRYPT_CMD_RESET_TRANSIENT_OBJECT: return ta_entry_reset_transient_object(nParamTypes, pParams); case TA_CRYPT_CMD_POPULATE_TRANSIENT_OBJECT: return ta_entry_populate_transient_object(nParamTypes, pParams); case TA_CRYPT_CMD_COPY_OBJECT_ATTRIBUTES: return ta_entry_copy_object_attributes(nParamTypes, pParams); case TA_CRYPT_CMD_GENERATE_KEY: return ta_entry_generate_key(nParamTypes, pParams); case TA_CRYPT_CMD_ASYMMETRIC_ENCRYPT: return ta_entry_asymmetric_encrypt(nParamTypes, pParams); case TA_CRYPT_CMD_ASYMMETRIC_DECRYPT: return ta_entry_asymmetric_decrypt(nParamTypes, pParams); case TA_CRYPT_CMD_ASYMMETRIC_SIGN_DIGEST: return ta_entry_asymmetric_sign_digest(nParamTypes, pParams); case TA_CRYPT_CMD_ASYMMETRIC_VERIFY_DIGEST: return ta_entry_asymmetric_verify_digest(nParamTypes, pParams); case TA_CRYPT_CMD_DERIVE_KEY: return ta_entry_derive_key(nParamTypes, pParams); case TA_CRYPT_CMD_RANDOM_NUMBER_GENEREATE: return ta_entry_random_number_generate(nParamTypes, pParams); case TA_CRYPT_CMD_AE_INIT: return ta_entry_ae_init(nParamTypes, pParams); case TA_CRYPT_CMD_AE_UPDATE_AAD: return ta_entry_ae_update_aad(nParamTypes, pParams); case TA_CRYPT_CMD_AE_UPDATE: return ta_entry_ae_update(nParamTypes, pParams); case TA_CRYPT_CMD_AE_ENCRYPT_FINAL: return ta_entry_ae_encrypt_final(nParamTypes, pParams); case TA_CRYPT_CMD_AE_DECRYPT_FINAL: return ta_entry_ae_decrypt_final(nParamTypes, pParams); case TA_CRYPT_CMD_GET_OBJECT_BUFFER_ATTRIBUTE: return ta_entry_get_object_buffer_attribute(nParamTypes, pParams); case TA_CRYPT_CMD_GET_OBJECT_VALUE_ATTRIBUTE: return ta_entry_get_object_value_attribute(nParamTypes, pParams); case TA_CRYPT_CMD_SETGLOBAL: return set_global(nParamTypes, pParams); case TA_CRYPT_CMD_GETGLOBAL: return get_global(nParamTypes, pParams); default: return TEE_ERROR_BAD_PARAMETERS; } }
int main(int argc, char* const* argv) { static int debug_mode = false; static int verbose_mode = false; static int interactive_mode = false; ObjectPtr<Array> require_files = create_array(); while (true) { int c; static struct option long_options[] = { {"debug", no_argument, &debug_mode, 'd'}, {"version", no_argument, NULL, 'v'}, {"require", required_argument, NULL, 'r'}, {"interactive", no_argument, &interactive_mode, 1 }, {"verbose", no_argument, &verbose_mode, 1 }, {0,0,0,0} }; int option_index = -1; c = getopt_long(argc, argv, "dvir:", long_options, &option_index); if (c < 0) break; switch (c) { case 'v': { print_version_info(); return 0; } case 'r': { ObjectPtr<String> filename = create_string_constant(optarg); array_push(require_files, filename); break; } case 'i': { interactive_mode = true; break; } case '?': TRAP(); // unknown argument default: break; } } // require first loose argument, unless -- was used if (optind < argc && strcmp("--", argv[optind-1]) != 0) { ObjectPtr<String> filename = create_string_constant(argv[optind++]); array_push(require_files, filename); } // stuff the rest in ARGV ObjectPtr<Array> ARGV = create_array_with_size(argc); while (optind < argc) { ObjectPtr<String> argument = create_string_constant(argv[optind++]); array_push(ARGV, argument); } set_global(snow::sym("ARGV"), ARGV); for (size_t i = 0; i < array_size(require_files); ++i) { ObjectPtr<String> str = array_get(require_files, i); ASSERT(str != NULL); load(str); } if (interactive_mode) { interactive_prompt(); } return 0; }