1 /* The kernel call implemented in this file: 2 * m_type: SYS_SAFEMEMSET 3 * 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 10 */ 11 #include <assert.h> 12 13 #include <minix/safecopies.h> 14 15 #include "kernel/system.h" 16 #include "kernel/kernel.h" 17 18 /*===========================================================================* 19 * do_safememset * 20 *===========================================================================*/ 21 int do_safememset(struct proc *caller, message *m_ptr) { 22 /* Implementation of the do_safememset() kernel call */ 23 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; 31 32 struct proc *dst_p; 33 endpoint_t new_granter; 34 static vir_bytes v_offset; 35 int r; 36 37 if (dst_endpt == NONE || caller_endpt == NONE) 38 return EFAULT; 39 40 if (!(dst_p = endpoint_lookup(dst_endpt))) 41 return EINVAL; 42 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; 46 } 47 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, NULL); 51 52 if (r != OK) { 53 printf("safememset: grant %d verify failed %d", grantid, r); 54 return r; 55 } 56 57 return vm_memset(caller, new_granter, v_offset, pattern, len); 58 } 59