565f13088f
Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
92 lines
2.1 KiB
C
92 lines
2.1 KiB
C
#define _SYSTEM 1
|
|
|
|
#include <minix/type.h>
|
|
#include <minix/const.h>
|
|
#include <sys/param.h>
|
|
#include <assert.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <libexec.h>
|
|
#include <string.h>
|
|
#include <assert.h>
|
|
#include <minix/ipc.h>
|
|
#include <minix/com.h>
|
|
#include <minix/callnr.h>
|
|
#include <minix/vm.h>
|
|
#include <minix/ipc.h>
|
|
#include <minix/syslib.h>
|
|
#include <sys/mman.h>
|
|
#include <machine/elf.h>
|
|
|
|
int libexec_alloc_mmap_prealloc_junk(struct exec_info *execi, vir_bytes vaddr, size_t len)
|
|
{
|
|
if(minix_mmap_for(execi->proc_e, (void *) vaddr, len,
|
|
PROT_READ|PROT_WRITE|PROT_EXEC,
|
|
MAP_ANON|MAP_PREALLOC|MAP_UNINITIALIZED|MAP_FIXED, -1, 0) == MAP_FAILED) {
|
|
return ENOMEM;
|
|
}
|
|
|
|
return OK;
|
|
}
|
|
|
|
int libexec_alloc_mmap_prealloc_cleared(struct exec_info *execi, vir_bytes vaddr, size_t len)
|
|
{
|
|
if(minix_mmap_for(execi->proc_e, (void *) vaddr, len,
|
|
PROT_READ|PROT_WRITE|PROT_EXEC,
|
|
MAP_ANON|MAP_PREALLOC|MAP_FIXED, -1, 0) == MAP_FAILED) {
|
|
return ENOMEM;
|
|
}
|
|
|
|
return OK;
|
|
}
|
|
|
|
int libexec_alloc_mmap_ondemand(struct exec_info *execi, vir_bytes vaddr, size_t len)
|
|
{
|
|
if(minix_mmap_for(execi->proc_e, (void *) vaddr, len,
|
|
PROT_READ|PROT_WRITE|PROT_EXEC,
|
|
MAP_ANON|MAP_FIXED, -1, 0) == MAP_FAILED) {
|
|
return ENOMEM;
|
|
}
|
|
|
|
return OK;
|
|
}
|
|
|
|
int libexec_clearproc_vm_procctl(struct exec_info *execi)
|
|
{
|
|
return vm_procctl_clear(execi->proc_e);
|
|
}
|
|
|
|
int libexec_clear_sys_memset(struct exec_info *execi, vir_bytes vaddr, size_t len)
|
|
{
|
|
return sys_memset(execi->proc_e, 0, vaddr, len);
|
|
}
|
|
|
|
int libexec_copy_memcpy(struct exec_info *execi,
|
|
off_t off, vir_bytes vaddr, size_t len)
|
|
{
|
|
assert(off + len <= execi->hdr_len);
|
|
memcpy((char *) vaddr, (char *) execi->hdr + off, len);
|
|
return OK;
|
|
}
|
|
|
|
int libexec_clear_memset(struct exec_info *execi, vir_bytes vaddr, size_t len)
|
|
{
|
|
memset((char *) vaddr, 0, len);
|
|
return OK;
|
|
}
|
|
|
|
int libexec_pm_newexec(endpoint_t proc_e, struct exec_info *e)
|
|
{
|
|
int r;
|
|
message m;
|
|
|
|
memset(&m, 0, sizeof(m));
|
|
m.m_type = PM_EXEC_NEW;
|
|
m.PM_EXEC_NEW_ENDPT = proc_e;
|
|
m.PM_EXEC_NEW_PTR = (char *)e;
|
|
if ((r = ipc_sendrec(PM_PROC_NR, &m)) != OK) return(r);
|
|
|
|
e->allow_setuid = !!m.PM_EXEC_NEW_SUID;
|
|
|
|
return(m.m_type);
|
|
}
|