1 /* The kernel call implemented in this file:
2 * m_type: SYS_SAFEMEMSET
4 * The parameters for this kernel call are:
7 * SMS_OFFSET offset within grant
8 * SMS_PATTERN memset pattern byte
9 * SMS_BYTES bytes from offset
13 #include <minix/safecopies.h>
15 #include "kernel/system.h"
17 /*===========================================================================*
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
;
32 endpoint_t new_granter
;
33 static vir_bytes v_offset
;
36 if (dst_endpt
== NONE
|| caller_endpt
== NONE
)
39 if (!(dst_p
= endpoint_lookup(dst_endpt
)))
42 if (!(priv(dst_p
) && priv(dst_p
)->s_grant_table
)) {
43 printf("safememset: dst %d has no grant table\n", dst_endpt
);
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
);
52 printf("safememset: grant %d verify failed %d", grantid
, r
);
56 return vm_memset(caller
, new_granter
, v_offset
, pattern
, len
);