Drop main() prototype. Syncs with NetBSD-8
[minix.git] / minix / kernel / system / do_safememset.c
blob9b356051a1b349b963170feb3e17519b5e14d4a5
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"
17 /*===========================================================================*
18 * do_safememset *
19 *===========================================================================*/
20 int do_safememset(struct proc *caller, message *m_ptr) {
21 /* Implementation of the do_safememset() kernel call */
23 /* Extract parameters */
24 endpoint_t dst_endpt = m_ptr->SMS_DST;
25 endpoint_t caller_endpt = caller->p_endpoint;
26 cp_grant_id_t grantid = m_ptr->SMS_GID;
27 vir_bytes g_offset = m_ptr->SMS_OFFSET;
28 int pattern = m_ptr->SMS_PATTERN;
29 size_t len = (size_t)m_ptr->SMS_BYTES;
31 struct proc *dst_p;
32 endpoint_t new_granter;
33 static vir_bytes v_offset;
34 int r;
36 if (dst_endpt == NONE || caller_endpt == NONE)
37 return EFAULT;
39 if (!(dst_p = endpoint_lookup(dst_endpt)))
40 return EINVAL;
42 if (!(priv(dst_p) && priv(dst_p)->s_grant_table)) {
43 printf("safememset: dst %d has no grant table\n", dst_endpt);
44 return EINVAL;
47 /* Verify permission exists, memset always requires CPF_WRITE */
48 r = verify_grant(dst_endpt, caller_endpt, grantid, len, CPF_WRITE,
49 g_offset, &v_offset, &new_granter, NULL);
51 if (r != OK) {
52 printf("safememset: grant %d verify failed %d", grantid, r);
53 return r;
56 return vm_memset(caller, new_granter, v_offset, pattern, len);