More unfinished work on kernel API
This commit is contained in:
@@ -1,17 +1,28 @@
|
||||
#include "syscalls.hpp"
|
||||
#include "kernel.hpp"
|
||||
#include "memorytype.hpp"
|
||||
|
||||
int mmap(void* location, size_t length, int flags)
|
||||
{
|
||||
// TODO: check that the requested region does not overlap something important
|
||||
if(kernel.getActiveProcess().map(location, length))
|
||||
{
|
||||
if(kernel.allocateRegion(location, length, flags))
|
||||
return 0;
|
||||
else if(kernel.getActiveProcess().unmap(location, length))
|
||||
return 1;
|
||||
kernel.terminateActiveProcess();
|
||||
}
|
||||
return kernel.allocateRegion(location, length, flags);
|
||||
}
|
||||
|
||||
int munmap(void* location, size_t length)
|
||||
{
|
||||
// TODO: check that the requested region does not overlap something important
|
||||
kernel.freeRegion(location, length);
|
||||
return 0;
|
||||
if(kernel.getActiveProcess().unmap(location, length))
|
||||
{
|
||||
kernel.freeRegion(location, length);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned int createSharedBlock(void* location, size_t length, int flags)
|
||||
@@ -19,7 +30,7 @@ unsigned int createSharedBlock(void* location, size_t length, int flags)
|
||||
unsigned int blockID = kernel.createSharedBlock(length, flags);
|
||||
if(blockID > 0)
|
||||
{
|
||||
const MemoryBlock& block = kernel.getSharedBlock(blockID);
|
||||
const SharedBlock& block = kernel.getSharedBlock(blockID);
|
||||
kernel.mapRegion(location, block.getLocation(), length, flags);
|
||||
// TODO: add block to current process
|
||||
// TODO: perform safety checks
|
||||
@@ -29,8 +40,8 @@ unsigned int createSharedBlock(void* location, size_t length, int flags)
|
||||
|
||||
int aquireSharedBlock(void* location, unsigned int id)
|
||||
{
|
||||
const MemoryBlock& block = kernel.getSharedBlock(id);
|
||||
kernel.mapRegion(location, block.getLocation(), block.getSize(), block.getAttributes());
|
||||
const SharedBlock& block = kernel.getSharedBlock(id);
|
||||
kernel.mapRegion(location, block.getLocation(), block.getSize(), block.getFlags());
|
||||
// TODO: (somehow) handle invalid ids -- possibly hard while using references
|
||||
// TODO: add block to current process
|
||||
// TODO: perform safety checks
|
||||
@@ -59,4 +70,24 @@ int aquirePhysicalBlock(void* location, physaddr_t physicalAddress, size_t lengt
|
||||
int releasePhysicalBlock(int id)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sendMessage(unsigned int recipient, const Message* message)
|
||||
{
|
||||
Message* copy = new Message(*message);
|
||||
copy->m_sender = kernel.getActiveProcess().getID();
|
||||
kernel.getProcess(recipient).pushMessage(copy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int receiveMessage(Message* buffer)
|
||||
{
|
||||
if(buffer == nullptr)
|
||||
return 1;
|
||||
Message* message = kernel.getActiveProcess().popMessage();
|
||||
if(message == nullptr)
|
||||
return 1;
|
||||
*buffer = *message;
|
||||
delete message;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user