don't suspend the process as a side-effect if
[minix.git] / kernel / system / do_vmctl.c
blobf522a20f8f7a35b5397f650c0c738e2bf4f0f7f6
1 /* The kernel call implemented in this file:
2 * m_type: SYS_VMCTL
4 * The parameters for this kernel call are:
5 * SVMCTL_WHO which process
6 * SVMCTL_PARAM set this setting (VMCTL_*)
7 * SVMCTL_VALUE to this value
8 */
10 #include "../system.h"
11 #include "../vm.h"
12 #include "../debug.h"
13 #include <minix/type.h>
14 #include <minix/config.h>
16 /*===========================================================================*
17 * do_vmctl *
18 *===========================================================================*/
19 PUBLIC int do_vmctl(m_ptr)
20 register message *m_ptr; /* pointer to request message */
22 int proc_nr, i;
23 endpoint_t ep = m_ptr->SVMCTL_WHO;
24 struct proc *p, *rp;
26 if(ep == SELF) { ep = m_ptr->m_source; }
28 vm_init();
30 if(!isokendpt(ep, &proc_nr)) {
31 kprintf("do_vmctl: unexpected endpoint %d from VM\n", ep);
32 return EINVAL;
35 p = proc_addr(proc_nr);
37 switch(m_ptr->SVMCTL_PARAM) {
38 case VMCTL_CLEAR_PAGEFAULT:
39 RTS_LOCK_UNSET(p, PAGEFAULT);
40 return OK;
41 case VMCTL_MEMREQ_GET:
42 /* Send VM the information about the memory request. */
43 if(!(rp = vmrequest))
44 return ESRCH;
45 if(!RTS_ISSET(rp, VMREQUEST))
46 minix_panic("do_vmctl: no VMREQUEST set", NO_NUM);
48 /* Reply with request fields. */
49 m_ptr->SVMCTL_MRG_ADDR = (char *) rp->p_vmrequest.start;
50 m_ptr->SVMCTL_MRG_LEN = rp->p_vmrequest.length;
51 m_ptr->SVMCTL_MRG_WRITE = rp->p_vmrequest.writeflag;
52 m_ptr->SVMCTL_MRG_EP = rp->p_vmrequest.who;
53 rp->p_vmrequest.vmresult = VMSUSPEND;
55 /* Remove from request chain. */
56 vmrequest = vmrequest->p_vmrequest.nextrequestor;
58 return OK;
59 case VMCTL_MEMREQ_REPLY:
60 if(!(rp = p->p_vmrequest.requestor))
61 minix_panic("do_vmctl: no requestor set", ep);
62 p->p_vmrequest.requestor = NULL;
63 if(!RTS_ISSET(rp, VMREQUEST))
64 minix_panic("do_vmctl: no VMREQUEST set", ep);
65 if(rp->p_vmrequest.vmresult != VMSUSPEND)
66 minix_panic("do_vmctl: result not VMSUSPEND set",
67 rp->p_vmrequest.vmresult);
68 rp->p_vmrequest.vmresult = m_ptr->SVMCTL_VALUE;
69 if(rp->p_vmrequest.vmresult == VMSUSPEND)
70 minix_panic("VM returned VMSUSPEND?", NO_NUM);
71 if(rp->p_vmrequest.vmresult != OK)
72 kprintf("SYSTEM: VM replied %d to mem request\n",
73 rp->p_vmrequest.vmresult);
75 /* Put on restart chain. */
76 rp->p_vmrequest.nextrestart = vmrestart;
77 vmrestart = rp;
79 #if DEBUG_VMASSERT
80 /* Sanity check. */
81 if(rp->p_vmrequest.vmresult == OK) {
82 if(CHECKRANGE(p,
83 rp->p_vmrequest.start,
84 rp->p_vmrequest.length,
85 rp->p_vmrequest.writeflag) != OK) {
86 kprintf("SYSTEM: request %d:0x%lx-0x%lx, wrflag %d, failed\n",
87 rp->p_endpoint,
88 rp->p_vmrequest.start, rp->p_vmrequest.start + rp->p_vmrequest.length,
89 rp->p_vmrequest.writeflag);
91 minix_panic("SYSTEM: fail but VM said OK", NO_NUM);
94 #endif
95 return OK;
96 #if VM_KERN_NOPAGEZERO
97 case VMCTL_NOPAGEZERO:
98 return OK;
99 #endif
102 /* Try architecture-specific vmctls. */
103 return arch_do_vmctl(m_ptr, p);