Kernel: Implement basic shared memory objects
These can allocate memory that can be shared between processes using a global key. There is currenly no safety checks meaning anyone can map any shared memory object just by trying to map every possible key.
This commit is contained in:
@@ -36,6 +36,11 @@ int poweroff(int command);
|
||||
|
||||
int load_keymap(const char* path);
|
||||
|
||||
// Create shared memory object and return its key or -1 on error
|
||||
long smo_create(size_t size, int prot);
|
||||
// Map shared memory object defined by its key and return address or null on error
|
||||
void* smo_map(long key);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
||||
@@ -74,6 +74,8 @@ __BEGIN_DECLS
|
||||
O(SYS_LISTEN, listen) \
|
||||
O(SYS_PSELECT, pselect) \
|
||||
O(SYS_TRUNCATE, truncate) \
|
||||
O(SYS_SMO_CREATE, smo_create) \
|
||||
O(SYS_SMO_MAP, smo_map) \
|
||||
|
||||
enum Syscall
|
||||
{
|
||||
|
||||
@@ -16,3 +16,16 @@ int load_keymap(const char* path)
|
||||
{
|
||||
return syscall(SYS_LOAD_KEYMAP, path);
|
||||
}
|
||||
|
||||
long smo_create(size_t size, int prot)
|
||||
{
|
||||
return syscall(SYS_SMO_CREATE, size, prot);
|
||||
}
|
||||
|
||||
void* smo_map(long key)
|
||||
{
|
||||
long ret = syscall(SYS_SMO_MAP, key);
|
||||
if (ret < 0)
|
||||
return nullptr;
|
||||
return reinterpret_cast<void*>(ret);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user