static std::error_code loadTrigger(ExecState& exec, const JSObject& ruleObject, Trigger& trigger) { VM& vm = exec.vm(); auto scope = DECLARE_THROW_SCOPE(vm); const JSValue triggerObject = ruleObject.get(&exec, Identifier::fromString(&exec, "trigger")); if (!triggerObject || scope.exception() || !triggerObject.isObject()) return ContentExtensionError::JSONInvalidTrigger; const JSValue urlFilterObject = triggerObject.get(&exec, Identifier::fromString(&exec, "url-filter")); if (!urlFilterObject || scope.exception() || !urlFilterObject.isString()) return ContentExtensionError::JSONInvalidURLFilterInTrigger; String urlFilter = urlFilterObject.toWTFString(&exec); if (urlFilter.isEmpty()) return ContentExtensionError::JSONInvalidURLFilterInTrigger; trigger.urlFilter = urlFilter; const JSValue urlFilterCaseValue = triggerObject.get(&exec, Identifier::fromString(&exec, "url-filter-is-case-sensitive")); if (urlFilterCaseValue && !scope.exception() && urlFilterCaseValue.isBoolean()) trigger.urlFilterIsCaseSensitive = urlFilterCaseValue.toBoolean(&exec); const JSValue resourceTypeValue = triggerObject.get(&exec, Identifier::fromString(&exec, "resource-type")); if (!scope.exception() && resourceTypeValue.isObject()) { auto typeFlagsError = getTypeFlags(exec, resourceTypeValue, trigger.flags, readResourceType); if (typeFlagsError) return typeFlagsError; } else if (!resourceTypeValue.isUndefined()) return ContentExtensionError::JSONInvalidTriggerFlagsArray; const JSValue loadTypeValue = triggerObject.get(&exec, Identifier::fromString(&exec, "load-type")); if (!scope.exception() && loadTypeValue.isObject()) { auto typeFlagsError = getTypeFlags(exec, loadTypeValue, trigger.flags, readLoadType); if (typeFlagsError) return typeFlagsError; } else if (!loadTypeValue.isUndefined()) return ContentExtensionError::JSONInvalidTriggerFlagsArray; const JSValue ifDomain = triggerObject.get(&exec, Identifier::fromString(&exec, "if-domain")); if (!scope.exception() && ifDomain.isObject()) { auto ifDomainError = getDomainList(exec, asObject(ifDomain), trigger.domains); if (ifDomainError) return ifDomainError; if (trigger.domains.isEmpty()) return ContentExtensionError::JSONInvalidDomainList; ASSERT(trigger.domainCondition == Trigger::DomainCondition::None); trigger.domainCondition = Trigger::DomainCondition::IfDomain; } else if (!ifDomain.isUndefined()) return ContentExtensionError::JSONInvalidDomainList; const JSValue unlessDomain = triggerObject.get(&exec, Identifier::fromString(&exec, "unless-domain")); if (!scope.exception() && unlessDomain.isObject()) { if (trigger.domainCondition != Trigger::DomainCondition::None) return ContentExtensionError::JSONUnlessAndIfDomain; auto unlessDomainError = getDomainList(exec, asObject(unlessDomain), trigger.domains); if (unlessDomainError) return unlessDomainError; if (trigger.domains.isEmpty()) return ContentExtensionError::JSONInvalidDomainList; trigger.domainCondition = Trigger::DomainCondition::UnlessDomain; } else if (!unlessDomain.isUndefined()) return ContentExtensionError::JSONInvalidDomainList; return { }; }
void exception::throwOnError ( FudgeStatus status ) { if ( status != FUDGE_OK ) throw exception ( status ); }
BX_CPU_C::call_protected(bxInstruction_c *i, Bit16u cs_raw, bx_address disp) { bx_selector_t cs_selector; Bit32u dword1, dword2; bx_descriptor_t cs_descriptor; /* new cs selector must not be null, else #GP(0) */ if ((cs_raw & 0xfffc) == 0) { BX_ERROR(("call_protected: CS selector null")); exception(BX_GP_EXCEPTION, 0); } parse_selector(cs_raw, &cs_selector); // check new CS selector index within its descriptor limits, // else #GP(new CS selector) fetch_raw_descriptor(&cs_selector, &dword1, &dword2, BX_GP_EXCEPTION); parse_descriptor(dword1, dword2, &cs_descriptor); // examine AR byte of selected descriptor for various legal values if (cs_descriptor.valid==0) { BX_ERROR(("call_protected: invalid CS descriptor")); exception(BX_GP_EXCEPTION, cs_raw & 0xfffc); } if (cs_descriptor.segment) // normal segment { check_cs(&cs_descriptor, cs_raw, BX_SELECTOR_RPL(cs_raw), CPL); #if BX_SUPPORT_X86_64 if (long_mode() && cs_descriptor.u.segment.l) { Bit64u temp_rsp = RSP; // moving to long mode, push return address onto 64-bit stack if (i->os64L()) { write_new_stack_qword_64(temp_rsp - 8, cs_descriptor.dpl, BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value); write_new_stack_qword_64(temp_rsp - 16, cs_descriptor.dpl, RIP); temp_rsp -= 16; } else if (i->os32L()) { write_new_stack_dword_64(temp_rsp - 4, cs_descriptor.dpl, BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value); write_new_stack_dword_64(temp_rsp - 8, cs_descriptor.dpl, EIP); temp_rsp -= 8; } else { write_new_stack_word_64(temp_rsp - 2, cs_descriptor.dpl, BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value); write_new_stack_word_64(temp_rsp - 4, cs_descriptor.dpl, IP); temp_rsp -= 4; } // load code segment descriptor into CS cache // load CS with new code segment selector // set RPL of CS to CPL branch_far64(&cs_selector, &cs_descriptor, disp, CPL); RSP = temp_rsp; } else #endif { Bit32u temp_RSP; // moving to legacy mode, push return address onto 32-bit stack if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) temp_RSP = ESP; else temp_RSP = SP; #if BX_SUPPORT_X86_64 if (i->os64L()) { write_new_stack_qword_32(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS], temp_RSP - 8, cs_descriptor.dpl, BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value); write_new_stack_qword_32(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS], temp_RSP - 16, cs_descriptor.dpl, RIP); temp_RSP -= 16; } else #endif if (i->os32L()) { write_new_stack_dword_32(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS], temp_RSP - 4, cs_descriptor.dpl, BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value); write_new_stack_dword_32(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS], temp_RSP - 8, cs_descriptor.dpl, EIP); temp_RSP -= 8; } else { write_new_stack_word_32(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS], temp_RSP - 2, cs_descriptor.dpl, BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value); write_new_stack_word_32(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS], temp_RSP - 4, cs_descriptor.dpl, IP); temp_RSP -= 4; } // load code segment descriptor into CS cache // load CS with new code segment selector // set RPL of CS to CPL branch_far64(&cs_selector, &cs_descriptor, disp, CPL); if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) ESP = (Bit32u) temp_RSP; else SP = (Bit16u) temp_RSP; } return; } else { // gate & special segment bx_descriptor_t gate_descriptor = cs_descriptor; bx_selector_t gate_selector = cs_selector; // descriptor DPL must be >= CPL else #GP(gate selector) if (gate_descriptor.dpl < CPL) { BX_ERROR(("call_protected: descriptor.dpl < CPL")); exception(BX_GP_EXCEPTION, cs_raw & 0xfffc); } // descriptor DPL must be >= gate selector RPL else #GP(gate selector) if (gate_descriptor.dpl < gate_selector.rpl) { BX_ERROR(("call_protected: descriptor.dpl < selector.rpl")); exception(BX_GP_EXCEPTION, cs_raw & 0xfffc); } #if BX_SUPPORT_X86_64 if (long_mode()) { // call gate type is higher priority than non-present bit check if (gate_descriptor.type != BX_386_CALL_GATE) { BX_ERROR(("call_protected: gate type %u unsupported in long mode", (unsigned) gate_descriptor.type)); exception(BX_GP_EXCEPTION, cs_raw & 0xfffc); } // gate descriptor must be present else #NP(gate selector) if (! IS_PRESENT(gate_descriptor)) { BX_ERROR(("call_protected: call gate not present")); exception(BX_NP_EXCEPTION, cs_raw & 0xfffc); } call_gate64(&gate_selector); return; } #endif switch (gate_descriptor.type) { case BX_SYS_SEGMENT_AVAIL_286_TSS: case BX_SYS_SEGMENT_AVAIL_386_TSS: if (gate_descriptor.type==BX_SYS_SEGMENT_AVAIL_286_TSS) BX_DEBUG(("call_protected: 16bit available TSS")); else BX_DEBUG(("call_protected: 32bit available TSS")); if (gate_descriptor.valid==0 || gate_selector.ti) { BX_ERROR(("call_protected: call bad TSS selector !")); exception(BX_GP_EXCEPTION, cs_raw & 0xfffc); } // TSS must be present, else #NP(TSS selector) if (! IS_PRESENT(gate_descriptor)) { BX_ERROR(("call_protected: call not present TSS !")); exception(BX_NP_EXCEPTION, cs_raw & 0xfffc); } // SWITCH_TASKS _without_ nesting to TSS task_switch(i, &gate_selector, &gate_descriptor, BX_TASK_FROM_CALL, dword1, dword2); // EIP must be in code seg limit, else #GP(0) if (EIP > BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.limit_scaled) { BX_ERROR(("call_protected: EIP not within CS limits")); exception(BX_GP_EXCEPTION, 0); } return; case BX_TASK_GATE: task_gate(i, &gate_selector, &gate_descriptor, BX_TASK_FROM_CALL); return; case BX_286_CALL_GATE: case BX_386_CALL_GATE: // gate descriptor must be present else #NP(gate selector) if (! IS_PRESENT(gate_descriptor)) { BX_ERROR(("call_protected: gate not present")); exception(BX_NP_EXCEPTION, cs_raw & 0xfffc); } call_gate(&gate_descriptor); return; default: // can't get here BX_ERROR(("call_protected(): gate.type(%u) unsupported", (unsigned) gate_descriptor.type)); exception(BX_GP_EXCEPTION, cs_raw & 0xfffc); } } }
//Tool radius compensation right void GCodeInterpreter::G42(GCodeLine& line) { if(workingPlane != XY) throw exception("Volání funkce G42 pøi neaktivní pracovní rovinì XY"); offset.SetToolComp(line.GetParam('D')); }
void module::operator = ( const module & ) { throw exception("openmpt::module is non-copyable"); }
BX_CPU_C::read_virtual_checks(bx_segment_reg_t *seg, bx_address offset, unsigned length) { Bit32u upper_limit; #if BX_SUPPORT_X86_64 if (BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64) { // do canonical checks if (!IsCanonical(offset)) { BX_ERROR(("read_virtual_checks(): canonical Failure 0x%08x:%08x", GET32H(offset), GET32L(offset))); exception(int_number(seg), 0, 0); } seg->cache.valid |= SegAccessROK; return; } #endif if (protected_mode()) { if (seg->cache.valid==0) { BX_DEBUG(("read_virtual_checks(): segment descriptor not valid")); exception(int_number(seg), 0, 0); } if (seg->cache.p == 0) { /* not present */ BX_ERROR(("read_virtual_checks(): segment not present")); exception(int_number(seg), 0, 0); } switch (seg->cache.type) { case 0: case 1: /* read only */ case 2: case 3: /* read/write */ case 10: case 11: /* execute/read */ case 14: case 15: /* execute/read-only, conforming */ if (offset > (seg->cache.u.segment.limit_scaled - length + 1) || (length-1 > seg->cache.u.segment.limit_scaled)) { BX_ERROR(("read_virtual_checks(): read beyond limit")); exception(int_number(seg), 0, 0); } if (seg->cache.u.segment.limit_scaled >= 7) { // Mark cache as being OK type for succeeding reads. See notes for // write checks; similar code. seg->cache.valid |= SegAccessROK; } break; case 4: case 5: /* read only, expand down */ case 6: case 7: /* read/write, expand down */ if (seg->cache.u.segment.d_b) upper_limit = 0xffffffff; else upper_limit = 0x0000ffff; if ((offset <= seg->cache.u.segment.limit_scaled) || (offset > upper_limit) || ((upper_limit - offset) < (length - 1))) { BX_ERROR(("read_virtual_checks(): read beyond limit")); exception(int_number(seg), 0, 0); } break; case 8: case 9: /* execute only */ case 12: case 13: /* execute only, conforming */ /* can't read or write an execute-only segment */ BX_ERROR(("read_virtual_checks(): execute only")); exception(int_number(seg), 0, 0); } return; } else { /* real mode */ if (offset > (seg->cache.u.segment.limit_scaled - length + 1) || (length-1 > seg->cache.u.segment.limit_scaled)) { BX_DEBUG(("read_virtual_checks(): read beyond limit (real mode)")); exception(int_number(seg), 0, 0); } if (seg->cache.u.segment.limit_scaled >= 7) { // Mark cache as being OK type for succeeding reads. See notes for // write checks; similar code. seg->cache.valid |= SegAccessROK; } } }
void Response::GenerateResponse( SSL* inSSL, bool isGET, bool isProtocolVersion_1_1, bool isWebSocket, bool isWebSocketVersion_13, string& inFileName, string& inFileType, string& inWebSocketKey) { if(!isWebSocket) { string HTTPResponse; if(isGET && isProtocolVersion_1_1) HTTPResponse = "HTTP/1.1 200 OK\n"; else throw exception("Error: Unknow type of request or protocol version"); HTTPResponse += "Server: VaV/V2\n"; switch(getFileType(inFileType, inFileName)) { case fHtmlType: { HTTPResponse += "Content-Type: text/html;\n"; HTTPResponse += "Connection: keep-alive\n"; HTTPResponse += "X-Powered-By: c++\r\n\r\n"; }break; case fCssType: { HTTPResponse += "Content-Type: text/css;\r\n\r\n"; }break; case fJSType: { HTTPResponse += "Content-Type: application/javascript;\r\n\r\n"; }break; case fImageType: { HTTPResponse += "Content-Type: image/png;\r\n\r\n"; }break; case fErrorType: default: { throw exception("Error: Unknow type of file"); }break; } if(inFileName == "" && inFileType == "") HTTPResponse += CD.get_file_from_db("index.html"); else HTTPResponse += CD.get_file_from_db(inFileName + "." + inFileType); MyCover mySend; mySend.my_send(inSSL, HTTPResponse, true); } else { if(isWebSocketVersion_13) { SR.websocket_handshake(inSSL, inWebSocketKey); MyCover myCleanUp; myCleanUp.my_Cleanup_OpenSSL(inSSL); } else { throw exception("Error: Unknow WebSocket version"); } } }
/** * This emits the error signal and resets the error state * of the python interpreter. */ void PythonScript::emit_error() { // gil is necessary so other things don't continue ScopedPythonGIL lock; // return early if nothing happened if (!PyErr_Occurred()) { emit finished(MSG_FINISHED); return; } // get the error information out PyObject *exception(nullptr), *value(nullptr), *traceback(nullptr); PyErr_Fetch(&exception, &value, &traceback); // special check for system exceptions if (bool(exception) && PyErr_GivenExceptionMatches(exception, PyExc_SystemExit) && PyObject_HasAttrString(exception, "code")) { // value is the return code handed to sys.exit long code = 0; if (bool(value) && INT_CHECK(value)) { code = TO_LONG(value); } // if we are returning 0 then cleanup and return if (code == 0) { // maybe shouldn't clear the error, but for now this // is the agreed upon behavior PyErr_Clear(); Py_XDECREF(traceback); Py_XDECREF(exception); Py_XDECREF(value); emit finished(MSG_FINISHED); return; } } // prework on the exception handling PyErr_NormalizeException(&exception, &value, &traceback); PyErr_Clear(); // convert the traceback into something useful int lineNumber = 0; QString filename; if (traceback) { PyTracebackObject *tb = (PyTracebackObject *)traceback; lineNumber = tb->tb_lineno; filename = TO_CSTRING(tb->tb_frame->f_code->co_filename); } // the error message is the full (formated) traceback PyObject *str_repr = PyObject_Str(value); QString message; QTextStream msgStream(&message); if (value && str_repr) { if (exception == PyExc_SyntaxError) { msgStream << constructSyntaxErrorStr(value); } else { QString excTypeName( value->ob_type ->tp_name); // This is fully qualified with the module name excTypeName = excTypeName.section(".", -1); msgStream << excTypeName << ": " << TO_CSTRING(str_repr); } } else { msgStream << "Unknown exception has occurred."; } tracebackToMsg(msgStream, (PyTracebackObject *)(traceback)); msgStream << "\n"; Py_XDECREF(traceback); Py_XDECREF(exception); Py_XDECREF(value); emit error(msgStream.readAll(), filename, lineNumber); }
static Result abort() { boost::unit_test::framework::test_unit_aborted( boost::unit_test::framework::current_test_case() ); throw boost::enable_current_exception( exception() ); }
void Scopa::startRound() { if(!hand[PLAYER_ZERO].empty() || !hand[PLAYER_ONE].empty()) { throw exception(exception::HANDS_ARE_NOT_EMPTY); } dealHand(PLAYER_ZERO); dealHand(PLAYER_ONE); }
range_t Bridge:: find_zeta_range(const double alpha, range_t &tr) { bool isFlat = false; const double zeta0 = CriticalZetaOfAlpha(alpha); range_t zr; double &zeta_min = zr.vmin; double &zeta_max = zr.vmax; double &theta_min = tr.vmin; double &theta_max = tr.vmax; const double theta0 = find_theta(alpha, zeta0, isFlat); theta_min = theta_max = theta0; if( theta0 <= 0 ) { throw exception("No theta for critical zeta"); } zeta_min = zeta_max = zeta0; const double ztol = (numeric<double>::sqrt_ftol); { double zeta_top = zeta0; double zeta_bot = -2; // bad while( Fabs(zeta_top-zeta_bot) > ztol ) { const double zeta_mid = 0.5*(zeta_top+zeta_bot); const double theta_mid = find_theta(alpha,zeta_mid,isFlat); if(theta_mid<=0) { // invalid zeta_bot = zeta_mid; } else { // good zeta_top = zeta_mid; theta_max = theta_mid; } } zeta_min = zeta_top; } // std::cerr << "zeta_min = " << zeta_min << std::endl; //std::cerr << "theta_max = " << theta_max << " => " << Rad2Deg(theta_max) << std::endl; { double zeta_bot = zeta0; // good double zeta_top = 0; // is it bad ? while( find_theta(alpha, zeta_top,isFlat) > 0 ) { zeta_top += 1; } while( Fabs(zeta_top-zeta_bot) > ztol ) { const double zeta_mid = 0.5*(zeta_top+zeta_bot); const double theta_mid = find_theta(alpha,zeta_mid,isFlat); if(theta_mid<=0) { // invalid zeta_top = zeta_mid; } else { // good zeta_bot = zeta_mid; theta_min = theta_mid; } } zeta_max = zeta_bot; } //std::cerr << "zeta_max = " << zeta_max << std::endl; //std::cerr << "theta_min = " << theta_min<< " => " << Rad2Deg(theta_min) << std::endl; return zr; }
void Scopa::dealTable() { if(deck.size() < 4) { throw exception(exception::DECK_HAS_TOO_FEW_CARDS); } deal(deck,table,4); }
void Scopa::dealHand(Who player) { if(deck.size() < 3) { throw exception(exception::DECK_HAS_TOO_FEW_CARDS); } deal(deck,hand[player],3); }
TEST(BaseExceptionTest, OutputWithParameter) { std::string message = "ERROR message (30)"; TestBaseException exception("30"); EXPECT_EQ(message, exception.what()); }
Signal::Interval requiredInterval( const Signal::Interval& I, Signal::Interval* ) const override { BOOST_THROW_EXCEPTION(exception() << Backtrace::make ()); }
bool button::acceptEvent( window_event& e ) { scoped_lock< mutex > slock_b( element_mutex ); switch( e.type ) { case STROKE: // TODO: Consider using a series of if statements here, as in // the very unlikely case that the event.stroke's position and // prev_pos are the same & both outside the button (window:: // acceptEvent() should prevent this) as the button state will bug // out. if( ( state == OFF_DOWN || state == ON_DOWN ) && e.stroke.dev_id != captured_dev ) // Ignore but accept other devices wile capturing another { return true; } switch( state ) { case OFF_UP: if( ( e.stroke.click & CLICK_PRIMARY ) && pointInsideRect( e.stroke.position[ 0 ] - e.offset[ 0 ], e.stroke.position[ 1 ] - e.offset[ 1 ], position[ 0 ], position[ 1 ], dimensions[ 0 ], dimensions[ 1 ] ) ) { state = OFF_DOWN; parent.associateDevice( e.stroke.dev_id, this, e.offset[ 0 ], e.offset[ 1 ] ); captured_dev = e.stroke.dev_id; parent.requestRedraw(); } break; case OFF_DOWN: if( pointInsideRect( e.stroke.position[ 0 ] - e.offset[ 0 ], e.stroke.position[ 1 ] - e.offset[ 1 ], position[ 0 ], position[ 1 ], dimensions[ 0 ], dimensions[ 1 ] ) ) { if( !( e.stroke.click & CLICK_PRIMARY ) ) { state = ON_UP; parent.deassociateDevice( e.stroke.dev_id ); parent.requestRedraw(); } } else // Works because we still get strokes that have just gone out of the mask { state = OFF_UP; // Cancel the button press parent.deassociateDevice( e.stroke.dev_id ); parent.requestRedraw(); } break; case ON_UP: if( ( e.stroke.click & CLICK_PRIMARY ) && pointInsideRect( e.stroke.position[ 0 ] - e.offset[ 0 ], e.stroke.position[ 1 ] - e.offset[ 1 ], position[ 0 ], position[ 1 ], dimensions[ 0 ], dimensions[ 1 ] ) ) { state = ON_DOWN; parent.associateDevice( e.stroke.dev_id, this, e.offset[ 0 ], e.offset[ 1 ] ); captured_dev = e.stroke.dev_id; parent.requestRedraw(); } break; case ON_DOWN: if( pointInsideRect( e.stroke.position[ 0 ] - e.offset[ 0 ], e.stroke.position[ 1 ] - e.offset[ 1 ], position[ 0 ], position[ 1 ], dimensions[ 0 ], dimensions[ 1 ] ) ) { if( !( e.stroke.click & CLICK_PRIMARY ) ) { state = OFF_UP; parent.deassociateDevice( e.stroke.dev_id ); parent.requestRedraw(); } } else { state = ON_UP; parent.deassociateDevice( e.stroke.dev_id ); parent.requestRedraw(); } break; default: throw exception( "button::acceptEvent(): Unknown button state" ); } return true; default: return false; } }
int main( int argc, char *argv[] ) { const char *progname = vfs::get_base_name(argv[0]); try { if(argc<=1) throw exception("usage: %s config.lua", progname); Lua::State VM; lua_State *L = VM(); Lua::Config::DoFile(L, argv[1]); const size_t Nx = size_t(Lua::Config::Get<lua_Number>(L, "Nx")); const size_t Ny = size_t(Lua::Config::Get<lua_Number>(L, "Ny")); const Real dt = Real( Lua::Config::Get<lua_Number>(L,"dt")); _rand.wseed(); //---------------------------------------------------------------------- //info for VisIt //---------------------------------------------------------------------- const string sim_name = "Sludge.v3"; const string sim_comment = "Simple Laponite Using Dissolved Gas"; const string sim_path = "."; //---------------------------------------------------------------------- // initialize MPI //---------------------------------------------------------------------- YOCTO_MPI; const string trace_name = "trace.dat"; VisIt:: TraceFile trace_file(MPI.CommWorldRank,trace_name ); //---------------------------------------------------------------------- // parallel VisIt //---------------------------------------------------------------------- VisIt:: SetupParallel( MPI, sim_name, sim_comment, sim_path, NULL); //---------------------------------------------------------------------- // Setup simulation //---------------------------------------------------------------------- Simulation sim(MPI, Coord(Nx,Ny), Vertex(10,10) ); __Grid::SaveDat( sim.mesh, "grid" + MPI.CommWorldID + ".dat"); sim.init_one_bubble("cc"); sim.bubbles.gamma = 0.0; sim.dt = dt; //---------------------------------------------------------------------- // Main Loop //---------------------------------------------------------------------- sim.initialize(); VisIt:: MainLoop(sim); return 0; } catch( const exception &e ) { std::cerr << e.what() << std::endl; std::cerr << e.when() << std::endl; } catch(...) { std::cerr << "Unhandled Exception" << std::endl; } return 1; }
void button::draw() { scoped_lock< mutex > slock_e( element_mutex ); scoped_lock< mutex > slock_r( button_rsrc_mutex ); state_set* top_set; state_set* center_set; state_set* bottom_set; switch( state ) { case OFF_UP: top_set = &button_set.rounded_set.off_up; center_set = &button_set.rounded_set.off_up; bottom_set = &button_set.rounded_set.off_up; break; case OFF_DOWN: top_set = &button_set.rounded_set.off_down; center_set = &button_set.rounded_set.off_down; bottom_set = &button_set.rounded_set.off_down; break; case ON_UP: top_set = &button_set.rounded_set.on_up; center_set = &button_set.rounded_set.on_up; bottom_set = &button_set.rounded_set.on_up; break; case ON_DOWN: top_set = &button_set.rounded_set.on_down; center_set = &button_set.rounded_set.on_down; bottom_set = &button_set.rounded_set.on_down; break; default: throw exception( "button::draw(): Unknown state" ); } glTranslatef( position[ 0 ], position[ 1 ], 0.0f ); { glPushMatrix(); // Draw vertical centers { glTranslatef( BUTTON_MIN_WIDTH / 2.0f, 0.0f, 0.0f ); glScalef( dimensions[ 0 ] - BUTTON_MIN_WIDTH, 1.0f, 1.0f ); top_set -> top_center -> draw(); glTranslatef( 0.0f, dimensions[ 1 ] - BUTTON_MIN_HEIGHT / 2.0f, 0.0f ); bottom_set -> bottom_center -> draw(); } glPopMatrix(); glPushMatrix(); // Draw horizontal centers { glTranslatef( 0.0f, BUTTON_MIN_HEIGHT / 2.0f, 0.0f ); glScalef( 1.0f, dimensions[ 1 ] - BUTTON_MIN_HEIGHT, 1.0f ); center_set -> center_left -> draw(); glTranslatef( dimensions[ 0 ] - BUTTON_MIN_WIDTH / 2.0f, 0.0f, 0.0f ); center_set -> center_right -> draw(); } glPopMatrix(); glPushMatrix(); // Center { glTranslatef( BUTTON_MIN_WIDTH / 2.0f, BUTTON_MIN_HEIGHT / 2.0f, 0.0f ); glScalef( dimensions[ 0 ] - BUTTON_MIN_WIDTH, dimensions[ 1 ] - BUTTON_MIN_HEIGHT, 1.0f ); center_set -> center_center -> draw(); } glPopMatrix(); glPushMatrix(); // Corners { top_set -> top_left -> draw(); glTranslatef( dimensions[ 0 ] - BUTTON_MIN_WIDTH / 2.0f, 0.0f, 0.0f ); top_set -> top_right -> draw(); glTranslatef( 0.0f, dimensions[ 1 ] - BUTTON_MIN_HEIGHT / 2.0f, 0.0f ); bottom_set -> bottom_right -> draw(); glTranslatef( ( dimensions[ 0 ] - BUTTON_MIN_WIDTH / 2.0f ) * -1.0f, 0.0f, 0.0f ); bottom_set -> bottom_left -> draw(); } glPopMatrix(); } glTranslatef( position[ 0 ] * -1.0f, position[ 1 ] * -1.0f, 0.0f ); if( contents != NULL ) { glPushMatrix(); { switch( contents_align ) { case TOP_LEFT: case CENTER_LEFT: case BOTTOM_LEFT: glTranslatef( position[ 0 ], 0.0f, 0.0f ); break; case TOP_CENTER: case CENTER_CENTER: case BOTTOM_CENTER: glTranslatef( position[ 0 ] + floor( ( dimensions[ 0 ] - contents -> getDimensions().first ) / 2.0f ), 0.0f, 0.0f ); break; case TOP_RIGHT: case CENTER_RIGHT: case BOTTOM_RIGHT: glTranslatef( position[ 0 ] + dimensions[ 0 ] - contents -> getDimensions().first, 0.0f, 0.0f ); break; default: throw exception( "button::draw(): Uknown contents alignment" ); } switch( contents_align ) { case TOP_LEFT: case TOP_CENTER: case TOP_RIGHT: glTranslatef( 0.0f, position[ 1 ], 0.0f ); break; case CENTER_LEFT: case CENTER_CENTER: case CENTER_RIGHT: glTranslatef( 0.0f, position[ 1 ] + floor( ( dimensions[ 1 ] - contents -> getDimensions().second ) / 2.0f ), 0.0f ); break; case BOTTOM_LEFT: case BOTTOM_CENTER: case BOTTOM_RIGHT: glTranslatef( 0.0f, position[ 1 ] + dimensions[ 1 ] - contents -> getDimensions().second, 0.0f ); break; default: throw exception( "button::draw(): Uknown contents alignment" ); } contents -> draw(); } glPopMatrix(); } }
BX_CPU_C::write_virtual_checks(bx_segment_reg_t *seg, bx_address offset, unsigned length) { Bit32u upper_limit; #if BX_SUPPORT_X86_64 if (BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64) { // do canonical checks if (!IsCanonical(offset)) { BX_ERROR(("write_virtual_checks(): canonical Failure 0x%08x:%08x", GET32H(offset), GET32L(offset))); exception(int_number(seg), 0, 0); } seg->cache.valid |= SegAccessWOK; return; } #endif if (protected_mode()) { if (seg->cache.valid==0) { BX_DEBUG(("write_virtual_checks(): segment descriptor not valid")); exception(int_number(seg), 0, 0); } if (seg->cache.p == 0) { /* not present */ BX_ERROR(("write_virtual_checks(): segment not present")); exception(int_number(seg), 0, 0); } switch (seg->cache.type) { case 0: case 1: // read only case 4: case 5: // read only, expand down case 8: case 9: // execute only case 10: case 11: // execute/read case 12: case 13: // execute only, conforming case 14: case 15: // execute/read-only, conforming BX_ERROR(("write_virtual_checks(): no write access to seg")); exception(int_number(seg), 0, 0); case 2: case 3: /* read/write */ if (offset > (seg->cache.u.segment.limit_scaled - length + 1) || (length-1 > seg->cache.u.segment.limit_scaled)) { BX_ERROR(("write_virtual_checks(): write beyond limit, r/w")); exception(int_number(seg), 0, 0); } if (seg->cache.u.segment.limit_scaled >= 7) { // Mark cache as being OK type for succeeding writes. The limit // checks still needs to be done though, but is more simple. We // could probably also optimize that out with a flag for the case // when limit is the maximum 32bit value. Limit should accomodate // at least a dword, since we subtract from it in the simple // limit check in other functions, and we don't want the value to roll. // Only normal segments (not expand down) are handled this way. seg->cache.valid |= SegAccessWOK; } break; case 6: case 7: /* read/write, expand down */ if (seg->cache.u.segment.d_b) upper_limit = 0xffffffff; else upper_limit = 0x0000ffff; if ((offset <= seg->cache.u.segment.limit_scaled) || (offset > upper_limit) || ((upper_limit - offset) < (length - 1))) { BX_ERROR(("write_virtual_checks(): write beyond limit, r/w ED")); exception(int_number(seg), 0, 0); } break; } return; } else { /* real mode */ if (offset > (seg->cache.u.segment.limit_scaled - length + 1) || (length-1 > seg->cache.u.segment.limit_scaled)) { BX_DEBUG(("write_virtual_checks(): write beyond limit (real mode)")); exception(int_number(seg), 0, 0); } if (seg->cache.u.segment.limit_scaled >= 7) { // Mark cache as being OK type for succeeding writes. See notes above. seg->cache.valid |= SegAccessWOK; } } }
JSObject* JSLazyEventListener::initializeJSFunction(ScriptExecutionContext* executionContext) const { ASSERT(is<Document>(executionContext)); if (!executionContext) return nullptr; ASSERT(!m_code.isNull()); ASSERT(!m_eventParameterName.isNull()); if (m_code.isNull() || m_eventParameterName.isNull()) return nullptr; Document& document = downcast<Document>(*executionContext); if (!document.frame()) return nullptr; if (!document.contentSecurityPolicy()->allowInlineEventHandlers(m_sourceURL, m_sourcePosition.m_line)) return nullptr; ScriptController& script = document.frame()->script(); if (!script.canExecuteScripts(AboutToExecuteScript) || script.isPaused()) return nullptr; JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(executionContext, isolatedWorld()); if (!globalObject) return nullptr; VM& vm = globalObject->vm(); JSLockHolder lock(vm); auto scope = DECLARE_CATCH_SCOPE(vm); ExecState* exec = globalObject->globalExec(); MarkedArgumentBuffer args; args.append(jsNontrivialString(exec, m_eventParameterName)); args.append(jsStringWithCache(exec, m_code)); // We want all errors to refer back to the line on which our attribute was // declared, regardless of any newlines in our JavaScript source text. int overrideLineNumber = m_sourcePosition.m_line.oneBasedInt(); JSObject* jsFunction = constructFunctionSkippingEvalEnabledCheck( exec, exec->lexicalGlobalObject(), args, Identifier::fromString(exec, m_functionName), SourceOrigin { m_sourceURL }, m_sourceURL, m_sourcePosition, overrideLineNumber); if (UNLIKELY(scope.exception())) { reportCurrentException(exec); scope.clearException(); return nullptr; } JSFunction* listenerAsFunction = jsCast<JSFunction*>(jsFunction); if (m_originalNode) { if (!wrapper()) { // Ensure that 'node' has a JavaScript wrapper to mark the event listener we're creating. // FIXME: Should pass the global object associated with the node setWrapper(vm, asObject(toJS(exec, globalObject, *m_originalNode))); } // Add the event's home element to the scope // (and the document, and the form - see JSHTMLElement::eventHandlerScope) listenerAsFunction->setScope(vm, jsCast<JSNode*>(wrapper())->pushEventHandlerScope(exec, listenerAsFunction->scope())); } return jsFunction; }
object_t* z_exception(char* e) { return exception(e, CURRENT_OBJECT); }
int player::init(OBJECT *parent) { // check the connection if ( get_connection()!=NULL ) db = (database*)(get_connection()+1); if ( db==NULL ) exception("no database connection available or specified"); if ( !db->isa("database") ) exception("connection is not a mysql database"); gl_verbose("connection to mysql server '%s', schema '%s' ok", db->get_hostname(), db->get_schema()); // check mode if ( strlen(mode)>0 ) { int options = 0xffffffff; struct { char *str; set bits; } modes[] = { {"r", 0x0000}, {"r+", 0x0000}, {"w", 0xffff}, {"w+", 0xffff}, {"a", 0xffff}, {"a+", 0xffff}, }; int n; for ( n=0 ; n<sizeof(modes)/sizeof(modes[0]) ; n++ ) { if ( strcmp(mode,modes[n].str)==0 ) { options = modes[n].bits; break; } } if ( options==0xffffffff ) exception("mode '%s' is not recognized",mode); else if ( options==0xffff ) exception("mode '%s' is not valid for a recorder", mode); } // connect the target property if ( get_parent()==NULL ) exception("parent is not set"); target.set_object(get_parent()); char propname[64]="", propunit[64]=""; switch ( sscanf(get_property(),"%[^[][%[^]]",propname,propunit) ) { case 2: if ( !unit.set_unit(propunit) ) exception("property '%s' has an invalid unit", get_property()); // drop through case 1: strncpy(field,propname,sizeof(field)-1); target.set_property(propname); scale = 1.0; if ( unit.is_valid() && target.get_unit()!=NULL ) { target.get_unit()->convert(unit,scale); sprintf(field,"%s[%s]",propname,propunit); } else if ( propunit[0]=='\0' && options&MO_USEUNITS && target.get_unit() ) sprintf(field,"%s[%s]",propname,target.get_unit()->get_name()); break; default: exception("property '%s' is not valid", get_property()); break; } // check for table existence and create if not found if ( !target.is_valid() ) exception("target property '%s' is not valid", get_property()); if ( !db->table_exists(get_table()) ) exception("table '%s' does not exist", get_table()); // run the main query gld_clock start; data = db->select("SELECT t,`%s` FROM `%s` WHERE t>=from_unixtime(%llu) ORDER BY id",get_property(),get_table(),start.get_localtimestamp()); if ( data==NULL ) return 0; // no data n_rows = mysql_num_rows(data); n_fields = mysql_num_fields(data); row_num = 0; gl_verbose("%s: %d rows with %d fields found", get_name(), n_rows, n_fields); // fetch first row row = mysql_fetch_row(data); row_num++; fields = mysql_fetch_fields(data); // get the time of the next data item (assume in first column) gld_clock next(row[0]); next_t = next.get_timestamp(); gl_verbose("%s: row %d, %s='%s', %s='%s'", get_name(), row_num, fields[0].name, row[0], fields[1].name, row[1]); return 1; }
module::module( const module & ) { throw exception("openmpt::module is non-copyable"); }
void Field::set_missing(const unsigned k) { if (k >= ne) throw exception("Field::set_missing(): out of range"); if (!dat_vec[k].missing) col_struct.count_miss(1); dat_vec[k].missing = 1; }
void check_macro(expr const & m) const { if (!is_macro(m) || macro_num_args(m) != 1) throw exception(sstream() << "invalid '" << m_proj_name << "' projection macro, incorrect number of arguments"); }
void Field::pretend_missing(const unsigned k) { if (k >= ne) throw exception("Field::pretend_missing(): out of range"); dat_vec[k].missing++; col_struct.count_miss(1); }
void BX_CPP_AttrRegparmN(1) BX_CPU_C::call_gate(bx_descriptor_t *gate_descriptor) { bx_selector_t cs_selector; Bit32u dword1, dword2; bx_descriptor_t cs_descriptor; // examine code segment selector in call gate descriptor BX_DEBUG(("call_protected: call gate")); Bit16u dest_selector = gate_descriptor->u.gate.dest_selector; Bit32u new_EIP = gate_descriptor->u.gate.dest_offset; // selector must not be null else #GP(0) if ((dest_selector & 0xfffc) == 0) { BX_ERROR(("call_protected: selector in gate null")); exception(BX_GP_EXCEPTION, 0); } parse_selector(dest_selector, &cs_selector); // selector must be within its descriptor table limits, // else #GP(code segment selector) fetch_raw_descriptor(&cs_selector, &dword1, &dword2, BX_GP_EXCEPTION); parse_descriptor(dword1, dword2, &cs_descriptor); // AR byte of selected descriptor must indicate code segment, // else #GP(code segment selector) // DPL of selected descriptor must be <= CPL, // else #GP(code segment selector) if (cs_descriptor.valid==0 || cs_descriptor.segment==0 || IS_DATA_SEGMENT(cs_descriptor.type) || cs_descriptor.dpl > CPL) { BX_ERROR(("call_protected: selected descriptor is not code")); exception(BX_GP_EXCEPTION, dest_selector & 0xfffc); } // code segment must be present else #NP(selector) if (! IS_PRESENT(cs_descriptor)) { BX_ERROR(("call_protected: code segment not present !")); exception(BX_NP_EXCEPTION, dest_selector & 0xfffc); } // CALL GATE TO MORE PRIVILEGE // if non-conforming code segment and DPL < CPL then if (IS_CODE_SEGMENT_NON_CONFORMING(cs_descriptor.type) && (cs_descriptor.dpl < CPL)) { Bit16u SS_for_cpl_x; Bit32u ESP_for_cpl_x; bx_selector_t ss_selector; bx_descriptor_t ss_descriptor; Bit16u return_SS, return_CS; Bit32u return_ESP, return_EIP; BX_DEBUG(("CALL GATE TO MORE PRIVILEGE LEVEL")); // get new SS selector for new privilege level from TSS get_SS_ESP_from_TSS(cs_descriptor.dpl, &SS_for_cpl_x, &ESP_for_cpl_x); // check selector & descriptor for new SS: // selector must not be null, else #TS(0) if ((SS_for_cpl_x & 0xfffc) == 0) { BX_ERROR(("call_protected: new SS null")); exception(BX_TS_EXCEPTION, 0); } // selector index must be within its descriptor table limits, // else #TS(SS selector) parse_selector(SS_for_cpl_x, &ss_selector); fetch_raw_descriptor(&ss_selector, &dword1, &dword2, BX_TS_EXCEPTION); parse_descriptor(dword1, dword2, &ss_descriptor); // selector's RPL must equal DPL of code segment, // else #TS(SS selector) if (ss_selector.rpl != cs_descriptor.dpl) { BX_ERROR(("call_protected: SS selector.rpl != CS descr.dpl")); exception(BX_TS_EXCEPTION, SS_for_cpl_x & 0xfffc); } // stack segment DPL must equal DPL of code segment, // else #TS(SS selector) if (ss_descriptor.dpl != cs_descriptor.dpl) { BX_ERROR(("call_protected: SS descr.rpl != CS descr.dpl")); exception(BX_TS_EXCEPTION, SS_for_cpl_x & 0xfffc); } // descriptor must indicate writable data segment, // else #TS(SS selector) if (ss_descriptor.valid==0 || ss_descriptor.segment==0 || IS_CODE_SEGMENT(ss_descriptor.type) || !IS_DATA_SEGMENT_WRITEABLE(ss_descriptor.type)) { BX_ERROR(("call_protected: ss descriptor is not writable data seg")); exception(BX_TS_EXCEPTION, SS_for_cpl_x & 0xfffc); } // segment must be present, else #SS(SS selector) if (! IS_PRESENT(ss_descriptor)) { BX_ERROR(("call_protected: ss descriptor not present")); exception(BX_SS_EXCEPTION, SS_for_cpl_x & 0xfffc); } // get word count from call gate, mask to 5 bits unsigned param_count = gate_descriptor->u.gate.param_count & 0x1f; // save return SS:eSP to be pushed on new stack return_SS = BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value; if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) return_ESP = ESP; else return_ESP = SP; // save return CS:eIP to be pushed on new stack return_CS = BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value; if (cs_descriptor.u.segment.d_b) return_EIP = EIP; else return_EIP = IP; // Prepare new stack segment bx_segment_reg_t new_stack; new_stack.selector = ss_selector; new_stack.cache = ss_descriptor; new_stack.selector.rpl = cs_descriptor.dpl; // add cpl to the selector value new_stack.selector.value = (0xfffc & new_stack.selector.value) | new_stack.selector.rpl; /* load new SS:SP value from TSS */ if (ss_descriptor.u.segment.d_b) { Bit32u temp_ESP = ESP_for_cpl_x; // push pointer of old stack onto new stack if (gate_descriptor->type==BX_386_CALL_GATE) { write_new_stack_dword_32(&new_stack, temp_ESP-4, cs_descriptor.dpl, return_SS); write_new_stack_dword_32(&new_stack, temp_ESP-8, cs_descriptor.dpl, return_ESP); temp_ESP -= 8; for (unsigned n=param_count; n>0; n--) { temp_ESP -= 4; Bit32u param = read_virtual_dword_32(BX_SEG_REG_SS, return_ESP + (n-1)*4); write_new_stack_dword_32(&new_stack, temp_ESP, cs_descriptor.dpl, param); } // push return address onto new stack write_new_stack_dword_32(&new_stack, temp_ESP-4, cs_descriptor.dpl, return_CS); write_new_stack_dword_32(&new_stack, temp_ESP-8, cs_descriptor.dpl, return_EIP); temp_ESP -= 8; } else { write_new_stack_word_32(&new_stack, temp_ESP-2, cs_descriptor.dpl, return_SS); write_new_stack_word_32(&new_stack, temp_ESP-4, cs_descriptor.dpl, (Bit16u) return_ESP); temp_ESP -= 4; for (unsigned n=param_count; n>0; n--) { temp_ESP -= 2; Bit16u param = read_virtual_word_32(BX_SEG_REG_SS, return_ESP + (n-1)*2); write_new_stack_word_32(&new_stack, temp_ESP, cs_descriptor.dpl, param); } // push return address onto new stack write_new_stack_word_32(&new_stack, temp_ESP-2, cs_descriptor.dpl, return_CS); write_new_stack_word_32(&new_stack, temp_ESP-4, cs_descriptor.dpl, (Bit16u) return_EIP); temp_ESP -= 4; } ESP = temp_ESP; } else { Bit16u temp_SP = (Bit16u) ESP_for_cpl_x; // push pointer of old stack onto new stack if (gate_descriptor->type==BX_386_CALL_GATE) { write_new_stack_dword_32(&new_stack, (Bit16u)(temp_SP-4), cs_descriptor.dpl, return_SS); write_new_stack_dword_32(&new_stack, (Bit16u)(temp_SP-8), cs_descriptor.dpl, return_ESP); temp_SP -= 8; for (unsigned n=param_count; n>0; n--) { temp_SP -= 4; Bit32u param = read_virtual_dword_32(BX_SEG_REG_SS, return_ESP + (n-1)*4); write_new_stack_dword_32(&new_stack, temp_SP, cs_descriptor.dpl, param); } // push return address onto new stack write_new_stack_dword_32(&new_stack, (Bit16u)(temp_SP-4), cs_descriptor.dpl, return_CS); write_new_stack_dword_32(&new_stack, (Bit16u)(temp_SP-8), cs_descriptor.dpl, return_EIP); temp_SP -= 8; } else { write_new_stack_word_32(&new_stack, (Bit16u)(temp_SP-2), cs_descriptor.dpl, return_SS); write_new_stack_word_32(&new_stack, (Bit16u)(temp_SP-4), cs_descriptor.dpl, (Bit16u) return_ESP); temp_SP -= 4; for (unsigned n=param_count; n>0; n--) { temp_SP -= 2; Bit16u param = read_virtual_word_32(BX_SEG_REG_SS, return_ESP + (n-1)*2); write_new_stack_word_32(&new_stack, temp_SP, cs_descriptor.dpl, param); } // push return address onto new stack write_new_stack_word_32(&new_stack, (Bit16u)(temp_SP-2), cs_descriptor.dpl, return_CS); write_new_stack_word_32(&new_stack, (Bit16u)(temp_SP-4), cs_descriptor.dpl, (Bit16u) return_EIP); temp_SP -= 4; } SP = temp_SP; } // new eIP must be in code segment limit else #GP(0) if (new_EIP > cs_descriptor.u.segment.limit_scaled) { BX_ERROR(("call_protected: EIP not within CS limits")); exception(BX_GP_EXCEPTION, 0); } /* load SS descriptor */ load_ss(&ss_selector, &ss_descriptor, cs_descriptor.dpl); /* load new CS:IP value from gate */ /* load CS descriptor */ /* set CPL to stack segment DPL */ /* set RPL of CS to CPL */ load_cs(&cs_selector, &cs_descriptor, cs_descriptor.dpl); EIP = new_EIP; } else // CALL GATE TO SAME PRIVILEGE { BX_DEBUG(("CALL GATE TO SAME PRIVILEGE")); if (gate_descriptor->type == BX_386_CALL_GATE) { // call gate 32bit, push return address onto stack push_32(BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value); push_32(EIP); } else { // call gate 16bit, push return address onto stack push_16(BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value); push_16(IP); } // load CS:EIP from gate // load code segment descriptor into CS register // set RPL of CS to CPL branch_far32(&cs_selector, &cs_descriptor, new_EIP, CPL); } }
Signal::pBuffer process(Signal::pBuffer b) override { BOOST_THROW_EXCEPTION(exception() << Backtrace::make ()); }
void BX_CPP_AttrRegparmN(1) BX_CPU_C::call_gate64(bx_selector_t *gate_selector) { bx_selector_t cs_selector; Bit32u dword1, dword2, dword3; bx_descriptor_t cs_descriptor; bx_descriptor_t gate_descriptor; // examine code segment selector in call gate descriptor BX_DEBUG(("call_gate64: CALL 64bit call gate")); fetch_raw_descriptor_64(gate_selector, &dword1, &dword2, &dword3, BX_GP_EXCEPTION); parse_descriptor(dword1, dword2, &gate_descriptor); Bit16u dest_selector = gate_descriptor.u.gate.dest_selector; // selector must not be null else #GP(0) if ((dest_selector & 0xfffc) == 0) { BX_ERROR(("call_gate64: selector in gate null")); exception(BX_GP_EXCEPTION, 0); } parse_selector(dest_selector, &cs_selector); // selector must be within its descriptor table limits, // else #GP(code segment selector) fetch_raw_descriptor(&cs_selector, &dword1, &dword2, BX_GP_EXCEPTION); parse_descriptor(dword1, dword2, &cs_descriptor); // find the RIP in the gate_descriptor Bit64u new_RIP = gate_descriptor.u.gate.dest_offset; new_RIP |= ((Bit64u)dword3 << 32); // AR byte of selected descriptor must indicate code segment, // else #GP(code segment selector) // DPL of selected descriptor must be <= CPL, // else #GP(code segment selector) if (cs_descriptor.valid==0 || cs_descriptor.segment==0 || IS_DATA_SEGMENT(cs_descriptor.type) || cs_descriptor.dpl > CPL) { BX_ERROR(("call_gate64: selected descriptor is not code")); exception(BX_GP_EXCEPTION, dest_selector & 0xfffc); } // In long mode, only 64-bit call gates are allowed, and they must point // to 64-bit code segments, else #GP(selector) if (! IS_LONG64_SEGMENT(cs_descriptor) || cs_descriptor.u.segment.d_b) { BX_ERROR(("call_gate64: not 64-bit code segment in call gate 64")); exception(BX_GP_EXCEPTION, dest_selector & 0xfffc); } // code segment must be present else #NP(selector) if (! IS_PRESENT(cs_descriptor)) { BX_ERROR(("call_gate64: code segment not present !")); exception(BX_NP_EXCEPTION, dest_selector & 0xfffc); } Bit64u old_CS = BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value; Bit64u old_RIP = RIP; // CALL GATE TO MORE PRIVILEGE // if non-conforming code segment and DPL < CPL then if (IS_CODE_SEGMENT_NON_CONFORMING(cs_descriptor.type) && (cs_descriptor.dpl < CPL)) { BX_DEBUG(("CALL GATE TO MORE PRIVILEGE LEVEL")); // get new RSP for new privilege level from TSS Bit64u RSP_for_cpl_x = get_RSP_from_TSS(cs_descriptor.dpl); Bit64u old_SS = BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value; Bit64u old_RSP = RSP; // push old stack long pointer onto new stack write_new_stack_qword_64(RSP_for_cpl_x - 8, cs_descriptor.dpl, old_SS); write_new_stack_qword_64(RSP_for_cpl_x - 16, cs_descriptor.dpl, old_RSP); // push long pointer to return address onto new stack write_new_stack_qword_64(RSP_for_cpl_x - 24, cs_descriptor.dpl, old_CS); write_new_stack_qword_64(RSP_for_cpl_x - 32, cs_descriptor.dpl, old_RIP); RSP_for_cpl_x -= 32; // load CS:RIP (guaranteed to be in 64 bit mode) branch_far64(&cs_selector, &cs_descriptor, new_RIP, cs_descriptor.dpl); // set up null SS descriptor load_null_selector(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS], cs_descriptor.dpl); RSP = RSP_for_cpl_x; } else { BX_DEBUG(("CALL GATE TO SAME PRIVILEGE")); // push to 64-bit stack, switch to long64 guaranteed write_new_stack_qword_64(RSP - 8, CPL, old_CS); write_new_stack_qword_64(RSP - 16, CPL, old_RIP); // load CS:RIP (guaranteed to be in 64 bit mode) branch_far64(&cs_selector, &cs_descriptor, new_RIP, CPL); RSP -= 16; } }
Link interpret(Link codeblock_link , Link This, Link Arg){ CallEnv env = callenv_new_root( codeblock_link, This, Arg); LinkStack stack = env->stack; Link b = NULL; Link link = NULL; Link parent = NULL; Link child_key = NULL; Link pusher = NULL; // Anything in this variable gets pushed onto the stack Link trapped = NULL; // This is the last critical caught by the trap operator int delta = 0; // jump delta /* Main interpreter loop */ while(1){ switch( *(env->current++) ){ case INTRO: env->current+=4; break; case ALLOC_MODULE: delta = read_offset(env); env->module->global_vars = linkarray_new(delta); break; case ALLOC_LOCAL: delta = read_offset(env); env->local = linkarray_new(delta); break; case NO_OP: break; case RETURN: // if there is something on the env->stack stack pop it off and return it, if not return null link if ( stack_length(stack) - env->stack_offset ){ pusher = stack_pop(stack); }else{ pusher = object_create(Global->null_type); } goto done; case RAISE: // if there is something on the stack stack pop it off and return it, if not return null link if ( stack_length(stack) - env->stack_offset ){ pusher = create_critical(stack_pop(stack)); }else{ pusher = create_critical(object_create(Global->null_type)); } goto done; case PUSH_LEX: delta = read_offset(env); //fprintf(stderr , "push lex [%i] %p\n", delta,env->function->value.codeblock->lexicals); pusher = link_dup(env->function->value.codeblock->lexicals->vars[delta]); break; case STORE_LEX: delta = read_offset(env); //fprintf(stderr , "storing lex [%i] %p\n", delta,env->function->value.codeblock->lexicals); b = env->function->value.codeblock->lexicals->vars[delta]; if (b){ if ( (b->type == Global->function_type) && (b->value.codeblock->lexicals == env->function->value.codeblock->lexicals) ) b->value.codeblock->lexical_cycles--; link_free(b); } b = link_dup(stack_peek(stack)); if ( (b->type == Global->function_type) && (b->value.codeblock->lexicals == env->function->value.codeblock->lexicals) ) b->value.codeblock->lexical_cycles++; env->function->value.codeblock->lexicals->vars[delta] = b; break; case DEF: if (env->Def) link_free(env->Def); env->Def = stack_pop(env->stack); pusher = link_dup(env->Def); break; case PUSH_DEF: if ( ! env->Def){ pusher = exception("NoDefObject",NULL, NULL); } pusher = link_dup(env->Def); break; case ALLOC_LEXICAL: delta = read_offset(env); lexicals_alloc( env->function, delta); //env->lexical_root = 1; break; case STORE_ARG: delta = read_offset(env); if (env->Arg->value.array->length > delta){ retry_store_arg: env->Arg->value.array->links[delta] = link_dup( stack_peek(stack) ); }else{ array_push(env->Arg, NULL); goto retry_store_arg; } break; case PUSH_ARG: delta = read_offset(env); if (env->Arg->value.array->length > delta){ pusher = link_dup( env->Arg->value.array->links[delta]); }else{ pusher = exception("ArgsIndexOutOfBounds", NULL, NULL); } break; case STORE_GVAR: delta = read_offset(env); if (env->module->global_vars->links[delta]){ link_free(env->module->global_vars->links[delta]); } env->module->global_vars->links[delta] = link_dup( stack_peek(stack) ); break; case STORE_VAR: delta = read_offset(env); if (env->local->links[delta]){ link_free(env->local->links[delta]); } env->local->links[delta] = link_dup( stack_peek(stack) ); break; case STORE_CHILD: link = stack_pop(stack); // value child_key = stack_pop(stack); // key to find the child parent = stack_pop(stack); // parent to look in pusher = object_addChild(parent, link, child_key); goto STORE_COMMON; case STORE_ATTR: link = stack_pop(stack); // value child_key = stack_pop(stack); // key to find the child parent = stack_pop(stack); // parent to look in pusher = addAttr(parent, link,child_key); goto STORE_COMMON; STORE_COMMON: if (! pusher){ pusher = exception("AssignError", NULL, NULL); link_free(link); } link_free(child_key); link_free(parent); break; case LT: delta = compare(env); pusher = create_numberi( (delta < 0) ? 1 : 0 ); break; case GT: delta = compare(env); pusher = create_numberi( (delta > 0) ? 1 : 0 ); break; case EQ: delta = compare(env); pusher = create_numberi( (delta == 0) ? 1 : 0 ); break; case NE: delta = compare(env); pusher = create_numberi( (delta == 0) ? 0 : 1 ); break; case LE: delta = compare(env); pusher = create_numberi( (delta <= 0) ? 1 : 0 ); break; case GE: delta = compare(env); pusher = create_numberi( (delta >= 0) ? 1 : 0 ); break; case CMP: delta = compare(env); pusher = create_numberi( delta ); break; case OR: case AND: break; case SUB: b = stack_pop(env->stack); link = stack_pop(env->stack); if ( (link->type == Global->number_type) && (link->type == b->type)){ pusher = create_number(link->value.number - b->value.number); link_free(link); link_free(b); break; } pusher = object_op_minus(link,b); link_free(link); link_free(b); break; case ADD: b = stack_pop(env->stack); link = stack_pop(env->stack); if ( (link->type == Global->number_type) && (link->type == b->type)){ pusher = create_number(link->value.number + b->value.number); link_free(link); link_free(b); break; } pusher = object_op_plus(link,b); link_free(link); link_free(b); break; case DIV: binary_op(env , object_op_divide); break; case MULT: binary_op(env , object_op_multiply); break; case MOD: binary_op(env , object_op_modulus); break; case POW: binary_op(env , object_op_power); break; case NEG: unary_op(env, object_op_neg); break; case NOT: link = stack_pop(stack); pusher = create_numberi( (object_is_true(link)) ? 0 : 1 ); link_free(link); break; case TEST: case ELSE: break; case DO: delta = read_offset(env); link = codeblock_literal2( env->function->value.codeblock->parent, delta ); if (env->function->value.codeblock->lexicals) { lexicals_attach( env->function->value.codeblock->lexicals, link); } env = callenv_new_doblock(env,link); break; case PUSH_ARRAY: delta = read_offset(env); pusher = array_new_subarray( stack , delta); break; case CALL: link = stack_pop(stack); // the arguments in an array b = stack_pop(stack); // the function that gets called parent = link_dup(env->This); // caller goto CALL_COMMON; case CALL_ATTR: link = stack_pop(stack); // arguments child_key = stack_pop(stack); // name of the function parent = stack_pop(stack); // caller b = getAttr(parent,child_key); // the function that gets called link_free(child_key); // no longer need the attributes key if (! b) { pusher = exception("AttrNotFound", NULL, NULL); break; } goto CALL_COMMON; case CALL_CHILD: link = stack_pop(stack); // ARG child_key = stack_pop(stack); parent = stack_pop(stack); // THIS b = object_getChild(parent,child_key); link_free(child_key); goto CALL_COMMON; CALL_COMMON: /* function type so we can call it inline */ if (b->type == Global->function_type){ env = callenv_new_function(env, b, parent, link); // ce , func,this, arg /* Not a CodeBlock so we have to use its virtual call function */ }else{ pusher = object_call(b, parent, link);// function, caller, args link_free(link); if (parent) link_free(parent); link_free(b); if (! pusher) pusher = object_create(Global->null_type); } break; case DEL_CHILD: child_key = stack_pop(stack); // key to find the child parent = stack_pop(stack); // parent to look in /* delete child from container */ pusher = object_delChild(parent,child_key); if (! pusher) pusher = exception("ChildNotFound", object_getString(child_key), NULL); link_free(child_key); link_free(parent); break; case DEL_ATTR: child_key = stack_pop(stack); // key to find the child parent = stack_pop(stack); // parent to look in /* delete attr from container */ pusher = delAttr(parent,child_key); if (! pusher) pusher = exception("AttrNotFound", object_getString(child_key), NULL); link_free(child_key); link_free(parent); break; case GET_CHILD: child_key = stack_pop(stack); // key to find the child parent = stack_pop(stack); // parent to look in pusher = object_getChild(parent, child_key); if (! pusher) pusher = exception("ChildNotFound", object_getString(child_key), NULL); link_free(parent); link_free(child_key); break; case GET_ATTR: child_key = stack_pop(stack); // key to find the child parent = stack_pop(stack); // parent to look in pusher = getAttr(parent, child_key); if (! pusher) pusher = exception("AttrNotFound", object_getString(child_key), NULL); link_free(parent); link_free(child_key); break; case TRAP: break; case CLEAR: for ( delta = stack_length( stack ) ; delta > env->stack_offset ; delta--){ link_free( stack_pop(stack) ); } break; case STOP: break; done: case END: for ( delta = stack_length( stack ) ; delta > env->stack_offset ; delta--){ link_free( stack_pop(stack) ); } addBacktrace(pusher, env->function, env->linenum); env = callenv_free(env); if (! env) goto end; if (! pusher) pusher = object_create(Global->null_type); break; /* JUMPS */ case JIT: /* Jump if true */ delta = read_offset(env); link = stack_peek(stack); if ( link->type->is_true(link) ) env->current = env->start+delta; break; case JIF: /* Jump if false */ delta = read_offset(env); link = stack_peek(stack); if ( ! link->type->is_true(link) ) env->current = env->start+delta; break; case JIF_POP: /* Pop value then jump if value is false, */ delta = read_offset(env); link = stack_pop(stack); if ( ! link->type->is_true(link) ) env->current = env->start+delta; link_free(link); break; case JUMP: /* Absolute jump */ delta = read_offset(env); env->current = env->start + delta; break; case JINC: /* Jump If Not Critical */ delta = read_offset(env); env->current = env->start+delta; break; jinc_critical: delta = read_offset(env); if (trapped) link_free(trapped); trapped = pusher->value.link; pusher->value.link = NULL; link_free(pusher); pusher = NULL; break; case PUSH_NULL: pusher = create_null(); break; case PUSH_NUM: pusher = create_number( *((number_t *)env->current) ); env->current+= sizeof(number_t); break; case PUSH_STR: delta = read_offset(env); pusher = create_string_literal( env->start + delta ); break; case PUSH_GVAR: delta = read_offset(env); pusher = link_dup(env->module->global_vars->links[delta]); if (! pusher){ pusher = exception("GlobalVariableUsedBeforeSet",NULL,NULL); } break; case PUSH_VAR: delta = read_offset(env); pusher = link_dup(env->local->links[delta]); if (! pusher){ pusher = exception("VariableUsedBeforeSet",NULL,NULL);; } break; case PUSH_BLOCK: delta = read_offset(env); pusher = codeblock_literal2( env->function->value.codeblock->parent, delta ); if (env->function->value.codeblock->lexicals) { lexicals_attach( env->function->value.codeblock->lexicals, pusher); } break; case PUSH_SYS: pusher = link_dup(Global->SYS_MODULE); break; case PUSH_MODULE: pusher = link_dup( env->function->value.codeblock->parent); break; case TYPEOF: link = stack_pop(stack); pusher = link_dup( link->type->type_link); link_free(link); break; case PUSH_THIS: pusher = link_dup(env->This); break; case PUSH_SELF: pusher = link_dup(env->Self); break; case PUSH_ARGS: pusher = link_dup(env->Arg); break; case PUSH_TRAPPED: pusher = trapped ? link_dup(trapped) : object_create(Global->null_type); break; case POP: link_free( stack_pop(stack) ); break; case LINE: env->linenum = read_offset(env); break; default: fprintf(stderr," UNRECOGNIZED OPCODE ERROR %i\n", *(env->current)); fprintf(stderr," near line %i\n", (int)(env->linenum)); exit(1); break; } if (pusher) { if ( is_critical( pusher ) ){ if ( *(env->current) == JINC) goto jinc_critical; goto done; } stack_push(stack , pusher); pusher = NULL; } } end: if (trapped) link_free(trapped); return pusher; }