Esempio n. 1
0
Error SystemInfoHandler(SystemInformation *info)
{
    Memory *memory = Kernel::instance->getMemory();
    ProcessManager *procs = Kernel::instance->getProcessManager();

    // Verify memory access
    if (!memory->access(procs->current(), (Address) info,
                        sizeof(SystemInformation)))
    {
        return EFAULT;
    }
    // Fill in our current information
    info->version          = VERSIONCODE;
    info->memorySize       = memory->getTotalMemory();
    info->memoryAvail      = memory->getAvailableMemory();
    // TODO: this interface could be improved using libarch?
    info->bootImageAddress = Kernel::instance->getBootImageAddress();
    info->bootImageSize    = Kernel::instance->getBootImageSize();

    // TODO: we dont have the commandline info of kernel yet.
    MemoryBlock::copy(info->cmdline, "", 64);
    return 0;
}
Esempio n. 2
0
Error ProcessCtlHandler(ProcessID procID, ProcessOperation action, Address addr)
{
#ifdef __i386__
    IntelProcess *proc = ZERO;
    Memory *memory = Kernel::instance->getMemory();
    ProcessInfo *info = (ProcessInfo *) addr;
    ProcessManager *procs = Kernel::instance->getProcessManager();

    DEBUG("#" << procs->current()->getID() << " " << action << " -> " << procID << " (" << addr << ")");

    /* Verify memory address. */
    if (action == InfoPID)
    {
	if (!memory->access(procs->current(), addr, sizeof(ProcessInfo)))
	{
	    return API::AccessViolation;
	}
    }
    /* Does the target process exist? */
    if(action != GetPID && action != Spawn)
    {
        if (procID == SELF)
            proc = (IntelProcess *) procs->current();
        else if (!(proc = (IntelProcess *)procs->get(procID)))
	    return API::NotFound;
    }
    /* Handle request. */
    switch (action)
    {
	case Spawn:
	    proc = (IntelProcess *) procs->create(addr);
	    return proc->getID();
	
	case KillPID:
            procs->remove(proc);
	    break;

	case GetPID:
	    return procs->current()->getID();

	case Schedule:
            procs->schedule();
	    break;

	case Resume:
	    proc->setState(Process::Ready);
	    break;
	
	case AllowIO:
            return API::InvalidArgument;
	    //proc->IOPort(addr, true);
	    //break;
	
	case WatchIRQ:
	    Kernel::instance->hookInterrupt(IRQ(addr),
		(InterruptHandler *)interruptNotify, (ulong)proc);
	    Kernel::instance->enableIRQ(addr, true);
	    break;
	
	case InfoPID:
	    info->id    = proc->getID();
	    info->state = proc->getState();
	    info->stack = proc->getStack();
	    info->pageDirectory = proc->getPageDirectory();
	    break;
	    
	case SetStack:
	    proc->setStack(addr);
	    break;
    }
#endif
    return API::Success;
}
Esempio n. 3
0
Error VMCopyHandler(ProcessID procID, API::Operation how, Address ours,
                    Address theirs, Size sz)
{
    ProcessManager *procs = Kernel::instance->getProcessManager();
    Memory *memory = Kernel::instance->getMemory();
    Process *proc;
    Address paddr, tmpAddr;
    Size bytes = 0, pageOff, total = 0;
    
#ifdef __i386__

    /* Find the corresponding Process. */
    if (!(proc = procs->get(procID)))
    {
        return API::NotFound;
    }
    /* Verify memory addresses. */
    if (!memory->access(procs->current(), ours, sz) ||
        !memory->access(proc, theirs, sz))
    {
        return API::AccessViolation;
    }
    /* Keep on going until all memory is processed. */
    while (total < sz)
    {
        /* Update variables. */
        paddr   = memory->lookup(proc, theirs) & PAGEMASK;
        pageOff = theirs & ~PAGEMASK;
        bytes   = (PAGESIZE - pageOff) < (sz - total) ?
                  (PAGESIZE - pageOff) : (sz - total);
                
        /* Valid address? */
        if (!paddr) break;
                
        /* Map the physical page. */
        tmpAddr = memory->map(paddr);

        /* Process the action appropriately. */
        switch (how)
        {
            case API::Read:
                MemoryBlock::copy((void *)ours, (void *)(tmpAddr + pageOff), bytes);
                break;
                        
            case API::Write:
                MemoryBlock::copy((void *)(tmpAddr + pageOff), (void *)ours, bytes);
                break;
            
            default:
                ;
        }       
        /* Remove mapping. */
        memory->map((Address) 0, (Address) tmpAddr, Memory::None);
        ours   += bytes;
        theirs += bytes;
        total  += bytes;
    }
#endif
    /* Success. */
    return total;
}