*/ void Init_Errors(REBVAL *errors) /* ***********************************************************************/ { REBSER *errs; REBVAL *val; // Create error objects and error type objects: *ROOT_ERROBJ = *Get_System(SYS_STANDARD, STD_ERROR); errs = Construct_Object(0, VAL_BLK(errors), 0); Set_Object(Get_System(SYS_CATALOG, CAT_ERRORS), errs); Set_Root_Series(TASK_ERR_TEMPS, Make_Block(3)); // Create objects for all error types: for (val = BLK_SKIP(errs, 1); NOT_END(val); val++) { errs = Construct_Object(0, VAL_BLK(val), 0); SET_OBJECT(val, errs); } // Catch top level errors, to provide decent output: PUSH_STATE(Top_State, Saved_State); if (SET_JUMP(Top_State)) { POP_STATE(Top_State, Saved_State); DSP++; // Room for return value Catch_Error(DS_TOP); // Stores error value here Print_Value(DS_TOP, 0, FALSE); Crash(RP_NO_CATCH); } SET_STATE(Top_State, Saved_State); }
/// <summary> /// Copy original function bytes /// </summary> /// <param name="Ptr">Origianl function address</param> void DetourBase::CopyOldCode( uint8_t* ptr ) { // Store original bytes uint8_t* src = ptr; uint8_t* thunk = _origThunk, *original = _origCode; uint32_t all_len = 0; ldasm_data ld = { 0 }; do { uint32_t len = ldasm( src, &ld, is_x64 ); // Determine code end if (ld.flags & F_INVALID || (len == 1 && (src[ld.opcd_offset] == 0xCC || src[ld.opcd_offset] == 0xC3)) || (len == 3 && src[ld.opcd_offset] == 0xC2) || len + all_len > 128) { break; } // move instruction memcpy( original, src, len ); memcpy( thunk, src, len ); // if instruction has relative offset, calculate new offset if (ld.flags & F_RELATIVE) { int32_t diff = 0; const uintptr_t ofst = (ld.disp_offset != 0 ? ld.disp_offset : ld.imm_offset); const uintptr_t sz = ld.disp_size != 0 ? ld.disp_size : ld.imm_size; memcpy( &diff, src + ofst, sz ); #ifdef USE64 // exit if jump is greater then 2GB if (_abs64( src + len + diff - thunk ) > INT_MAX) { break; } else { diff += static_cast<int32_t>(src - thunk); memcpy( thunk + ofst, &diff, sz ); } #else diff += src - thunk; memcpy( thunk + ofst, &diff, sz ); #endif } src += len; thunk += len; original += len; all_len += len; } while (all_len < _origSize); // Failed to copy old code, use backup plan if (all_len < _origSize) { _type = HookType::InternalInline; memcpy( _origCode, ptr, _origSize ); } else { SET_JUMP( thunk, src ); _callOriginal = _origThunk; } }
*/ RL_API void RL_Print_TOS(REBCNT flags, REBYTE *marker) /* ** Print top REBOL stack value to the console. (pending changes) ** ** Returns: ** Nothing ** Arguments: ** flags - special flags (set to zero at this time). ** marker - placed at beginning of line to indicate output. ** Notes: ** This function is used for the main console evaluation ** input loop to print the results of evaluation from stack. ** The REBOL data stack is an abstract structure that can ** change between releases. This function allows the host ** to print the result of processed functions. ** Note that what is printed is actually TOS+1. ** Marker is usually "==" to show output. ** The system/options/result-types determine which values ** are automatically printed. ** ***********************************************************************/ { REBINT dsp = DSP; REBVAL *top = DS_VALUE(dsp+1); REBOL_STATE state; REBVAL *types; if (dsp != 0) Debug_Fmt(Str_Stack_Misaligned, dsp); PUSH_STATE(state, Saved_State); if (SET_JUMP(state)) { POP_STATE(state, Saved_State); Catch_Error(DS_NEXT); // Stores error value here Out_Value(DS_NEXT, 0, FALSE, 0); // error DSP = 0; return; } SET_STATE(state, Saved_State); if (!IS_UNSET(top)) { if (!IS_ERROR(top)) { types = Get_System(SYS_OPTIONS, OPTIONS_RESULT_TYPES); if (IS_TYPESET(types) && TYPE_CHECK(types, VAL_TYPE(top))) { if (marker) Out_Str(marker, 0); Out_Value(top, 500, TRUE, 1); // limit, molded } // else { // Out_Str(Get_Type_Name(top), 1); // } } else { if (VAL_ERR_NUM(top) != RE_HALT) { Out_Value(top, 640, FALSE, 0); // error FORMed // if (VAL_ERR_NUM(top) > RE_THROW_MAX) { // Out_Str("** Note: use WHY? for more about this error", 1); // } } } } POP_STATE(state, Saved_State); DSP = 0; }