//////////////////////////////////////////////////////////////////////////////// /// @brief 動き補償 (小ブロック単位) /// /// TODO: メモリアクセスの出力 /// /// @param SF [in] 画素差分データ /// @param b [in] ブロック番号 /// int mc(int SF[8][8], int b) { int p[8][8]; int mixf = 1 - (fptr[0][mb_y][mb_x] & 1); if(pic_coding_type == 1) mixf = 0; dump_header(dump_mv); dump(dump_mv, "mbx mby intra pat", " %2d %2d %d %d", mb_x, mb_y, mb_intra, (mb_pattern >> (5 - b)) & 1); if(!mb_mo_fw) mv[0][0][0] = mv[0][0][1] = 0; if(mb_intra) { dumpx_mc_fetch("# no fetch (mb_intra=1)\n"); } else { uint32_t fetch_a[9][5]; uint8_t fetch_d[9][10]; int ivx = mv[0][0][0]; int ivy = mv[0][0][1]; dump(dump_mv, "mvx mvy", " %5d %5d", ivx, ivy); if(b & 4) { ivx /= 2; ivy /= 2; } // 絶対値の小さい方へ丸め int halfx = ivx & 1; int halfy = ivy & 1; ivx = (ivx & ~1) / 2; ivy = (ivy & ~1) / 2; int oddx = ivx & 1; dump(dump_mv, "ivx halfx", " %3d %d", ivx, halfx); dump(dump_mv, "ivy halfy", " %3d %d", ivy, halfy); ivx += (b < 4) ? (mb_x * 16 + (b & 1) * 8) : (mb_x * 8); ivy += (b < 4) ? (mb_y * 16 + (b & 2) * 4) : (mb_y * 8); dump(dump_mv, "ox oy", " %3d %3d", ivx, ivy); dumpx_mc_fetch("# ivx=%d,halfx=%d,ivy=%d,halfy=%d\n", ivx, halfx, ivy, halfy); // フェッチアドレス計算 if(b < 4) { for(int y = 0; y < 9; ++y) for(int x = 0; x < 10; x += 2) { int ivx2 = x + ivx; int ivy2 = y + ivy; int f = fptr[0][(ivy2 >> 4) & MBY_MASK][(ivx2 >> 4) & MBX_MASK] & 1; fetch_a[y][x >> 1] = FBAGEN(b, f, (ivx2 >> 4), (ivx2 & 14) >> 1, (ivy2 >> 4), (ivy2 & 15)); } } else { for(int y = 0; y < 9; ++y) for(int x = 0; x < 10; x += 2) { int ivx2 = x + ivx; int ivy2 = y + ivy; int f = fptr[0][(ivy2 >> 3) & MBY_MASK][(ivx2 >> 3) & MBX_MASK] & 1; fetch_a[y][x >> 1] = FBAGEN(b, f, (ivx2 >> 3), (ivx2 & 14), (ivy2 >> 3), (ivy2 & 7) << 1); } } // フェッチ実行 for(int y = 0; y < 9; ++y) for(int x = 0; x < 10; x += 2) { uint32_t a = fetch_a[y][x >> 1]; fetch_d[y][x + 0] = fbuf[a + 0]; fetch_d[y][x + 1] = fbuf[a + 1]; dumpx_mc_fetch("%06x %02x%02x\n", fetch_a[y][x >> 1], fetch_d[y][x + 1], fetch_d[y][x + 0]); } // 整数画素・半画素合成 for(int y = 0; y < 8; ++y) for(int x = 0; x < 8; ++x) { int ym = y + halfy; p[y][x] = (fetch_d[y][x + oddx] + fetch_d[y][x + oddx + halfx] + fetch_d[ym][x + oddx] + fetch_d[ym][x + oddx + halfx] + 2) / 4; dumpx_mc_fetch("%s %2x%s", x == 0 ? "#" : "", p[y][x], x == 7 ? "\n" : ""); } dumpx_mc_fetch("#------------------------\n"); // memset(p, 0, sizeof(p)); }
int main(int argc, char **argv) { enum { NNP = CHAR_MAX + 1, RUID, EUID, RGID, EGID, REUID, REGID, CLEAR_GROUPS, KEEP_GROUPS, INIT_GROUPS, GROUPS, INHCAPS, AMBCAPS, LISTCAPS, CAPBSET, SECUREBITS, PDEATHSIG, SELINUX_LABEL, APPARMOR_PROFILE }; static const struct option longopts[] = { { "dump", no_argument, NULL, 'd' }, { "nnp", no_argument, NULL, NNP }, { "no-new-privs", no_argument, NULL, NNP }, { "inh-caps", required_argument, NULL, INHCAPS }, { "ambient-caps", required_argument, NULL, AMBCAPS }, { "list-caps", no_argument, NULL, LISTCAPS }, { "ruid", required_argument, NULL, RUID }, { "euid", required_argument, NULL, EUID }, { "rgid", required_argument, NULL, RGID }, { "egid", required_argument, NULL, EGID }, { "reuid", required_argument, NULL, REUID }, { "regid", required_argument, NULL, REGID }, { "clear-groups", no_argument, NULL, CLEAR_GROUPS }, { "keep-groups", no_argument, NULL, KEEP_GROUPS }, { "init-groups", no_argument, NULL, INIT_GROUPS }, { "groups", required_argument, NULL, GROUPS }, { "bounding-set", required_argument, NULL, CAPBSET }, { "securebits", required_argument, NULL, SECUREBITS }, { "pdeathsig", required_argument, NULL, PDEATHSIG, }, { "selinux-label", required_argument, NULL, SELINUX_LABEL }, { "apparmor-profile", required_argument, NULL, APPARMOR_PROFILE }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 } }; static const ul_excl_t excl[] = { /* keep in same order with enum definitions */ {CLEAR_GROUPS, KEEP_GROUPS, INIT_GROUPS, GROUPS}, {0} }; int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT; int c; struct privctx opts; struct passwd *pw = NULL; int dumplevel = 0; int total_opts = 0; int list_caps = 0; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); memset(&opts, 0, sizeof(opts)); while ((c = getopt_long(argc, argv, "+dhV", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); total_opts++; switch (c) { case 'd': dumplevel++; break; case NNP: if (opts.nnp) errx(EXIT_FAILURE, _("duplicate --no-new-privs option")); opts.nnp = 1; break; case RUID: if (opts.have_ruid) errx(EXIT_FAILURE, _("duplicate ruid")); opts.have_ruid = 1; pw = get_passwd(optarg, &opts.ruid, _("failed to parse ruid")); if (pw) { passwd_copy(&opts.passwd, pw); opts.have_passwd = 1; } break; case EUID: if (opts.have_euid) errx(EXIT_FAILURE, _("duplicate euid")); opts.have_euid = 1; opts.euid = get_user(optarg, _("failed to parse euid")); break; case REUID: if (opts.have_ruid || opts.have_euid) errx(EXIT_FAILURE, _("duplicate ruid or euid")); opts.have_ruid = opts.have_euid = 1; pw = get_passwd(optarg, &opts.ruid, _("failed to parse reuid")); opts.euid = opts.ruid; if (pw) { passwd_copy(&opts.passwd, pw); opts.have_passwd = 1; } break; case RGID: if (opts.have_rgid) errx(EXIT_FAILURE, _("duplicate rgid")); opts.have_rgid = 1; opts.rgid = get_group(optarg, _("failed to parse rgid")); break; case EGID: if (opts.have_egid) errx(EXIT_FAILURE, _("duplicate egid")); opts.have_egid = 1; opts.egid = get_group(optarg, _("failed to parse egid")); break; case REGID: if (opts.have_rgid || opts.have_egid) errx(EXIT_FAILURE, _("duplicate rgid or egid")); opts.have_rgid = opts.have_egid = 1; opts.rgid = opts.egid = get_group(optarg, _("failed to parse regid")); break; case CLEAR_GROUPS: if (opts.clear_groups) errx(EXIT_FAILURE, _("duplicate --clear-groups option")); opts.clear_groups = 1; break; case KEEP_GROUPS: if (opts.keep_groups) errx(EXIT_FAILURE, _("duplicate --keep-groups option")); opts.keep_groups = 1; break; case INIT_GROUPS: if (opts.init_groups) errx(EXIT_FAILURE, _("duplicate --init-groups option")); opts.init_groups = 1; break; case GROUPS: if (opts.have_groups) errx(EXIT_FAILURE, _("duplicate --groups option")); parse_groups(&opts, optarg); break; case PDEATHSIG: if (opts.pdeathsig) errx(EXIT_FAILURE, _("duplicate --keep-pdeathsig option")); parse_pdeathsig(&opts, optarg); break; case LISTCAPS: list_caps = 1; break; case INHCAPS: if (opts.caps_to_inherit) errx(EXIT_FAILURE, _("duplicate --inh-caps option")); opts.caps_to_inherit = optarg; break; case AMBCAPS: if (opts.ambient_caps) errx(EXIT_FAILURE, _("duplicate --ambient-caps option")); opts.ambient_caps = optarg; break; case CAPBSET: if (opts.bounding_set) errx(EXIT_FAILURE, _("duplicate --bounding-set option")); opts.bounding_set = optarg; break; case SECUREBITS: if (opts.have_securebits) errx(EXIT_FAILURE, _("duplicate --securebits option")); parse_securebits(&opts, optarg); break; case SELINUX_LABEL: if (opts.selinux_label) errx(EXIT_FAILURE, _("duplicate --selinux-label option")); opts.selinux_label = optarg; break; case APPARMOR_PROFILE: if (opts.apparmor_profile) errx(EXIT_FAILURE, _("duplicate --apparmor-profile option")); opts.apparmor_profile = optarg; break; case 'h': usage(); case 'V': printf(UTIL_LINUX_VERSION); return EXIT_SUCCESS; default: errtryhelp(EXIT_FAILURE); } } if (dumplevel) { if (total_opts != dumplevel || optind < argc) errx(EXIT_FAILURE, _("--dump is incompatible with all other options")); dump(dumplevel); return EXIT_SUCCESS; } if (list_caps) { if (total_opts != 1 || optind < argc) errx(EXIT_FAILURE, _("--list-caps must be specified alone")); list_known_caps(); return EXIT_SUCCESS; } if (argc <= optind) errx(EXIT_FAILURE, _("No program specified")); if ((opts.have_rgid || opts.have_egid) && !opts.keep_groups && !opts.clear_groups && !opts.init_groups && !opts.have_groups) errx(EXIT_FAILURE, _("--[re]gid requires --keep-groups, --clear-groups, --init-groups, or --groups")); if (opts.init_groups && !opts.have_ruid) errx(EXIT_FAILURE, _("--init-groups requires --ruid or --reuid")); if (opts.init_groups && !opts.have_passwd) errx(EXIT_FAILURE, _("uid %ld not found, --init-groups requires an user that " "can be found on the system"), (long) opts.ruid); if (opts.nnp && prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1) err(EXIT_FAILURE, _("disallow granting new privileges failed")); if (opts.selinux_label) do_selinux_label(opts.selinux_label); if (opts.apparmor_profile) do_apparmor_profile(opts.apparmor_profile); if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) == -1) err(EXIT_FAILURE, _("keep process capabilities failed")); /* We're going to want CAP_SETPCAP, CAP_SETUID, and CAP_SETGID if * possible. */ bump_cap(CAP_SETPCAP); bump_cap(CAP_SETUID); bump_cap(CAP_SETGID); if (capng_apply(CAPNG_SELECT_CAPS) != 0) err(SETPRIV_EXIT_PRIVERR, _("activate capabilities")); if (opts.have_ruid || opts.have_euid) { do_setresuid(&opts); /* KEEPCAPS doesn't work for the effective mask. */ if (capng_apply(CAPNG_SELECT_CAPS) != 0) err(SETPRIV_EXIT_PRIVERR, _("reactivate capabilities")); } if (opts.have_rgid || opts.have_egid) do_setresgid(&opts); if (opts.have_groups) { if (setgroups(opts.num_groups, opts.groups) != 0) err(SETPRIV_EXIT_PRIVERR, _("setgroups failed")); } else if (opts.init_groups) { if (initgroups(opts.passwd.pw_name, opts.passwd.pw_gid) != 0) err(SETPRIV_EXIT_PRIVERR, _("initgroups failed")); } else if (opts.clear_groups) { gid_t x = 0; if (setgroups(0, &x) != 0) err(SETPRIV_EXIT_PRIVERR, _("setgroups failed")); } if (opts.have_securebits && prctl(PR_SET_SECUREBITS, opts.securebits, 0, 0, 0) != 0) err(SETPRIV_EXIT_PRIVERR, _("set process securebits failed")); if (opts.bounding_set) { do_caps(CAP_TYPE_BOUNDING, opts.bounding_set); errno = EPERM; /* capng doesn't set errno if we're missing CAP_SETPCAP */ if (capng_apply(CAPNG_SELECT_BOUNDS) != 0) err(SETPRIV_EXIT_PRIVERR, _("apply bounding set")); } if (opts.caps_to_inherit) { do_caps(CAP_TYPE_INHERITABLE, opts.caps_to_inherit); if (capng_apply(CAPNG_SELECT_CAPS) != 0) err(SETPRIV_EXIT_PRIVERR, _("apply capabilities")); } if (opts.ambient_caps) { do_caps(CAP_TYPE_AMBIENT, opts.ambient_caps); } /* Clear or set parent death signal */ if (opts.pdeathsig && prctl(PR_SET_PDEATHSIG, opts.pdeathsig < 0 ? 0 : opts.pdeathsig) != 0) err(SETPRIV_EXIT_PRIVERR, _("set parent death signal failed")); execvp(argv[optind], argv + optind); errexec(argv[optind]); }
bool ConfigManager::initialize() { if (isInitialized()) { std::cerr << "CONFIG WARNING: The configuration framework is already initialized!" << std::endl; return true; } if (Getopt::instance().paramOptPresent("configfile")) { // Read the configuration file. icl_core::String filename = Getopt::instance().paramOpt("configfile"); if (!load(filename)) { std::cerr << "CONFIG ERROR: The configuration file '" << filename << "' could not be loaded!" << std::endl; return false; } insert(CONFIGFILE_CONFIG_KEY, filename); notify(CONFIGFILE_CONFIG_KEY); } // Check for registered parameters. for (ConfigParameterList::const_iterator it = m_parameter_list.begin(); it != m_parameter_list.end(); ++it) { if (it->configKey() != "") { // Fill the configuration parameter from the commandline. if (Getopt::instance().paramOptPresent(it->option())) { insert(it->configKey(), Getopt::instance().paramOpt(it->option())); notify(it->configKey()); } // If the parameter is still not present but has a default value, then set it. else if (!hasKey(it->configKey()) && it->hasDefaultValue()) { insert(it->configKey(), it->defaultValue()); notify(it->configKey()); } } } // Check for registered positional parameters. for (ConfigPositionalParameterList::const_iterator it = m_postional_parameter_list.begin(); it != m_postional_parameter_list.end(); ++it) { if (it->configKey() != "") { // Fill the configuration parameter from the commandline. if (Getopt::instance().paramOptPresent(it->name())) { insert(it->configKey(), Getopt::instance().paramOpt(it->name())); notify(it->configKey()); } // If the parameter is still not present but has a default value, then set it. else if (!hasKey(it->configKey()) && it->hasDefaultValue()) { insert(it->configKey(), it->defaultValue()); notify(it->configKey()); } } } // Check for option parameters. Getopt::KeyValueList option_params = Getopt::instance().paramPrefixOpt("config-option"); for (Getopt::KeyValueList::const_iterator it = option_params.begin(); it != option_params.end(); ++it) { insert(it->m_key, it->m_value); notify(it->m_key); } // Optionally dump the configuration. if (Getopt::instance().paramOptPresent("dump-config")) { dump(); } m_initialized = true; return true; }
void ConsumerBase::dump(String8& result) const { char buffer[1024]; dump(result, "", buffer, 1024); }
string toString() { ostringstream oss; dump(oss); return oss.str(); }
void AsiMS2000::selectCommand(int commandNum) { switch(commandNum) { case 0: accel(); break; case 1: aalign(); break; case 2: afcont(); break; case 3: aflim(); break; case 4: afocus(); break; case 5: afset(); break; case 6: afmove(); break; case 7: ahome(); break; case 8: aij(); break; case 9: array(); break; case 10: azero(); break; case 11: backlash(); break; case 12: bcustom(); break; case 13: benable(); break; case 14: build(); break; case 15: cdate(); break; case 16: cnts(); break; case 17: customa(); break; case 18: customb(); break; case 19: dack(); break; case 20: dump(); break; case 21: ensync(); break; case 22: epolarity(); break; case 23: error(); break; case 24: halt(); break; case 25: here(); break; case 26: home(); break; case 27: info(); break; case 28: joystick(); break; case 29: jsspd(); break; case 30: kadc(); break; case 31: kd(); break; case 32: ki(); break; case 33: kp(); break; case 34: lcd(); break; case 35: led(); break; case 36: lladdr(); break; case 37: load(); break; case 38: lock(); break; case 39: lockrg(); break; case 40: lockset(); break; case 41: maintain(); break; case 42: motctrl(); break; case 43: move(); break; case 44: movrel(); break; case 45: pcros(); break; case 46: pedal(); break; case 47: rbmode(); break; case 48: rdadc(); break; case 49: rdsbyte(); break; case 50: rdstat(); break; case 51: relock(); break; case 52: reset(); break; case 53: rt(); break; case 54: runaway(); break; case 55: saveset(); break; case 56: savepos(); break; case 57: scan(); break; case 58: scanr(); break; case 59: scanv(); break; case 60: secure(); break; case 61: sethome(); break; case 62: setlow(); break; case 63: setup(); break; case 64: si(); break; case 65: speed(); break; case 66: spin(); break; case 67: status(); break; case 68: stopbits(); break; case 69: ttl(); break; case 70: um(); break; case 71: units(); break; case 72: unlock(); break; case 73: vb(); break; case 74: vector(); break; case 75: version(); break; case 76: wait(); break; case 77: where(); break; case 78: who(); break; case 79: wrdac(); break; case 80: zero(); break; case 81: z2b(); break; case 82: zs(); break; case 83: overshoot(); break; } }
int main (void) { struct R1 A1 = My_R1; struct R2 A2 = My_R2; struct Nested1 N1; struct Nested2 N2; unsigned C1; unsigned C2; unsigned C3; put ("A1 :"); dump (&A1, sizeof (struct R1)); new_line (); /* { dg-output "A1 : c2 7b f3 2a 5e 12 9a 95\n" } */ put ("A2 :"); dump (&A2, sizeof (struct R2)); new_line (); /* { dg-output "A2 : 09 e2 af 37 bd 24 d2 b4\n" } */ N1 = A1.N; C1 = N1.C1; C2 = N1.C2; C3 = N1.C3; printf ("C1 : %d\n", C1); /* { dg-output "C1 : 18\n" } */ printf ("C2 : %d\n", C2); /* { dg-output "C2 : 52\n" } */ printf ("C3 : %d\n", C3); /* { dg-output "C3 : 86\n" } */ N1.C1 = C1; N1.C2 = C2; N1.C3 = C3; A1.N = N1; N2 = A2.N; C1 = N2.C1; C2 = N2.C2; C3 = N2.C3; printf ("C1 : %d\n", C1); /* { dg-output "C1 : 18\n" } */ printf ("C2 : %d\n", C2); /* { dg-output "C2 : 52\n" } */ printf ("C3 : %d\n", C3); /* { dg-output "C3 : 86\n" } */ N2.C1 = C1; N2.C2 = C2; N2.C3 = C3; A2.N = N2; put ("A1 :"); dump (&A1, sizeof (struct R1)); new_line (); /* { dg-output "A1 : c2 7b f3 2a 5e 12 9a 95\n" } */ put ("A2 :"); dump (&A2, sizeof (struct R2)); new_line (); /* { dg-output "A2 : 09 e2 af 37 bd 24 d2 b4\n" } */ return 0; }
void SurfaceMediaSource::dump(String8& result) const { char buffer[1024]; dump(result, "", buffer, 1024); }
inline void dump(const std::string& str, bool putColon = true) { dump(str.c_str(), str.size(), putColon); }
int main (void) { struct R1 Local_R1; struct R2 Local_R2; Local_R1.I = My_R1.I + 1; Local_R1.N.A[0] = My_R1.N.A[0] + 1; Local_R1.N.A[1] = My_R1.N.A[1] + 1; Local_R1.N.A[2] = My_R1.N.A[2] + 1; put ("Local_R1 :"); dump (&Local_R1, sizeof (struct R1)); new_line (); /* { dg-output "Local_R1 : 79 56 34 12 00 ab 00 13 00 cd 00 35 00 ef 00 57.*\n" } */ Local_R2.I = My_R2.I + 1; Local_R2.N.A[0] = My_R2.N.A[0] + 1; Local_R2.N.A[1] = My_R2.N.A[1] + 1; Local_R2.N.A[2] = My_R2.N.A[2] + 1; put ("Local_R2 :"); dump (&Local_R2, sizeof (struct R2)); new_line (); /* { dg-output "Local_R2 : 12 34 56 79 13 00 ab 00 35 00 cd 00 57 00 ef 00.*\n" } */ Local_R1.I = 0x12345678; Local_R1.N.A[0] = 0xAB0012; Local_R1.N.A[1] = 0xCD0034; Local_R1.N.A[2] = 0xEF0056; put ("Local_R1 :"); dump (&Local_R1, sizeof (struct R1)); new_line (); /* { dg-output "Local_R1 : 78 56 34 12 00 ab 00 12 00 cd 00 34 00 ef 00 56.*\n" } */ Local_R2.I = 0x12345678; Local_R2.N.A[0] = 0xAB0012; Local_R2.N.A[1] = 0xCD0034; Local_R2.N.A[2] = 0xEF0056; put ("Local_R2 :"); dump (&Local_R2, sizeof (struct R2)); new_line (); /* { dg-output "Local_R2 : 12 34 56 78 12 00 ab 00 34 00 cd 00 56 00 ef 00.*\n" } */ Local_R1.I = Local_R1.I + 1; Local_R1.N.A[0] = Local_R1.N.A[0] + 1; Local_R1.N.A[1] = Local_R1.N.A[1] + 1; Local_R1.N.A[2] = Local_R1.N.A[2] + 1; put ("Local_R1 :"); dump (&Local_R1, sizeof (struct R1)); new_line (); /* { dg-output "Local_R1 : 79 56 34 12 00 ab 00 13 00 cd 00 35 00 ef 00 57.*\n" } */ Local_R2.I = Local_R2.I + 1; Local_R2.N.A[0] = Local_R2.N.A[0] + 1; Local_R2.N.A[1] = Local_R2.N.A[1] + 1; Local_R2.N.A[2] = Local_R2.N.A[2] + 1; put ("Local_R2 :"); dump (&Local_R2, sizeof (struct R2)); new_line (); /* { dg-output "Local_R2 : 12 34 56 79 13 00 ab 00 35 00 cd 00 57 00 ef 00.*\n" } */ return 0; }
void shader::dump_ir() { if (ctx.dump_pass) dump(*this).run(); }
int main(int argc, char **argv) { int ch, mode = 0; char *arg = NULL; pid = getpid(); thiszone = gmt2local(0); while ((ch = getopt(argc, argv, "acd:f:Ii:nprstA:HPR")) != -1) switch (ch) { case 'a': case 'c': case 'p': case 'r': case 'H': case 'P': case 'R': case 's': case 'I': if (mode) { usage(); /*NOTREACHED*/ } mode = ch; arg = NULL; break; case 'f': exit(file(optarg) ? 1 : 0); case 'd': case 'i': if (mode) { usage(); /*NOTREACHED*/ } mode = ch; arg = optarg; break; case 'n': nflag = 1; break; case 't': tflag = 1; break; case 'A': if (mode) { usage(); /*NOTREACHED*/ } mode = 'a'; repeat = atoi(optarg); if (repeat < 0) { usage(); /*NOTREACHED*/ } break; default: usage(); } argc -= optind; argv += optind; switch (mode) { case 'a': case 'c': if (argc != 0) { usage(); /*NOTREACHED*/ } dump(0, mode == 'c'); break; case 'd': if (argc != 0) { usage(); /*NOTREACHED*/ } delete(arg); break; case 'I': #ifdef SIOCSDEFIFACE_IN6 /* XXX: check SIOCGDEFIFACE_IN6 as well? */ if (argc > 1) { usage(); /*NOTREACHED*/ } else if (argc == 1) { if (strcmp(*argv, "delete") == 0 || if_nametoindex(*argv)) setdefif(*argv); else errx(1, "invalid interface %s", *argv); } getdefif(); /* always call it to print the result */ break; #else errx(1, "not supported yet"); /*NOTREACHED*/ #endif case 'p': if (argc != 0) { usage(); /*NOTREACHED*/ } plist(); break; case 'i': ifinfo(arg, argc, argv); break; case 'r': if (argc != 0) { usage(); /*NOTREACHED*/ } rtrlist(); break; case 's': if (argc < 2 || argc > 4) usage(); exit(set(argc, argv) ? 1 : 0); case 'H': if (argc != 0) { usage(); /*NOTREACHED*/ } harmonize_rtr(); break; case 'P': if (argc != 0) { usage(); /*NOTREACHED*/ } pfx_flush(); break; case 'R': if (argc != 0) { usage(); /*NOTREACHED*/ } rtr_flush(); break; case 0: if (argc != 1) { usage(); /*NOTREACHED*/ } get(argv[0]); break; } exit(0); }
DumpRenderTree::DumpRenderTree() : m_stdin(0) , m_enableTextOutput(false) , m_standAloneMode(false) , m_graphicsBased(false) , m_persistentStoragePath(QString(getenv("DUMPRENDERTREE_TEMP"))) { QByteArray viewMode = getenv("QT_DRT_WEBVIEW_MODE"); if (viewMode == "graphics") setGraphicsBased(true); DumpRenderTreeSupportQt::initialize(); // Set running in DRT mode for qwebpage to create testable objects. DumpRenderTreeSupportQt::setDumpRenderTreeModeEnabled(true); DumpRenderTreeSupportQt::overwritePluginDirectories(); QWebSettings::enablePersistentStorage(m_persistentStoragePath); m_networkAccessManager = new NetworkAccessManager(this); // create our primary testing page/view. if (isGraphicsBased()) { WebViewGraphicsBased* view = new WebViewGraphicsBased(0); m_page = new WebPage(view, this); view->setPage(m_page); m_mainView = view; } else { QWebView* view = new QWebView(0); m_page = new WebPage(view, this); view->setPage(m_page); m_mainView = view; } // Use a frame group name for all pages created by DumpRenderTree to allow // testing of cross-page frame lookup. DumpRenderTreeSupportQt::webPageSetGroupName(m_page, "org.webkit.qt.DumpRenderTree"); m_mainView->setContextMenuPolicy(Qt::NoContextMenu); m_mainView->resize(QSize(TestRunner::maxViewWidth, TestRunner::maxViewHeight)); // clean up cache by resetting quota. qint64 quota = webPage()->settings()->offlineWebApplicationCacheQuota(); webPage()->settings()->setOfflineWebApplicationCacheQuota(quota); // create our controllers. This has to be done before connectFrame, // as it exports there to the JavaScript DOM window. m_controller = new TestRunner(this); connect(m_controller, SIGNAL(showPage()), this, SLOT(showPage())); connect(m_controller, SIGNAL(hidePage()), this, SLOT(hidePage())); // async geolocation permission set by controller connect(m_controller, SIGNAL(geolocationPermissionSet()), this, SLOT(geolocationPermissionSet())); connect(m_controller, SIGNAL(done()), this, SLOT(dump())); m_eventSender = new EventSender(m_page); m_textInputController = new TextInputController(m_page); m_gcController = new GCController(m_page); // now connect our different signals connect(m_page, SIGNAL(frameCreated(QWebFrame *)), this, SLOT(connectFrame(QWebFrame *))); connectFrame(m_page->mainFrame()); connect(m_page, SIGNAL(loadFinished(bool)), m_controller, SLOT(maybeDump(bool))); // We need to connect to loadStarted() because notifyDone should only // dump results itself when the last page loaded in the test has finished loading. connect(m_page, SIGNAL(loadStarted()), m_controller, SLOT(resetLoadFinished())); connect(m_page, SIGNAL(windowCloseRequested()), this, SLOT(windowCloseRequested())); connect(m_page, SIGNAL(printRequested(QWebFrame*)), this, SLOT(dryRunPrint(QWebFrame*))); connect(m_page->mainFrame(), SIGNAL(titleChanged(const QString&)), SLOT(titleChanged(const QString&))); connect(m_page, SIGNAL(databaseQuotaExceeded(QWebFrame*,QString)), this, SLOT(dumpDatabaseQuota(QWebFrame*,QString))); connect(m_page, SIGNAL(applicationCacheQuotaExceeded(QWebSecurityOrigin *, quint64, quint64)), this, SLOT(dumpApplicationCacheQuota(QWebSecurityOrigin *, quint64, quint64))); connect(m_page, SIGNAL(statusBarMessage(const QString&)), this, SLOT(statusBarMessage(const QString&))); QObject::connect(this, SIGNAL(quit()), qApp, SLOT(quit()), Qt::QueuedConnection); DumpRenderTreeSupportQt::setDumpRenderTreeModeEnabled(true); DumpRenderTreeSupportQt::setInteractiveFormValidationEnabled(webPage(), true); QFocusEvent event(QEvent::FocusIn, Qt::ActiveWindowFocusReason); QApplication::sendEvent(m_mainView, &event); }
int main(int argc, char** argv) { double ri = 0.0; double rf = 1.0; std::vector<int> npts(3); npts[0]=51;npts[1]=51;npts[2]=51; double xcut=0.23; double ycut=0.67; const int nk0=1; const int nk1=1; const int nk2=1; //Create one-dimensional grids for three orthogonal directions typedef LinearGrid<double> GridType; GridType gridX, gridY, gridZ; gridX.set(ri,rf,npts[0]); gridY.set(ri,rf,npts[1]); gridZ.set(ri,rf,npts[2]); //Create an analytic function for assignment ComboFunc infunc; infunc.push_back(0.5,new TestFunc(1,1,1)); //infunc.push_back(0.3,new TestFunc(1,1,2)); //infunc.push_back(0.1,new TestFunc(1,2,1)); //infunc.push_back(0.01,new TestFunc(2,1,1)); //infunc.push_back(0.01,new TestFunc(2,2,1)); //infunc.push_back(0.001,new TestFunc(2,1,2)); //infunc.push_back(0.001,new TestFunc(2,2,2)); //infunc.push_back(0.001,new TestFunc(5,5,5)); //infunc.push_back(-0.3,new TestFunc(7,2,3)); //infunc.push_back(0.01,new TestFunc(7,7,7)); //infunc.push_back(0.001,new TestFunc(5,5,5)); //Write to an array std::vector<double> inData(npts[0]*npts[1]*npts[2]); std::vector<double>::iterator it(inData.begin()); Pooma::Clock timer; timer.start(); //Assign the values for(int ix=0; ix<npts[0]; ix++) { double x(gridX(ix)); for(int iy=0; iy<npts[1]; iy++) { double y(gridY(iy)); for(int iz=0; iz<npts[2]; iz++) { (*it)=infunc.f(x,y,gridZ(iz));++it; } } } timer.stop(); cout << "Time to evaluate " << timer.cpu_time() << endl; //Test TriCubicSplineT function //Create XYZCubicGrid XYZCubicGrid<double> grid3(&gridX,&gridY,&gridZ); //Create a TriCubicSpline with PBC: have to think more about fixed-boundary conditions TriCubicSplineT<double> aorb(&grid3); //Reset the coefficients aorb.reset(inData.begin(), inData.end()); double lap,val; TinyVector<double,3> grad; //aorb.reset(); //Write for vtk ImageData string fname("spline3d.vti"); std::ofstream dfile(fname.c_str()); dfile.setf(ios::scientific, ios::floatfield); dfile.setf(ios::left,ios::adjustfield); dfile.precision(10); dfile << "<?xml version=\"1.0\"?>" << endl; dfile << "<VTKFile type=\"ImageData\" version=\"0.1\">" << endl; dfile << " <ImageData WholeExtent=\"0 " << npts[0]-2 << " 0 " << npts[1]-2 << " 0 " << npts[2]-2 << "\" Origin=\"0 0 0\" Spacing=\"1 1 1\">"<< endl; dfile << " <Piece Extent=\"0 " << npts[0]-2 << " 0 " << npts[1]-2 << " 0 " << npts[2]-2 << "\">" << endl; dfile << " <PointData Scalars=\"wfs\">" << endl; dfile << " <DataArray type=\"Float32\" Name=\"wfs\">" << endl; timer.start(); int ng=0; for(int ix=0; ix<npts[0]-1; ix++) { double x(gridX(ix)); for(int iy=0; iy<npts[1]-1; iy++) { double y(gridY(iy)); for(int iz=0; iz<npts[2]-1; iz++, ng++) { TinyVector<double,3> p(x,y,gridZ(iz)); //aorb.setgrid(p); //Timing with the ofstream is not correct. //Uncomment the line below and comment out the next two line. //double t=aorb.evaluate(p,grad,lap); dfile << setw(20) << aorb.evaluate(p,grad,lap); if(ng%5 == 4) dfile << endl; } } } timer.stop(); cout << "Time to evaluate with spline " << timer.cpu_time() << endl; dfile << " </DataArray>" << endl; dfile << " </PointData>" << endl; dfile << " </Piece>" << endl; dfile << " </ImageData>" << endl; dfile << "</VTKFile>" << endl; hid_t h_file = H5Fcreate("spline3d.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT); HDFAttribIO<std::vector<double> > dump(inData,npts); dump.write(h_file,"orb0000"); HDFAttribIO<TriCubicSplineT<double> > dump1(aorb); dump1.write(h_file,"spline0000"); H5Fclose(h_file); //double lap; //TinyVector<double,3> grad; //for(int k=0; k<nptY-1; k++) { // //TinyVector<double,3> p(xcut,ycut,gridZ(k)+0.11*gridZ.dr(k)); // TinyVector<double,3> p(xcut,gridY(k)+0.11*gridY.dr(k),ycut); // aorb.setgrid(p); // double y=aorb.evaluate(p,grad,lap); // dfile << setw(30) << p[1] << setw(30) << infunc.f(p) << setw(30) << y << setw(30) << infunc.d2f(p) << setw(30) << lap << endl; //} return 0; }
int main(int argc, char **argv){ // Local variables struct sockaddr_in our_addr; void *buf = NULL; int sock = -1; unsigned int slen = 0; int err = 0; int i; // Parse parameters while ((i = getopt(argc, argv, "n:s:t:q")) != -1){ switch(i){ case 'n': // Number of packets npkts = atoi(optarg); break; case 's': // Payload size bufsz = atoi(optarg); if (bufsz < sizeof(udpdata_t)){ fprintf(stderr, "Payload size must be at least %zd bytes\n", sizeof(udpdata_t)); goto err; } break; case 't': // Tolerance timer duration toler_sec = atoi(optarg); break; case 'q': // Suppress per-packet output suppress_dump = 1; break; default: usage(argv[0]); goto err; } } // Initialise timer timer_init(); // Allocate receive buffer if ((udpdata = (udpdata_t *)calloc(npkts, sizeof(*udpdata))) == NULL) { perror("calloc"); goto err; } if ((buf = malloc(bufsz)) == NULL){ perror("malloc"); goto err; } // Handles kill signal(SIGINT, sigterm_h); // Handles timer signal(SIGALRM, sigalrm_h); // Setup UDP socket if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0){ perror("socket"); fprintf(stderr, "Error creating temporary socket.\n"); goto err; } memset(&our_addr, 0, sizeof(our_addr)); our_addr.sin_family = AF_INET; our_addr.sin_addr.s_addr = INADDR_ANY; our_addr.sin_port = htons(UDPPORT); if (bind(sock, (struct sockaddr *)&our_addr, sizeof(struct sockaddr)) < 0){ perror("bind"); goto err; } // Receive packets for (i=0; i<npkts; i++){ slen = sizeof(struct sockaddr); err = recvfrom(sock, buf, bufsz, 0, (struct sockaddr *)&our_addr, &slen); if (err < 0){ perror("recvfrom"); goto err; } else if (err != bufsz){ fprintf(stderr, "Received unknown packet.\n"); goto err; } memcpy(&udpdata[i], buf, sizeof(udpdata_t)); udpdata[i].tscrx = rdtsc(); timer_reset(); } // Dump dump(); out: if (sock >= 0) close(sock); if (buf) free(buf); // Return return(err); err: err = 1; goto out; }
std::string dump() const { std::string out; dump(out); return out; }
void sigterm_h(int signal){ dump(); exit(0); }
int ss_encrypt_all(buffer_t *plain, int method, int auth, size_t capacity) { if (method > TABLE) { cipher_ctx_t evp; cipher_context_init(&evp, method, 1); size_t iv_len = enc_iv_len; int err = 1; static buffer_t tmp = { 0, 0, 0, NULL }; brealloc(&tmp, iv_len + plain->len, capacity); buffer_t *cipher = &tmp; cipher->len = plain->len; uint8_t iv[MAX_IV_LENGTH]; rand_bytes(iv, iv_len); cipher_context_set_iv(&evp, iv, iv_len, 1); memcpy(cipher->array, iv, iv_len); if (auth) { ss_onetimeauth(plain, iv, capacity); cipher->len = plain->len; } if (method >= SALSA20) { crypto_stream_xor_ic((uint8_t *)(cipher->array + iv_len), (const uint8_t *)plain->array, (uint64_t)(plain->len), (const uint8_t *)iv, 0, enc_key, method); } else { err = cipher_context_update(&evp, (uint8_t *)(cipher->array + iv_len), &cipher->len, (const uint8_t *)plain->array, plain->len); } if (!err) { bfree(plain); cipher_context_release(&evp); return -1; } #ifdef DEBUG dump("PLAIN", plain->array, plain->len); dump("CIPHER", cipher->array + iv_len, cipher->len); #endif cipher_context_release(&evp); brealloc(plain, iv_len + cipher->len, capacity); memcpy(plain->array, cipher->array, iv_len + cipher->len); plain->len = iv_len + cipher->len; return 0; } else { char *begin = plain->array; char *ptr = plain->array; while (ptr < begin + plain->len) { *ptr = (char)enc_table[(uint8_t)*ptr]; ptr++; } return 0; } }
int tool_debug_cb(CURL *handle, curl_infotype type, unsigned char *data, size_t size, void *userdata) { struct OperationConfig *operation = userdata; struct GlobalConfig *config = operation->global; FILE *output = operation->errors; const char *text; struct timeval tv; struct tm *now; char timebuf[20]; time_t secs; static time_t epoch_offset; static int known_offset; (void)handle; /* not used */ if(config->tracetime) { tv = tvnow(); if(!known_offset) { epoch_offset = time(NULL) - tv.tv_sec; known_offset = 1; } secs = epoch_offset + tv.tv_sec; now = localtime(&secs); /* not thread safe but we don't care */ snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld ", now->tm_hour, now->tm_min, now->tm_sec, (long)tv.tv_usec); } else timebuf[0] = 0; if(!config->trace_stream) { /* open for append */ if(curlx_strequal("-", config->trace_dump)) config->trace_stream = stdout; else if(curlx_strequal("%", config->trace_dump)) /* Ok, this is somewhat hackish but we do it undocumented for now */ config->trace_stream = operation->errors; /* aka stderr */ else { config->trace_stream = fopen(config->trace_dump, "w"); config->trace_fopened = TRUE; } } if(config->trace_stream) output = config->trace_stream; if(!output) { warnf(operation, "Failed to create/open output"); return 0; } if(config->tracetype == TRACE_PLAIN) { /* * This is the trace look that is similar to what libcurl makes on its * own. */ static const char * const s_infotype[] = { "*", "<", ">", "{", "}", "{", "}" }; size_t i; size_t st = 0; static bool newl = FALSE; static bool traced_data = FALSE; switch(type) { case CURLINFO_HEADER_OUT: if(size > 0) { for(i = 0; i < size - 1; i++) { if(data[i] == '\n') { /* LF */ if(!newl) { fprintf(output, "%s%s ", timebuf, s_infotype[type]); } (void)fwrite(data + st, i - st + 1, 1, output); st = i + 1; newl = FALSE; } } if(!newl) fprintf(output, "%s%s ", timebuf, s_infotype[type]); (void)fwrite(data + st, i - st + 1, 1, output); } newl = (size && (data[size - 1] != '\n')) ? TRUE : FALSE; traced_data = FALSE; break; case CURLINFO_TEXT: case CURLINFO_HEADER_IN: if(!newl) fprintf(output, "%s%s ", timebuf, s_infotype[type]); (void)fwrite(data, size, 1, output); newl = (size && (data[size - 1] != '\n')) ? TRUE : FALSE; traced_data = FALSE; break; case CURLINFO_DATA_OUT: case CURLINFO_DATA_IN: case CURLINFO_SSL_DATA_IN: case CURLINFO_SSL_DATA_OUT: if(!traced_data) { /* if the data is output to a tty and we're sending this debug trace to stderr or stdout, we don't display the alert about the data not being shown as the data _is_ shown then just not via this function */ if(!operation->isatty || ((output != stderr) && (output != stdout))) { if(!newl) fprintf(output, "%s%s ", timebuf, s_infotype[type]); fprintf(output, "[data not shown]\n"); newl = FALSE; traced_data = TRUE; } } break; default: /* nada */ newl = FALSE; traced_data = FALSE; break; } return 0; } #ifdef CURL_DOES_CONVERSIONS /* Special processing is needed for CURLINFO_HEADER_OUT blocks * if they contain both headers and data (separated by CRLFCRLF). * We dump the header text and then switch type to CURLINFO_DATA_OUT. */ if((type == CURLINFO_HEADER_OUT) && (size > 4)) { size_t i; for(i = 0; i < size - 4; i++) { if(memcmp(&data[i], "\r\n\r\n", 4) == 0) { /* dump everything through the CRLFCRLF as a sent header */ text = "=> Send header"; dump(timebuf, text, output, data, i + 4, config->tracetype, type); data += i + 3; size -= i + 4; type = CURLINFO_DATA_OUT; data += 1; break; } } } #endif /* CURL_DOES_CONVERSIONS */ switch (type) { case CURLINFO_TEXT: fprintf(output, "%s== Info: %s", timebuf, data); default: /* in case a new one is introduced to shock us */ return 0; case CURLINFO_HEADER_OUT: text = "=> Send header"; break; case CURLINFO_DATA_OUT: text = "=> Send data"; break; case CURLINFO_HEADER_IN: text = "<= Recv header"; break; case CURLINFO_DATA_IN: text = "<= Recv data"; break; case CURLINFO_SSL_DATA_IN: text = "<= Recv SSL data"; break; case CURLINFO_SSL_DATA_OUT: text = "=> Send SSL data"; break; } dump(timebuf, text, output, data, size, config->tracetype, type); return 0; }
int ss_encrypt(buffer_t *plain, enc_ctx_t *ctx, size_t capacity) { if (ctx != NULL) { static buffer_t tmp = { 0, 0, 0, NULL }; int err = 1; size_t iv_len = 0; if (!ctx->init) { iv_len = enc_iv_len; } brealloc(&tmp, iv_len + plain->len, capacity); buffer_t *cipher = &tmp; cipher->len = plain->len; if (!ctx->init) { cipher_context_set_iv(&ctx->evp, ctx->evp.iv, iv_len, 1); memcpy(cipher->array, ctx->evp.iv, iv_len); ctx->counter = 0; ctx->init = 1; } if (enc_method >= SALSA20) { int padding = ctx->counter % SODIUM_BLOCK_SIZE; brealloc(cipher, iv_len + (padding + cipher->len) * 2, capacity); if (padding) { brealloc(plain, plain->len + padding, capacity); memmove(plain->array + padding, plain->array, plain->len); sodium_memzero(plain->array, padding); } crypto_stream_xor_ic((uint8_t *)(cipher->array + iv_len), (const uint8_t *)plain->array, (uint64_t)(plain->len + padding), (const uint8_t *)ctx->evp.iv, ctx->counter / SODIUM_BLOCK_SIZE, enc_key, enc_method); ctx->counter += plain->len; if (padding) { memmove(cipher->array + iv_len, cipher->array + iv_len + padding, cipher->len); } } else { err = cipher_context_update(&ctx->evp, (uint8_t *)(cipher->array + iv_len), &cipher->len, (const uint8_t *)plain->array, plain->len); if (!err) { return -1; } } #ifdef DEBUG dump("PLAIN", plain->array, plain->len); dump("CIPHER", cipher->array + iv_len, cipher->len); #endif brealloc(plain, iv_len + cipher->len, capacity); memcpy(plain->array, cipher->array, iv_len + cipher->len); plain->len = iv_len + cipher->len; return 0; } else { char *begin = plain->array; char *ptr = plain->array; while (ptr < begin + plain->len) { *ptr = (char)enc_table[(uint8_t)*ptr]; ptr++; } return 0; } }
/* * attempt to generate 64-bit * res = n * return 1 on success, 0 if op not handled. */ void cgen64(Node *n, Node *res) { Node t1, t2, *l, *r; Node lo1, lo2, hi1, hi2; Node al, ah, bl, bh, cl, ch, s, n1, creg; Prog *p1, *p2, *p3, *p4, *p5, *p6; uint64 v; if(res->op != OINDREG && res->op != ONAME) { dump("n", n); dump("res", res); fatal("cgen64 %O of %O", n->op, res->op); } l = n->left; if(!l->addable) { tempname(&t1, l->type); cgen(l, &t1); l = &t1; } split64(l, &lo1, &hi1); switch(n->op) { default: fatal("cgen64 %O", n->op); case OMINUS: split64(res, &lo2, &hi2); regalloc(&t1, lo1.type, N); regalloc(&al, lo1.type, N); regalloc(&ah, hi1.type, N); gins(AMOVW, &lo1, &al); gins(AMOVW, &hi1, &ah); gmove(ncon(0), &t1); p1 = gins(ASUB, &al, &t1); p1->scond |= C_SBIT; gins(AMOVW, &t1, &lo2); gmove(ncon(0), &t1); gins(ASBC, &ah, &t1); gins(AMOVW, &t1, &hi2); regfree(&t1); regfree(&al); regfree(&ah); splitclean(); splitclean(); return; case OCOM: split64(res, &lo2, &hi2); regalloc(&n1, lo1.type, N); gins(AMOVW, &lo1, &n1); gins(AMVN, &n1, &n1); gins(AMOVW, &n1, &lo2); gins(AMOVW, &hi1, &n1); gins(AMVN, &n1, &n1); gins(AMOVW, &n1, &hi2); regfree(&n1); splitclean(); splitclean(); return; case OADD: case OSUB: case OMUL: case OLSH: case ORSH: case OAND: case OOR: case OXOR: // binary operators. // common setup below. break; } // setup for binary operators r = n->right; if(r != N && !r->addable) { tempname(&t2, r->type); cgen(r, &t2); r = &t2; } if(is64(r->type)) split64(r, &lo2, &hi2); regalloc(&al, lo1.type, N); regalloc(&ah, hi1.type, N); // Do op. Leave result in ah:al. switch(n->op) { default: fatal("cgen64: not implemented: %N\n", n); case OADD: // TODO: Constants regalloc(&bl, types[TPTR32], N); regalloc(&bh, types[TPTR32], N); gins(AMOVW, &hi1, &ah); gins(AMOVW, &lo1, &al); gins(AMOVW, &hi2, &bh); gins(AMOVW, &lo2, &bl); p1 = gins(AADD, &bl, &al); p1->scond |= C_SBIT; gins(AADC, &bh, &ah); regfree(&bl); regfree(&bh); break; case OSUB: // TODO: Constants. regalloc(&bl, types[TPTR32], N); regalloc(&bh, types[TPTR32], N); gins(AMOVW, &lo1, &al); gins(AMOVW, &hi1, &ah); gins(AMOVW, &lo2, &bl); gins(AMOVW, &hi2, &bh); p1 = gins(ASUB, &bl, &al); p1->scond |= C_SBIT; gins(ASBC, &bh, &ah); regfree(&bl); regfree(&bh); break; case OMUL: // TODO(kaib): this can be done with 4 regs and does not need 6 regalloc(&bl, types[TPTR32], N); regalloc(&bh, types[TPTR32], N); regalloc(&cl, types[TPTR32], N); regalloc(&ch, types[TPTR32], N); // load args into bh:bl and bh:bl. gins(AMOVW, &hi1, &bh); gins(AMOVW, &lo1, &bl); gins(AMOVW, &hi2, &ch); gins(AMOVW, &lo2, &cl); // bl * cl p1 = gins(AMULLU, N, N); p1->from.type = D_REG; p1->from.reg = bl.val.u.reg; p1->reg = cl.val.u.reg; p1->to.type = D_REGREG; p1->to.reg = ah.val.u.reg; p1->to.offset = al.val.u.reg; //print("%P\n", p1); // bl * ch p1 = gins(AMULA, N, N); p1->from.type = D_REG; p1->from.reg = bl.val.u.reg; p1->reg = ch.val.u.reg; p1->to.type = D_REGREG; p1->to.reg = ah.val.u.reg; p1->to.offset = ah.val.u.reg; //print("%P\n", p1); // bh * cl p1 = gins(AMULA, N, N); p1->from.type = D_REG; p1->from.reg = bh.val.u.reg; p1->reg = cl.val.u.reg; p1->to.type = D_REGREG; p1->to.reg = ah.val.u.reg; p1->to.offset = ah.val.u.reg; //print("%P\n", p1); regfree(&bh); regfree(&bl); regfree(&ch); regfree(&cl); break; case OLSH: regalloc(&bl, lo1.type, N); regalloc(&bh, hi1.type, N); gins(AMOVW, &hi1, &bh); gins(AMOVW, &lo1, &bl); if(r->op == OLITERAL) { v = mpgetfix(r->val.u.xval); if(v >= 64) { // TODO(kaib): replace with gins(AMOVW, nodintconst(0), &al) // here and below (verify it optimizes to EOR) gins(AEOR, &al, &al); gins(AEOR, &ah, &ah); } else if(v > 32) { gins(AEOR, &al, &al); // MOVW bl<<(v-32), ah gshift(AMOVW, &bl, SHIFT_LL, (v-32), &ah); } else if(v == 32) { gins(AEOR, &al, &al); gins(AMOVW, &bl, &ah); } else if(v > 0) { // MOVW bl<<v, al gshift(AMOVW, &bl, SHIFT_LL, v, &al); // MOVW bh<<v, ah gshift(AMOVW, &bh, SHIFT_LL, v, &ah); // OR bl>>(32-v), ah gshift(AORR, &bl, SHIFT_LR, 32-v, &ah); } else { gins(AMOVW, &bl, &al); gins(AMOVW, &bh, &ah); } goto olsh_break; } regalloc(&s, types[TUINT32], N); regalloc(&creg, types[TUINT32], N); if (is64(r->type)) { // shift is >= 1<<32 split64(r, &cl, &ch); gmove(&ch, &s); p1 = gins(AMOVW, &s, &s); p1->scond |= C_SBIT; p6 = gbranch(ABNE, T); gmove(&cl, &s); splitclean(); } else { gmove(r, &s); p6 = P; } p1 = gins(AMOVW, &s, &s); p1->scond |= C_SBIT; // shift == 0 p1 = gins(AMOVW, &bl, &al); p1->scond = C_SCOND_EQ; p1 = gins(AMOVW, &bh, &ah); p1->scond = C_SCOND_EQ; p2 = gbranch(ABEQ, T); // shift is < 32 nodconst(&n1, types[TUINT32], 32); gmove(&n1, &creg); gcmp(ACMP, &s, &creg); // MOVW.LO bl<<s, al p1 = gregshift(AMOVW, &bl, SHIFT_LL, &s, &al); p1->scond = C_SCOND_LO; // MOVW.LO bh<<s, ah p1 = gregshift(AMOVW, &bh, SHIFT_LL, &s, &ah); p1->scond = C_SCOND_LO; // SUB.LO s, creg p1 = gins(ASUB, &s, &creg); p1->scond = C_SCOND_LO; // OR.LO bl>>creg, ah p1 = gregshift(AORR, &bl, SHIFT_LR, &creg, &ah); p1->scond = C_SCOND_LO; // BLO end p3 = gbranch(ABLO, T); // shift == 32 p1 = gins(AEOR, &al, &al); p1->scond = C_SCOND_EQ; p1 = gins(AMOVW, &bl, &ah); p1->scond = C_SCOND_EQ; p4 = gbranch(ABEQ, T); // shift is < 64 nodconst(&n1, types[TUINT32], 64); gmove(&n1, &creg); gcmp(ACMP, &s, &creg); // EOR.LO al, al p1 = gins(AEOR, &al, &al); p1->scond = C_SCOND_LO; // MOVW.LO creg>>1, creg p1 = gshift(AMOVW, &creg, SHIFT_LR, 1, &creg); p1->scond = C_SCOND_LO; // SUB.LO creg, s p1 = gins(ASUB, &creg, &s); p1->scond = C_SCOND_LO; // MOVW bl<<s, ah p1 = gregshift(AMOVW, &bl, SHIFT_LL, &s, &ah); p1->scond = C_SCOND_LO; p5 = gbranch(ABLO, T); // shift >= 64 if (p6 != P) patch(p6, pc); gins(AEOR, &al, &al); gins(AEOR, &ah, &ah); patch(p2, pc); patch(p3, pc); patch(p4, pc); patch(p5, pc); regfree(&s); regfree(&creg); olsh_break: regfree(&bl); regfree(&bh); break; case ORSH: regalloc(&bl, lo1.type, N); regalloc(&bh, hi1.type, N); gins(AMOVW, &hi1, &bh); gins(AMOVW, &lo1, &bl); if(r->op == OLITERAL) { v = mpgetfix(r->val.u.xval); if(v >= 64) { if(bh.type->etype == TINT32) { // MOVW bh->31, al gshift(AMOVW, &bh, SHIFT_AR, 31, &al); // MOVW bh->31, ah gshift(AMOVW, &bh, SHIFT_AR, 31, &ah); } else { gins(AEOR, &al, &al); gins(AEOR, &ah, &ah); } } else if(v > 32) { if(bh.type->etype == TINT32) { // MOVW bh->(v-32), al gshift(AMOVW, &bh, SHIFT_AR, v-32, &al); // MOVW bh->31, ah gshift(AMOVW, &bh, SHIFT_AR, 31, &ah); } else { // MOVW bh>>(v-32), al gshift(AMOVW, &bh, SHIFT_LR, v-32, &al); gins(AEOR, &ah, &ah); } } else if(v == 32) { gins(AMOVW, &bh, &al); if(bh.type->etype == TINT32) { // MOVW bh->31, ah gshift(AMOVW, &bh, SHIFT_AR, 31, &ah); } else { gins(AEOR, &ah, &ah); } } else if( v > 0) { // MOVW bl>>v, al gshift(AMOVW, &bl, SHIFT_LR, v, &al); // OR bh<<(32-v), al gshift(AORR, &bh, SHIFT_LL, 32-v, &al); if(bh.type->etype == TINT32) { // MOVW bh->v, ah gshift(AMOVW, &bh, SHIFT_AR, v, &ah); } else { // MOVW bh>>v, ah gshift(AMOVW, &bh, SHIFT_LR, v, &ah); } } else { gins(AMOVW, &bl, &al); gins(AMOVW, &bh, &ah); } goto orsh_break; } regalloc(&s, types[TUINT32], N); regalloc(&creg, types[TUINT32], N); if (is64(r->type)) { // shift is >= 1<<32 split64(r, &cl, &ch); gmove(&ch, &s); p1 = gins(AMOVW, &s, &s); p1->scond |= C_SBIT; p6 = gbranch(ABNE, T); gmove(&cl, &s); splitclean(); } else { gmove(r, &s); p6 = P; } p1 = gins(AMOVW, &s, &s); p1->scond |= C_SBIT; // shift == 0 p1 = gins(AMOVW, &bl, &al); p1->scond = C_SCOND_EQ; p1 = gins(AMOVW, &bh, &ah); p1->scond = C_SCOND_EQ; p2 = gbranch(ABEQ, T); // check if shift is < 32 nodconst(&n1, types[TUINT32], 32); gmove(&n1, &creg); gcmp(ACMP, &s, &creg); // MOVW.LO bl>>s, al p1 = gregshift(AMOVW, &bl, SHIFT_LR, &s, &al); p1->scond = C_SCOND_LO; // SUB.LO s,creg p1 = gins(ASUB, &s, &creg); p1->scond = C_SCOND_LO; // OR.LO bh<<(32-s), al p1 = gregshift(AORR, &bh, SHIFT_LL, &creg, &al); p1->scond = C_SCOND_LO; if(bh.type->etype == TINT32) { // MOVW bh->s, ah p1 = gregshift(AMOVW, &bh, SHIFT_AR, &s, &ah); } else { // MOVW bh>>s, ah p1 = gregshift(AMOVW, &bh, SHIFT_LR, &s, &ah); } p1->scond = C_SCOND_LO; // BLO end p3 = gbranch(ABLO, T); // shift == 32 if(bh.type->etype == TINT32) p1 = gshift(AMOVW, &bh, SHIFT_AR, 31, &ah); else p1 = gins(AEOR, &al, &al); p1->scond = C_SCOND_EQ; p1 = gins(AMOVW, &bh, &al); p1->scond = C_SCOND_EQ; p4 = gbranch(ABEQ, T); // check if shift is < 64 nodconst(&n1, types[TUINT32], 64); gmove(&n1, &creg); gcmp(ACMP, &s, &creg); // MOVW.LO creg>>1, creg p1 = gshift(AMOVW, &creg, SHIFT_LR, 1, &creg); p1->scond = C_SCOND_LO; // SUB.LO creg, s p1 = gins(ASUB, &creg, &s); p1->scond = C_SCOND_LO; if(bh.type->etype == TINT32) { // MOVW bh->(s-32), al p1 = gregshift(AMOVW, &bh, SHIFT_AR, &s, &al); p1->scond = C_SCOND_LO; // MOVW bh->31, ah p1 = gshift(AMOVW, &bh, SHIFT_AR, 31, &ah); p1->scond = C_SCOND_LO; } else { // MOVW bh>>(v-32), al p1 = gregshift(AMOVW, &bh, SHIFT_LR, &s, &al); p1->scond = C_SCOND_LO; p1 = gins(AEOR, &ah, &ah); p1->scond = C_SCOND_LO; } // BLO end p5 = gbranch(ABLO, T); // s >= 64 if (p6 != P) patch(p6, pc); if(bh.type->etype == TINT32) { // MOVW bh->31, al gshift(AMOVW, &bh, SHIFT_AR, 31, &al); // MOVW bh->31, ah gshift(AMOVW, &bh, SHIFT_AR, 31, &ah); } else { gins(AEOR, &al, &al); gins(AEOR, &ah, &ah); } patch(p2, pc); patch(p3, pc); patch(p4, pc); patch(p5, pc); regfree(&s); regfree(&creg); orsh_break: regfree(&bl); regfree(&bh); break; case OXOR: case OAND: case OOR: // TODO(kaib): literal optimizations // make constant the right side (it usually is anyway). // if(lo1.op == OLITERAL) { // nswap(&lo1, &lo2); // nswap(&hi1, &hi2); // } // if(lo2.op == OLITERAL) { // // special cases for constants. // lv = mpgetfix(lo2.val.u.xval); // hv = mpgetfix(hi2.val.u.xval); // splitclean(); // right side // split64(res, &lo2, &hi2); // switch(n->op) { // case OXOR: // gmove(&lo1, &lo2); // gmove(&hi1, &hi2); // switch(lv) { // case 0: // break; // case 0xffffffffu: // gins(ANOTL, N, &lo2); // break; // default: // gins(AXORL, ncon(lv), &lo2); // break; // } // switch(hv) { // case 0: // break; // case 0xffffffffu: // gins(ANOTL, N, &hi2); // break; // default: // gins(AXORL, ncon(hv), &hi2); // break; // } // break; // case OAND: // switch(lv) { // case 0: // gins(AMOVL, ncon(0), &lo2); // break; // default: // gmove(&lo1, &lo2); // if(lv != 0xffffffffu) // gins(AANDL, ncon(lv), &lo2); // break; // } // switch(hv) { // case 0: // gins(AMOVL, ncon(0), &hi2); // break; // default: // gmove(&hi1, &hi2); // if(hv != 0xffffffffu) // gins(AANDL, ncon(hv), &hi2); // break; // } // break; // case OOR: // switch(lv) { // case 0: // gmove(&lo1, &lo2); // break; // case 0xffffffffu: // gins(AMOVL, ncon(0xffffffffu), &lo2); // break; // default: // gmove(&lo1, &lo2); // gins(AORL, ncon(lv), &lo2); // break; // } // switch(hv) { // case 0: // gmove(&hi1, &hi2); // break; // case 0xffffffffu: // gins(AMOVL, ncon(0xffffffffu), &hi2); // break; // default: // gmove(&hi1, &hi2); // gins(AORL, ncon(hv), &hi2); // break; // } // break; // } // splitclean(); // splitclean(); // goto out; // } regalloc(&n1, lo1.type, N); gins(AMOVW, &lo1, &al); gins(AMOVW, &hi1, &ah); gins(AMOVW, &lo2, &n1); gins(optoas(n->op, lo1.type), &n1, &al); gins(AMOVW, &hi2, &n1); gins(optoas(n->op, lo1.type), &n1, &ah); regfree(&n1); break; } if(is64(r->type)) splitclean(); splitclean(); split64(res, &lo1, &hi1); gins(AMOVW, &al, &lo1); gins(AMOVW, &ah, &hi1); splitclean(); //out: regfree(&al); regfree(&ah); }
int ss_decrypt_all(buffer_t *cipher, int method, int auth, size_t capacity) { if (method > TABLE) { size_t iv_len = enc_iv_len; int ret = 1; if (cipher->len <= iv_len) { return -1; } cipher_ctx_t evp; cipher_context_init(&evp, method, 0); static buffer_t tmp = { 0, 0, 0, NULL }; brealloc(&tmp, cipher->len, capacity); buffer_t *plain = &tmp; plain->len = cipher->len - iv_len; uint8_t iv[MAX_IV_LENGTH]; memcpy(iv, cipher->array, iv_len); cipher_context_set_iv(&evp, iv, iv_len, 0); if (method >= SALSA20) { crypto_stream_xor_ic((uint8_t *)plain->array, (const uint8_t *)(cipher->array + iv_len), (uint64_t)(cipher->len - iv_len), (const uint8_t *)iv, 0, enc_key, method); } else { ret = cipher_context_update(&evp, (uint8_t *)plain->array, &plain->len, (const uint8_t *)(cipher->array + iv_len), cipher->len - iv_len); } if (auth || (plain->array[0] & ONETIMEAUTH_FLAG)) { if (plain->len > ONETIMEAUTH_BYTES) { ret = !ss_onetimeauth_verify(plain, iv); if (ret) { plain->len -= ONETIMEAUTH_BYTES; } } else { ret = 0; } } if (!ret) { bfree(cipher); cipher_context_release(&evp); return -1; } #ifdef DEBUG dump("PLAIN", plain->array, plain->len); dump("CIPHER", cipher->array + iv_len, cipher->len - iv_len); #endif cipher_context_release(&evp); brealloc(cipher, plain->len, capacity); memcpy(cipher->array, plain->array, plain->len); cipher->len = plain->len; return 0; } else { char *begin = cipher->array; char *ptr = cipher->array; while (ptr < begin + cipher->len) { *ptr = (char)dec_table[(uint8_t)*ptr]; ptr++; } return 0; } }
void ConsumerBase::dump(String8& result) const { dump(result, ""); }
int ss_decrypt(buffer_t *cipher, enc_ctx_t *ctx, size_t capacity) { if (ctx != NULL) { static buffer_t tmp = { 0, 0, 0, NULL }; size_t iv_len = 0; int err = 1; brealloc(&tmp, cipher->len, capacity); buffer_t *plain = &tmp; plain->len = cipher->len; if (!ctx->init) { uint8_t iv[MAX_IV_LENGTH]; iv_len = enc_iv_len; plain->len -= iv_len; memcpy(iv, cipher->array, iv_len); cipher_context_set_iv(&ctx->evp, iv, iv_len, 0); ctx->counter = 0; ctx->init = 1; if (enc_method > RC4) { if (cache_key_exist(iv_cache, (char *)iv, iv_len)) { bfree(cipher); return -1; } else { cache_insert(iv_cache, (char *)iv, iv_len, NULL); } } } if (enc_method >= SALSA20) { int padding = ctx->counter % SODIUM_BLOCK_SIZE; brealloc(plain, (plain->len + padding) * 2, capacity); if (padding) { brealloc(cipher, cipher->len + padding, capacity); memmove(cipher->array + iv_len + padding, cipher->array + iv_len, cipher->len - iv_len); sodium_memzero(cipher->array + iv_len, padding); } crypto_stream_xor_ic((uint8_t *)plain->array, (const uint8_t *)(cipher->array + iv_len), (uint64_t)(cipher->len - iv_len + padding), (const uint8_t *)ctx->evp.iv, ctx->counter / SODIUM_BLOCK_SIZE, enc_key, enc_method); ctx->counter += cipher->len - iv_len; if (padding) { memmove(plain->array, plain->array + padding, plain->len); } } else { err = cipher_context_update(&ctx->evp, (uint8_t *)plain->array, &plain->len, (const uint8_t *)(cipher->array + iv_len), cipher->len - iv_len); } if (!err) { bfree(cipher); return -1; } #ifdef DEBUG dump("PLAIN", plain->array, plain->len); dump("CIPHER", cipher->array + iv_len, cipher->len - iv_len); #endif brealloc(cipher, plain->len, capacity); memcpy(cipher->array, plain->array, plain->len); cipher->len = plain->len; return 0; } else { char *begin = cipher->array; char *ptr = cipher->array; while (ptr < begin + cipher->len) { *ptr = (char)dec_table[(uint8_t)*ptr]; ptr++; } return 0; } }
int set_key_cmd_cb(int numParam, char* buf, void* ctx) { struct wl_ssid_t ssid; struct wl_mac_addr_t bssid; uint8_t idx=0, len=0; char key[13], key_hex[27]; char keyIdx[2]; wl_err_t err = WL_SUCCESS; tParam* params = (tParam*) buf; INFO_SPI("%s params=%d\n", __FUNCTION__, numParam); // SSID memset(&ssid, 0, sizeof ssid); if (params->paramLen < WL_SSID_MAX_LENGTH) { memcpy(ssid.ssid, ¶ms->param, params->paramLen); ssid.len = params->paramLen; INFO_SPI("%s\n", ssid.ssid); } else { //printk("SSID len out of range"); RETURN_ERR(WL_FAILURE) } params = (tParam*)((char*)buf+PARAM_LEN_SIZE+params->paramLen); strncpy(keyIdx, (const char*)¶ms->param, params->paramLen); keyIdx[(uint8_t)params->paramLen]='\0'; idx = (uint8_t)atoi(keyIdx); // KEY IDX if ((params->paramLen != 1)||(idx < 0)||(idx > 3)){ //printk("KEY IDX out of range %d\n", idx); RETURN_ERR(WL_FAILURE) } params = (tParam*)((char*)params+PARAM_LEN_SIZE+params->paramLen); strncpy(key_hex, (const char*)¶ms->param, params->paramLen); key_hex[(uint8_t)params->paramLen]='\0'; len = ascii_to_key(key, key_hex); // KEY if (( len != 5)&&(len != 13)) { //printk("KEY len out of range %d", len); RETURN_ERR(WL_FAILURE) } #if 0 printk("KEY IDX = %d\n", idx); dump(key, len); printk("KEY len %d\n", len); #endif memset(&bssid.octet, 0xff, sizeof bssid.octet); wl_add_wep_key(idx, len, key, &bssid); //wl_set_auth_mode(AUTH_MODE_SHARED_KEY); wl_set_default_wep_key(idx); //Connect err = wl_cm_set_network(&ssid, NULL); if (err != 1) WARN("err=%d\n", err); RETURN_ERR(err) }
void cipher_context_set_iv(cipher_ctx_t *ctx, uint8_t *iv, size_t iv_len, int enc) { const unsigned char *true_key; if (iv == NULL) { LOGE("cipher_context_set_iv(): IV is null"); return; } if (!enc) { memcpy(ctx->iv, iv, iv_len); } if (enc_method >= SALSA20) { return; } if (enc_method == RC4_MD5 || enc_method == RC4_MD5_6) { unsigned char key_iv[32]; memcpy(key_iv, enc_key, 16); memcpy(key_iv + 16, iv, iv_len); true_key = enc_md5(key_iv, 16 + iv_len, NULL); iv_len = 0; } else { true_key = enc_key; } #ifdef USE_CRYPTO_APPLECC cipher_cc_t *cc = &ctx->cc; if (cc->valid == kCCContextValid) { memcpy(cc->iv, iv, iv_len); memcpy(cc->key, true_key, enc_key_len); cc->iv_len = iv_len; cc->key_len = enc_key_len; cc->encrypt = enc ? kCCEncrypt : kCCDecrypt; if (cc->cryptor != NULL) { CCCryptorRelease(cc->cryptor); cc->cryptor = NULL; } CCCryptorStatus ret; ret = CCCryptorCreateWithMode( cc->encrypt, cc->mode, cc->cipher, cc->padding, cc->iv, cc->key, cc->key_len, NULL, 0, 0, 0, &cc->cryptor); if (ret != kCCSuccess) { if (cc->cryptor != NULL) { CCCryptorRelease(cc->cryptor); cc->cryptor = NULL; } FATAL("Cannot set CommonCrypto key and IV"); } return; } #endif cipher_evp_t *evp = &ctx->evp; if (evp == NULL) { LOGE("cipher_context_set_iv(): Cipher context is null"); return; } #if defined(USE_CRYPTO_OPENSSL) if (!EVP_CipherInit_ex(evp, NULL, NULL, true_key, iv, enc)) { EVP_CIPHER_CTX_cleanup(evp); FATAL("Cannot set key and IV"); } #elif defined(USE_CRYPTO_POLARSSL) // XXX: PolarSSL 1.3.11: cipher_free_ctx deprecated, Use cipher_free() instead. if (cipher_setkey(evp, true_key, enc_key_len * 8, enc) != 0) { cipher_free_ctx(evp); FATAL("Cannot set PolarSSL cipher key"); } #if POLARSSL_VERSION_NUMBER >= 0x01030000 if (cipher_set_iv(evp, iv, iv_len) != 0) { cipher_free_ctx(evp); FATAL("Cannot set PolarSSL cipher IV"); } if (cipher_reset(evp) != 0) { cipher_free_ctx(evp); FATAL("Cannot finalize PolarSSL cipher context"); } #else if (cipher_reset(evp, iv) != 0) { cipher_free_ctx(evp); FATAL("Cannot set PolarSSL cipher IV"); } #endif #elif defined(USE_CRYPTO_MBEDTLS) if (mbedtls_cipher_setkey(evp, true_key, enc_key_len * 8, enc) != 0) { mbedtls_cipher_free(evp); FATAL("Cannot set mbed TLS cipher key"); } if (mbedtls_cipher_set_iv(evp, iv, iv_len) != 0) { mbedtls_cipher_free(evp); FATAL("Cannot set mbed TLS cipher IV"); } if (mbedtls_cipher_reset(evp) != 0) { mbedtls_cipher_free(evp); FATAL("Cannot finalize mbed TLS cipher context"); } #endif #ifdef DEBUG dump("IV", (char *)iv, iv_len); #endif }
/*! Dumps all configuration keys and the corresponding values to * stdout. * \deprecated Obsolete coding style. */ void ConfigManager::Dump() const { dump(); }
int main(int argc, char *argv[]) { int i, j; void *buf; u8 g1[TEST_SOURCES], g2[TEST_SOURCES], g_tbls[2 * TEST_SOURCES * 32]; u8 *dest1, *dest2, *dest_ref1, *dest_ref2, *dest_ptrs[2]; u8 *buffs[TEST_SOURCES]; struct perf start, stop; printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d\n", TEST_SOURCES, TEST_LEN); // Allocate the arrays for (i = 0; i < TEST_SOURCES; i++) { if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } buffs[i] = buf; } if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } dest1 = buf; if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } dest2 = buf; if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } dest_ref1 = buf; if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } dest_ref2 = buf; dest_ptrs[0] = dest1; dest_ptrs[1] = dest2; // Performance test for (i = 0; i < TEST_SOURCES; i++) for (j = 0; j < TEST_LEN; j++) buffs[i][j] = rand(); memset(dest1, 0, TEST_LEN); memset(dest2, 0, TEST_LEN); memset(dest_ref1, 0, TEST_LEN); memset(dest_ref2, 0, TEST_LEN); for (i = 0; i < TEST_SOURCES; i++) { g1[i] = rand(); g2[i] = rand(); } for (j = 0; j < TEST_SOURCES; j++) { gf_vect_mul_init(g1[j], &g_tbls[j * 32]); gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]); } gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1); gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES], buffs, dest_ref2); #ifdef DO_REF_PERF perf_start(&start); for (i = 0; i < TEST_LOOPS / 100; i++) { for (j = 0; j < TEST_SOURCES; j++) { gf_vect_mul_init(g1[j], &g_tbls[j * 32]); gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]); } gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1); gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES], buffs, dest_ref2); } perf_stop(&stop); printf("gf_2vect_dot_prod_base" TEST_TYPE_STR ": "); perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 2) * i); #endif FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs); perf_start(&start); for (i = 0; i < TEST_LOOPS; i++) { for (j = 0; j < TEST_SOURCES; j++) { gf_vect_mul_init(g1[j], &g_tbls[j * 32]); gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]); } FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs); } perf_stop(&stop); printf(xstr(FUNCTION_UNDER_TEST) TEST_TYPE_STR ": "); perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 2) * i); if (0 != memcmp(dest_ref1, dest1, TEST_LEN)) { printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test1\n"); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref1, 25); printf("dprod_dut:"); dump(dest1, 25); return -1; } if (0 != memcmp(dest_ref2, dest2, TEST_LEN)) { printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test2\n"); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref2, 25); printf("dprod_dut:"); dump(dest2, 25); return -1; } printf("pass perf check\n"); return 0; }
void main(int argc, char **argv) { char *mtpt, *srvname; mtpt = nil; srvname = "font"; ARGBEGIN{ case 'D': chatty9p++; break; case 'F': chattyfuse++; break; case 'm': mtpt = EARGF(usage()); break; case 's': srvname = EARGF(usage()); break; case 'p': pflag++; break; default: usage(); }ARGEND xsrv.attach = xattach; xsrv.open = xopen; xsrv.read = xread; xsrv.stat = xstat; xsrv.walk1 = xwalk1; xsrv.destroyfid = xdestroyfid; fmtinstall('R', Rfmt); fmtinstall('P', Pfmt); memimageinit(); defont = getmemdefont(); loadfonts(); qsort(xfont, nxfont, sizeof xfont[0], fontcmp); if(pflag) { if(argc != 1 || chatty9p || chattyfuse) usage(); dump(argv[0]); exits(0); } if(pflag || argc != 0) usage(); /* * Check twice -- if there is an exited instance * mounted there, the first access will fail but unmount it. */ if(mtpt && access(mtpt, AEXIST) < 0 && access(mtpt, AEXIST) < 0) sysfatal("mountpoint %s does not exist", mtpt); xsrv.foreground = 1; threadpostmountsrv(&xsrv, srvname, mtpt, 0); }
bool UploadDump(const char* file, const char* user, int build, int branch, DelegateI<Prog_s&>* progress, const char* szTracer) { if (build == 0) build = 9999; if (branch == 0) branch = BUILDID_PUBLIC; g_Logger.write("---------------------------------------\r\n"); time_t ltime; /* calendar time */ ltime=time(nullptr); /* get current cal time */ #if defined(WIN32) && !defined(__MINGW32__) char buff[255] = {0}; struct tm t; localtime_s(&t, <ime); asctime_s(buff, 255, &t); #else struct tm *t = localtime(<ime); char* buff = asctime(t); #endif g_Logger.write("%s\r\n", buff); g_Logger.write("---------------------------------------\r\n"); g_Logger.write("Uploaded crash dump: [%s]\r\n", file); gcString dump(file); gcString tracer(szTracer); gcString log(dump + ".log"); if (PrepDumpForUpload(dump) == false) { g_Logger.write("Failed to prepare crash dump.\r\n"); return false; } else { g_Logger.write("Prepared crash dump to: [%s]\r\n", dump.c_str()); } if (!tracer.empty()) { try { auto valid = false; UTIL::FS::FileHandle fh; std::function<void(const char*, uint32)> write = [&fh, &valid, log](const char* szData, uint32 nSize) { if (!valid) fh.open(log.c_str(), UTIL::FS::FILE_WRITE); valid = true; fh.write(szData, nSize); }; DumpTracerToFile(tracer, write); if (!valid) log = ""; } catch (...) { log = ""; } if (!log.empty()) PrepDumpForUpload(log); #ifdef WIN32 //Let desura exit now. gcString tracerEventName("Global\\{0}Event", tracer); auto hHandle = OpenEvent(EVENT_MODIFY_STATE, FALSE, tracerEventName.c_str()); if (hHandle) { SetEvent(hHandle); CloseHandle(hHandle); } #endif } std::string os = UTIL::OS::getOSString(); HttpHandle hh(DUMP_UPLOAD_URL); if (progress) hh->getProgressEvent() += progress; hh->setUserAgent(DUMP_UPLOAD_AGENT); hh->cleanUp(); hh->addPostText("os", os.c_str()); hh->addPostText("build", build); hh->addPostText("appid", branch); if (user) hh->addPostText("user", user); hh->addPostFile("crashfile", dump.c_str()); if (!log.empty()) hh->addPostFile("crashlog", log.c_str()); try { hh->postWeb(); } catch (gcException &except) { g_Logger.write("Failed to upload crash: %s [%d.%d].\r\n", except.getErrMsg(), except.getErrId(), except.getSecErrId()); return false; } XML::gcXMLDocument doc(const_cast<char*>(hh->getData()), hh->getDataSize()); try { doc.ProcessStatus("crashupload"); g_Logger.write("Uploaded dump\r\n"); UTIL::FS::delFile(UTIL::FS::Path(dump, "", true)); } catch (gcException &) { g_Logger.write("Bad status returned from upload crash dump.\r\n"); gcString res; res.assign(hh->getData(), hh->getDataSize()); g_Logger.write("Result: \r\n\r\n%s\r\n\r\n", res.c_str()); return false; } return true; }