mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
Kernel: Pass name+length to mmap() and remove SmapDisabler
This commit is contained in:
parent
33025a8049
commit
a47f0c93de
Notes:
sideshowbarker
2024-07-19 10:18:43 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/a47f0c93def
3 changed files with 23 additions and 26 deletions
|
@ -267,22 +267,24 @@ Vector<Region*, 2> Process::split_region_around_range(const Region& source_regio
|
|||
return new_regions;
|
||||
}
|
||||
|
||||
void* Process::sys$mmap(const Syscall::SC_mmap_params* params)
|
||||
void* Process::sys$mmap(const Syscall::SC_mmap_params* user_params)
|
||||
{
|
||||
if (!validate_read(params, sizeof(Syscall::SC_mmap_params)))
|
||||
if (!validate_read_typed(user_params))
|
||||
return (void*)-EFAULT;
|
||||
|
||||
SmapDisabler disabler;
|
||||
void* addr = (void*)params->addr;
|
||||
size_t size = params->size;
|
||||
int prot = params->prot;
|
||||
int flags = params->flags;
|
||||
int fd = params->fd;
|
||||
int offset = params->offset;
|
||||
const char* name = params->name;
|
||||
Syscall::SC_mmap_params params;
|
||||
copy_from_user(¶ms, user_params, sizeof(params));
|
||||
|
||||
if (name && !validate_read_str(name))
|
||||
void* addr = (void*)params.addr;
|
||||
size_t size = params.size;
|
||||
int prot = params.prot;
|
||||
int flags = params.flags;
|
||||
int fd = params.fd;
|
||||
int offset = params.offset;
|
||||
|
||||
if (params.name && !validate_read(params.name, params.name_length))
|
||||
return (void*)-EFAULT;
|
||||
auto name = copy_string_from_user(params.name, params.name_length);
|
||||
|
||||
if (size == 0)
|
||||
return (void*)-EINVAL;
|
||||
|
@ -312,13 +314,13 @@ void* Process::sys$mmap(const Syscall::SC_mmap_params* params)
|
|||
|
||||
if (map_purgeable) {
|
||||
auto vmobject = PurgeableVMObject::create_with_size(size);
|
||||
region = allocate_region_with_vmobject(VirtualAddress((u32)addr), size, vmobject, 0, name ? name : "mmap (purgeable)", prot);
|
||||
region = allocate_region_with_vmobject(VirtualAddress((u32)addr), size, vmobject, 0, !name.is_null() ? name : "mmap (purgeable)", prot);
|
||||
if (!region && (!map_fixed && addr != 0))
|
||||
region = allocate_region_with_vmobject({}, size, vmobject, 0, name ? name : "mmap (purgeable)", prot);
|
||||
region = allocate_region_with_vmobject({}, size, vmobject, 0, !name.is_null() ? name : "mmap (purgeable)", prot);
|
||||
} else if (map_anonymous) {
|
||||
region = allocate_region(VirtualAddress((u32)addr), size, name ? name : "mmap", prot, false);
|
||||
region = allocate_region(VirtualAddress((u32)addr), size, !name.is_null() ? name : "mmap", prot, false);
|
||||
if (!region && (!map_fixed && addr != 0))
|
||||
region = allocate_region({}, size, name ? name : "mmap", prot, false);
|
||||
region = allocate_region({}, size, !name.is_null() ? name : "mmap", prot, false);
|
||||
} else {
|
||||
if (offset < 0)
|
||||
return (void*)-EINVAL;
|
||||
|
@ -346,7 +348,7 @@ void* Process::sys$mmap(const Syscall::SC_mmap_params* params)
|
|||
region->set_shared(true);
|
||||
if (map_stack)
|
||||
region->set_stack(true);
|
||||
if (name)
|
||||
if (!name.is_null())
|
||||
region->set_name(name);
|
||||
return region->vaddr().as_ptr();
|
||||
}
|
||||
|
|
|
@ -196,7 +196,8 @@ struct SC_mmap_params {
|
|||
int32_t flags;
|
||||
int32_t fd;
|
||||
int32_t offset; // FIXME: 64-bit off_t?
|
||||
const char* name { nullptr };
|
||||
const char* name;
|
||||
size_t name_length;
|
||||
};
|
||||
|
||||
struct SC_open_params {
|
||||
|
|
|
@ -8,22 +8,16 @@ extern "C" {
|
|||
|
||||
void* mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset)
|
||||
{
|
||||
Syscall::SC_mmap_params params { (u32)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;
|
||||
return mmap_with_name(addr, size, prot, flags, fd, offset, nullptr);
|
||||
}
|
||||
|
||||
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 { (u32)addr, size, prot, flags, fd, offset, name };
|
||||
Syscall::SC_mmap_params params { (u32)addr, size, prot, flags, fd, offset, name, name ? strlen(name) : 0 };
|
||||
int rc = syscall(SC_mmap, ¶ms);
|
||||
if (rc < 0 && -rc < EMAXERRNO) {
|
||||
errno = -rc;
|
||||
return (void*)-1;
|
||||
return MAP_FAILED;
|
||||
}
|
||||
return (void*)rc;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue