static void init_user_stack(elf_prog_t *prog, int prot) { long argc = strings_count(prog->argv), envc = strings_count(prog->envp), auxc = auxv_count(prog->auxv); char *tmp_argv[argc+1], *tmp_envp[envc+1], *platform = (char *)get_aux(prog->auxv, AT_PLATFORM), *base_platform = (char *)get_aux(prog->auxv, AT_BASE_PLATFORM), *rand_bytes = (char *)get_aux(prog->auxv, AT_RANDOM); char *sp = (char *)(prog->task_size-get_stack_random_shift(prog->auxv)); sp -= sizeof(long); sp = prog->filename = stack_push_string(sp, prog->filename); char *untrusted_data_end=sp; sp = stack_push_strings(sp, tmp_envp, prog->envp); sp = stack_push_strings(sp, tmp_argv, prog->argv); taint_mem(sp, untrusted_data_end-sp, TAINT_ENV); sp = (char *)(((long)sp-0x100)&~0xf); if (platform) sp = platform = stack_push_string(sp, platform); if (base_platform) sp = base_platform = stack_push_string(sp, base_platform); if (rand_bytes) sp = rand_bytes = stack_push_data(sp, rand_bytes, 16); sp = (char *)((long)sp&~0xf); sp = stack_push_data(sp, prog->auxv, (auxc+1)*2*sizeof(long)); prog->auxv = (long *)sp; sp = stack_push_data(sp, tmp_envp, (envc+1)*sizeof(char *)); prog->envp = (char **)sp; sp = stack_push_data(sp, tmp_argv, (argc+1)*sizeof(char *)); prog->argv = (char **)sp; sp = stack_push_data(sp, &argc, sizeof(long)); set_aux(prog->auxv, AT_EXECFN, (long)prog->filename); set_aux(prog->auxv, AT_PLATFORM, (long)platform); set_aux(prog->auxv, AT_BASE_PLATFORM, (long)base_platform); set_aux(prog->auxv, AT_RANDOM, (long)rand_bytes); set_aux(prog->auxv, AT_PHDR, (long)prog->bin.phdr); set_aux(prog->auxv, AT_PHNUM, prog->bin.hdr.e_phnum); set_aux(prog->auxv, AT_BASE, prog->bin.base); set_aux(prog->auxv, AT_ENTRY, prog->bin.base + prog->bin.hdr.e_entry); prog->sp = (long *)sp; }
static really_inline const union AccelAux *get_accel(const struct sheng *sh, u8 id) { const struct sstate_aux *saux = get_aux(sh, id); DEBUG_PRINTF("Getting accel aux at offset %u\n", saux->accel); const union AccelAux *aux = (const union AccelAux *) ((const char *)sh + saux->accel - sizeof(struct NFA)); return aux; }
char nfaExecSheng0_inAnyAccept(const struct NFA *n, struct mq *q) { assert(n && q); const struct sheng *sh = get_sheng(n); u8 s = *(const u8 *)q->state; DEBUG_PRINTF("checking accepts for %u\n", (u8)(s & SHENG_STATE_MASK)); const struct sstate_aux *aux = get_aux(sh, s); return !!aux->accept; }
// We just parsed "parsed_tag". // If it matches "start_tag", and is followed by a string // and by the matching close tag, return the string in "buf", // and return true. // bool XML_PARSER::parse_str(const wxChar* start_tag, wxChar* buf, int len) { bool eof; wxChar end_tag[256], tag[256]; // handle the archaic form <tag/>, which means empty string // size_t n = _tcslen(parsed_tag); if (parsed_tag[n-1] == wxT('/')) { _tcscpy(tag, parsed_tag); tag[n-1] = 0; if (!_tcscmp(tag, start_tag)) { _tcscpy(buf, wxT("")); return true; } } // check for start tag // if (_tcscmp(parsed_tag, start_tag)) return false; end_tag[0] = '/'; _tcscpy(end_tag+1, start_tag); // get text after start tag // int retval = get_aux(buf, len, 0, 0); if (retval == XML_PARSE_EOF) return false; // if it's the end tag, return empty string // if (retval == XML_PARSE_TAG) { if (_tcscmp(buf, end_tag)) { return false; } else { _tcscpy(buf, wxT("")); return true; } } eof = get(tag, sizeof(tag), is_tag); if (eof) return false; if (!is_tag) return false; if (_tcscmp(tag, end_tag)) return false; if (retval != XML_PARSE_CDATA) { xml_unescape(buf); } return true; }
char nfaExecSheng0_inAccept(const struct NFA *n, ReportID report, struct mq *q) { assert(n && q); const struct sheng *sh = get_sheng(n); u8 s = *(const u8 *)q->state; DEBUG_PRINTF("checking accepts for %u\n", (u8)(s & SHENG_STATE_MASK)); const struct sstate_aux *aux = get_aux(sh, s); if (!aux->accept) { return 0; } return shengHasAccept(sh, aux, report); }
bool XML_PARSER::get( wxChar* buf, int len, bool& _is_tag, wxChar* attr_buf, int attr_len ) { switch (get_aux(buf, len, attr_buf, attr_len)) { case XML_PARSE_EOF: return true; case XML_PARSE_TAG: _is_tag = true; break; case XML_PARSE_DATA: case XML_PARSE_CDATA: default: _is_tag = false; break; } return false; }
char nfaExecSheng0_testEOD(const struct NFA *nfa, const char *state, UNUSED const char *streamState, u64a offset, NfaCallback cb, void *ctxt) { assert(nfa); const struct sheng *sh = get_sheng(nfa); u8 s = *(const u8 *)state; DEBUG_PRINTF("checking EOD accepts for %u\n", (u8)(s & SHENG_STATE_MASK)); const struct sstate_aux *aux = get_aux(sh, s); if (!aux->accept_eod) { return MO_CONTINUE_MATCHING; } return fireReports(sh, cb, ctxt, s, offset, NULL, NULL, 1); }
static really_inline char fireReports(const struct sheng *sh, NfaCallback cb, void *ctxt, const u8 state, u64a loc, u8 *const cached_accept_state, ReportID *const cached_accept_id, char eod) { DEBUG_PRINTF("reporting matches @ %llu\n", loc); if (!eod && state == *cached_accept_state) { DEBUG_PRINTF("reporting %u\n", *cached_accept_id); if (cb(0, loc, *cached_accept_id, ctxt) == MO_HALT_MATCHING) { return MO_HALT_MATCHING; /* termination requested */ } return MO_CONTINUE_MATCHING; /* continue execution */ } const struct sstate_aux *aux = get_aux(sh, state); const struct report_list *rl = eod ? get_eod_rl(sh, aux) : get_rl(sh, aux); assert(ISALIGNED(rl)); DEBUG_PRINTF("report list has %u entries\n", rl->count); u32 count = rl->count; if (!eod && count == 1) { *cached_accept_state = state; *cached_accept_id = rl->report[0]; DEBUG_PRINTF("reporting %u\n", rl->report[0]); if (cb(0, loc, rl->report[0], ctxt) == MO_HALT_MATCHING) { return MO_HALT_MATCHING; /* termination requested */ } return MO_CONTINUE_MATCHING; /* continue execution */ } for (u32 i = 0; i < count; i++) { DEBUG_PRINTF("reporting %u\n", rl->report[i]); if (cb(0, loc, rl->report[i], ctxt) == MO_HALT_MATCHING) { return MO_HALT_MATCHING; /* termination requested */ } } return MO_CONTINUE_MATCHING; /* continue execution */ }
char nfaExecSheng0_reportCurrent(const struct NFA *n, struct mq *q) { const struct sheng *sh = (const struct sheng *)getImplNfa(n); NfaCallback cb = q->cb; void *ctxt = q->context; u8 s = *(u8 *)q->state; const struct sstate_aux *aux = get_aux(sh, s); u64a offset = q_cur_offset(q); u8 cached_state_id = 0; ReportID cached_report_id = 0; assert(q_cur_type(q) == MQE_START); if (aux->accept) { if (sh->flags & SHENG_FLAG_SINGLE_REPORT) { fireSingleReport(cb, ctxt, sh->report, offset); } else { fireReports(sh, cb, ctxt, s, offset, &cached_state_id, &cached_report_id, 1); } } return 0; }
char nfaExecSheng0_B(const struct NFA *n, u64a offset, const u8 *buffer, size_t length, NfaCallback cb, void *context) { DEBUG_PRINTF("smallwrite Sheng\n"); assert(n->type == SHENG_NFA_0); const struct sheng *sh = getImplNfa(n); u8 state = sh->anchored; u8 can_die = sh->flags & SHENG_FLAG_CAN_DIE; u8 has_accel = sh->flags & SHENG_FLAG_HAS_ACCEL; u8 single = sh->flags & SHENG_FLAG_SINGLE_REPORT; u8 cached_accept_state = 0; ReportID cached_accept_id = 0; /* scan and report all matches */ int rv; s64a end = length; const u8 *scanned; rv = runShengCb(sh, cb, context, offset, &cached_accept_state, &cached_accept_id, buffer, buffer, buffer + end, can_die, has_accel, single, &scanned, &state); if (rv == MO_DEAD) { DEBUG_PRINTF("exiting in state %u\n", state & SHENG_STATE_MASK); return MO_DEAD; } DEBUG_PRINTF("%u\n", state & SHENG_STATE_MASK); const struct sstate_aux *aux = get_aux(sh, state); if (aux->accept_eod) { DEBUG_PRINTF("Reporting EOD matches\n"); fireReports(sh, cb, context, state, end + offset, &cached_accept_state, &cached_accept_id, 1); } return state & SHENG_STATE_DEAD ? MO_DEAD : MO_ALIVE; }
static never_inline char runSheng(const struct sheng *sh, struct mq *q, s64a b_end, enum MatchMode mode) { u8 state = *(u8 *)q->state; u8 can_die = sh->flags & SHENG_FLAG_CAN_DIE; u8 has_accel = sh->flags & SHENG_FLAG_HAS_ACCEL; u8 single = sh->flags & SHENG_FLAG_SINGLE_REPORT; u8 cached_accept_state = 0; ReportID cached_accept_id = 0; DEBUG_PRINTF("starting Sheng execution in state %u\n", state & SHENG_STATE_MASK); if (q->report_current) { DEBUG_PRINTF("reporting current pending matches\n"); assert(sh); q->report_current = 0; int rv; if (single) { rv = fireSingleReport(q->cb, q->context, sh->report, q_cur_offset(q)); } else { rv = fireReports(sh, q->cb, q->context, state, q_cur_offset(q), &cached_accept_state, &cached_accept_id, 0); } if (rv == MO_HALT_MATCHING) { DEBUG_PRINTF("exiting in state %u\n", state & SHENG_STATE_MASK); return MO_DEAD; } DEBUG_PRINTF("proceeding with matching\n"); } assert(q_cur_type(q) == MQE_START); s64a start = q_cur_loc(q); DEBUG_PRINTF("offset: %lli, location: %lli, mode: %s\n", q->offset, start, mode == CALLBACK_OUTPUT ? "CALLBACK OUTPUT" : mode == NO_MATCHES ? "NO MATCHES" : mode == STOP_AT_MATCH ? "STOP AT MATCH" : "???"); DEBUG_PRINTF("processing event @ %lli: %s\n", q->offset + q_cur_loc(q), q_cur_type(q) == MQE_START ? "START" : q_cur_type(q) == MQE_TOP ? "TOP" : q_cur_type(q) == MQE_END ? "END" : "???"); const u8* cur_buf; if (start < 0) { DEBUG_PRINTF("negative location, scanning history\n"); DEBUG_PRINTF("min location: %zd\n", -q->hlength); cur_buf = q->history + q->hlength; } else { DEBUG_PRINTF("positive location, scanning buffer\n"); DEBUG_PRINTF("max location: %lli\n", b_end); cur_buf = q->buffer; } /* if we our queue event is past our end */ if (mode != NO_MATCHES && q_cur_loc(q) > b_end) { DEBUG_PRINTF("current location past buffer end\n"); DEBUG_PRINTF("setting q location to %llu\n", b_end); DEBUG_PRINTF("exiting in state %u\n", state & SHENG_STATE_MASK); q->items[q->cur].location = b_end; return MO_ALIVE; } q->cur++; s64a cur_start = start; while (1) { DEBUG_PRINTF("processing event @ %lli: %s\n", q->offset + q_cur_loc(q), q_cur_type(q) == MQE_START ? "START" : q_cur_type(q) == MQE_TOP ? "TOP" : q_cur_type(q) == MQE_END ? "END" : "???"); s64a end = q_cur_loc(q); if (mode != NO_MATCHES) { end = MIN(end, b_end); } assert(end <= (s64a) q->length); s64a cur_end = end; /* we may cross the border between history and current buffer */ if (cur_start < 0) { cur_end = MIN(0, cur_end); } DEBUG_PRINTF("start: %lli end: %lli\n", start, end); /* don't scan zero length buffer */ if (cur_start != cur_end) { const u8 * scanned = cur_buf; char rv; /* if we're in nomatch mode or if we're scanning history buffer */ if (mode == NO_MATCHES || (cur_start < 0 && mode == CALLBACK_OUTPUT)) { runShengNm(sh, q->cb, q->context, q->offset, &cached_accept_state, &cached_accept_id, cur_buf, cur_buf + cur_start, cur_buf + cur_end, can_die, has_accel, single, &scanned, &state); } else if (mode == CALLBACK_OUTPUT) { rv = runShengCb(sh, q->cb, q->context, q->offset, &cached_accept_state, &cached_accept_id, cur_buf, cur_buf + cur_start, cur_buf + cur_end, can_die, has_accel, single, &scanned, &state); if (rv == MO_DEAD) { DEBUG_PRINTF("exiting in state %u\n", state & SHENG_STATE_MASK); return MO_DEAD; } } else if (mode == STOP_AT_MATCH) { rv = runShengSam(sh, q->cb, q->context, q->offset, &cached_accept_state, &cached_accept_id, cur_buf, cur_buf + cur_start, cur_buf + cur_end, can_die, has_accel, single, &scanned, &state); if (rv == MO_DEAD) { DEBUG_PRINTF("exiting in state %u\n", state & SHENG_STATE_MASK); return rv; } else if (rv == MO_MATCHES_PENDING) { assert(q->cur); DEBUG_PRINTF("found a match, setting q location to %zd\n", scanned - cur_buf + 1); q->cur--; q->items[q->cur].type = MQE_START; q->items[q->cur].location = scanned - cur_buf + 1; /* due to exiting early */ *(u8 *)q->state = state; DEBUG_PRINTF("exiting in state %u\n", state & SHENG_STATE_MASK); return rv; } } else { assert(!"invalid scanning mode!"); } assert(scanned == cur_buf + cur_end); cur_start = cur_end; } /* if we our queue event is past our end */ if (mode != NO_MATCHES && q_cur_loc(q) > b_end) { DEBUG_PRINTF("current location past buffer end\n"); DEBUG_PRINTF("setting q location to %llu\n", b_end); DEBUG_PRINTF("exiting in state %u\n", state & SHENG_STATE_MASK); q->cur--; q->items[q->cur].type = MQE_START; q->items[q->cur].location = b_end; *(u8 *)q->state = state; return MO_ALIVE; } /* crossing over into actual buffer */ if (cur_start == 0) { DEBUG_PRINTF("positive location, scanning buffer\n"); DEBUG_PRINTF("max offset: %lli\n", b_end); cur_buf = q->buffer; } /* continue scanning the same buffer */ if (end != cur_end) { continue; } switch (q_cur_type(q)) { case MQE_END: *(u8 *)q->state = state; q->cur++; DEBUG_PRINTF("exiting in state %u\n", state & SHENG_STATE_MASK); if (can_die) { return (state & SHENG_STATE_DEAD) ? MO_DEAD : MO_ALIVE; } return MO_ALIVE; case MQE_TOP: if (q->offset + cur_start == 0) { DEBUG_PRINTF("Anchored start, going to state %u\n", sh->anchored); state = sh->anchored; } else { u8 new_state = get_aux(sh, state)->top; DEBUG_PRINTF("Top event %u->%u\n", state & SHENG_STATE_MASK, new_state & SHENG_STATE_MASK); state = new_state; } break; default: assert(!"invalid queue event"); break; } q->cur++; } }
/* relocate the stack */ static long get_stack_random_shift(long *auxv) { return 0x1000000 - (PAGE_NEXT((long)get_aux(auxv, AT_EXECFN)) & 0xfff000); }
void DogStateCart3::ReportAfterStep() const { // map onto deprecated global method ::ConSoln(get_aux(),get_q(),get_time()); }
void AppStateCart2::ReportAfterStep()const { const dTensorBC4& aux = get_aux(); const dTensorBC4& q = get_q(); const double t = get_time(); assert(dogParams.get_mcapa()<1); // without capacity function void WriteConservation(const dTensorBC4& q, double t); WriteConservation(q, t); double OutputMagneticFluxes( int n_B1, int n_B2, const dTensorBC4& q, double t); const double bottom_to_rght_flux = OutputMagneticFluxes(_B1, _B2, q, t); void Output_center_E3(const dTensorBC4& q, double t, int _E3); Output_center_E3(q, t, _E3); void Output_center_gas_states( const dTensorBC4& q, double t, const char* outputfile, int species_offset, bool fiveMoment); const char* get_outputdir(); string outputfile_i = string(get_outputdir())+"/xpoint_gas_i.dat"; string outputfile_e = string(get_outputdir())+"/xpoint_gas_e.dat"; Output_center_gas_states(q, t, outputfile_i.c_str(), _rho_i-1,false); Output_center_gas_states(q, t, outputfile_e.c_str(), _rho_e-1,true); void Output_center_cell_state(const dTensorBC4& q, double t); Output_center_cell_state(q, t); // output the rate of production of entropy at the center // const int maux = aux.getsize(3); if(maux>0) { assert_eq(maux,2); void output_component_at_center( const dTensorBC4& q, double t, const char* outputfile, int idx); outputfile_i = string(get_outputdir())+"/xpoint_ent_prod_i.dat"; outputfile_e = string(get_outputdir())+"/xpoint_ent_prod_e.dat"; output_component_at_center(aux, t, outputfile_i.c_str(),1); output_component_at_center(aux, t, outputfile_e.c_str(),2); } void output_local_divergence_error( int method_order, double dx, double dy, int n_B1, int n_B2, const dTensorBC4& q, double t); const double dx = dogParamsCart2.get_dx(); const double dy = dogParamsCart2.get_dy(); output_local_divergence_error( dogParams.get_space_order(), dx, dy, _B1, _B2, q, t); static bool unit_flux_triggered = bottom_to_rght_flux >=1; if(!unit_flux_triggered && bottom_to_rght_flux >= 1.) { unit_flux_triggered = true; dprintf("writing restart file q8000.dat at time %f;" "\n\tbottom_to_rght_flux = %f", t, bottom_to_rght_flux); get_solver().write_restart(8000); } }