bool IsValid() const { if (pe_file_->Is64()) { return IMAGE_NT_SIGNATURE == GetSignature() && IMAGE_NT_OPTIONAL_HDR64_MAGIC == GetMagic() && IMAGE_FILE_MACHINE_AMD64 == GetMachine(); } else { return IMAGE_NT_SIGNATURE == GetSignature() && IMAGE_NT_OPTIONAL_HDR32_MAGIC == GetMagic() && IMAGE_FILE_MACHINE_I386 == GetMachine(); } }
main() { int FixtureIndex; double NewOriginOffset,OriginOffsetY,AxisOffsetY; double Machinex,Machiney,Machinez,Machinea,Machineb,Machinec; GetFixtureIndex(&FixtureIndex); GetOriginOffset(&OriginOffsetY, FixtureIndex, Yaxis); GetAxisOffset(&AxisOffsetY, Yaxis); GetMachine(&Machinex,&Machiney,&Machinez,&Machinea,&Machineb,&Machinec); // Compute Origin Offset to make DRO zero // // Since Machine = DRO + OriginOffset + AxisOffset // // Set DRO = 0 and solve for OriginOffset // NewOriginOffset = Machiney - AxisOffsetY; SetUserDataDouble(TMP,NewOriginOffset); SetVars(5201+FixtureIndex*20+1, 1, TMP); DoPC(PC_COMM_UPDATE_FIXTURE); }
main() { int FixtureIndex; double NewOriginOffset,OriginOffsetX,AxisOffsetX; double Machinex,Machiney,Machinez,Machinea,Machineb,Machinec; GetFixtureIndex(&FixtureIndex); GetOriginOffset(&OriginOffsetX, FixtureIndex, Xaxis); GetAxisOffset(&AxisOffsetX, Xaxis); GetMachine(&Machinex,&Machiney,&Machinez,&Machinea,&Machineb,&Machinec); // Compute Origin Offset to make DRO zero // // Since Machine = DRO + OriginOffset + AxisOffset // // Set DRO = 0 and solve for OriginOffset // NewOriginOffset = Machinex - AxisOffsetX; pD[TMP]=NewOriginOffset; SetVars(5201+FixtureIndex*20+0, 1, TMP); DoPC(PC_COMM_UPDATE_FIXTURE); }
bool MachineBridge::lockMachine() { // std::cout << "[" << getName().toStdString() << "] Trying to lock machine..." << std::endl; nsresult rc; uint32_t state; uint32_t machineState = getState(); if(machineState == MachineState::Starting || machineState == MachineState::Running || machineState == MachineState::Paused) return false; if(session != nsnull) { // Try to unlock session, then check if this action succeeded NS_CHECK_AND_DEBUG_ERROR(session, UnlockMachine(), rc); nsresult rc_tmp; GET_AND_DEBUG_MACHINE_STATE(session, state, rc_tmp); // If Session is not unlocked, VM is still running if(NS_FAILED(rc) || state != SessionState::Unlocked) { // std::cout << "[" << getName().toStdString() << "] Session already locked!" << std::endl; return false; } } session = vboxbridge->newSession(); GET_AND_DEBUG_MACHINE_STATE(session, state, rc); if(state == SessionState::Unlocked) NS_CHECK_AND_DEBUG_ERROR(machine, LockMachine(session, LockType::Write), rc); GET_AND_DEBUG_MACHINE_STATE(session, state, rc); if(NS_SUCCEEDED(rc) && state == SessionState::Locked) NS_CHECK_AND_DEBUG_ERROR(session, GetMachine(&machine), rc); // if(NS_SUCCEEDED(rc) && state == SessionState::Locked) // std::cout << "[" << getName().toStdString() << "] Machine locked" << std::endl; // else // std::cout << "[" << getName().toStdString() << "] Failed to lock machine (rc: 0x" << std::hex << rc << std::dec << ")" << std::endl; return NS_SUCCEEDED(rc); }
ComPtr<INetworkAdapter> MachineBridge::getIfaceRunTimeEditable(uint32_t iface) { nsresult rc; ComPtr<IMachine> tmp_machine; ComPtr<INetworkAdapter> nic; NS_CHECK_AND_DEBUG_ERROR(session, GetMachine(tmp_machine.asOutParam()), rc); // NS_CHECK_AND_DEBUG_ERROR(tmp_machine, LockMachine(session, LockType::Write), rc); if(NS_SUCCEEDED(rc)) NS_CHECK_AND_DEBUG_ERROR(tmp_machine, GetNetworkAdapter(iface, nic.asOutParam()), rc); if(NS_SUCCEEDED(rc)) return nic; return NULL; }
void CAlarmMachine::clear_ademco_event_list() { if (!_alarming) return; std::lock_guard<std::mutex> lock(_lock4AdemcoEventList); _alarming = false; _has_alarming_direct_zone = false; _highestEventLevel = EVENT_LEVEL_STATUS; _alarmingSubMachineCount = 0; _ademcoEventList.clear(); if (_is_submachine) { auto mgr = CAlarmMachineManager::get_instance(); CAlarmMachinePtr netMachine = mgr->GetMachine(_ademco_id); if (netMachine) { netMachine->dec_alarmingSubMachineCount(); } } if (!_is_submachine) { CWinApp* app = AfxGetApp(); ASSERT(app); auto wnd = static_cast<CAlarmMachineExDlg*>(app->GetMainWnd()); ASSERT(wnd); wnd->MachineDisalarm(shared_from_this()); } }
// RAGE AGAINST THE VIRTUAL MACHINE =) gmThread::State gmThread::Sys_Execute(gmVariable * a_return) { register union { const gmuint8 * instruction; const gmuint32 * instruction32; }; register gmVariable * top; gmVariable * base; gmVariable * operand; const gmuint8 * code; if(m_state != RUNNING) return m_state; #if GMDEBUG_SUPPORT if(m_debugFlags && m_machine->GetDebugMode() && m_machine->m_isBroken) { if(m_machine->m_isBroken(this)) return RUNNING; } #endif // GMDEBUG_SUPPORT // make sure we have a stack frame GM_ASSERT(m_frame); GM_ASSERT(GetFunction()->m_type == GM_FUNCTION); // cache our "registers" gmFunctionObject * fn = (gmFunctionObject *) GM_MOBJECT(m_machine, GetFunction()->m_value.m_ref); code = (const gmuint8 *) fn->GetByteCode(); if(m_instruction == NULL) instruction = code; else instruction = m_instruction; top = GetTop(); base = GetBase(); // // start byte code execution // for(;;) { #ifdef GM_CHECK_USER_BREAK_CALLBACK // This may be defined in gmConfig_p.h // Check external source to break execution with exception eg. Check for CTRL-BREAK // Endless loop protection could be implemented with this, or in a similar manner. if( gmMachine::s_userBreakCallback && gmMachine::s_userBreakCallback(this) ) { GMTHREAD_LOG("User break. Execution halted."); goto LabelException; } #endif //GM_CHECK_USER_BREAK_CALLBACK switch(*(instruction32++)) { // // unary operator // #if GM_USE_INCDECOPERATORS case BC_OP_INC : case BC_OP_DEC : #endif case BC_BIT_INV : case BC_OP_NEG : case BC_OP_POS : case BC_OP_NOT : { operand = top - 1; gmOperatorFunction op = OPERATOR(operand->m_type, (gmOperator) instruction32[-1]); if(op) { op(this, operand); } else if((fn = CALLOPERATOR(operand->m_type, (gmOperator) instruction32[-1]))) { operand[2] = operand[0]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 3); State res = PushStackFrame(1, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } else { GMTHREAD_LOG("unary operator %s undefined for type %s", gmGetOperatorName((gmOperator) instruction32[-1]), m_machine->GetTypeName(operand->m_type)); goto LabelException; } break; } // // operator // case BC_OP_ADD : case BC_OP_SUB : case BC_OP_MUL : case BC_OP_DIV : case BC_OP_REM : case BC_BIT_OR : case BC_BIT_XOR : case BC_BIT_AND : case BC_BIT_SHL : case BC_BIT_SHR : case BC_OP_LT : case BC_OP_GT : case BC_OP_LTE : case BC_OP_GTE : case BC_OP_EQ : case BC_OP_NEQ : { operand = top - 2; --top; // NOTE: Classic logic for operators. Higher type processes the operation. register gmType t1 = operand[1].m_type; if(operand->m_type > t1) t1 = operand->m_type; gmOperatorFunction op = OPERATOR(t1, (gmOperator) instruction32[-1]); if(op) { op(this, operand); } else if((fn = CALLOPERATOR(t1, (gmOperator) instruction32[-1]))) { operand[2] = operand[0]; operand[3] = operand[1]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 4); State res = PushStackFrame(2, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } else { GMTHREAD_LOG("operator %s undefined for type %s and %s", gmGetOperatorName((gmOperator) instruction32[-1]), m_machine->GetTypeName(operand->m_type), m_machine->GetTypeName((operand + 1)->m_type)); goto LabelException; } break; } case BC_GETIND : { operand = top - 2; --top; gmOperatorFunction op = OPERATOR(operand->m_type, (gmOperator) instruction32[-1]); if(op) { op(this, operand); } else if((fn = CALLOPERATOR(operand->m_type, (gmOperator) instruction32[-1]))) { operand[2] = operand[0]; operand[3] = operand[1]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 4); State res = PushStackFrame(2, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } else { GMTHREAD_LOG("operator %s undefined for type %s and %s", gmGetOperatorName((gmOperator) instruction32[-1]), m_machine->GetTypeName(operand->m_type), m_machine->GetTypeName((operand + 1)->m_type)); goto LabelException; } break; } case BC_SETIND : { operand = top - 3; top -= 3; gmOperatorFunction op = OPERATOR(operand->m_type, O_SETIND); if(op) { op(this, operand); } else if((fn = CALLOPERATOR(operand->m_type, O_SETIND))) { operand[4] = operand[2]; operand[3] = operand[1]; operand[2] = operand[0]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 5); State res = PushStackFrame(3, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } else { GMTHREAD_LOG("setind failed."); goto LabelException; } break; } case BC_NOP : { break; } case BC_LINE : { #if GMDEBUG_SUPPORT if(m_machine->GetDebugMode() && m_machine->m_line) { SetTop(top); m_instruction = instruction; if(m_machine->m_line(this)) return RUNNING; } #endif // GMDEBUG_SUPPORT break; } case BC_GETDOT : { operand = top - 1; gmptr member = OPCODE_PTR(instruction); top->m_type = GM_STRING; top->m_value.m_ref = member; gmType t1 = operand->m_type; gmOperatorFunction op = OPERATOR(t1, O_GETDOT); if(op) { op(this, operand); if(operand->m_type) break; } if(t1 == GM_NULL) { GMTHREAD_LOG("getdot failed."); goto LabelException; } *operand = m_machine->GetTypeVariable(t1, gmVariable(GM_STRING, member)); break; } case BC_SETDOT : { operand = top - 2; gmptr member = OPCODE_PTR(instruction); top->m_type = GM_STRING; top->m_value.m_ref = member; top -= 2; gmOperatorFunction op = OPERATOR(operand->m_type, O_SETDOT); if(op) { op(this, operand); } else { GMTHREAD_LOG("setdot failed."); goto LabelException; } break; } case BC_BRA : { instruction = code + OPCODE_PTR_NI(instruction); break; } case BC_BRZ : { #if GM_BOOL_OP operand = top - 1; --top; if (operand->m_type > GM_USER) { // Look for overridden operator. gmOperatorFunction op = OPERATOR(operand->m_type, O_BOOL); if (op) { op(this, operand); } else if ((fn = CALLOPERATOR(operand->m_type, O_BOOL))) { operand[2] = operand[0]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 3); // Return to the same instruction after making the call but it will be testing the results of the call. --instruction32; State res = PushStackFrame(1, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } } if(operand->m_value.m_int == 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #else // !GM_BOOL_OP --top; if(top->m_value.m_int == 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #endif // !GM_BOOL_OP break; } case BC_BRNZ : { #if GM_BOOL_OP operand = top - 1; --top; if (operand->m_type > GM_USER) { // Look for overridden operator. gmOperatorFunction op = OPERATOR(operand->m_type, O_BOOL); if (op) { op(this, operand); } else if ((fn = CALLOPERATOR(operand->m_type, O_BOOL))) { operand[2] = operand[0]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 3); // Return to the same instruction after making the call but it will be testing the results of the call. --instruction32; State res = PushStackFrame(1, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } } if(operand->m_value.m_int != 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #else // !GM_BOOL_OP --top; if(top->m_value.m_int != 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #endif // !GM_BOOL_OP break; } case BC_BRZK : { #if GM_BOOL_OP operand = top - 1; if (operand->m_type > GM_USER) { // Look for overridden operator. gmOperatorFunction op = OPERATOR(operand->m_type, O_BOOL); if (op) { op(this, operand); } else if ((fn = CALLOPERATOR(operand->m_type, O_BOOL))) { operand[2] = operand[0]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 3); // Return to the same instruction after making the call but it will be testing the results of the call. --instruction32; State res = PushStackFrame(1, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } } if(operand->m_value.m_int == 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #else // !GM_BOOL_OP if(top[-1].m_value.m_int == 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #endif // !GM_BOOL_OP break; } case BC_BRNZK : { #if GM_BOOL_OP operand = top - 1; if (operand->m_type > GM_USER) { // Look for overridden operator. gmOperatorFunction op = OPERATOR(operand->m_type, O_BOOL); if (op) { op(this, operand); } else if ((fn = CALLOPERATOR(operand->m_type, O_BOOL))) { operand[2] = operand[0]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 3); // Return to the same instruction after making the call but it will be testing the results of the call. --instruction32; State res = PushStackFrame(1, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } } if(operand->m_value.m_int != 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #else // !GM_BOOL_OP if(top[-1].m_value.m_int != 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #endif // !GM_BOOL_OP break; } case BC_CALL : { SetTop(top); int numParams = (int) OPCODE_INT(instruction); State res = PushStackFrame(numParams, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) { #if GMDEBUG_SUPPORT if(m_debugFlags && m_machine->GetDebugMode() && m_machine->m_call) { m_instruction = instruction; if(m_machine->m_call(this)) return RUNNING; } #endif // GMDEBUG_SUPPORT break; } if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { if(a_return) *a_return = m_stack[m_top - 1]; m_machine->Sys_SwitchState(this, KILLED); } return res; } case BC_RET : { PUSHNULL; } case BC_RETV : { SetTop(top); int res = Sys_PopStackFrame(instruction, code); top = GetTop(); base = GetBase(); if(res == RUNNING) { #if GMDEBUG_SUPPORT if(m_debugFlags && m_machine->GetDebugMode() && m_machine->m_return) { m_instruction = instruction; if(m_machine->m_return(this)) return RUNNING; } #endif // GMDEBUG_SUPPORT break; } if(res == KILLED) { if(a_return) *a_return = *(top - 1); m_machine->Sys_SwitchState(this, KILLED); return KILLED; } if(res == SYS_EXCEPTION) goto LabelException; break; } #if GM_USE_FORK // duplicates the current thread and just the local stack frame // and branches around the forked section of code case BC_FORK : { int id; gmThread* newthr = GetMachine()->CreateThread(&id); GM_ASSERT( newthr ); // make sure there is enough room newthr->Touch( m_size - m_base + 2 - GMTHREAD_SLACKSPACE); // copy stack and vars memcpy( newthr->m_stack, &m_stack[ m_base - 2 ], sizeof( gmVariable ) * (m_top - m_base + 2 ) ); newthr->m_top = m_top - m_base + 2; newthr->m_frame = m_machine->Sys_AllocStackFrame(); newthr->m_frame->m_prev = 0; newthr->m_frame->m_returnAddress = 0; newthr->m_frame->m_returnBase = 0; newthr->m_base = 2; newthr->m_instruction = instruction + sizeof(gmptr); // skip branch on other thread newthr->PushInt( GetId() ); instruction = code + OPCODE_PTR_NI( instruction ); // branch top->m_type = GM_INT; top->m_value.m_int = newthr->GetId(); ++top; break; } #endif //GM_USE_FORK case BC_FOREACH : { gmuint32 localvalue = OPCODE_INT(instruction); gmuint32 localkey = localvalue >> 16; localvalue &= 0xffff; // iterator is at tos-1, table is at tos -2, push int 1 if continuing loop. write key and value into localkey and localvalue if(top[-2].m_type != GM_TABLE) { #if GM_USER_FOREACH gmTypeIteratorCallback itrfunc = m_machine->GetUserTypeIteratorCallback(top[-2].m_type); if (!itrfunc) { GMTHREAD_LOG("foreach expression has no iterator function"); goto LabelException; } gmTypeIterator it = (gmTypeIterator) top[-1].m_value.m_int; gmUserObject *obj = (gmUserObject*)GM_MOBJECT(m_machine, top[-2].m_value.m_ref); // Do callback for getnext gmVariable localvar; gmVariable localkeyvar; itrfunc(this, obj, it, &localkeyvar, &localvar); if (it != GM_TYPE_ITR_NULL) { base[localkey] = localkeyvar; base[localvalue] = localvar; top->m_type = GM_INT; top->m_value.m_int = 1; } else { top->m_type = GM_INT; top->m_value.m_int = 0; } top[-1].m_value.m_int = it; ++top; #else //GM_USER_FOREACH (original) GMTHREAD_LOG("foreach expression is not table type"); goto LabelException; #endif //GM_USER_FOREACH } else { GM_ASSERT(top[-1].m_type == GM_INT); gmTableIterator it = (gmTableIterator) top[-1].m_value.m_int; gmTableObject * table = (gmTableObject *) GM_MOBJECT(m_machine, top[-2].m_value.m_ref); gmTableNode * node = table->GetNext(it); top[-1].m_value.m_int = it; if(node) { base[localkey] = node->m_key; base[localvalue] = node->m_value; top->m_type = GM_INT; top->m_value.m_int = 1; } else { top->m_type = GM_INT; top->m_value.m_int = 0; } ++top; } break; } case BC_POP : { --top; break; } case BC_POP2 : { top -= 2; break; } case BC_DUP : { top[0] = top[-1]; ++top; break; } case BC_DUP2 : { top[0] = top[-2]; top[1] = top[-1]; top += 2; break; } case BC_SWAP : { top[0] = top[-1]; top[-1] = top[-2]; top[-2] = top[0]; break; } case BC_PUSHNULL : { PUSHNULL; break; } case BC_PUSHINT : { top->m_type = GM_INT; top->m_value.m_int = OPCODE_INT(instruction); ++top; break; } case BC_PUSHINT0 : { top->m_type = GM_INT; top->m_value.m_int = 0; ++top; break; } case BC_PUSHINT1 : { top->m_type = GM_INT; top->m_value.m_int = 1; ++top; break; } case BC_PUSHFP : { top->m_type = GM_FLOAT; top->m_value.m_float = OPCODE_FLOAT(instruction); ++top; break; } case BC_PUSHSTR : { top->m_type = GM_STRING; top->m_value.m_ref = OPCODE_PTR(instruction); ++top; break; } case BC_PUSHTBL : { SetTop(top); top->m_type = GM_TABLE; top->m_value.m_ref = m_machine->AllocTableObject()->GetRef(); ++top; break; } case BC_PUSHFN : { top->m_type = GM_FUNCTION; top->m_value.m_ref = OPCODE_PTR(instruction); ++top; break; } case BC_PUSHTHIS : { *top = *GetThis(); ++top; break; } case BC_GETLOCAL : { gmuint32 offset = OPCODE_INT(instruction); *(top++) = base[offset]; break; } case BC_SETLOCAL : { gmuint32 offset = OPCODE_INT(instruction); // Write barrier old local objects { gmGarbageCollector* gc = m_machine->GetGC(); if( !gc->IsOff() && base[offset].IsReference() ) { gmObject * object = GM_MOBJECT(m_machine, base[offset].m_value.m_ref); gc->WriteBarrier(object); } } base[offset] = *(--top); break; } case BC_GETGLOBAL : { top->m_type = GM_STRING; top->m_value.m_ref = OPCODE_PTR(instruction); *top = m_machine->GetGlobals()->Get(*top); ++top; break; } case BC_SETGLOBAL : { top->m_type = GM_STRING; top->m_value.m_ref = OPCODE_PTR(instruction); m_machine->GetGlobals()->Set(m_machine, *top, *(top-1)); --top; break; } case BC_GETTHIS : { gmptr member = OPCODE_PTR(instruction); const gmVariable * thisVar = GetThis(); *top = *thisVar; top[1].m_type = GM_STRING; top[1].m_value.m_ref = member; gmOperatorFunction op = OPERATOR(thisVar->m_type, O_GETDOT); if(op) { op(this, top); if(top->m_type) { ++top; break; } } if(thisVar->m_type == GM_NULL) { GMTHREAD_LOG("getthis failed. this is null"); goto LabelException; } *top = m_machine->GetTypeVariable(thisVar->m_type, top[1]); ++top; break; } case BC_SETTHIS : { gmptr member = OPCODE_PTR(instruction); const gmVariable * thisVar = GetThis(); operand = top - 1; *top = *operand; *operand = *thisVar; top[1].m_type = GM_STRING; top[1].m_value.m_ref = member; --top; gmOperatorFunction op = OPERATOR(thisVar->m_type, O_SETDOT); if(op) { op(this, operand); } else { GMTHREAD_LOG("setthis failed."); goto LabelException; } break; } default : { break; } } } LabelException: // // exception handler // m_instruction = instruction; // spit out error info LogLineFile(); LogCallStack(); // call machine exception handler if(gmMachine::s_machineCallback) { if(gmMachine::s_machineCallback(m_machine, MC_THREAD_EXCEPTION, this)) { #if GMDEBUG_SUPPORT // if we are being debugged, put this thread into a limbo state, waiting for delete. if(m_machine->GetDebugMode() && m_machine->m_debugUser) { m_machine->Sys_SwitchState(this, EXCEPTION); return EXCEPTION; } #endif } } // kill the thread m_machine->Sys_SwitchState(this, KILLED); return KILLED; }
static PDH_STATUS PdhiExpandCounterPath ( IN LPCWSTR szWildCardPath, IN LPVOID pExpandedPathList, IN LPDWORD pcchPathListLength, IN BOOL bUnicode ) { PPERF_MACHINE pMachine; PPDHI_COUNTER_PATH pWildCounterPath = NULL; WCHAR szWorkBuffer[MAX_PATH]; WCHAR szCounterName[MAX_PATH]; WCHAR szInstanceName[MAX_PATH]; LPWSTR szEndOfObjectString; LPWSTR szInstanceString; LPWSTR szCounterString; LPVOID szNextUserString; PERF_OBJECT_TYPE *pObjectDef; PERF_OBJECT_TYPE *pParentObjectDef; PERF_COUNTER_DEFINITION *pCounterDef; PERF_INSTANCE_DEFINITION *pInstanceDef; PERF_INSTANCE_DEFINITION *pParentInstanceDef; DWORD dwBufferRemaining; DWORD dwSize; DWORD dwSizeReturned = 0; PDH_STATUS pdhStatus = ERROR_SUCCESS; DWORD dwCtrNdx, dwInstNdx; BOOL bMoreData = FALSE; // allocate buffers pWildCounterPath = G_ALLOC (GPTR, PDHI_COUNTER_PATH_BUFFER_SIZE); if (pWildCounterPath == NULL) { // unable to allocate memory so bail out pdhStatus = PDH_MEMORY_ALLOCATION_FAILURE; } else { __try { dwBufferRemaining = *pcchPathListLength; szNextUserString = pExpandedPathList; } __except (EXCEPTION_EXECUTE_HANDLER) { pdhStatus = PDH_INVALID_ARGUMENT; } } if (pdhStatus == ERROR_SUCCESS) { // Parse wild card Path dwSize = G_SIZE (pWildCounterPath); if (ParseFullPathNameW (szWildCardPath, &dwSize, pWildCounterPath)) { // get the machine referenced in the path pMachine = GetMachine (pWildCounterPath->szMachineName, 0); if (pMachine != NULL) { if (wcsncmp (cszDoubleBackSlash, szWildCardPath, 2) == 0) { // the caller wants the machine name in the path so // copy it to the work buffer lstrcpyW (szWorkBuffer, pWildCounterPath->szMachineName); } else { *szWorkBuffer = 0; } // append the object name (since wild card objects are not // currently supported. lstrcatW (szWorkBuffer, cszBackSlash); lstrcatW (szWorkBuffer, pWildCounterPath->szObjectName); szEndOfObjectString = &szWorkBuffer[lstrlenW(szWorkBuffer)]; // get object pointer (since objects are not wild) pObjectDef = GetObjectDefByName ( pMachine->pSystemPerfData, pMachine->dwLastPerfString, pMachine->szPerfStrings, pWildCounterPath->szObjectName); if (pObjectDef != NULL) { // for each counters and identify matches pCounterDef = FirstCounter (pObjectDef); for (dwCtrNdx = 0; dwCtrNdx < pObjectDef->NumCounters; dwCtrNdx++) { // for each counter check instances (if supported) // and keep matches if ((pCounterDef->CounterNameTitleIndex > 0) && (pCounterDef->CounterNameTitleIndex < pMachine->dwLastPerfString ) && (!((pCounterDef->CounterType & PERF_DISPLAY_NOSHOW) && // this is a hack because this type is not defined correctly (pCounterDef->CounterType != PERF_AVERAGE_BULK)))) { // look up name of each object & store size lstrcpyW (szCounterName, pMachine->szPerfStrings[pCounterDef->CounterNameTitleIndex]); if (WildStringMatchW(pWildCounterPath->szCounterName, szCounterName)) { // if this object has instances, then walk down // the instance list and save any matches if (pObjectDef->NumInstances != PERF_NO_INSTANCES) { // then walk instances to find matches pInstanceDef = FirstInstance (pObjectDef); if (pObjectDef->NumInstances > 0) { for (dwInstNdx = 0; dwInstNdx < (DWORD)pObjectDef->NumInstances; dwInstNdx++) { szInstanceString = szEndOfObjectString; if (pInstanceDef->ParentObjectTitleIndex > 0) { // then add in parent instance name pParentObjectDef = GetObjectDefByTitleIndex ( pMachine->pSystemPerfData, pInstanceDef->ParentObjectTitleIndex); if (pParentObjectDef != NULL) { pParentInstanceDef = GetInstance ( pParentObjectDef, pInstanceDef->ParentObjectInstance); if (pParentInstanceDef != NULL) { GetInstanceNameStr (pParentInstanceDef, szInstanceName, pObjectDef->CodePage); if (WildStringMatchW (pWildCounterPath->szParentName, szInstanceName)) { // add this string szInstanceString = szEndOfObjectString; lstrcpyW (szInstanceString, cszLeftParen); lstrcatW (szInstanceString, szInstanceName); lstrcatW (szInstanceString, cszSlash); } else { // get next instance and continue pInstanceDef = NextInstance(pInstanceDef); continue; } } else { // unable to locate parent instance // so cancel this one, then // get next instance and continue pInstanceDef = NextInstance(pInstanceDef); continue; } } else { // unable to locate parent object // so cancel this one, then // get next instance and continue pInstanceDef = NextInstance(pInstanceDef); continue; } } else { // no parent name so continue szInstanceString = szEndOfObjectString; lstrcpyW (szInstanceString, cszSlash); } GetInstanceNameStr (pInstanceDef, szInstanceName, pObjectDef->CodePage); // // BUGBUG: need to do something with indexes. // // if this instance name matches, then keep it if (WildStringMatchW (pWildCounterPath->szInstanceName, szInstanceName)) { lstrcatW (szInstanceString, szInstanceName); lstrcatW (szInstanceString, cszRightParenBackSlash); // now append this counter name lstrcatW (szInstanceString, szCounterName); // add it to the user's buffer if there's room dwSize = lstrlenW(szWorkBuffer) + 1; if (!bMoreData && (dwSize < dwBufferRemaining)) { if (bUnicode) { lstrcpyW ((LPWSTR)szNextUserString, szWorkBuffer); (LPBYTE)szNextUserString += dwSize * sizeof(WCHAR); } else { wcstombs ((LPSTR)szNextUserString, szWorkBuffer, dwSize); (LPBYTE)szNextUserString += dwSize * sizeof(CHAR); } dwSizeReturned += dwSize; dwBufferRemaining -= dwSize; } else { // they've run out of buffer so just update the size required bMoreData = TRUE; dwSizeReturned += dwSize; } } else { // they don't want this instance so skip it } pInstanceDef = NextInstance (pInstanceDef); } // end for each instance in object } else { // this object supports instances, // but doesn't currently have any // so do nothing. } } else { // this object does not use instances so copy this // counter to the caller's buffer. szCounterString = szEndOfObjectString; lstrcpyW (szCounterString, cszBackSlash); lstrcatW (szCounterString, szCounterName); dwSize = lstrlenW(szWorkBuffer) + 1; if (!bMoreData && (dwSize < dwBufferRemaining)) { if (bUnicode) { lstrcpyW ((LPWSTR)szNextUserString, szWorkBuffer); (LPBYTE)szNextUserString += dwSize * sizeof(WCHAR); } else { wcstombs ((LPSTR)szNextUserString, szWorkBuffer, dwSize); (LPBYTE)szNextUserString += dwSize * sizeof(CHAR); } dwSizeReturned += dwSize; dwBufferRemaining -= dwSize; } else { // they've run out of buffer so bail out of this loop bMoreData = TRUE; dwSizeReturned += dwSize; } } } else { // this counter doesn't match so skip it } } else { // this counter string is not available } pCounterDef = NextCounter(pCounterDef); } // end for each counter in this object if (bUnicode) { *(LPWSTR)szNextUserString = 0; // MSZ terminator } else { *(LPSTR)szNextUserString = 0; // MSZ terminator } *pcchPathListLength = dwSizeReturned; if (bMoreData) { pdhStatus = PDH_MORE_DATA; } else { pdhStatus = ERROR_SUCCESS; } } else { // unable to find object pdhStatus = PDH_INVALID_PATH; } } else { // unable to connect to machine. pdhStatus = PDH_CANNOT_CONNECT_MACHINE; } } else { // unable to read input path string pdhStatus = PDH_INVALID_PATH; } } if (pWildCounterPath != NULL) G_FREE (pWildCounterPath); return pdhStatus; }