2005-05-03 17:35:52 +02:00
|
|
|
/* Miscellaneous system calls. Author: Kees J. Bot
|
|
|
|
* 31 Mar 2000
|
|
|
|
* The entry points into this file are:
|
|
|
|
* do_reboot: kill all processes, then reboot system
|
2005-06-02 14:43:21 +02:00
|
|
|
* do_getsysinfo: request copy of PM data structure (Jorrit N. Herder)
|
|
|
|
* do_getprocnr: lookup process slot number (Jorrit N. Herder)
|
2009-10-31 15:09:28 +01:00
|
|
|
* do_getepinfo: get the pid/uid/gid of a process given its endpoint
|
2005-07-01 19:58:29 +02:00
|
|
|
* do_getsetpriority: get/set process priority
|
2006-03-10 17:10:05 +01:00
|
|
|
* do_svrctl: process manager control
|
2005-05-03 17:35:52 +02:00
|
|
|
*/
|
|
|
|
|
2006-06-30 16:36:11 +02:00
|
|
|
#define brk _brk
|
|
|
|
|
2005-05-13 10:57:08 +02:00
|
|
|
#include "pm.h"
|
2005-05-03 17:35:52 +02:00
|
|
|
#include <minix/callnr.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/svrctl.h>
|
2005-07-01 19:58:29 +02:00
|
|
|
#include <sys/resource.h>
|
2006-05-19 14:19:37 +02:00
|
|
|
#include <sys/utsname.h>
|
2005-05-03 17:35:52 +02:00
|
|
|
#include <minix/com.h>
|
2005-10-13 14:48:43 +02:00
|
|
|
#include <minix/config.h>
|
2013-03-20 16:29:03 +01:00
|
|
|
#include <minix/reboot.h>
|
2006-07-27 18:23:01 +02:00
|
|
|
#include <minix/sysinfo.h>
|
2005-10-13 14:48:43 +02: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 <string.h>
|
2010-03-09 10:41:14 +01:00
|
|
|
#include <machine/archtypes.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 <lib.h>
|
2009-10-09 12:48:46 +02:00
|
|
|
#include <assert.h>
|
2005-05-03 17:35:52 +02:00
|
|
|
#include "mproc.h"
|
|
|
|
#include "param.h"
|
2010-04-02 00:22:33 +02:00
|
|
|
#include "kernel/proc.h"
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
struct utsname uts_val = {
|
2006-05-19 14:19:37 +02:00
|
|
|
"Minix", /* system name */
|
|
|
|
"noname", /* node/network name */
|
|
|
|
OS_RELEASE, /* O.S. release (e.g. 1.5) */
|
|
|
|
OS_VERSION, /* O.S. version (e.g. 10) */
|
|
|
|
"xyzzy", /* machine (cpu) type (filled in later) */
|
2012-08-11 17:45:06 +02:00
|
|
|
#if defined(__i386__)
|
2006-05-19 14:19:37 +02:00
|
|
|
"i386", /* architecture */
|
2012-08-11 17:45:06 +02:00
|
|
|
#elif defined(__arm__)
|
|
|
|
"arm", /* architecture */
|
2006-05-19 14:19:37 +02:00
|
|
|
#else
|
|
|
|
#error /* oops, no 'uname -mk' */
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static char *uts_tbl[] = {
|
2006-05-19 14:19:37 +02:00
|
|
|
uts_val.arch,
|
|
|
|
NULL, /* No kernel architecture */
|
|
|
|
uts_val.machine,
|
|
|
|
NULL, /* No hostname */
|
|
|
|
uts_val.nodename,
|
|
|
|
uts_val.release,
|
|
|
|
uts_val.version,
|
|
|
|
uts_val.sysname,
|
|
|
|
NULL, /* No bus */ /* No bus */
|
|
|
|
};
|
|
|
|
|
2006-07-10 14:44:43 +02:00
|
|
|
#if ENABLE_SYSCALL_STATS
|
2012-03-25 20:25:53 +02:00
|
|
|
unsigned long calls_stats[NCALLS];
|
2006-07-10 14:44:43 +02:00
|
|
|
#endif
|
|
|
|
|
2006-05-19 14:19:37 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_sysuname *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_sysuname()
|
2006-05-19 14:19:37 +02:00
|
|
|
{
|
|
|
|
/* Set or get uname strings. */
|
|
|
|
|
|
|
|
int r;
|
2007-02-16 16:55:20 +01:00
|
|
|
size_t n;
|
|
|
|
char *string;
|
2006-05-19 14:19:37 +02:00
|
|
|
#if 0 /* for updates */
|
|
|
|
char tmp[sizeof(uts_val.nodename)];
|
|
|
|
static short sizes[] = {
|
|
|
|
0, /* arch, (0 = read-only) */
|
|
|
|
0, /* kernel */
|
|
|
|
0, /* machine */
|
|
|
|
0, /* sizeof(uts_val.hostname), */
|
|
|
|
sizeof(uts_val.nodename),
|
|
|
|
0, /* release */
|
|
|
|
0, /* version */
|
|
|
|
0, /* sysname */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((unsigned) m_in.sysuname_field >= _UTS_MAX) return(EINVAL);
|
|
|
|
|
|
|
|
string = uts_tbl[m_in.sysuname_field];
|
|
|
|
if (string == NULL)
|
|
|
|
return EINVAL; /* Unsupported field */
|
|
|
|
|
|
|
|
switch (m_in.sysuname_req) {
|
|
|
|
case _UTS_GET:
|
|
|
|
/* Copy an uname string to the user. */
|
|
|
|
n = strlen(string) + 1;
|
|
|
|
if (n > m_in.sysuname_len) n = m_in.sysuname_len;
|
2012-06-16 19:29:37 +02:00
|
|
|
r = sys_vircopy(SELF, (phys_bytes) string,
|
|
|
|
mp->mp_endpoint, (phys_bytes) m_in.sysuname_value,
|
2006-05-19 14:19:37 +02:00
|
|
|
(phys_bytes) n);
|
|
|
|
if (r < 0) return(r);
|
|
|
|
break;
|
|
|
|
|
|
|
|
#if 0 /* no updates yet */
|
|
|
|
case _UTS_SET:
|
|
|
|
/* Set an uname string, needs root power. */
|
|
|
|
len = sizes[m_in.sysuname_field];
|
|
|
|
if (mp->mp_effuid != 0 || len == 0) return(EPERM);
|
|
|
|
n = len < m_in.sysuname_len ? len : m_in.sysuname_len;
|
|
|
|
if (n <= 0) return(EINVAL);
|
2012-06-16 19:29:37 +02:00
|
|
|
r = sys_vircopy(mp->mp_endpoint, (phys_bytes) m_in.sysuname_value,
|
|
|
|
SELF, (phys_bytes) tmp, (phys_bytes) n);
|
2006-05-19 14:19:37 +02:00
|
|
|
if (r < 0) return(r);
|
|
|
|
tmp[n-1] = 0;
|
|
|
|
strcpy(string, tmp);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
/* Return the number of bytes moved. */
|
|
|
|
return(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-06 15:51:50 +02:00
|
|
|
/*===========================================================================*
|
2005-09-11 18:45:46 +02:00
|
|
|
* do_getsysinfo *
|
2005-06-06 15:51:50 +02:00
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_getsysinfo()
|
2005-05-03 17:35:52 +02:00
|
|
|
{
|
2005-06-06 15:51:50 +02:00
|
|
|
vir_bytes src_addr, dst_addr;
|
|
|
|
size_t len;
|
|
|
|
|
2011-11-07 21:11:30 +01:00
|
|
|
/* This call leaks important information. In the future, requests from
|
|
|
|
* non-system processes should be denied.
|
|
|
|
*/
|
2006-05-19 14:19:37 +02:00
|
|
|
if (mp->mp_effuid != 0)
|
|
|
|
{
|
|
|
|
printf("PM: unauthorized call of do_getsysinfo by proc %d '%s'\n",
|
|
|
|
mp->mp_endpoint, mp->mp_name);
|
2009-02-17 13:09:59 +01:00
|
|
|
sys_sysctl_stacktrace(mp->mp_endpoint);
|
2006-05-19 14:19:37 +02:00
|
|
|
return EPERM;
|
|
|
|
}
|
|
|
|
|
2011-12-11 22:30:35 +01:00
|
|
|
switch(m_in.SI_WHAT) {
|
2005-06-07 16:43:35 +02:00
|
|
|
case SI_PROC_TAB: /* copy entire process table */
|
|
|
|
src_addr = (vir_bytes) mproc;
|
|
|
|
len = sizeof(struct mproc) * NR_PROCS;
|
|
|
|
break;
|
2006-07-10 14:44:43 +02:00
|
|
|
#if ENABLE_SYSCALL_STATS
|
|
|
|
case SI_CALL_STATS:
|
|
|
|
src_addr = (vir_bytes) calls_stats;
|
|
|
|
len = sizeof(calls_stats);
|
|
|
|
break;
|
|
|
|
#endif
|
2005-06-06 15:51:50 +02:00
|
|
|
default:
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
|
2011-12-11 22:30:35 +01:00
|
|
|
if (len != m_in.SI_SIZE)
|
|
|
|
return(EINVAL);
|
|
|
|
|
|
|
|
dst_addr = (vir_bytes) m_in.SI_WHERE;
|
|
|
|
return sys_datacopy(SELF, src_addr, who_e, dst_addr, len);
|
2005-05-03 17:35:52 +02:00
|
|
|
}
|
|
|
|
|
2005-06-06 15:51:50 +02:00
|
|
|
/*===========================================================================*
|
2005-09-11 18:45:46 +02:00
|
|
|
* do_getprocnr *
|
2005-06-06 15:51:50 +02:00
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_getprocnr()
|
2005-05-19 11:38:29 +02:00
|
|
|
{
|
2005-06-02 14:43:21 +02:00
|
|
|
register struct mproc *rmp;
|
2005-06-20 11:35:23 +02:00
|
|
|
static char search_key[PROC_NAME_LEN+1];
|
2005-06-02 14:43:21 +02:00
|
|
|
int key_len;
|
|
|
|
int s;
|
|
|
|
|
2006-05-19 14:19:37 +02:00
|
|
|
/* This call should be moved to DS. */
|
|
|
|
if (mp->mp_effuid != 0)
|
|
|
|
{
|
2009-12-02 11:06:58 +01:00
|
|
|
/* For now, allow non-root processes to request their own endpoint. */
|
|
|
|
if (m_in.pid < 0 && m_in.namelen == 0) {
|
|
|
|
mp->mp_reply.PM_ENDPT = who_e;
|
|
|
|
mp->mp_reply.PM_PENDPT = NONE;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2009-04-22 14:42:37 +02:00
|
|
|
printf("PM: unauthorized call of do_getprocnr by proc %d\n",
|
2006-05-19 14:19:37 +02:00
|
|
|
mp->mp_endpoint);
|
2009-02-17 13:09:59 +01:00
|
|
|
sys_sysctl_stacktrace(mp->mp_endpoint);
|
2006-05-19 14:19:37 +02:00
|
|
|
return EPERM;
|
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
|
|
|
printf("PM: do_getprocnr(%d) call from endpoint %d, %s\n",
|
|
|
|
m_in.pid, mp->mp_endpoint, mp->mp_name);
|
|
|
|
#endif
|
2007-08-07 14:28:42 +02:00
|
|
|
|
2005-10-12 17:07:38 +02:00
|
|
|
if (m_in.pid >= 0) { /* lookup process by pid */
|
2010-05-10 15:26:00 +02:00
|
|
|
if ((rmp = find_proc(m_in.pid)) != NULL) {
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
mp->mp_reply.PM_ENDPT = rmp->mp_endpoint;
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
printf("PM: pid result: %d\n", rmp->mp_endpoint);
|
2008-11-19 13:26:10 +01:00
|
|
|
#endif
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
return(OK);
|
2005-08-02 17:29:17 +02:00
|
|
|
}
|
|
|
|
return(ESRCH);
|
2005-10-12 17:07:38 +02:00
|
|
|
} else if (m_in.namelen > 0) { /* lookup process by name */
|
2005-06-20 11:35:23 +02:00
|
|
|
key_len = MIN(m_in.namelen, PROC_NAME_LEN);
|
2009-09-21 16:48:19 +02:00
|
|
|
if (OK != (s=sys_datacopy(who_e, (vir_bytes) m_in.PMBRK_ADDR,
|
2005-06-02 14:43:21 +02:00
|
|
|
SELF, (vir_bytes) search_key, key_len)))
|
|
|
|
return(s);
|
|
|
|
search_key[key_len] = '\0'; /* terminate for safety */
|
|
|
|
for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) {
|
2009-07-10 00:33:56 +02:00
|
|
|
if (((rmp->mp_flags & (IN_USE | EXITING)) == IN_USE) &&
|
2005-06-02 14:43:21 +02:00
|
|
|
strncmp(rmp->mp_name, search_key, key_len)==0) {
|
2009-09-21 16:48:19 +02:00
|
|
|
mp->mp_reply.PM_ENDPT = rmp->mp_endpoint;
|
2005-06-02 14:43:21 +02:00
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(ESRCH);
|
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
|
|
|
} else { /* return own/parent process number */
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
2009-09-21 16:48:19 +02:00
|
|
|
printf("PM: endpt result: %d\n", mp->mp_reply.PM_ENDPT);
|
2008-11-19 13:26:10 +01:00
|
|
|
#endif
|
2009-09-21 16:48:19 +02:00
|
|
|
mp->mp_reply.PM_ENDPT = who_e;
|
|
|
|
mp->mp_reply.PM_PENDPT = mproc[mp->mp_parent].mp_endpoint;
|
2005-06-02 14:43:21 +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
|
|
|
|
2005-05-19 11:38:29 +02:00
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
2007-04-27 14:21:06 +02:00
|
|
|
/*===========================================================================*
|
2009-10-31 15:09:28 +01:00
|
|
|
* do_getepinfo *
|
2007-04-27 14:21:06 +02:00
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_getepinfo()
|
2007-04-27 14:21:06 +02:00
|
|
|
{
|
|
|
|
register struct mproc *rmp;
|
|
|
|
endpoint_t ep;
|
|
|
|
|
2011-09-05 15:56:14 +02:00
|
|
|
ep = m_in.PM_ENDPT;
|
2007-04-27 14:21:06 +02:00
|
|
|
|
|
|
|
for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) {
|
|
|
|
if ((rmp->mp_flags & IN_USE) && (rmp->mp_endpoint == ep)) {
|
|
|
|
mp->mp_reply.reply_res2 = rmp->mp_effuid;
|
2009-10-31 15:09:28 +01:00
|
|
|
mp->mp_reply.reply_res3 = rmp->mp_effgid;
|
|
|
|
return(rmp->mp_pid);
|
2007-04-27 14:21:06 +02:00
|
|
|
}
|
2011-09-05 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process not found */
|
|
|
|
return(ESRCH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_getepinfo_o *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_getepinfo_o()
|
2011-09-05 15:56:14 +02:00
|
|
|
{
|
|
|
|
register struct mproc *rmp;
|
|
|
|
endpoint_t ep;
|
|
|
|
|
|
|
|
/* This call should be moved to DS. */
|
|
|
|
if (mp->mp_effuid != 0) {
|
|
|
|
printf("PM: unauthorized call of do_getepinfo_o by proc %d\n",
|
|
|
|
mp->mp_endpoint);
|
|
|
|
sys_sysctl_stacktrace(mp->mp_endpoint);
|
|
|
|
return EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
ep = m_in.PM_ENDPT;
|
|
|
|
|
|
|
|
for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) {
|
|
|
|
if ((rmp->mp_flags & IN_USE) && (rmp->mp_endpoint == ep)) {
|
|
|
|
mp->mp_reply.reply_res2 = (short) rmp->mp_effuid;
|
|
|
|
mp->mp_reply.reply_res3 = (char) rmp->mp_effgid;
|
|
|
|
return(rmp->mp_pid);
|
|
|
|
}
|
|
|
|
}
|
2007-04-27 14:21:06 +02:00
|
|
|
|
|
|
|
/* Process not found */
|
2009-10-31 15:09:28 +01:00
|
|
|
return(ESRCH);
|
2007-04-27 14:21:06 +02:00
|
|
|
}
|
|
|
|
|
2005-09-11 18:45:46 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_reboot *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_reboot()
|
2005-05-03 17:35:52 +02:00
|
|
|
{
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
message m;
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2006-03-10 17:10:05 +01:00
|
|
|
/* Check permission to abort the system. */
|
2005-06-24 18:21:21 +02:00
|
|
|
if (mp->mp_effuid != SUPER_USER) return(EPERM);
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2006-03-10 17:10:05 +01:00
|
|
|
/* See how the system should be aborted. */
|
|
|
|
abort_flag = (unsigned) m_in.reboot_flag;
|
|
|
|
if (abort_flag >= RBT_INVALID) return(EINVAL);
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2010-06-10 16:04:46 +02:00
|
|
|
/* Order matters here. When VFS is told to reboot, it exits all its
|
2005-10-21 13:10:16 +02:00
|
|
|
* processes, and then would be confused if they're exited again by
|
2006-03-10 17:10:05 +01:00
|
|
|
* SIGKILL. So first kill, then reboot.
|
2005-10-21 13:10:16 +02:00
|
|
|
*/
|
|
|
|
|
2010-02-02 16:10:00 +01:00
|
|
|
check_sig(-1, SIGKILL, FALSE /* ksig*/); /* kill all users except init */
|
|
|
|
sys_stop(INIT_PROC_NR); /* stop init, but keep it around */
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
|
2010-06-09 16:31:30 +02:00
|
|
|
/* Tell VFS to reboot */
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
m.m_type = PM_REBOOT;
|
|
|
|
|
2010-06-09 16:31:30 +02:00
|
|
|
tell_vfs(&mproc[VFS_PROC_NR], &m);
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2006-03-10 17:10:05 +01:00
|
|
|
return(SUSPEND); /* don't reply to caller */
|
2005-05-03 17:35:52 +02:00
|
|
|
}
|
|
|
|
|
2005-09-11 18:45:46 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_getsetpriority *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_getsetpriority()
|
2005-07-01 19:58:29 +02:00
|
|
|
{
|
2010-06-02 21:41:38 +02:00
|
|
|
int r, arg_which, arg_who, arg_pri;
|
2005-07-01 19:58:29 +02:00
|
|
|
struct mproc *rmp;
|
|
|
|
|
|
|
|
arg_which = m_in.m1_i1;
|
|
|
|
arg_who = m_in.m1_i2;
|
|
|
|
arg_pri = m_in.m1_i3; /* for SETPRIORITY */
|
|
|
|
|
|
|
|
/* Code common to GETPRIORITY and SETPRIORITY. */
|
|
|
|
|
|
|
|
/* Only support PRIO_PROCESS for now. */
|
2005-09-11 18:45:46 +02:00
|
|
|
if (arg_which != PRIO_PROCESS)
|
2005-07-19 14:11:11 +02:00
|
|
|
return(EINVAL);
|
2005-07-01 19:58:29 +02:00
|
|
|
|
2005-09-11 18:45:46 +02:00
|
|
|
if (arg_who == 0)
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
rmp = mp;
|
2005-07-01 19:58:29 +02:00
|
|
|
else
|
2010-05-10 15:26:00 +02:00
|
|
|
if ((rmp = find_proc(arg_who)) == NULL)
|
2005-07-19 14:11:11 +02:00
|
|
|
return(ESRCH);
|
2005-07-01 19:58:29 +02:00
|
|
|
|
2005-09-11 18:45:46 +02:00
|
|
|
if (mp->mp_effuid != SUPER_USER &&
|
2005-07-01 19:58:29 +02:00
|
|
|
mp->mp_effuid != rmp->mp_effuid && mp->mp_effuid != rmp->mp_realuid)
|
|
|
|
return EPERM;
|
|
|
|
|
|
|
|
/* If GET, that's it. */
|
2005-09-11 18:45:46 +02:00
|
|
|
if (call_nr == GETPRIORITY) {
|
2005-07-19 14:11:11 +02:00
|
|
|
return(rmp->mp_nice - PRIO_MIN);
|
2005-07-01 19:58:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Only root is allowed to reduce the nice level. */
|
2005-09-11 18:45:46 +02:00
|
|
|
if (rmp->mp_nice > arg_pri && mp->mp_effuid != SUPER_USER)
|
2005-07-19 14:11:11 +02:00
|
|
|
return(EACCES);
|
|
|
|
|
Userspace scheduling
- cotributed by Bjorn Swift
- In this first phase, scheduling is moved from the kernel to the PM
server. The next steps are to a) moving scheduling to its own server
and b) include useful information in the "out of quantum" message,
so that the scheduler can make use of this information.
- The kernel process table now keeps record of who is responsible for
scheduling each process (p_scheduler). When this pointer is NULL,
the process will be scheduled by the kernel. If such a process runs
out of quantum, the kernel will simply renew its quantum an requeue
it.
- When PM loads, it will take over scheduling of all running
processes, except system processes, using sys_schedctl().
Essentially, this only results in taking over init. As children
inherit a scheduler from their parent, user space programs forked by
init will inherit PM (for now) as their scheduler.
- Once a process has been assigned a scheduler, and runs out of
quantum, its RTS_NO_QUANTUM flag will be set and the process
dequeued. The kernel will send a message to the scheduler, on the
process' behalf, informing the scheduler that it has run out of
quantum. The scheduler can take what ever action it pleases, based
on its policy, and then reschedule the process using the
sys_schedule() system call.
- Balance queues does not work as before. While the old in-kernel
function used to renew the quantum of processes in the highest
priority run queue, the user-space implementation only acts on
processes that have been bumped down to a lower priority queue.
This approach reacts slower to changes than the old one, but saves
us sending a sys_schedule message for each process every time we
balance the queues. Currently, when processes are moved up a
priority queue, their quantum is also renewed, but this can be
fiddled with.
- do_nice has been removed from kernel. PM answers to get- and
setpriority calls, updates it's own nice variable as well as the
max_run_queue. This will be refactored once scheduling is moved to a
separate server. We will probably have PM update it's local nice
value and then send a message to whoever is scheduling the process.
- changes to fix an issue in do_fork() where processes could run out
of quantum but bypassing the code path that handles it correctly.
The future plan is to remove the policy from do_fork() and implement
it in userspace too.
2010-03-29 13:07:20 +02:00
|
|
|
/* We're SET, and it's allowed.
|
|
|
|
*
|
|
|
|
* The value passed in is currently between PRIO_MIN and PRIO_MAX.
|
|
|
|
* We have to scale this between MIN_USER_Q and MAX_USER_Q to match
|
|
|
|
* the kernel's scheduling queues.
|
|
|
|
*/
|
|
|
|
|
Scheduling server (by Bjorn Swift)
In this second phase, scheduling is moved from PM to its own
scheduler (see r6557 for phase one). In the next phase we hope to a)
include useful information in the "out of quantum" message and b)
create some simple scheduling policy that makes use of that
information.
When the system starts up, PM will iterate over its process table and
ask SCHED to take over scheduling unprivileged processes. This is
done by sending a SCHEDULING_START message to SCHED. This message
includes the processes endpoint, the parent's endpoint and its nice
level. The scheduler adds this process to its schedproc table, issues
a schedctl, and returns its own endpoint to PM - as the endpoint of
the effective scheduler. When a process terminates, a SCHEDULING_STOP
message is sent to the scheduler.
The reason for this effective endpoint is for future compatibility.
Some day, we may have a scheduler that, instead of scheduling the
process itself, forwards the SCHEDULING_START message on to another
scheduler.
PM has information on who schedules whom. As such, scheduling
messages from user-land are sent through PM. An example is when
processes change their priority, using nice(). In that case, a
getsetpriority message is sent to PM, which then sends a
SCHEDULING_SET_NICE to the process's effective scheduler.
When a process is forked through PM, it inherits its parent's
scheduler, but is spawned with an empty quantum. As before, a request
to fork a process flows through VM before returning to PM, which then
wakes up the child process. This flow has been modified slightly so
that PM notifies the scheduler of the new process, before waking up
the child process. If the scheduler fails to take over scheduling,
the child process is torn down and the fork fails with an erroneous
value.
Process priority is entirely decided upon using nice levels. PM
stores a copy of each process's nice level and when a child is
forked, its parent's nice level is sent in the SCHEDULING_START
message. How this level is mapped to a priority queue is up to the
scheduler. It should be noted that the nice level is used to
determine the max_priority and the parent could have been in a lower
priority when it was spawned. To prevent a CPU intensive process from
hawking the CPU by continuously forking children that get scheduled
in the max_priority, the scheduler should determine in which queue
the parent is currently scheduled, and schedule the child in that
same queue.
Other fixes: The USER_Q in kernel/proc.h was incorrectly defined as
NR_SCHED_QUEUES/2. That results in a "off by one" error when
converting priority->nice->priority for nice=0. This also had the
side effect that if someone were to set the MAX_USER_Q to something
else than 0, then USER_Q would be off.
2010-05-18 15:39:04 +02:00
|
|
|
if ((r = sched_nice(rmp, arg_pri)) != OK) {
|
|
|
|
return r;
|
|
|
|
}
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
|
2005-07-01 19:58:29 +02:00
|
|
|
rmp->mp_nice = arg_pri;
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
return(OK);
|
2005-07-01 19:58:29 +02:00
|
|
|
}
|
|
|
|
|
2005-09-11 18:45:46 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_svrctl *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_svrctl()
|
2005-05-03 17:35:52 +02:00
|
|
|
{
|
|
|
|
int s, req;
|
|
|
|
vir_bytes ptr;
|
2005-07-22 20:29:58 +02:00
|
|
|
#define MAX_LOCAL_PARAMS 2
|
|
|
|
static struct {
|
|
|
|
char name[30];
|
|
|
|
char value[30];
|
|
|
|
} local_param_overrides[MAX_LOCAL_PARAMS];
|
|
|
|
static int local_params = 0;
|
|
|
|
|
2005-05-03 17:35:52 +02:00
|
|
|
req = m_in.svrctl_req;
|
|
|
|
ptr = (vir_bytes) m_in.svrctl_argp;
|
|
|
|
|
2010-06-10 16:04:46 +02:00
|
|
|
/* Is the request indeed for the PM? */
|
2005-08-03 18:58:22 +02:00
|
|
|
if (((req >> 8) & 0xFF) != 'M') return(EINVAL);
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2005-05-13 10:57:08 +02:00
|
|
|
/* Control operations local to the PM. */
|
2005-05-03 17:35:52 +02:00
|
|
|
switch(req) {
|
2010-06-10 16:04:46 +02:00
|
|
|
case PMSETPARAM:
|
|
|
|
case PMGETPARAM: {
|
2005-05-03 17:35:52 +02:00
|
|
|
struct sysgetenv sysgetenv;
|
|
|
|
char search_key[64];
|
|
|
|
char *val_start;
|
|
|
|
size_t val_len;
|
|
|
|
size_t copy_len;
|
|
|
|
|
2005-05-13 10:57:08 +02:00
|
|
|
/* Copy sysgetenv structure to PM. */
|
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 (sys_datacopy(who_e, ptr, SELF, (vir_bytes) &sysgetenv,
|
2005-05-03 17:35:52 +02:00
|
|
|
sizeof(sysgetenv)) != OK) return(EFAULT);
|
|
|
|
|
2005-07-22 20:29:58 +02:00
|
|
|
/* Set a param override? */
|
2010-06-10 16:04:46 +02:00
|
|
|
if (req == PMSETPARAM) {
|
2005-09-11 18:45:46 +02:00
|
|
|
if (local_params >= MAX_LOCAL_PARAMS) return ENOSPC;
|
|
|
|
if (sysgetenv.keylen <= 0
|
2005-08-29 18:47:18 +02:00
|
|
|
|| sysgetenv.keylen >=
|
|
|
|
sizeof(local_param_overrides[local_params].name)
|
|
|
|
|| sysgetenv.vallen <= 0
|
|
|
|
|| sysgetenv.vallen >=
|
|
|
|
sizeof(local_param_overrides[local_params].value))
|
|
|
|
return EINVAL;
|
2005-07-22 20:29:58 +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
|
|
|
if ((s = sys_datacopy(who_e, (vir_bytes) sysgetenv.key,
|
2005-08-29 18:47:18 +02:00
|
|
|
SELF, (vir_bytes) local_param_overrides[local_params].name,
|
|
|
|
sysgetenv.keylen)) != OK)
|
|
|
|
return s;
|
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 ((s = sys_datacopy(who_e, (vir_bytes) sysgetenv.val,
|
2005-08-29 18:47:18 +02:00
|
|
|
SELF, (vir_bytes) local_param_overrides[local_params].value,
|
2008-11-19 13:26:10 +01:00
|
|
|
sysgetenv.vallen)) != OK)
|
2005-08-29 18:47:18 +02:00
|
|
|
return s;
|
|
|
|
local_param_overrides[local_params].name[sysgetenv.keylen] = '\0';
|
|
|
|
local_param_overrides[local_params].value[sysgetenv.vallen] = '\0';
|
|
|
|
|
|
|
|
local_params++;
|
|
|
|
|
|
|
|
return OK;
|
2005-07-22 20:29:58 +02:00
|
|
|
}
|
|
|
|
|
2005-05-03 17:35:52 +02:00
|
|
|
if (sysgetenv.keylen == 0) { /* copy all parameters */
|
|
|
|
val_start = monitor_params;
|
|
|
|
val_len = sizeof(monitor_params);
|
|
|
|
}
|
|
|
|
else { /* lookup value for key */
|
2005-07-22 20:29:58 +02:00
|
|
|
int p;
|
2005-05-03 17:35:52 +02:00
|
|
|
/* Try to get a copy of the requested key. */
|
|
|
|
if (sysgetenv.keylen > sizeof(search_key)) return(EINVAL);
|
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 ((s = sys_datacopy(who_e, (vir_bytes) sysgetenv.key,
|
2005-05-03 17:35:52 +02:00
|
|
|
SELF, (vir_bytes) search_key, sysgetenv.keylen)) != OK)
|
|
|
|
return(s);
|
|
|
|
|
2005-07-22 20:29:58 +02:00
|
|
|
/* Make sure key is null-terminated and lookup value.
|
|
|
|
* First check local overrides.
|
|
|
|
*/
|
2005-05-03 17:35:52 +02:00
|
|
|
search_key[sysgetenv.keylen-1]= '\0';
|
2005-07-22 20:29:58 +02:00
|
|
|
for(p = 0; p < local_params; p++) {
|
2005-09-11 18:45:46 +02:00
|
|
|
if (!strcmp(search_key, local_param_overrides[p].name)) {
|
2005-07-22 20:29:58 +02:00
|
|
|
val_start = local_param_overrides[p].value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-09-11 18:45:46 +02:00
|
|
|
if (p >= local_params && (val_start = find_param(search_key)) == NULL)
|
2005-05-03 17:35:52 +02:00
|
|
|
return(ESRCH);
|
|
|
|
val_len = strlen(val_start) + 1;
|
|
|
|
}
|
|
|
|
|
2005-06-20 11:35:23 +02:00
|
|
|
/* See if it fits in the client's buffer. */
|
|
|
|
if (val_len > sysgetenv.vallen)
|
|
|
|
return E2BIG;
|
|
|
|
|
2005-05-03 17:35:52 +02:00
|
|
|
/* Value found, make the actual copy (as far as possible). */
|
2005-06-20 11:35:23 +02:00
|
|
|
copy_len = MIN(val_len, sysgetenv.vallen);
|
2005-05-03 17:35:52 +02:00
|
|
|
if ((s=sys_datacopy(SELF, (vir_bytes) val_start,
|
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
|
|
|
who_e, (vir_bytes) sysgetenv.val, copy_len)) != OK)
|
2005-05-03 17:35:52 +02:00
|
|
|
return(s);
|
|
|
|
|
2005-06-20 11:35:23 +02:00
|
|
|
return OK;
|
2005-05-03 17:35:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
}
|
2006-06-30 16:36:11 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* _brk *
|
|
|
|
*===========================================================================*/
|
|
|
|
|
|
|
|
extern char *_brksize;
|
2012-03-25 20:25:53 +02:00
|
|
|
int brk(brk_addr)
|
2011-04-27 15:00:52 +02:00
|
|
|
void *brk_addr;
|
2006-06-30 16:36:11 +02:00
|
|
|
{
|
2008-11-19 13:26:10 +01:00
|
|
|
int r;
|
2006-06-30 16:36:11 +02:00
|
|
|
/* PM wants to call brk() itself. */
|
2008-11-19 13:26:10 +01:00
|
|
|
if((r=vm_brk(PM_PROC_NR, brk_addr)) != OK) {
|
|
|
|
#if 0
|
|
|
|
printf("PM: own brk(%p) failed: vm_brk() returned %d\n",
|
|
|
|
brk_addr, r);
|
|
|
|
#endif
|
2006-06-30 16:36:11 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
_brksize = brk_addr;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-06-25 14:41:01 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_getrusage *
|
|
|
|
*===========================================================================*/
|
|
|
|
int do_getrusage()
|
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
clock_t user_time = 0;
|
|
|
|
clock_t sys_time = 0;
|
|
|
|
struct rusage r_usage;
|
|
|
|
u64_t usec;
|
|
|
|
if (m_in.RU_WHO != RUSAGE_SELF && m_in.RU_WHO != RUSAGE_CHILDREN)
|
|
|
|
return EINVAL;
|
|
|
|
if ((res = sys_getrusage(&r_usage, who_e)) < 0)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
if (m_in.RU_WHO == RUSAGE_CHILDREN) {
|
|
|
|
usec = mp->mp_child_utime * 1000000 / sys_hz();
|
|
|
|
r_usage.ru_utime.tv_sec = usec / 1000000;
|
|
|
|
r_usage.ru_utime.tv_usec = usec % 1000000;
|
|
|
|
usec = mp->mp_child_stime * 1000000 / sys_hz();
|
|
|
|
r_usage.ru_stime.tv_sec = usec / 1000000;
|
|
|
|
r_usage.ru_stime.tv_usec = usec % 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sys_datacopy(SELF, &r_usage, who_e,
|
|
|
|
(vir_bytes) m_in.RU_RUSAGE_ADDR, (vir_bytes) sizeof(r_usage));
|
|
|
|
}
|