Kernel/Userspace: Replace my custom SHM system with SysV shm
This allows xbanan to use shm!
This commit is contained in:
@@ -43,13 +43,6 @@ 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);
|
||||
// Delete shared memory object such that it will be no longer accessible with smo_map(). Existing mappings are still valid
|
||||
int smo_delete(long key);
|
||||
// Map shared memory object defined by its key and return address or null on error. Mappings can be unmapped using munmap()
|
||||
void* smo_map(long key);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,13 +22,15 @@ struct ipc_perm
|
||||
mode_t mode; /* Read/write permission. */
|
||||
};
|
||||
|
||||
#define IPC_CREAT 0x01
|
||||
#define IPC_EXCL 0x02
|
||||
#define IPC_NOWAIT 0x04
|
||||
#define IPC_PRIVATE 0x08
|
||||
#define IPC_RMID 0x10
|
||||
#define IPC_SET 0x20
|
||||
#define IPC_STAT 0x40
|
||||
#define IPC_CREAT 01000
|
||||
#define IPC_EXCL 02000
|
||||
#define IPC_NOWAIT 04000
|
||||
|
||||
#define IPC_PRIVATE 0
|
||||
|
||||
#define IPC_RMID 1
|
||||
#define IPC_SET 2
|
||||
#define IPC_STAT 3
|
||||
|
||||
key_t ftok(const char* path, int id);
|
||||
|
||||
|
||||
@@ -12,14 +12,14 @@ __BEGIN_DECLS
|
||||
#define __need_time_t
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/ipc.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#define SHM_RDONLY 0x01
|
||||
#define SHM_RND 0x02
|
||||
|
||||
#define SHMLBA (sysconf(_SC_PAGE_SIZE))
|
||||
#define SHM_FAILED ((void*)(intptr_t)-1)
|
||||
#define SHMLBA (getpagesize())
|
||||
|
||||
typedef unsigned int shmatt_t;
|
||||
|
||||
|
||||
@@ -72,9 +72,10 @@ __BEGIN_DECLS
|
||||
O(SYS_PSELECT, pselect) \
|
||||
O(SYS_PPOLL, ppoll) \
|
||||
O(SYS_FTRUNCATE, ftruncate) \
|
||||
O(SYS_SMO_CREATE, smo_create) \
|
||||
O(SYS_SMO_DELETE, smo_delete) \
|
||||
O(SYS_SMO_MAP, smo_map) \
|
||||
O(SYS_SHMAT, shmat) \
|
||||
O(SYS_SHMDT, shmdt) \
|
||||
O(SYS_SHMGET, shmget) \
|
||||
O(SYS_SHMCTL, shmctl) \
|
||||
O(SYS_GETSOCKNAME, getsockname) \
|
||||
O(SYS_GETPEERNAME, getpeername) \
|
||||
O(SYS_GETSOCKOPT, getsockopt) \
|
||||
|
||||
@@ -16,21 +16,3 @@ 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);
|
||||
}
|
||||
|
||||
int smo_delete(long key)
|
||||
{
|
||||
return syscall(SYS_SMO_DELETE, key);
|
||||
}
|
||||
|
||||
void* smo_map(long key)
|
||||
{
|
||||
long ret = syscall(SYS_SMO_MAP, key);
|
||||
if (ret < 0)
|
||||
return nullptr;
|
||||
return reinterpret_cast<void*>(ret);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,26 @@
|
||||
#include <BAN/Debug.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define TODO_FUNC(type, name, ...) type name(__VA_ARGS__) { dwarnln("TODO: " #name); errno = ENOTSUP; return (type)-1; }
|
||||
void* shmat(int shmid, const void* shmaddr, int shmflg)
|
||||
{
|
||||
const auto result = syscall(SYS_SHMAT, shmid, shmaddr, shmflg);
|
||||
if (result == -1)
|
||||
return SHM_FAILED;
|
||||
return reinterpret_cast<void*>(result);
|
||||
}
|
||||
|
||||
TODO_FUNC(void*, shmat, int, const void*, int)
|
||||
TODO_FUNC(int, shmctl, int, int, struct shmid_ds*)
|
||||
TODO_FUNC(int, shmdt, const void*)
|
||||
TODO_FUNC(int, shmget, key_t, size_t, int)
|
||||
int shmctl(int shmid, int cmd, struct shmid_ds* buf)
|
||||
{
|
||||
return syscall(SYS_SHMCTL, shmid, cmd, buf);
|
||||
}
|
||||
|
||||
int shmdt(const void* shmaddr)
|
||||
{
|
||||
return syscall(SYS_SHMDT, shmaddr);
|
||||
}
|
||||
|
||||
int shmget(key_t key, size_t size, int shmflg)
|
||||
{
|
||||
return syscall(SYS_SHMGET, key, size, shmflg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user