minix/kernel/system/do_safememset.c

59 lines
1.7 KiB
C
Raw Normal View History

2012-09-22 22:01:05 +02:00
/* The kernel call implemented in this file:
* m_type: SYS_SAFEMEMSET
*
* The parameters for this kernel call are:
* SMS_DST dst endpoint
* SMS_GID grant id
* SMS_OFFSET offset within grant
* SMS_PATTERN memset pattern byte
* SMS_BYTES bytes from offset
*/
#include <assert.h>
#include <minix/safecopies.h>
#include "kernel/system.h"
#include "kernel/kernel.h"
2012-09-22 22:01:05 +02:00
/*===========================================================================*
* do_safememset *
*===========================================================================*/
int do_safememset(struct proc *caller, message *m_ptr) {
/* Implementation of the do_safememset() kernel call */
/* Extract parameters */
endpoint_t dst_endpt = m_ptr->SMS_DST;
endpoint_t caller_endpt = caller->p_endpoint;
cp_grant_id_t grantid = m_ptr->SMS_GID;
vir_bytes g_offset = m_ptr->SMS_OFFSET;
int pattern = m_ptr->SMS_PATTERN;
size_t len = (size_t)m_ptr->SMS_BYTES;
struct proc *dst_p;
endpoint_t new_granter;
static vir_bytes v_offset;
int r;
if (dst_endpt == NONE || caller_endpt == NONE)
return EFAULT;
if (!(dst_p = endpoint_lookup(dst_endpt)))
return EINVAL;
if (!(priv(dst_p) && priv(dst_p)->s_grant_table)) {
printf("safememset: dst %d has no grant table\n", dst_endpt);
return EINVAL;
}
/* Verify permission exists, memset always requires CPF_WRITE */
r = verify_grant(dst_endpt, caller_endpt, grantid, len, CPF_WRITE,
make vfs & filesystems use failable copying 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
2014-01-16 14:22:13 +01:00
g_offset, &v_offset, &new_granter, NULL);
2012-09-22 22:01:05 +02:00
if (r != OK) {
printf("safememset: grant %d verify failed %d", grantid, r);
return r;
}
return vm_memset(caller, new_granter, v_offset, pattern, len);
}