2005-05-13 10:57:08 +02:00
|
|
|
/* This file contains the main program of the process manager and some related
|
2005-05-03 17:35:52 +02:00
|
|
|
* procedures. When MINIX starts up, the kernel runs for a little while,
|
2005-05-13 10:57:08 +02:00
|
|
|
* initializing itself and its tasks, and then it runs PM and FS. Both PM
|
2005-06-17 11:10:30 +02:00
|
|
|
* and FS initialize themselves as far as they can. PM asks the kernel for
|
|
|
|
* all free memory and starts serving requests.
|
2005-05-03 17:35:52 +02:00
|
|
|
*
|
|
|
|
* The entry points into this file are:
|
2005-05-13 10:57:08 +02:00
|
|
|
* main: starts PM running
|
|
|
|
* setreply: set the reply to be sent to process making an PM system call
|
2005-05-03 17:35:52 +02:00
|
|
|
*/
|
|
|
|
|
2005-05-13 10:57:08 +02:00
|
|
|
#include "pm.h"
|
|
|
|
#include <minix/keymap.h>
|
2005-05-03 17:35:52 +02:00
|
|
|
#include <minix/callnr.h>
|
|
|
|
#include <minix/com.h>
|
2007-08-07 14:28:42 +02:00
|
|
|
#include <minix/ds.h>
|
|
|
|
#include <minix/type.h>
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
#include <minix/endpoint.h>
|
2006-05-19 14:19:37 +02:00
|
|
|
#include <minix/minlib.h>
|
2007-02-16 16:55:20 +01:00
|
|
|
#include <minix/type.h>
|
2008-11-19 13:26:10 +01:00
|
|
|
#include <minix/vm.h>
|
2005-05-03 17:35:52 +02:00
|
|
|
#include <signal.h>
|
2005-06-17 11:10:30 +02:00
|
|
|
#include <stdlib.h>
|
2005-05-03 17:35:52 +02:00
|
|
|
#include <fcntl.h>
|
2005-08-22 17:14:11 +02:00
|
|
|
#include <sys/resource.h>
|
2006-05-19 14:19:37 +02:00
|
|
|
#include <sys/utsname.h>
|
2005-05-13 10:57:08 +02:00
|
|
|
#include <string.h>
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
#include <archconst.h>
|
|
|
|
#include <archtypes.h>
|
2007-02-16 16:55:20 +01:00
|
|
|
#include <env.h>
|
2005-05-03 17:35:52 +02:00
|
|
|
#include "mproc.h"
|
|
|
|
#include "param.h"
|
|
|
|
|
2005-05-31 11:50:51 +02:00
|
|
|
#include "../../kernel/const.h"
|
2005-07-14 17:16:12 +02:00
|
|
|
#include "../../kernel/config.h"
|
2005-08-22 17:14:11 +02:00
|
|
|
#include "../../kernel/proc.h"
|
2005-05-13 10:57:08 +02:00
|
|
|
|
2006-07-10 14:44:43 +02:00
|
|
|
#if ENABLE_SYSCALL_STATS
|
|
|
|
EXTERN unsigned long calls_stats[NCALLS];
|
|
|
|
#endif
|
|
|
|
|
2005-05-03 17:35:52 +02:00
|
|
|
FORWARD _PROTOTYPE( void get_work, (void) );
|
2005-05-13 10:57:08 +02:00
|
|
|
FORWARD _PROTOTYPE( void pm_init, (void) );
|
2005-09-11 18:45:46 +02:00
|
|
|
FORWARD _PROTOTYPE( int get_nice_value, (int queue) );
|
2006-05-11 16:57:23 +02:00
|
|
|
FORWARD _PROTOTYPE( void send_work, (void) );
|
|
|
|
FORWARD _PROTOTYPE( void handle_fs_reply, (message *m_ptr) );
|
2005-05-03 17:35:52 +02:00
|
|
|
|
|
|
|
#define click_to_round_k(n) \
|
|
|
|
((unsigned) ((((unsigned long) (n) << CLICK_SHIFT) + 512) / 1024))
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* main *
|
|
|
|
*===========================================================================*/
|
2005-08-25 14:05:09 +02:00
|
|
|
PUBLIC int main()
|
2005-05-03 17:35:52 +02:00
|
|
|
{
|
2005-05-13 10:57:08 +02:00
|
|
|
/* Main routine of the process manager. */
|
2005-05-27 15:10:58 +02:00
|
|
|
int result, s, proc_nr;
|
2005-05-03 17:35:52 +02:00
|
|
|
struct mproc *rmp;
|
2005-07-19 14:11:11 +02:00
|
|
|
sigset_t sigset;
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2005-05-13 10:57:08 +02:00
|
|
|
pm_init(); /* initialize process manager tables */
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2005-05-13 10:57:08 +02:00
|
|
|
/* This is PM's main loop- get work and do it, forever and forever. */
|
2005-05-03 17:35:52 +02:00
|
|
|
while (TRUE) {
|
2005-05-13 10:57:08 +02:00
|
|
|
get_work(); /* wait for an PM system call */
|
2005-05-03 17:35:52 +02:00
|
|
|
|
|
|
|
/* Check for system notifications first. Special cases. */
|
2006-05-11 16:57:23 +02:00
|
|
|
switch(call_nr)
|
|
|
|
{
|
|
|
|
case SYN_ALARM:
|
2005-08-05 12:45:54 +02:00
|
|
|
pm_expire_timers(m_in.NOTIFY_TIMESTAMP);
|
2005-07-14 17:16:12 +02:00
|
|
|
result = SUSPEND; /* don't reply */
|
2006-05-11 16:57:23 +02:00
|
|
|
break;
|
|
|
|
case SYS_SIG: /* signals pending */
|
2005-07-19 14:11:11 +02:00
|
|
|
sigset = m_in.NOTIFY_ARG;
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
if (sigismember(&sigset, SIGKSIG)) {
|
|
|
|
(void) ksig_pending();
|
|
|
|
}
|
2005-05-03 17:35:52 +02:00
|
|
|
result = SUSPEND; /* don't reply */
|
2006-05-11 16:57:23 +02:00
|
|
|
break;
|
|
|
|
case PM_GET_WORK:
|
|
|
|
if (who_e == FS_PROC_NR)
|
|
|
|
{
|
|
|
|
send_work();
|
|
|
|
result= SUSPEND; /* don't reply */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result= ENOSYS;
|
|
|
|
break;
|
|
|
|
case PM_EXIT_REPLY:
|
|
|
|
case PM_REBOOT_REPLY:
|
|
|
|
case PM_EXEC_REPLY:
|
|
|
|
case PM_CORE_REPLY:
|
|
|
|
case PM_EXIT_REPLY_TR:
|
|
|
|
if (who_e == FS_PROC_NR)
|
|
|
|
{
|
|
|
|
handle_fs_reply(&m_in);
|
|
|
|
result= SUSPEND; /* don't reply */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result= ENOSYS;
|
|
|
|
break;
|
2006-05-19 14:19:37 +02:00
|
|
|
case ALLOCMEM:
|
|
|
|
result= do_allocmem();
|
|
|
|
break;
|
|
|
|
case FORK_NB:
|
|
|
|
result= do_fork_nb();
|
|
|
|
break;
|
|
|
|
case EXEC_NEWMEM:
|
|
|
|
result= exec_newmem();
|
|
|
|
break;
|
|
|
|
case EXEC_RESTART:
|
|
|
|
result= do_execrestart();
|
|
|
|
break;
|
|
|
|
case PROCSTAT:
|
|
|
|
result= do_procstat();
|
|
|
|
break;
|
|
|
|
case GETPROCNR:
|
|
|
|
result= do_getprocnr();
|
|
|
|
break;
|
2007-04-27 14:21:06 +02:00
|
|
|
case GETPUID:
|
|
|
|
result= do_getpuid();
|
|
|
|
break;
|
2006-05-11 16:57:23 +02:00
|
|
|
default:
|
|
|
|
/* Else, if the system call number is valid, perform the
|
|
|
|
* call.
|
|
|
|
*/
|
|
|
|
if ((unsigned) call_nr >= NCALLS) {
|
|
|
|
result = ENOSYS;
|
|
|
|
} else {
|
2006-07-10 14:44:43 +02:00
|
|
|
#if ENABLE_SYSCALL_STATS
|
|
|
|
calls_stats[call_nr]++;
|
|
|
|
#endif
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2006-05-11 16:57:23 +02:00
|
|
|
result = (*call_vec[call_nr])();
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2006-05-11 16:57:23 +02:00
|
|
|
}
|
|
|
|
break;
|
2005-05-03 17:35:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Send the results back to the user to indicate completion. */
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
if (result != SUSPEND) setreply(who_p, result);
|
2005-05-03 17:35:52 +02:00
|
|
|
|
|
|
|
/* Send out all pending reply messages, including the answer to
|
2008-11-19 13:26:10 +01:00
|
|
|
* the call just made above.
|
2005-05-03 17:35:52 +02:00
|
|
|
*/
|
|
|
|
for (proc_nr=0, rmp=mproc; proc_nr < NR_PROCS; proc_nr++, rmp++) {
|
2005-07-04 17:20:46 +02:00
|
|
|
/* In the meantime, the process may have been killed by a
|
|
|
|
* signal (e.g. if a lethal pending signal was unblocked)
|
|
|
|
* without the PM realizing it. If the slot is no longer in
|
|
|
|
* use or just a zombie, don't try to reply.
|
|
|
|
*/
|
2008-11-19 13:26:10 +01:00
|
|
|
if ((rmp->mp_flags & (REPLY | IN_USE | ZOMBIE)) ==
|
2005-07-04 17:20:46 +02:00
|
|
|
(REPLY | IN_USE)) {
|
2008-02-21 17:33:34 +01:00
|
|
|
s=sendnb(rmp->mp_endpoint, &rmp->mp_reply);
|
|
|
|
if (s != OK) {
|
|
|
|
printf("PM can't reply to %d (%s): %d\n",
|
|
|
|
rmp->mp_endpoint, rmp->mp_name, s);
|
2005-05-27 15:10:58 +02:00
|
|
|
}
|
2005-05-03 17:35:52 +02:00
|
|
|
rmp->mp_flags &= ~REPLY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-08-25 14:05:09 +02:00
|
|
|
return(OK);
|
2005-05-03 17:35:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* get_work *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void get_work()
|
|
|
|
{
|
|
|
|
/* Wait for the next message and extract useful information from it. */
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
if (receive(ANY, &m_in) != OK)
|
|
|
|
panic(__FILE__,"PM receive error", NO_NUM);
|
|
|
|
who_e = m_in.m_source; /* who sent the message */
|
|
|
|
if(pm_isokendpt(who_e, &who_p) != OK)
|
|
|
|
panic(__FILE__, "PM got message from invalid endpoint", who_e);
|
2005-05-03 17:35:52 +02:00
|
|
|
call_nr = m_in.m_type; /* system call number */
|
|
|
|
|
2005-05-13 10:57:08 +02:00
|
|
|
/* Process slot of caller. Misuse PM's own process slot if the kernel is
|
2005-07-19 14:11:11 +02:00
|
|
|
* calling. This can happen in case of synchronous alarms (CLOCK) or or
|
|
|
|
* event like pending kernel signals (SYSTEM).
|
2005-05-03 17:35:52 +02:00
|
|
|
*/
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
mp = &mproc[who_p < 0 ? PM_PROC_NR : who_p];
|
|
|
|
if(who_p >= 0 && mp->mp_endpoint != who_e) {
|
|
|
|
panic(__FILE__, "PM endpoint number out of sync with source",
|
|
|
|
mp->mp_endpoint);
|
|
|
|
}
|
2005-05-03 17:35:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* setreply *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void setreply(proc_nr, result)
|
|
|
|
int proc_nr; /* process to reply to */
|
2005-05-13 10:57:08 +02:00
|
|
|
int result; /* result of call (usually OK or error #) */
|
2005-05-03 17:35:52 +02:00
|
|
|
{
|
|
|
|
/* Fill in a reply message to be sent later to a user process. System calls
|
|
|
|
* may occasionally fill in other fields, this is only for the main return
|
|
|
|
* value, and for setting the "must send reply" flag.
|
|
|
|
*/
|
|
|
|
register struct mproc *rmp = &mproc[proc_nr];
|
|
|
|
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
if(proc_nr < 0 || proc_nr >= NR_PROCS)
|
|
|
|
panic(__FILE__,"setreply arg out of range", proc_nr);
|
|
|
|
|
2005-05-03 17:35:52 +02:00
|
|
|
rmp->mp_reply.reply_res = result;
|
|
|
|
rmp->mp_flags |= REPLY; /* reply pending */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
2005-05-13 10:57:08 +02:00
|
|
|
* pm_init *
|
2005-05-03 17:35:52 +02:00
|
|
|
*===========================================================================*/
|
2005-05-13 10:57:08 +02:00
|
|
|
PRIVATE void pm_init()
|
2005-05-03 17:35:52 +02:00
|
|
|
{
|
2008-11-19 13:26:10 +01:00
|
|
|
int failed = 0;
|
|
|
|
int f = 0;
|
2005-08-16 13:37:33 +02:00
|
|
|
/* Initialize the process manager.
|
|
|
|
* Memory use info is collected from the boot monitor, the kernel, and
|
|
|
|
* all processes compiled into the system image. Initially this information
|
|
|
|
* is put into an array mem_chunks. Elements of mem_chunks are struct memory,
|
|
|
|
* and hold base, size pairs in units of clicks. This array is small, there
|
|
|
|
* should be no more than 8 chunks. After the array of chunks has been built
|
|
|
|
* the contents are used to initialize the hole list. Space for the hole list
|
|
|
|
* is reserved as an array with twice as many elements as the maximum number
|
|
|
|
* of processes allowed. It is managed as a linked list, and elements of the
|
|
|
|
* array are struct hole, which, in addition to storage for a base and size in
|
|
|
|
* click units also contain space for a link, a pointer to another element.
|
|
|
|
*/
|
2005-08-25 14:05:09 +02:00
|
|
|
int s;
|
2005-07-29 17:00:49 +02:00
|
|
|
static struct boot_image image[NR_BOOT_PROCS];
|
|
|
|
register struct boot_image *ip;
|
2005-05-03 17:35:52 +02:00
|
|
|
static char core_sigs[] = { SIGQUIT, SIGILL, SIGTRAP, SIGABRT,
|
|
|
|
SIGEMT, SIGFPE, SIGUSR1, SIGSEGV, SIGUSR2 };
|
2006-01-30 17:27:49 +01:00
|
|
|
static char ign_sigs[] = { SIGCHLD, SIGWINCH, SIGCONT };
|
2005-10-12 17:07:38 +02:00
|
|
|
static char mess_sigs[] = { SIGTERM, SIGHUP, SIGABRT, SIGQUIT };
|
2005-05-03 17:35:52 +02:00
|
|
|
register struct mproc *rmp;
|
|
|
|
register char *sig_ptr;
|
|
|
|
message mess;
|
|
|
|
|
2005-07-14 17:16:12 +02:00
|
|
|
/* Initialize process table, including timers. */
|
|
|
|
for (rmp=&mproc[0]; rmp<&mproc[NR_PROCS]; rmp++) {
|
|
|
|
tmr_inittimer(&rmp->mp_timer);
|
2006-05-11 16:57:23 +02:00
|
|
|
|
|
|
|
rmp->mp_fs_call= PM_IDLE;
|
2006-05-15 14:06:19 +02:00
|
|
|
rmp->mp_fs_call2= PM_IDLE;
|
2005-07-14 17:16:12 +02:00
|
|
|
}
|
|
|
|
|
2005-05-03 17:35:52 +02:00
|
|
|
/* Build the set of signals which cause core dumps, and the set of signals
|
|
|
|
* that are by default ignored.
|
|
|
|
*/
|
|
|
|
sigemptyset(&core_sset);
|
|
|
|
for (sig_ptr = core_sigs; sig_ptr < core_sigs+sizeof(core_sigs); sig_ptr++)
|
|
|
|
sigaddset(&core_sset, *sig_ptr);
|
|
|
|
sigemptyset(&ign_sset);
|
|
|
|
for (sig_ptr = ign_sigs; sig_ptr < ign_sigs+sizeof(ign_sigs); sig_ptr++)
|
|
|
|
sigaddset(&ign_sset, *sig_ptr);
|
|
|
|
|
2005-06-17 11:10:30 +02:00
|
|
|
/* Obtain a copy of the boot monitor parameters and the kernel info struct.
|
|
|
|
* Parse the list of free memory chunks. This list is what the boot monitor
|
|
|
|
* reported, but it must be corrected for the kernel and system processes.
|
|
|
|
*/
|
|
|
|
if ((s=sys_getmonparams(monitor_params, sizeof(monitor_params))) != OK)
|
|
|
|
panic(__FILE__,"get monitor params failed",s);
|
|
|
|
if ((s=sys_getkinfo(&kinfo)) != OK)
|
|
|
|
panic(__FILE__,"get kernel info failed",s);
|
|
|
|
|
|
|
|
/* Initialize PM's process table. Request a copy of the system image table
|
|
|
|
* that is defined at the kernel level to see which slots to fill in.
|
2005-05-03 17:35:52 +02:00
|
|
|
*/
|
2005-06-24 18:21:21 +02:00
|
|
|
if (OK != (s=sys_getimage(image)))
|
2005-08-05 12:45:54 +02:00
|
|
|
panic(__FILE__,"couldn't get image table: %d\n", s);
|
2005-05-13 10:57:08 +02:00
|
|
|
procs_in_use = 0; /* start populating table */
|
2008-11-19 13:26:10 +01:00
|
|
|
for (ip = &image[0]; ip < &image[NR_BOOT_PROCS]; ip++) {
|
2005-05-13 10:57:08 +02:00
|
|
|
if (ip->proc_nr >= 0) { /* task have negative nrs */
|
|
|
|
procs_in_use += 1; /* found user process */
|
|
|
|
|
2005-06-17 11:10:30 +02:00
|
|
|
/* Set process details found in the image table. */
|
|
|
|
rmp = &mproc[ip->proc_nr];
|
2005-05-13 10:57:08 +02:00
|
|
|
strncpy(rmp->mp_name, ip->proc_name, PROC_NAME_LEN);
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
2005-08-23 13:31:32 +02:00
|
|
|
rmp->mp_parent = RS_PROC_NR;
|
2008-11-19 13:26:10 +01:00
|
|
|
#endif
|
2005-08-22 17:14:11 +02:00
|
|
|
rmp->mp_nice = get_nice_value(ip->priority);
|
2005-10-12 17:07:38 +02:00
|
|
|
sigemptyset(&rmp->mp_sig2mess);
|
|
|
|
sigemptyset(&rmp->mp_ignore);
|
|
|
|
sigemptyset(&rmp->mp_sigmask);
|
|
|
|
sigemptyset(&rmp->mp_catch);
|
2005-07-19 14:11:11 +02:00
|
|
|
if (ip->proc_nr == INIT_PROC_NR) { /* user process */
|
2006-02-03 15:54:20 +01:00
|
|
|
rmp->mp_procgrp = rmp->mp_pid = INIT_PID;
|
2005-07-19 14:11:11 +02:00
|
|
|
rmp->mp_flags |= IN_USE;
|
|
|
|
}
|
|
|
|
else { /* system process */
|
|
|
|
rmp->mp_pid = get_free_pid();
|
2008-11-19 13:26:10 +01:00
|
|
|
rmp->mp_flags |= IN_USE | PRIV_PROC;
|
2005-10-12 17:07:38 +02:00
|
|
|
for (sig_ptr = mess_sigs;
|
|
|
|
sig_ptr < mess_sigs+sizeof(mess_sigs);
|
|
|
|
sig_ptr++)
|
|
|
|
sigaddset(&rmp->mp_sig2mess, *sig_ptr);
|
2005-07-19 14:11:11 +02:00
|
|
|
}
|
2005-05-13 10:57:08 +02:00
|
|
|
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
/* Get kernel endpoint identifier. */
|
|
|
|
rmp->mp_endpoint = ip->endpoint;
|
|
|
|
|
2005-05-13 10:57:08 +02:00
|
|
|
/* Tell FS about this system process. */
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
mess.PR_SLOT = ip->proc_nr;
|
2005-05-13 10:57:08 +02:00
|
|
|
mess.PR_PID = rmp->mp_pid;
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
mess.PR_ENDPT = rmp->mp_endpoint;
|
2005-05-13 10:57:08 +02:00
|
|
|
if (OK != (s=send(FS_PROC_NR, &mess)))
|
2005-08-05 12:45:54 +02:00
|
|
|
panic(__FILE__,"can't sync up with FS", s);
|
2007-08-07 14:28:42 +02:00
|
|
|
|
|
|
|
/* Register proces with ds */
|
|
|
|
s= ds_publish_u32(rmp->mp_name, rmp->mp_endpoint);
|
|
|
|
if (s != OK)
|
2008-11-19 13:26:10 +01:00
|
|
|
failed++;
|
2005-05-13 10:57:08 +02:00
|
|
|
}
|
2005-05-03 17:35:52 +02:00
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
if(failed > 0)
|
|
|
|
printf("PM: failed to register %d/%d boot processes\n",
|
|
|
|
failed, NR_BOOT_PROCS);
|
|
|
|
|
2005-10-12 17:07:38 +02:00
|
|
|
/* Override some details. INIT, PM, FS and RS are somewhat special. */
|
|
|
|
mproc[PM_PROC_NR].mp_pid = PM_PID; /* PM has magic pid */
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
2005-10-12 17:07:38 +02:00
|
|
|
mproc[RS_PROC_NR].mp_parent = INIT_PROC_NR; /* INIT is root */
|
2008-11-19 13:26:10 +01:00
|
|
|
#endif
|
2005-10-12 17:07:38 +02:00
|
|
|
sigfillset(&mproc[PM_PROC_NR].mp_ignore); /* guard against signals */
|
2005-06-24 18:21:21 +02:00
|
|
|
|
2005-06-17 11:10:30 +02:00
|
|
|
/* Tell FS that no more system processes follow and synchronize. */
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
mess.PR_ENDPT = NONE;
|
2005-05-13 10:57:08 +02:00
|
|
|
if (sendrec(FS_PROC_NR, &mess) != OK || mess.m_type != OK)
|
2005-08-05 12:45:54 +02:00
|
|
|
panic(__FILE__,"can't sync up with FS", NO_NUM);
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2006-05-19 14:19:37 +02:00
|
|
|
#if (CHIP == INTEL)
|
2008-11-19 13:26:10 +01:00
|
|
|
uts_val.machine[0] = 'i';
|
|
|
|
strcpy(uts_val.machine + 1, itoa(getprocessor()));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(f > 0) printf("PM: failed to register %d processes with DS.\n", f);
|
2008-12-11 15:49:17 +01:00
|
|
|
|
|
|
|
system_hz = sys_hz();
|
2005-06-17 11:10:30 +02:00
|
|
|
}
|
|
|
|
|
2005-09-11 18:45:46 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* get_nice_value *
|
|
|
|
*===========================================================================*/
|
2005-08-22 17:14:11 +02:00
|
|
|
PRIVATE int get_nice_value(queue)
|
|
|
|
int queue; /* store mem chunks here */
|
|
|
|
{
|
|
|
|
/* Processes in the boot image have a priority assigned. The PM doesn't know
|
|
|
|
* about priorities, but uses 'nice' values instead. The priority is between
|
|
|
|
* MIN_USER_Q and MAX_USER_Q. We have to scale between PRIO_MIN and PRIO_MAX.
|
|
|
|
*/
|
|
|
|
int nice_val = (queue - USER_Q) * (PRIO_MAX-PRIO_MIN+1) /
|
|
|
|
(MIN_USER_Q-MAX_USER_Q+1);
|
|
|
|
if (nice_val > PRIO_MAX) nice_val = PRIO_MAX; /* shouldn't happen */
|
|
|
|
if (nice_val < PRIO_MIN) nice_val = PRIO_MIN; /* shouldn't happen */
|
|
|
|
return nice_val;
|
|
|
|
}
|
2005-06-17 11:10:30 +02:00
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
void checkme(char *str, int line)
|
2005-09-30 14:56:00 +02:00
|
|
|
{
|
2008-11-19 13:26:10 +01:00
|
|
|
struct mproc *trmp;
|
|
|
|
int boned = 0;
|
|
|
|
int proc_nr;
|
|
|
|
for (proc_nr=0, trmp=mproc; proc_nr < NR_PROCS; proc_nr++, trmp++) {
|
|
|
|
if ((trmp->mp_flags & (REPLY | IN_USE | ZOMBIE)) ==
|
|
|
|
(REPLY | IN_USE)) {
|
|
|
|
int tp;
|
|
|
|
if(pm_isokendpt(trmp->mp_endpoint, &tp) != OK) {
|
|
|
|
printf("PM: %s:%d: reply %d to %s is bogus endpoint %d after call %d by %d\n",
|
|
|
|
str, line, trmp->mp_reply.m_type,
|
|
|
|
trmp->mp_name, trmp->mp_endpoint, call_nr, who_e);
|
|
|
|
boned=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(boned) panic(__FILE__, "corrupt mp_endpoint?", NO_NUM);
|
2005-09-30 14:56:00 +02:00
|
|
|
}
|
|
|
|
}
|
2006-05-11 16:57:23 +02:00
|
|
|
|
|
|
|
/*=========================================================================*
|
|
|
|
* send_work *
|
|
|
|
*=========================================================================*/
|
|
|
|
PRIVATE void send_work()
|
|
|
|
{
|
|
|
|
int r, call;
|
|
|
|
struct mproc *rmp;
|
|
|
|
message m;
|
|
|
|
|
|
|
|
m.m_type= PM_IDLE;
|
|
|
|
for (rmp= mproc; rmp < &mproc[NR_PROCS]; rmp++)
|
|
|
|
{
|
|
|
|
call= rmp->mp_fs_call;
|
2006-05-15 14:06:19 +02:00
|
|
|
if (call == PM_IDLE)
|
|
|
|
call= rmp->mp_fs_call2;
|
2006-05-11 16:57:23 +02:00
|
|
|
if (call == PM_IDLE)
|
|
|
|
continue;
|
|
|
|
switch(call)
|
|
|
|
{
|
|
|
|
case PM_SETSID:
|
|
|
|
m.m_type= call;
|
|
|
|
m.PM_SETSID_PROC= rmp->mp_endpoint;
|
|
|
|
|
|
|
|
/* FS does not reply */
|
|
|
|
rmp->mp_fs_call= PM_IDLE;
|
|
|
|
|
|
|
|
/* Wakeup the original caller */
|
|
|
|
setreply(rmp-mproc, rmp->mp_procgrp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PM_SETGID:
|
|
|
|
m.m_type= call;
|
|
|
|
m.PM_SETGID_PROC= rmp->mp_endpoint;
|
|
|
|
m.PM_SETGID_EGID= rmp->mp_effgid;
|
|
|
|
m.PM_SETGID_RGID= rmp->mp_realgid;
|
|
|
|
|
|
|
|
/* FS does not reply */
|
|
|
|
rmp->mp_fs_call= PM_IDLE;
|
|
|
|
|
|
|
|
/* Wakeup the original caller */
|
|
|
|
setreply(rmp-mproc, OK);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PM_SETUID:
|
|
|
|
m.m_type= call;
|
|
|
|
m.PM_SETUID_PROC= rmp->mp_endpoint;
|
|
|
|
m.PM_SETUID_EGID= rmp->mp_effuid;
|
|
|
|
m.PM_SETUID_RGID= rmp->mp_realuid;
|
|
|
|
|
|
|
|
/* FS does not reply */
|
|
|
|
rmp->mp_fs_call= PM_IDLE;
|
|
|
|
|
|
|
|
/* Wakeup the original caller */
|
|
|
|
setreply(rmp-mproc, OK);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PM_FORK:
|
|
|
|
{
|
2007-02-16 16:55:20 +01:00
|
|
|
int parent_p;
|
2006-05-11 16:57:23 +02:00
|
|
|
struct mproc *parent_mp;
|
|
|
|
|
|
|
|
parent_p = rmp->mp_parent;
|
|
|
|
parent_mp = &mproc[parent_p];
|
|
|
|
|
|
|
|
m.m_type= call;
|
|
|
|
m.PM_FORK_PPROC= parent_mp->mp_endpoint;
|
|
|
|
m.PM_FORK_CPROC= rmp->mp_endpoint;
|
|
|
|
m.PM_FORK_CPID= rmp->mp_pid;
|
|
|
|
|
|
|
|
/* FS does not reply */
|
|
|
|
rmp->mp_fs_call= PM_IDLE;
|
|
|
|
|
|
|
|
/* Wakeup the newly created process */
|
|
|
|
setreply(rmp-mproc, OK);
|
|
|
|
|
|
|
|
/* Wakeup the parent */
|
|
|
|
setreply(parent_mp-mproc, rmp->mp_pid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PM_EXIT:
|
|
|
|
case PM_EXIT_TR:
|
|
|
|
m.m_type= call;
|
|
|
|
m.PM_EXIT_PROC= rmp->mp_endpoint;
|
|
|
|
|
|
|
|
/* Mark the process as busy */
|
|
|
|
rmp->mp_fs_call= PM_BUSY;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PM_UNPAUSE:
|
2006-05-15 14:06:19 +02:00
|
|
|
m.m_type= call;
|
|
|
|
m.PM_UNPAUSE_PROC= rmp->mp_endpoint;
|
|
|
|
|
|
|
|
/* FS does not reply */
|
|
|
|
rmp->mp_fs_call2= PM_IDLE;
|
|
|
|
|
|
|
|
/* Ask the kernel to deliver the signal */
|
|
|
|
r= sys_sigsend(rmp->mp_endpoint,
|
|
|
|
&rmp->mp_sigmsg);
|
2008-11-19 13:26:10 +01:00
|
|
|
if (r != OK) {
|
|
|
|
#if 0
|
2006-05-15 14:06:19 +02:00
|
|
|
panic(__FILE__,"sys_sigsend failed",r);
|
2008-11-19 13:26:10 +01:00
|
|
|
#else
|
|
|
|
printf("PM: PM_UNPAUSE: sys_sigsend failed to %d: %d\n",
|
|
|
|
rmp->mp_endpoint, r);
|
|
|
|
#endif
|
|
|
|
}
|
2006-05-15 14:06:19 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2006-05-11 16:57:23 +02:00
|
|
|
case PM_UNPAUSE_TR:
|
|
|
|
m.m_type= call;
|
|
|
|
m.PM_UNPAUSE_PROC= rmp->mp_endpoint;
|
|
|
|
|
|
|
|
/* FS does not reply */
|
|
|
|
rmp->mp_fs_call= PM_IDLE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PM_EXEC:
|
|
|
|
m.m_type= call;
|
|
|
|
m.PM_EXEC_PROC= rmp->mp_endpoint;
|
|
|
|
m.PM_EXEC_PATH= rmp->mp_exec_path;
|
|
|
|
m.PM_EXEC_PATH_LEN= rmp->mp_exec_path_len;
|
|
|
|
m.PM_EXEC_FRAME= rmp->mp_exec_frame;
|
|
|
|
m.PM_EXEC_FRAME_LEN= rmp->mp_exec_frame_len;
|
|
|
|
|
|
|
|
/* Mark the process as busy */
|
|
|
|
rmp->mp_fs_call= PM_BUSY;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PM_FORK_NB:
|
|
|
|
{
|
2007-02-16 16:55:20 +01:00
|
|
|
int parent_p;
|
2006-05-11 16:57:23 +02:00
|
|
|
struct mproc *parent_mp;
|
|
|
|
|
|
|
|
parent_p = rmp->mp_parent;
|
|
|
|
parent_mp = &mproc[parent_p];
|
|
|
|
|
|
|
|
m.m_type= PM_FORK;
|
|
|
|
m.PM_FORK_PPROC= parent_mp->mp_endpoint;
|
|
|
|
m.PM_FORK_CPROC= rmp->mp_endpoint;
|
|
|
|
m.PM_FORK_CPID= rmp->mp_pid;
|
|
|
|
|
|
|
|
/* FS does not reply */
|
|
|
|
rmp->mp_fs_call= PM_IDLE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PM_DUMPCORE:
|
|
|
|
m.m_type= call;
|
|
|
|
m.PM_CORE_PROC= rmp->mp_endpoint;
|
2008-11-19 13:26:10 +01:00
|
|
|
/* XXX
|
2006-05-11 16:57:23 +02:00
|
|
|
m.PM_CORE_SEGPTR= (char *)rmp->mp_seg;
|
2008-11-19 13:26:10 +01:00
|
|
|
*/
|
2006-05-11 16:57:23 +02:00
|
|
|
|
|
|
|
/* Mark the process as busy */
|
|
|
|
rmp->mp_fs_call= PM_BUSY;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("send_work: should report call 0x%x to FS\n",
|
|
|
|
call);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (m.m_type != PM_IDLE)
|
|
|
|
{
|
|
|
|
if (rmp->mp_fs_call == PM_IDLE &&
|
2006-05-15 14:06:19 +02:00
|
|
|
rmp->mp_fs_call2 == PM_IDLE &&
|
2006-05-11 16:57:23 +02:00
|
|
|
(rmp->mp_flags & PM_SIG_PENDING))
|
|
|
|
{
|
|
|
|
rmp->mp_flags &= ~PM_SIG_PENDING;
|
|
|
|
check_pending(rmp);
|
|
|
|
if (!(rmp->mp_flags & PM_SIG_PENDING))
|
|
|
|
{
|
|
|
|
/* Allow the process to be scheduled */
|
|
|
|
sys_nice(rmp->mp_endpoint, rmp->mp_nice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (report_reboot)
|
|
|
|
{
|
|
|
|
m.m_type= PM_REBOOT;
|
|
|
|
report_reboot= FALSE;
|
|
|
|
}
|
|
|
|
r= send(FS_PROC_NR, &m);
|
|
|
|
if (r != OK) panic("pm", "send_work: send failed", r);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE void handle_fs_reply(m_ptr)
|
|
|
|
message *m_ptr;
|
|
|
|
{
|
2008-11-19 13:26:10 +01:00
|
|
|
int r, proc_e, proc_n, s;
|
2006-05-11 16:57:23 +02:00
|
|
|
struct mproc *rmp;
|
|
|
|
|
|
|
|
switch(m_ptr->m_type)
|
|
|
|
{
|
|
|
|
case PM_EXIT_REPLY:
|
|
|
|
case PM_EXIT_REPLY_TR:
|
|
|
|
proc_e= m_ptr->PM_EXIT_PROC;
|
|
|
|
if (pm_isokendpt(proc_e, &proc_n) != OK)
|
|
|
|
{
|
|
|
|
panic(__FILE__,
|
|
|
|
"PM_EXIT_REPLY: got bad endpoint from FS",
|
|
|
|
proc_e);
|
|
|
|
}
|
|
|
|
rmp= &mproc[proc_n];
|
|
|
|
|
|
|
|
/* Call is finished */
|
|
|
|
rmp->mp_fs_call= PM_IDLE;
|
|
|
|
|
|
|
|
if (!(rmp->mp_flags & PRIV_PROC))
|
|
|
|
{
|
|
|
|
/* destroy the (user) process */
|
|
|
|
if((r=sys_exit(proc_e)) != OK)
|
|
|
|
{
|
|
|
|
panic(__FILE__,
|
|
|
|
"PM_EXIT_REPLY: sys_exit failed", r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the memory occupied by the child. */
|
2008-11-19 13:26:10 +01:00
|
|
|
if((s=vm_exit(rmp->mp_endpoint)) != OK) {
|
|
|
|
panic(__FILE__, "vm_exit() failed", s);
|
2008-02-21 17:33:34 +01:00
|
|
|
}
|
2006-05-11 16:57:23 +02:00
|
|
|
|
|
|
|
if (m_ptr->m_type == PM_EXIT_REPLY_TR &&
|
|
|
|
rmp->mp_parent != INIT_PROC_NR)
|
|
|
|
{
|
|
|
|
/* Wake up the parent */
|
|
|
|
mproc[rmp->mp_parent].mp_reply.reply_trace = 0;
|
|
|
|
setreply(rmp->mp_parent, OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clean up if the parent has collected the exit
|
|
|
|
* status
|
|
|
|
*/
|
2006-10-25 13:29:43 +02:00
|
|
|
if (rmp->mp_flags & TOLD_PARENT)
|
2006-05-11 16:57:23 +02:00
|
|
|
real_cleanup(rmp);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PM_REBOOT_REPLY:
|
|
|
|
{
|
|
|
|
vir_bytes code_addr;
|
|
|
|
size_t code_size;
|
|
|
|
|
|
|
|
/* Ask the kernel to abort. All system services, including
|
|
|
|
* the PM, will get a HARD_STOP notification. Await the
|
|
|
|
* notification in the main loop.
|
|
|
|
*/
|
|
|
|
code_addr = (vir_bytes) monitor_code;
|
|
|
|
code_size = strlen(monitor_code) + 1;
|
|
|
|
sys_abort(abort_flag, PM_PROC_NR, code_addr, code_size);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PM_EXEC_REPLY:
|
|
|
|
proc_e= m_ptr->PM_EXEC_PROC;
|
|
|
|
if (pm_isokendpt(proc_e, &proc_n) != OK)
|
|
|
|
{
|
|
|
|
panic(__FILE__,
|
|
|
|
"PM_EXIT_REPLY: got bad endpoint from FS",
|
|
|
|
proc_e);
|
|
|
|
}
|
|
|
|
rmp= &mproc[proc_n];
|
|
|
|
|
|
|
|
/* Call is finished */
|
|
|
|
rmp->mp_fs_call= PM_IDLE;
|
|
|
|
|
|
|
|
exec_restart(rmp, m_ptr->PM_EXEC_STATUS);
|
|
|
|
|
|
|
|
if (rmp->mp_flags & PM_SIG_PENDING)
|
|
|
|
{
|
|
|
|
printf("handle_fs_reply: restarting signals\n");
|
|
|
|
rmp->mp_flags &= ~PM_SIG_PENDING;
|
|
|
|
check_pending(rmp);
|
|
|
|
if (!(rmp->mp_flags & PM_SIG_PENDING))
|
|
|
|
{
|
|
|
|
printf("handle_fs_reply: calling sys_nice\n");
|
|
|
|
/* Allow the process to be scheduled */
|
|
|
|
sys_nice(rmp->mp_endpoint, rmp->mp_nice);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("handle_fs_reply: more signals\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PM_CORE_REPLY:
|
|
|
|
{
|
|
|
|
int parent_waiting, right_child;
|
|
|
|
pid_t pidarg;
|
|
|
|
struct mproc *p_mp;
|
|
|
|
|
|
|
|
proc_e= m_ptr->PM_CORE_PROC;
|
|
|
|
if (pm_isokendpt(proc_e, &proc_n) != OK)
|
|
|
|
{
|
|
|
|
panic(__FILE__,
|
|
|
|
"PM_EXIT_REPLY: got bad endpoint from FS",
|
|
|
|
proc_e);
|
|
|
|
}
|
|
|
|
rmp= &mproc[proc_n];
|
|
|
|
|
|
|
|
if (m_ptr->PM_CORE_STATUS == OK)
|
|
|
|
rmp->mp_sigstatus |= DUMPED;
|
|
|
|
|
|
|
|
/* Call is finished */
|
|
|
|
rmp->mp_fs_call= PM_IDLE;
|
|
|
|
|
|
|
|
p_mp = &mproc[rmp->mp_parent]; /* process' parent */
|
|
|
|
pidarg = p_mp->mp_wpid; /* who's being waited for? */
|
|
|
|
parent_waiting = p_mp->mp_flags & WAITING;
|
|
|
|
right_child = /* child meets one of the 3 tests? */
|
|
|
|
(pidarg == -1 || pidarg == rmp->mp_pid ||
|
|
|
|
-pidarg == rmp->mp_procgrp);
|
|
|
|
|
|
|
|
if (parent_waiting && right_child) {
|
|
|
|
tell_parent(rmp); /* tell parent */
|
|
|
|
} else {
|
|
|
|
/* parent not waiting, zombify child */
|
2008-02-21 17:33:34 +01:00
|
|
|
rmp->mp_flags &= (IN_USE|PRIV_PROC|HAS_DMA);
|
2006-05-11 16:57:23 +02:00
|
|
|
rmp->mp_flags |= ZOMBIE;
|
|
|
|
/* send parent a "child died" signal */
|
|
|
|
sig_proc(p_mp, SIGCHLD);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(rmp->mp_flags & PRIV_PROC))
|
|
|
|
{
|
|
|
|
/* destroy the (user) process */
|
|
|
|
if((r=sys_exit(proc_e)) != OK)
|
|
|
|
{
|
|
|
|
panic(__FILE__,
|
|
|
|
"PM_CORE_REPLY: sys_exit failed", r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the memory occupied by the child. */
|
2008-11-19 13:26:10 +01:00
|
|
|
if((s=vm_exit(rmp->mp_endpoint)) != OK) {
|
|
|
|
panic(__FILE__, "vm_exit() failed", s);
|
2008-02-21 17:33:34 +01:00
|
|
|
}
|
2006-05-11 16:57:23 +02:00
|
|
|
|
|
|
|
/* Clean up if the parent has collected the exit
|
|
|
|
* status
|
|
|
|
*/
|
2006-10-25 13:29:43 +02:00
|
|
|
if (rmp->mp_flags & TOLD_PARENT)
|
2006-05-11 16:57:23 +02:00
|
|
|
real_cleanup(rmp);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
panic(__FILE__, "handle_fs_reply: unknown reply type",
|
|
|
|
m_ptr->m_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|