2009-09-21 16:49:49 +02:00
|
|
|
|
|
|
|
#define _SYSTEM 1
|
|
|
|
|
|
|
|
#include <minix/callnr.h>
|
|
|
|
#include <minix/com.h>
|
|
|
|
#include <minix/config.h>
|
|
|
|
#include <minix/const.h>
|
|
|
|
#include <minix/ds.h>
|
|
|
|
#include <minix/endpoint.h>
|
|
|
|
#include <minix/minlib.h>
|
|
|
|
#include <minix/type.h>
|
|
|
|
#include <minix/ipc.h>
|
|
|
|
#include <minix/sysutil.h>
|
|
|
|
#include <minix/syslib.h>
|
|
|
|
#include <minix/safecopies.h>
|
|
|
|
#include <minix/bitmap.h>
|
|
|
|
#include <minix/vm.h>
|
|
|
|
#include <minix/ds.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <env.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "glo.h"
|
|
|
|
#include "proto.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
struct query_exit_struct {
|
|
|
|
int avail;
|
|
|
|
endpoint_t ep;
|
|
|
|
};
|
|
|
|
static struct query_exit_struct array[NR_PROCS];
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_query_exit *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_query_exit(message *m)
|
2009-09-21 16:49:49 +02:00
|
|
|
{
|
|
|
|
int i, nr;
|
2011-06-01 11:30:58 +02:00
|
|
|
endpoint_t ep = NONE;
|
2009-09-21 16:49:49 +02:00
|
|
|
|
|
|
|
for (i = 0; i < NR_PROCS; i++) {
|
|
|
|
if (!array[i].avail) {
|
|
|
|
array[i].avail = 1;
|
|
|
|
ep = array[i].ep;
|
|
|
|
array[i].ep = 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nr = 0;
|
|
|
|
for (i = 0; i < NR_PROCS; i++) {
|
|
|
|
if (!array[i].avail)
|
|
|
|
nr++;
|
|
|
|
}
|
2014-07-26 13:53:47 +02:00
|
|
|
m->m_lsys_vm_query_exit.ret_pt = ep;
|
|
|
|
m->m_lsys_vm_query_exit.is_more = (nr > 0);
|
2009-09-21 16:49:49 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_notify_sig *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_notify_sig(message *m)
|
2009-09-21 16:49:49 +02:00
|
|
|
{
|
2011-09-08 15:57:03 +02:00
|
|
|
int i, avails = 0;
|
2009-09-21 16:49:49 +02:00
|
|
|
endpoint_t ep = m->VM_NOTIFY_SIG_ENDPOINT;
|
|
|
|
endpoint_t ipc_ep = m->VM_NOTIFY_SIG_IPC;
|
|
|
|
int r;
|
2011-08-05 01:52:03 +02:00
|
|
|
struct vmproc *vmp;
|
|
|
|
int pslot;
|
|
|
|
|
|
|
|
if(vm_isokendpt(ep, &pslot) != OK) return ESRCH;
|
|
|
|
vmp = &vmproc[pslot];
|
|
|
|
|
|
|
|
/* Only record the event if we've been asked to report it. */
|
|
|
|
if(!(vmp->vm_flags & VMF_WATCHEXIT))
|
|
|
|
return OK;
|
2009-09-21 16:49:49 +02:00
|
|
|
|
|
|
|
for (i = 0; i < NR_PROCS; i++) {
|
|
|
|
/* its signal is already here */
|
|
|
|
if (!array[i].avail && array[i].ep == ep)
|
|
|
|
goto out;
|
|
|
|
if (array[i].avail)
|
|
|
|
avails++;
|
|
|
|
}
|
|
|
|
if (!avails) {
|
2011-08-05 01:52:03 +02:00
|
|
|
/* no slot for signals, unlikely */
|
2009-09-21 16:49:49 +02:00
|
|
|
printf("VM: no slot for signals!\n");
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < NR_PROCS; i++) {
|
|
|
|
if (array[i].avail) {
|
|
|
|
array[i].avail = 0;
|
|
|
|
array[i].ep = ep;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
/* only care when IPC server starts up,
|
|
|
|
* and bypass the process to be signal is IPC itself.
|
|
|
|
*/
|
|
|
|
if (ipc_ep != 0 && ep != ipc_ep) {
|
2013-11-01 13:34:14 +01:00
|
|
|
r = ipc_notify(ipc_ep);
|
2009-09-21 16:49:49 +02:00
|
|
|
if (r != OK)
|
2013-11-01 13:34:14 +01:00
|
|
|
printf("VM: ipc_notify error!\n");
|
2009-09-21 16:49:49 +02:00
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2011-08-05 01:52:03 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_watch_exit *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_watch_exit(message *m)
|
2011-08-05 01:52:03 +02:00
|
|
|
{
|
2014-07-26 13:53:50 +02:00
|
|
|
endpoint_t e = m->m_lsys_vm_watch_exit.ep;
|
2011-08-05 01:52:03 +02:00
|
|
|
struct vmproc *vmp;
|
|
|
|
int p;
|
|
|
|
if(vm_isokendpt(e, &p) != OK) return ESRCH;
|
|
|
|
vmp = &vmproc[p];
|
|
|
|
vmp->vm_flags |= VMF_WATCHEXIT;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2009-09-21 16:49:49 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* init_query_exit *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
void init_query_exit(void)
|
2009-09-21 16:49:49 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NR_PROCS; i++) {
|
|
|
|
array[i].avail = 1;
|
|
|
|
array[i].ep = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|