For /dev/mem, map in memory to be copied to memory's own address space
[minix3.git] / kernel / system / do_newmap.c
bloba179f5631a8e1c9693372af7280a0f9f627ce61b
1 /* The kernel call implemented in this file:
2 * m_type: SYS_NEWMAP
4 * The parameters for this kernel call are:
5 * m1_i1: PR_ENDPT (install new map for this process)
6 * m1_p1: PR_MEM_PTR (pointer to the new memory map)
7 */
8 #include "../system.h"
9 #include <minix/endpoint.h>
11 #if USE_NEWMAP
13 /*===========================================================================*
14 * do_newmap *
15 *===========================================================================*/
16 PUBLIC int do_newmap(m_ptr)
17 message *m_ptr; /* pointer to request message */
19 /* Handle sys_newmap(). Fetch the memory map from PM. */
20 register struct proc *rp; /* process whose map is to be loaded */
21 struct mem_map *map_ptr; /* virtual address of map inside caller (PM) */
22 phys_bytes src_phys; /* physical address of map at the PM */
23 int proc;
25 map_ptr = (struct mem_map *) m_ptr->PR_MEM_PTR;
26 if (! isokendpt(m_ptr->PR_ENDPT, &proc)) return(EINVAL);
27 if (iskerneln(proc)) return(EPERM);
28 rp = proc_addr(proc);
30 return newmap(rp, map_ptr);
34 /*===========================================================================*
35 * newmap *
36 *===========================================================================*/
37 PUBLIC int newmap(rp, map_ptr)
38 struct proc *rp; /* process whose map is to be loaded */
39 struct mem_map *map_ptr; /* virtual address of map inside caller (PM) */
41 /* Fetch the memory map from PM. */
42 phys_bytes src_phys; /* physical address of map at the PM */
43 int proc;
45 /* Copy the map from PM. */
46 src_phys = umap_local(proc_addr(who_p), D, (vir_bytes) map_ptr,
47 sizeof(rp->p_memmap));
48 if (src_phys == 0) return(EFAULT);
49 phys_copy(src_phys,vir2phys(rp->p_memmap),
50 (phys_bytes)sizeof(rp->p_memmap));
52 alloc_segments(rp);
54 return(OK);
56 #endif /* USE_NEWMAP */