1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 17:08:13 +00:00

Start working on memory-mapped files.

First of all, change sys$mmap to take a struct SC_mmap_params since our
sycsall calling convention can't handle more than 3 arguments.

This exposed a bug in Syscall::invoke() needing to use clobber lists.
It was a bit confusing to debug. :^)
This commit is contained in:
Andreas Kling 2018-11-08 11:37:01 +01:00
parent 41a751c90c
commit fdbd9f1e27
14 changed files with 82 additions and 26 deletions

View file

@ -26,15 +26,17 @@
// FIXME: Only do a single validation for accesses that don't span multiple pages.
// FIXME: Some places pass strlen(arg1) as arg2. This doesn't seem entirely perfect..
#define VALIDATE_USER_READ(b, s) \
#define VALIDATE_USER_READ_WITH_RETURN_TYPE(b, s, ret_type) \
do { \
LinearAddress laddr((dword)(b)); \
if (!validate_user_read(laddr) || !validate_user_read(laddr.offset((s) - 1))) { \
dbgprintf("Bad read address passed to syscall: %p +%u\n", laddr.get(), (s)); \
return -EFAULT; \
return (ret_type)-EFAULT; \
} \
} while(0)
#define VALIDATE_USER_READ(b, s) VALIDATE_USER_READ_WITH_RETURN_TYPE(b, s, int)
#define VALIDATE_USER_WRITE(b, s) \
do { \
LinearAddress laddr((dword)(b)); \
@ -136,15 +138,21 @@ int Process::sys$set_mmap_name(void* addr, size_t size, const char* name)
return 0;
}
void* Process::sys$mmap(void* addr, size_t size)
void* Process::sys$mmap(const Syscall::SC_mmap_params* params)
{
VALIDATE_USER_READ_WITH_RETURN_TYPE(params, sizeof(Syscall::SC_mmap_params), void*);
InterruptDisabler disabler;
// FIXME: Implement mapping at a client-preferred address.
void* addr = (void*)params->addr;
size_t size = params->size;
int prot = params->prot;
int flags = params->flags;
int fd = params->fd;
Unix::off_t offset = params->offset;
// FIXME: Implement mapping at a client-preferred address. Most of the support is already in plcae.
ASSERT(addr == nullptr);
auto* region = allocate_region(LinearAddress(), size, "mmap");
if (!region)
return (void*)-1;
MM.mapRegion(*this, *region);
return (void*)region->linearAddress.get();
}