2018-11-08 11:37:01 +01:00
|
|
|
#include <mman.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
2018-10-24 09:48:24 +02:00
|
|
|
#include <Kernel/Syscall.h>
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
2018-11-08 11:37:01 +01:00
|
|
|
void* mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset)
|
2018-10-24 09:48:24 +02:00
|
|
|
{
|
2019-05-19 15:54:56 +02:00
|
|
|
Syscall::SC_mmap_params params { (dword)addr, size, prot, flags, fd, offset, nullptr };
|
|
|
|
int rc = syscall(SC_mmap, ¶ms);
|
|
|
|
if (rc < 0 && -rc < EMAXERRNO) {
|
|
|
|
errno = -rc;
|
|
|
|
return (void*)-1;
|
|
|
|
}
|
|
|
|
return (void*)rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* mmap_with_name(void* addr, size_t size, int prot, int flags, int fd, off_t offset, const char* name)
|
|
|
|
{
|
|
|
|
Syscall::SC_mmap_params params { (dword)addr, size, prot, flags, fd, offset, name };
|
2018-12-21 03:02:06 +01:00
|
|
|
int rc = syscall(SC_mmap, ¶ms);
|
2019-02-16 15:34:31 +01:00
|
|
|
if (rc < 0 && -rc < EMAXERRNO) {
|
|
|
|
errno = -rc;
|
|
|
|
return (void*)-1;
|
|
|
|
}
|
|
|
|
return (void*)rc;
|
2018-10-24 09:48:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int munmap(void* addr, size_t size)
|
|
|
|
{
|
2018-12-21 03:02:06 +01:00
|
|
|
int rc = syscall(SC_munmap, addr, size);
|
2018-10-25 12:06:00 +02:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-10-24 09:48:24 +02:00
|
|
|
}
|
|
|
|
|
2018-10-28 09:57:22 +01:00
|
|
|
int set_mmap_name(void* addr, size_t size, const char* name)
|
|
|
|
{
|
2018-12-21 03:02:06 +01:00
|
|
|
int rc = syscall(SC_set_mmap_name, addr, size, name);
|
2018-10-28 09:57:22 +01:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2019-04-08 23:44:12 +02:00
|
|
|
int shm_open(const char* name, int flags, mode_t mode)
|
|
|
|
{
|
|
|
|
int rc = syscall(SC_shm_open, name, flags, mode);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int shm_unlink(const char* name)
|
|
|
|
{
|
|
|
|
int rc = syscall(SC_unlink, name);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-10-24 09:48:24 +02:00
|
|
|
}
|