kernel: kill proc with bogus ipc address
[minix.git] / kernel / system / do_safememset.c
blobcfccec996607ae069c61fe53c102c5192366cfdf
1 /* The kernel call implemented in this file:
2 * m_type: SYS_SAFEMEMSET
4 * The parameters for this kernel call are:
5 * SMS_DST dst endpoint
6 * SMS_GID grant id
7 * SMS_OFFSET offset within grant
8 * SMS_PATTERN memset pattern byte
9 * SMS_BYTES bytes from offset
11 #include <assert.h>
13 #include <minix/safecopies.h>
15 #include "kernel/system.h"
16 #include "kernel.h"
18 /*===========================================================================*
19 * do_safememset *
20 *===========================================================================*/
21 int do_safememset(struct proc *caller, message *m_ptr) {
22 /* Implementation of the do_safememset() kernel call */
24 /* Extract parameters */
25 endpoint_t dst_endpt = m_ptr->SMS_DST;
26 endpoint_t caller_endpt = caller->p_endpoint;
27 cp_grant_id_t grantid = m_ptr->SMS_GID;
28 vir_bytes g_offset = m_ptr->SMS_OFFSET;
29 int pattern = m_ptr->SMS_PATTERN;
30 size_t len = (size_t)m_ptr->SMS_BYTES;
32 struct proc *dst_p;
33 endpoint_t new_granter;
34 static vir_bytes v_offset;
35 int r;
37 if (dst_endpt == NONE || caller_endpt == NONE)
38 return EFAULT;
40 if (!(dst_p = endpoint_lookup(dst_endpt)))
41 return EINVAL;
43 if (!(priv(dst_p) && priv(dst_p)->s_grant_table)) {
44 printf("safememset: dst %d has no grant table\n", dst_endpt);
45 return EINVAL;
48 /* Verify permission exists, memset always requires CPF_WRITE */
49 r = verify_grant(dst_endpt, caller_endpt, grantid, len, CPF_WRITE,
50 g_offset, &v_offset, &new_granter);
52 if (r != OK) {
53 printf("safememset: grant %d verify failed %d", grantid, r);
54 return r;
57 return vm_memset(caller, new_granter, v_offset, pattern, len);