cb176df60f
UPDATING INFO: 20100317: /usr/src/etc/system.conf updated to ignore default kernel calls: copy it (or merge it) to /etc/system.conf. The hello driver (/dev/hello) added to the distribution: # cd /usr/src/commands/scripts && make clean install # cd /dev && MAKEDEV hello KERNEL CHANGES: - Generic signal handling support. The kernel no longer assumes PM as a signal manager for every process. The signal manager of a given process can now be specified in its privilege slot. When a signal has to be delivered, the kernel performs the lookup and forwards the signal to the appropriate signal manager. PM is the default signal manager for user processes, RS is the default signal manager for system processes. To enable ptrace()ing for system processes, it is sufficient to change the default signal manager to PM. This will temporarily disable crash recovery, though. - sys_exit() is now split into sys_exit() (i.e. exit() for system processes, which generates a self-termination signal), and sys_clear() (i.e. used by PM to ask the kernel to clear a process slot when a process exits). - Added a new kernel call (i.e. sys_update()) to swap two process slots and implement live update. PM CHANGES: - Posix signal handling is no longer allowed for system processes. System signals are split into two fixed categories: termination and non-termination signals. When a non-termination signaled is processed, PM transforms the signal into an IPC message and delivers the message to the system process. When a termination signal is processed, PM terminates the process. - PM no longer assumes itself as the signal manager for system processes. It now makes sure that every system signal goes through the kernel before being actually processes. The kernel will then dispatch the signal to the appropriate signal manager which may or may not be PM. SYSLIB CHANGES: - Simplified SEF init and LU callbacks. - Added additional predefined SEF callbacks to debug crash recovery and live update. - Fixed a temporary ack in the SEF init protocol. SEF init reply is now completely synchronous. - Added SEF signal event type to provide a uniform interface for system processes to deal with signals. A sef_cb_signal_handler() callback is available for system processes to handle every received signal. A sef_cb_signal_manager() callback is used by signal managers to process system signals on behalf of the kernel. - Fixed a few bugs with memory mapping and DS. VM CHANGES: - Page faults and memory requests coming from the kernel are now implemented using signals. - Added a new VM call to swap two process slots and implement live update. - The call is used by RS at update time and in turn invokes the kernel call sys_update(). RS CHANGES: - RS has been reworked with a better functional decomposition. - Better kernel call masks. com.h now defines the set of very basic kernel calls every system service is allowed to use. This makes system.conf simpler and easier to maintain. In addition, this guarantees a higher level of isolation for system libraries that use one or more kernel calls internally (e.g. printf). - RS is the default signal manager for system processes. By default, RS intercepts every signal delivered to every system process. This makes crash recovery possible before bringing PM and friends in the loop. - RS now supports fast rollback when something goes wrong while initializing the new version during a live update. - Live update is now implemented by keeping the two versions side-by-side and swapping the process slots when the old version is ready to update. - Crash recovery is now implemented by keeping the two versions side-by-side and cleaning up the old version only when the recovery process is complete. DS CHANGES: - Fixed a bug when the process doing ds_publish() or ds_delete() is not known by DS. - Fixed the completely broken support for strings. String publishing is now implemented in the system library and simply wraps publishing of memory ranges. Ideally, we should adopt a similar approach for other data types as well. - Test suite fixed. DRIVER CHANGES: - The hello driver has been added to the Minix distribution to demonstrate basic live update and crash recovery functionalities. - Other drivers have been adapted to conform the new SEF interface.
191 lines
5.2 KiB
C
191 lines
5.2 KiB
C
/* This file handles the EXEC system call. It performs the work as follows:
|
|
* - see if the permissions allow the file to be executed
|
|
* - read the header and extract the sizes
|
|
* - fetch the initial args and environment from the user space
|
|
* - allocate the memory for the new process
|
|
* - copy the initial stack from PM to the process
|
|
* - read in the text and data segments and copy to the process
|
|
* - take care of setuid and setgid bits
|
|
* - fix up 'mproc' table
|
|
* - tell kernel about EXEC
|
|
* - save offset to initial argc (for ps)
|
|
*
|
|
* The entry points into this file are:
|
|
* do_exec: perform the EXEC system call
|
|
* do_exec_newmem: allocate new memory map for a process that tries to exec
|
|
* do_execrestart: finish the special exec call for RS
|
|
* exec_restart: finish a regular exec call
|
|
* find_share: find a process whose text segment can be shared
|
|
*/
|
|
|
|
#include "pm.h"
|
|
#include <sys/stat.h>
|
|
#include <minix/callnr.h>
|
|
#include <minix/endpoint.h>
|
|
#include <minix/com.h>
|
|
#include <minix/vm.h>
|
|
#include <a.out.h>
|
|
#include <signal.h>
|
|
#include <string.h>
|
|
#include <sys/ptrace.h>
|
|
#include "mproc.h"
|
|
#include "param.h"
|
|
|
|
#define ESCRIPT (-2000) /* Returned by read_header for a #! script. */
|
|
#define PTRSIZE sizeof(char *) /* Size of pointers in argv[] and envp[]. */
|
|
|
|
/*===========================================================================*
|
|
* do_exec *
|
|
*===========================================================================*/
|
|
PUBLIC int do_exec()
|
|
{
|
|
message m;
|
|
int r;
|
|
|
|
/* Forward call to FS */
|
|
m.m_type = PM_EXEC;
|
|
m.PM_PROC = mp->mp_endpoint;
|
|
m.PM_PATH = m_in.exec_name;
|
|
m.PM_PATH_LEN = m_in.exec_len;
|
|
m.PM_FRAME = m_in.stack_ptr;
|
|
m.PM_FRAME_LEN = m_in.stack_bytes;
|
|
|
|
tell_fs(mp, &m);
|
|
|
|
/* Do not reply */
|
|
return SUSPEND;
|
|
}
|
|
|
|
|
|
/*===========================================================================*
|
|
* do_exec_newmem *
|
|
*===========================================================================*/
|
|
PUBLIC int do_exec_newmem()
|
|
{
|
|
int proc_e, proc_n, allow_setuid;
|
|
char *ptr;
|
|
struct mproc *rmp;
|
|
struct exec_newmem args;
|
|
int r, flags;
|
|
char *stack_top;
|
|
|
|
if (who_e != FS_PROC_NR && who_e != RS_PROC_NR)
|
|
return EPERM;
|
|
|
|
proc_e= m_in.EXC_NM_PROC;
|
|
if (pm_isokendpt(proc_e, &proc_n) != OK) {
|
|
panic("do_exec_newmem: got bad endpoint: %d", proc_e);
|
|
}
|
|
rmp= &mproc[proc_n];
|
|
ptr= m_in.EXC_NM_PTR;
|
|
r= sys_datacopy(who_e, (vir_bytes)ptr,
|
|
SELF, (vir_bytes)&args, sizeof(args));
|
|
if (r != OK)
|
|
panic("do_exec_newmem: sys_datacopy failed: %d", r);
|
|
|
|
if((r=vm_exec_newmem(proc_e, &args, sizeof(args), &stack_top, &flags)) == OK) {
|
|
allow_setuid= 0; /* Do not allow setuid execution */
|
|
|
|
if (rmp->mp_tracer == NO_TRACER) {
|
|
/* Okay, setuid execution is allowed */
|
|
allow_setuid= 1;
|
|
rmp->mp_effuid = args.new_uid;
|
|
rmp->mp_effgid = args.new_gid;
|
|
}
|
|
|
|
/* System will save command line for debugging, ps(1) output, etc. */
|
|
strncpy(rmp->mp_name, args.progname, PROC_NAME_LEN-1);
|
|
rmp->mp_name[PROC_NAME_LEN-1] = '\0';
|
|
|
|
/* Save offset to initial argc (for ps) */
|
|
rmp->mp_procargs = (vir_bytes) stack_top - args.args_bytes;
|
|
|
|
/* Kill process if something goes wrong after this point. */
|
|
rmp->mp_flags |= PARTIAL_EXEC;
|
|
|
|
mp->mp_reply.reply_res2= (vir_bytes) stack_top;
|
|
mp->mp_reply.reply_res3= flags;
|
|
if (allow_setuid)
|
|
mp->mp_reply.reply_res3 |= EXC_NM_RF_ALLOW_SETUID;
|
|
} else {
|
|
printf("PM: newmem failed for %s\n", args.progname);
|
|
}
|
|
return r;
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* do_execrestart *
|
|
*===========================================================================*/
|
|
PUBLIC int do_execrestart()
|
|
{
|
|
int proc_e, proc_n, result;
|
|
struct mproc *rmp;
|
|
|
|
if (who_e != RS_PROC_NR)
|
|
return EPERM;
|
|
|
|
proc_e= m_in.EXC_RS_PROC;
|
|
if (pm_isokendpt(proc_e, &proc_n) != OK) {
|
|
panic("do_execrestart: got bad endpoint: %d", proc_e);
|
|
}
|
|
rmp= &mproc[proc_n];
|
|
result= m_in.EXC_RS_RESULT;
|
|
|
|
exec_restart(rmp, result);
|
|
|
|
return OK;
|
|
}
|
|
|
|
|
|
/*===========================================================================*
|
|
* exec_restart *
|
|
*===========================================================================*/
|
|
PUBLIC void exec_restart(rmp, result)
|
|
struct mproc *rmp;
|
|
int result;
|
|
{
|
|
int r, sn;
|
|
vir_bytes pc;
|
|
char *new_sp;
|
|
|
|
if (result != OK)
|
|
{
|
|
if (rmp->mp_flags & PARTIAL_EXEC)
|
|
{
|
|
/* Use SIGKILL to signal that something went wrong */
|
|
sys_kill(rmp->mp_endpoint, SIGKILL);
|
|
return;
|
|
}
|
|
setreply(rmp-mproc, result);
|
|
return;
|
|
}
|
|
|
|
rmp->mp_flags &= ~PARTIAL_EXEC;
|
|
|
|
/* Fix 'mproc' fields, tell kernel that exec is done, reset caught
|
|
* sigs.
|
|
*/
|
|
for (sn = 1; sn < _NSIG; sn++) {
|
|
if (sigismember(&rmp->mp_catch, sn)) {
|
|
sigdelset(&rmp->mp_catch, sn);
|
|
rmp->mp_sigact[sn].sa_handler = SIG_DFL;
|
|
sigemptyset(&rmp->mp_sigact[sn].sa_mask);
|
|
}
|
|
}
|
|
|
|
/* Cause a signal if this process is traced.
|
|
* Do this before making the process runnable again!
|
|
*/
|
|
if (rmp->mp_tracer != NO_TRACER && !(rmp->mp_trace_flags & TO_NOEXEC))
|
|
{
|
|
sn = (rmp->mp_trace_flags & TO_ALTEXEC) ? SIGSTOP : SIGTRAP;
|
|
|
|
check_sig(rmp->mp_pid, sn, FALSE /* ksig */);
|
|
}
|
|
|
|
new_sp= (char *)rmp->mp_procargs;
|
|
pc= 0; /* for now */
|
|
r= sys_exec(rmp->mp_endpoint, new_sp, rmp->mp_name, pc);
|
|
if (r != OK) panic("sys_exec failed: %d", r);
|
|
}
|
|
|