示例#1
0
/**
 * Executes a single instruction.
 *
 * @param tid The thread ID of the thread that executes the instruction.
 * @param address The address of the instruction pointer after the single step.
 *
 * @return A NaviError code that describes whether the operation was successful or not.
 */
NaviError LinuxSystem::doSingleStep(unsigned int& pid, CPUADDRESS& address) {


  msglog->log(LOG_VERBOSE, "Trying to do single step");

  STOP_PROCESS_IF_NECESSARY

  if (ptrace(PTRACE_SINGLESTEP, getPID(), 0, 0)) {
    RESUME_PROCESS_IF_NECESSARY

    msglog->log(LOG_ALWAYS, "Error: Couldn't perform single step");
    return NaviErrors::COULDNT_SINGLE_STEP;
  }

  wait(0);

  RESUME_PROCESS_IF_NECESSARY

  NaviError eipResult = getInstructionPointer(getPID(), address);

  if (eipResult) {
    return NaviErrors::COULDNT_READ_REGISTERS;
  }

  return NaviErrors::SUCCESS;
}
示例#2
0
/**
 * Sets the instruction pointer in the target process to a new value.
 *
 * @param tid Thread ID of the target thread.
 * @param address The new value of the instruction pointer.
 *
 * @return A NaviError code that describes whether the operation was successful or not.
 */
NaviError LinuxSystem::setInstructionPointer(unsigned int tid,
                                             CPUADDRESS address) {


  msglog->log(LOG_VERBOSE,
              "Trying to set the instruction pointer to address %08X", address);

  STOP_PROCESS_IF_NECESSARY

  user_regs_struct regs;

  if (ptrace(PTRACE_GETREGS, getPID(), 0, &regs)) {
    RESUME_PROCESS_IF_NECESSARY

    msglog->log(LOG_ALWAYS, "Error: Couldn't get register value: %s",
                strerror(errno));
    return NaviErrors::COULDNT_READ_REGISTERS;
  }

  // TODO: Not platform independent
  regs.eip = address;

  if (ptrace(PTRACE_SETREGS, getPID(), 0, &regs)) {
    RESUME_PROCESS_IF_NECESSARY

    msglog->log(LOG_ALWAYS, "Couldn't set register value: %s", strerror(errno));
    return NaviErrors::COULDNT_WRITE_REGISTERS;
  }

  RESUME_PROCESS_IF_NECESSARY

  return NaviErrors::SUCCESS;
}
示例#3
0
/**
 * Load the PID Parameters of the Eeprom into Memory.
 */
void loadPID(void) {
    int pidIndex;
    for (pidIndex = 0; pidIndex < PID_STORED_COUNT; pidIndex++) {
        Pid* localPid = getPID(pidIndex, 0);
        localPid->p = internalLoadPidParameter(pidIndex, EEPROM_KP);
        localPid->i = internalLoadPidParameter(pidIndex, EEPROM_KI);
        localPid->d = internalLoadPidParameter(pidIndex, EEPROM_KD);
        localPid->maxIntegral = internalLoadPidParameter(pidIndex, EEPROM_MI);
        localPid->enabled = TRUE;
    }

    // Load rolling Test parameters
    /*
    Pid* rollingTestModePid = getPID(ROLLING_TEST);
    rollingTestModePid->p = ROLLING_TEST_P;
    rollingTestModePid->i = ROLLING_TEST_I;
    rollingTestModePid->d = ROLLING_TEST_D;
    rollingTestModePid->maxIntegral = ROLLING_TEST_MAX_INTEGRAL;
    rollingTestModePid->derivativePeriod = DEFAULT_DERIVATIVE_PERIOD;
    rollingTestModePid->enabled = TRUE;
     */

    // Parameter for End of trajectory
    int instructionIndex = 0;
    // For Alpha / Theta
    for (instructionIndex = 0; instructionIndex < INSTRUCTION_COUNT; instructionIndex++) {
        pidIndex = getIndexOfPid(instructionIndex, PID_TYPE_FINAL_APPROACH_INDEX);
        Pid* endApproachPid = getPID(pidIndex, 0);
        endApproachPid->p = END_APPROACH_P;
        endApproachPid->i = END_APPROACH_I;
        endApproachPid->d = END_APPROACH_D;
        endApproachPid->maxIntegral = END_APPROACH_MAX_INTEGRAL;
        endApproachPid->enabled = TRUE;
    }
}
示例#4
0
/*virtual*/ SysStatus
ProcessShared<ALLOC>::kill()
{
    // 0 for process replicated 1 for process shared
    TraceOSUserProcKill(getPID(), 1);
    destroy();
    TraceOSUserProcKillDone(getPID(), 1);
    return 0;
}
示例#5
0
NaviError LinuxSystem::resumeProcess() {


  int resumeResult = ptrace(PTRACE_CONT, getPID(), 0, 0);

  if (resumeResult) {
    msglog->log(LOG_ALWAYS, "Error: Couldn't resume process %d", getPID());
    return NaviErrors::COULDNT_RESUME_THREAD;
  }

  return NaviErrors::SUCCESS;
}
示例#6
0
int proctable_add_process(struct proc *proc_created, struct proc *proc_parent) {
  KASSERT(procTableLock != NULL);
  KASSERT(proc_created != NULL);
  
  // Grow the proctable as more processes come in.
  // Subtract 1 for zero-indexing.
  if (procCount == pidLimit - 1) {
    if (pidLimit < MAX_PID) {
      pidLimit = pidLimit * 2;
      procarray_setsize(procTable, pidLimit);
    }
    else {
      return -1;
    }
  }

  // Assign a PID to the new process
  for (int i = MIN_PID; i < pidLimit; i++) {
    if (procarray_get(procTable, i) == NULL) {
      setPID(proc_created, i);
      procarray_set(procTable, i, proc_created);
      break;
    }
  }

  // Check to see if a PID was available
  if (getPID(proc_created) == PROC_NO_PID) {
    return -1;
  }

  DEBUG(DB_EXEC, "New process in table: %d\n", getPID(proc_created));

  // Increase the count of processes in the procTable
  procCount++;

  // Assign the process' parent PID
  if (proc_parent == NULL) {
    setPPID(proc_created, PROC_NO_PID);
  }
  else {
    setPPID(proc_created, getPID(proc_parent));
  }

  // Finally, set the state of the proces to running
  setState(proc_created, PROC_RUNNING);

  return 0;
}
示例#7
0
void snp() {
	int back = kernel;
	kernel = 1;
	printf("Segment Not Present\n");
	kill(0, 0, getPID());
	kernel = back;
}
示例#8
0
文件: terminal.c 项目: Dinuuu/TPE3-SO
char * getKey(void) {
	int i = 0;
	char * ret = (char *) Malloc(MAX_BUFFER);
	if (terminals[getTTY()].insertShellBuffer == 0) {
		if (getPID() == terminals[getTTY()].foregroundProcess) {
			terminals[getTTY()].blockedPID = getPID();
		}
		block();
	}
	for (; i < terminals[tty].insertShellBuffer; i++) {
		ret[i] = terminals[tty].shellBuffer[i];
	}
	ret[i] = '\0';
	cleanShellBuffer();
	return ret;
}
示例#9
0
/**
 * Stores the original data that is replaced by a given breakpoint.
 *
 * @param bp The breakpoint in question.
 *
 * @return A NaviError code that describes whether the operation was successful or not.
 */
NaviError LinuxSystem::storeOriginalData(const BREAKPOINT& bp) {


  std::string addressString = cpuAddressToString(bp.addr);

  msglog->log(LOG_VERBOSE, "Trying to store the original data of address %s",
              addressString.c_str());

  if (originalBytes.find(addressString) != originalBytes.end()) {
    // Already backed up.
    return NaviErrors::SUCCESS;
  }

  DATA data;

  STOP_PROCESS_IF_NECESSARY

  data.value = ptrace(PTRACE_PEEKTEXT, getPID(), bp.addr, NULL);

  RESUME_PROCESS_IF_NECESSARY

  if (errno) {
    msglog->log(LOG_ALWAYS, "Error: Couldn't read byte from address %s",
                addressString.c_str());
    return NaviErrors::COULDNT_READ_MEMORY;
  }

  originalBytes[addressString] = data.value;

  return NaviErrors::SUCCESS;
}
示例#10
0
fulliautomatix_data* UAPItem::getData(unsigned char* pData, long len, int byteoffset)
{
  int byteShift = m_nBit/8;
  if (byteShift<len)
    return newDataUL(NULL, getPID(), byteoffset+byteShift, 1, *(pData+byteShift));
  return NULL;
}
示例#11
0
/**
 * Sets a breakpoint in the target process.
 *
 * @param breakpoint The breakpoint to be set.
 *
 * @return A NaviError code that describes whether the operation was successful or not.
 */
NaviError LinuxSystem::setBreakpoint(const BREAKPOINT& bp, bool) {


  std::string addressString = cpuAddressToString(bp.addr);

  msglog->log(LOG_VERBOSE, "Trying to set a breakpoint at address %s",
              addressString.c_str());

  DATA data;

  data.value = originalBytes[addressString];

  // TODO: Not platform independent
  data.chars[0] = 0xCC;

  STOP_PROCESS_IF_NECESSARY

  int result = ptrace(PTRACE_POKETEXT, getPID(), bp.addr, data.value);

  RESUME_PROCESS_IF_NECESSARY

  if (result) {
    msglog->log(LOG_ALWAYS, "Error: Couldn't set breakpoint at address %s",
                addressString.c_str());
    return NaviErrors::COULDNT_SET_BREAKPOINT;
  }

  return NaviErrors::SUCCESS;
}
示例#12
0
/*virtual*/ SysStatusUval
ProcessShared<ALLOC>::handleFault(AccessMode::pageFaultInfo pfinfo, uval vaddr,
				  PageFaultNotification *pn, VPNum vp)
{
    // LOCKING: internal to region list
    RegionRef reg;
    SysStatus rc;
    ScopeTime scope(ProcessTimer);
    StatTimer timer(RegionLookup);

    rc = rlst.vaddrToRegion(vaddr, reg);

    if (rc != 0) {
	err_printf("%s,%d: Invalid memory access: "
		   "processID 0x%lx addr 0x%lx, type %ld\n",
		   __FILE__, __LINE__,
		   _SGETUVAL(getPID()), vaddr,pfinfo);
	return rc;
    }

    timer.record();
    rc = DREF(reg)->handleFault(pfinfo, vaddr, pn, vp);

    return rc;
}
示例#13
0
STDMETHODIMP ProcessWrap::COMGETTER(PID)(ULONG *aPID)
{
    LogRelFlow(("{%p} %s: enter aPID=%p\n", this, "Process::getPID", aPID));

    VirtualBoxBase::clearError();

    HRESULT hrc;

    try
    {
        CheckComArgOutPointerValidThrow(aPID);

        AutoCaller autoCaller(this);
        if (FAILED(autoCaller.rc()))
            throw autoCaller.rc();

        hrc = getPID(aPID);
    }
    catch (HRESULT hrc2)
    {
        hrc = hrc2;
    }
    catch (...)
    {
        hrc = VirtualBoxBase::handleUnexpectedExceptions(this, RT_SRC_POS);
    }

    LogRelFlow(("{%p} %s: leave *aPID=%RU32 hrc=%Rhrc\n", this, "Process::getPID", *aPID, hrc));
    return hrc;
}
示例#14
0
/**
 * Terminates the target process.
 *
 * @return A NaviError code that describes whether the operation was successful or not.
 */
NaviError LinuxSystem::terminateProcess() {


  ptrace(PTRACE_KILL, getPID(), 0, 0);

  return NaviErrors::SUCCESS;
}
示例#15
0
/**
 * Detaches from the target process.
 *
 * @return A NaviError code that describes whether the operation was successful or not.
 */
NaviError LinuxSystem::detach() {


  msglog->log(LOG_VERBOSE, "Trying to detach from process %d", getPID());

  STOP_PROCESS_IF_NECESSARY

  int result = ptrace(PTRACE_DETACH, getPID(), 0, 0);

  if (result) {
    msglog->log(LOG_ALWAYS, "Error: Couldn't detach from target process %d",
                getPID());
    return NaviErrors::COULDNT_DETACH;
  }

  return NaviErrors::SUCCESS;
}
示例#16
0
void TGeneralThread::prethreadstart()
{
	onstart();	//subclass init info
	mThreadPID=getPID();
	mThreadName=getName();
    env.threadName = mThreadName.c_str();
	threadEnvSet((void *)&env);	//设置线程全局的env变量,把env设置进去
}
示例#17
0
bool fp_AnnotationRun::_setValue(void)
{
  UT_uint32 pos = getBlock()->getDocLayout()->getAnnotationVal(getPID()) + 1;
  UT_String tmp;
  UT_String_sprintf(tmp,"(%d)",pos);
  m_sValue = tmp.c_str();
  return true;
}
示例#18
0
/*virtual*/ SysStatus
ProcessShared<ALLOC>::destroy()
{
    SysStatus rc;

    /* FIXME: we want to destroy ourselves, just not the nested data structures
     * we have passed on in a hot-swap */
    if (updatedFlagDoNotDestroy) {
        return 0;
    }

    // delete all the fault notifications and annexes
    vpList.deleteAll();

    {   // remove all ObjRefs to this object
	SysStatus rc=closeExportedXObjectList();
	// most likely cause is that another destroy is in progress
	// in which case we return success
	if (_FAILURE(rc)) return _SCLSCD(rc)==1?0:rc;
    }

    // **************************************************************
    // From here on, only one destroy can be in progress.  see
    // closeExportedXObjectList for implementation of this syncronization

    lazyState.detach();

    // remove all ObjRefs owned by the process
    rc=closeMatchedXObjectList();
    tassert(_SUCCESS(rc),
	    err_printf("Free of process owned ObjRefs failed %p\n", this));

    // remove reference to us from processset - must be done after
    // closeMatchedXObjectList since XBaseObjs record ProcID's and must
    // be able to convert them to ProcessRefs.
    rc = DREFGOBJ(TheProcessSetRef)->remove(_SGETUVAL(getPID()));
    tassertWrn(_SUCCESS(rc), "Removing pid failed.\n");

    // delete all the regions we are using
    rlst.deleteRegionsAll();

    // now free the HAT
    DREF(hatRefProcess)->destroy();

    // tell pm we are releasing our reference
    DREF(pmRef)->detachRef();

    // more to do here ...
    // ports and procs - unless we just punt till they go away.

#ifdef USE_PROCESS_FACTORIES
    DREF(factoryRef)->destroy(getRef());
#else
    destroyUnchecked();
#endif

    return (0);
}
void ProcessMonitor::logMessage(const wchar_t* message, bool showPID){
	//method sends message to the logger
	if (logger){
		std::wstringstream messageStream;
		messageStream << L"ProcessMonitor: ";
		if(showPID)messageStream << "[" << getPID() << "] ";
		messageStream << message;
		logger->log(messageStream.str());
	}
}
示例#20
0
void proctable_remove_process(struct proc *proc_removed) {
  KASSERT(proc_removed != NULL);

  int pid = getPID(proc_removed);
  procarray_set(procTable, pid, NULL);
  procCount--;

  /* if this is the last user process in the system, proc_destroy()
     will wake up the kernel menu thread */
  proc_destroy(proc_removed);
}
示例#21
0
/**
 * Save the parameters of the PID into Memory.
 */
void savePID(void) {
    int pidIndex;
    // we save both NORMAL_MODE AND ROLLING_TEST_MODE
    for (pidIndex = 0; pidIndex < PID_STORED_COUNT; pidIndex++) {
        Pid* localPid = getPID(pidIndex, 0);
        internalSavePidParameter(pidIndex, EEPROM_KP, localPid->p);
        internalSavePidParameter(pidIndex, EEPROM_KI, localPid->i);
        internalSavePidParameter(pidIndex, EEPROM_KD, localPid->d);
        internalSavePidParameter(pidIndex, EEPROM_MI, localPid->maxIntegral);
    }
}
示例#22
0
/**
 * Fills a given register container structure with information about the
 * current values of the CPU registers.
 *
 * @param registers The register information structure.
 * @param tid The thread ID from which the data is read.
 *
 * @return A NaviError code that describes whether the operation was successful or not.
 */
NaviError LinuxSystem::readRegisters(RegisterContainer& registers) {


  user_regs_struct regs;

  STOP_PROCESS_IF_NECESSARY

  if (ptrace(PTRACE_GETREGS, getPID(), 0, &regs)) {
    RESUME_PROCESS_IF_NECESSARY

    return NaviErrors::COULDNT_READ_REGISTERS;
  }
示例#23
0
void NetworkSocket::showInfo() const {

    qDebug() << "-------------------[ SOCKET ]---------------------";
    qDebug() << " Protocol type . . : " << getProtocolType();
    qDebug() << " ReceiveQ. . . . . : " << getReceiveQ()<< " bytes";
    qDebug() << " SendQ . . . . . . : " << getSendQ() << " bytes";
    qDebug() << " Local Address . . : " << getLocalAddress() << " bytes";
    qDebug() << " Foreign Address . : " << getForeignAddress();
    qDebug() << " State . . . . . . : " << getState();
    qDebug() << " PID . . . . . . . : " << getPID();
    qDebug() << " Program Name. . . : " << getProgramName();
    qDebug() << "--------------------------------------------------";
}
示例#24
0
/**
 * Removes a breakpoint from the target process.
 *
 * @param bp The breakpoint to be removed.
 *
 * @return A NaviError code that describes whether the operation was successful or not.
 */
NaviError LinuxSystem::removeBreakpoint(const BREAKPOINT& bp, bool) {


  std::string addressString = cpuAddressToString(bp.addr);

  unsigned int value = originalBytes[addressString];

  msglog->log(LOG_VERBOSE,
              "Removing breakpoint at address %s with original value %08X",
              addressString.c_str(), value);

  STOP_PROCESS_IF_NECESSARY

  int result = ptrace(PTRACE_POKETEXT, getPID(), bp.addr, value);

  if (result) {
    msglog->log(LOG_VERBOSE,
                "Failed to remove breakpoint with result %d (errno: %d)",
                result, errno);
  } else {
    msglog->log(LOG_VERBOSE, "Successfully removed breakpoint");
  }

  DATA data;

  data.value = ptrace(PTRACE_PEEKTEXT, getPID(), bp.addr, NULL);

  msglog->log(LOG_VERBOSE, "New memory value at address %s is %08X",
              addressString.c_str(), data.value);

  RESUME_PROCESS_IF_NECESSARY

  if (result) {
    msglog->log(LOG_ALWAYS, "Error: Couldn't remove breakpoint");
    return NaviErrors::COULDNT_REMOVE_BREAKPOINT;
  }

  return NaviErrors::SUCCESS;
}
示例#25
0
	bool attachProcess(const std::string& sName, bool bBlock)
	{
		do
		{
			std::this_thread::sleep_for(std::chrono::seconds(2));
			unsigned int procID = getPID(sName);

			ProcessName = sName;
			Process = OpenProcess(PROCESS_ALL_ACCESS, false, procID);

		}while (bBlock && Process == NULL);

		return Process != NULL;
	}
示例#26
0
/*virtual*/ SysStatus
ProcessShared<ALLOC>::waitForTermination()
{
    ProcessID tmppid = _SGETUVAL(getPID());
    BaseProcessRef tmpref;
    Scheduler::DeactivateSelf();
    while (_SUCCESS(DREFGOBJ(TheProcessSetRef)->
				getRefFromPID(tmppid, tmpref))) {
	// cprintf("waiting for \"%s\".\n", name.getString());
	Scheduler::DelayMicrosecs(100000);
    }
    Scheduler::ActivateSelf();

    return 0;
}
示例#27
0
文件: test.c 项目: GamerSource/openOS
void _start(void)
{
	//int i;
	char test[100] = "Hallo an so one\nGreetings from User space :D\n\0";
	//for (i = 0; i < 20; i++)
	//{
	// asm("xor eax,eax"::"b"('0'+i));
	// syscall(SYSCALL_PUTC); F*CK! -.- "searching solution" is on the roadmap :)
	
	asm ("int $0x30"::"a"(SYSCALL_PRINTF), "b"(test) );
	getPID();
	exit(0);
	
	while(1);
}
示例#28
0
void proctable_exit_process(struct proc *proc_exited, int exitcode) {
  // DEBUG(DB_EXEC, "Exiting PID: %d from proctable\n", getPID(proc_exited));

  KASSERT(proc_exited != NULL);
  KASSERT(proc_exited->p_pid > 0);

  // set the process state to exited
  setState(proc_exited, PROC_EXITED);

  // encode the exit code as per the docs.
  setExitcode(proc_exited, _MKWAIT_EXIT(exitcode));

  // Next we need to evaluate some cases:
  // If proc_exited has living children, they should now have a NULL parent.
  // If proc_exited has dead children, they should now be destroyed.

  int exitedPID = getPID(proc_exited);

  // Find the children of proc_exited.
  for (int i = MIN_PID; i < pidLimit; i++) {
    struct proc* cur = procarray_get(procTable, i);
    if (cur != NULL && getPPID(cur) == exitedPID) {
      // Check state of child
      int state = getState(cur);
      
      // A running child has its parent set to NULL
      if (state == PROC_RUNNING) {
        setPPID(cur, PROC_NO_PID);
      }

      // An exited child can now be completely removed.
      else if (state == PROC_EXITED) {
        proctable_remove_process(cur);
      }
    }
  }

  // If proc_exited has no parent, it can be removed
  if (getPPID(proc_exited) == PROC_NO_PID) {
    proctable_remove_process(proc_exited);
  }

  // Otherwise if proc_exited has a parent
  // then proc_exited must wake its potentially waiting parent
  else {
    cv_signal(proc_exited->wait_cv, procTableLock);
  }
}
示例#29
0
/**
 * Retrieves the value of the instruction pointer in a given thread.
 *
 * @param tid The thread ID of the thread.
 * @param addr The variable where the value of the instruction pointer is stored.
 *
 * @return A NaviError code that describes whether the operation was successful or not.
 */
NaviError LinuxSystem::getInstructionPointer(unsigned int tid,
                                             CPUADDRESS& addr) {


  msglog->log(LOG_VERBOSE, "Trying to read the instruction pointer");

  user_regs_struct regs;

  if (ptrace(PTRACE_GETREGS, getPID(), 0, &regs)) {
    msglog->log(LOG_ALWAYS, "get_eip: PTRACE_GETREGS: %s", strerror(errno));
    return NaviErrors::COULDNT_READ_REGISTERS;
  }

  addr = regs.eip;

  return NaviErrors::SUCCESS;
}
示例#30
0
/**
 * @private
 * Computes the next value of the pid.
 * @param instructionIndex the pid that we want to compute (0 = alpha, 1 = theta)
 * @param pidType the type of pid that we want to compute (between 0 and PID_TYPE_COUNT)
 * @param currentPosition the current position of the wheels (either alphaPosition, either thetaPosition)
 * @param time the time in pid sampling
 */
float computeNextPID(int instructionIndex, MotionInstruction* motionInstruction, Motion* motion, MotionError* motionError, float time) {
    unsigned char rollingTestMode = getRollingTestMode();
	unsigned char pidType = motionInstruction->pidType;
	float currentPosition = motion->position;

    // instructionIndex = Alpha / Theta
    // pidType = Forward / Rotation / Final Approach ...
    unsigned pidIndex = getIndexOfPid(instructionIndex, pidType);
    Pid* pid = getPID(pidIndex, rollingTestMode);

    if (!pid->enabled) {
        return 0.0f;
    }

    float normalPosition = computeNormalPosition(motionInstruction, time);
    float normalSpeed = computeNormalSpeed(motionInstruction, time);

	float positionError = normalPosition - currentPosition;
    float result = computePidCorrection(motionError, pid, normalSpeed, positionError);

    return result;
}