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
This commit is contained in:
@@ -166,6 +166,7 @@ struct proc *t;
|
||||
* k_reenter larger than zero.
|
||||
*/
|
||||
if (k_reenter == 0 && ! iskernelp(saved_proc)) {
|
||||
#if 0
|
||||
{
|
||||
|
||||
kprintf(
|
||||
@@ -181,6 +182,7 @@ struct proc *t;
|
||||
proc_stacktrace(saved_proc);
|
||||
}
|
||||
|
||||
#endif
|
||||
cause_sig(proc_nr(saved_proc), ep->signum);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -367,10 +367,8 @@ set_restart1:
|
||||
_s_call:
|
||||
_p_s_call:
|
||||
cld ! set direction flag to a known value
|
||||
sub esp, 6*4 ! skip RETADR, eax, ecx, edx, ebx, est
|
||||
push ebp ! stack already points into proc table
|
||||
push esi
|
||||
push edi
|
||||
sub esp, 4 ! skip RETADR
|
||||
pushad ! save "general" registers
|
||||
o16 push ds
|
||||
o16 push es
|
||||
o16 push fs
|
||||
|
||||
@@ -353,3 +353,23 @@ PUBLIC int arch_set_params(char *params, int size)
|
||||
return OK;
|
||||
}
|
||||
|
||||
PUBLIC void arch_do_syscall(struct proc *proc)
|
||||
{
|
||||
/* Perform a previously postponed system call.
|
||||
*/
|
||||
int call_nr, src_dst_e;
|
||||
message *m_ptr;
|
||||
long bit_map;
|
||||
|
||||
/* Get the system call parameters from their respective registers. */
|
||||
call_nr = proc->p_reg.cx;
|
||||
src_dst_e = proc->p_reg.retreg;
|
||||
m_ptr = (message *) proc->p_reg.bx;
|
||||
bit_map = proc->p_reg.dx;
|
||||
|
||||
/* sys_call() expects the given process's memory to be accessible. */
|
||||
vm_set_cr3(proc);
|
||||
|
||||
/* Make the system call, for real this time. */
|
||||
proc->p_reg.retreg = sys_call(call_nr, src_dst_e, m_ptr, bit_map);
|
||||
}
|
||||
|
||||
+14
-6
@@ -34,6 +34,7 @@
|
||||
#include "proc.h"
|
||||
#include <signal.h>
|
||||
#include <minix/com.h>
|
||||
#include <minix/endpoint.h>
|
||||
#include <minix/portio.h>
|
||||
|
||||
/* Function prototype for PRIVATE functions.
|
||||
@@ -79,14 +80,21 @@ PUBLIC void clock_task()
|
||||
minix_panic("receive() failed", result);
|
||||
|
||||
/* Handle the request. Only clock ticks are expected. */
|
||||
switch (m.m_type) {
|
||||
case HARD_INT:
|
||||
do_clocktick(&m); /* handle clock tick */
|
||||
break;
|
||||
default: /* illegal request type */
|
||||
if (is_notify(m.m_type)) {
|
||||
switch (_ENDPOINT_P(m.m_source)) {
|
||||
case HARDWARE:
|
||||
do_clocktick(&m); /* handle clock tick */
|
||||
break;
|
||||
default: /* illegal request type */
|
||||
kprintf("CLOCK: illegal notify %d from %d.\n",
|
||||
m.m_type, m.m_source);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* illegal request type */
|
||||
kprintf("CLOCK: illegal request %d from %d.\n",
|
||||
m.m_type, m.m_source);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#define USE_PHYSCOPY 1 /* copy using physical addressing */
|
||||
#define USE_PHYSVCOPY 1 /* vector with physical copy requests */
|
||||
#define USE_MEMSET 1 /* write char to a given memory area */
|
||||
#define USE_RUNCTL 1 /* control stop flags of a process */
|
||||
|
||||
/* Length of program names stored in the process table. This is only used
|
||||
* for the debugging dumps that can be generated with the IS server. The PM
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ rtsflagstr(int flags)
|
||||
#define FLAG(n) if(flags & n) { strcat(str, #n " "); }
|
||||
|
||||
FLAG(SLOT_FREE);
|
||||
FLAG(NO_PRIORITY);
|
||||
FLAG(PROC_STOP);
|
||||
FLAG(SENDING);
|
||||
FLAG(RECEIVING);
|
||||
FLAG(SIGNALED);
|
||||
|
||||
+2
-2
@@ -87,7 +87,7 @@ PUBLIC void main()
|
||||
priv(rp)->s_trap_mask = ip->trap_mask; /* allowed traps */
|
||||
|
||||
/* Warn about violations of the boot image table order consistency. */
|
||||
if (priv_id(rp) != s_nr_to_id(ip->proc_nr))
|
||||
if (priv_id(rp) != s_nr_to_id(ip->proc_nr) && (ip->flags & SYS_PROC))
|
||||
kprintf("Warning: boot image table has wrong process order\n");
|
||||
|
||||
/* Initialize call mask bitmap from unordered set.
|
||||
@@ -173,7 +173,7 @@ PUBLIC void main()
|
||||
RTS_SET(rp, VMINHIBIT);
|
||||
|
||||
/* Set ready. The HARDWARE task is never ready. */
|
||||
if (rp->p_nr == HARDWARE) RTS_SET(rp, NO_PRIORITY);
|
||||
if (rp->p_nr == HARDWARE) RTS_SET(rp, PROC_STOP);
|
||||
RTS_UNSET(rp, SLOT_FREE); /* remove SLOT_FREE and schedule */
|
||||
alloc_segments(rp);
|
||||
}
|
||||
|
||||
+140
-38
@@ -59,7 +59,8 @@ FORWARD _PROTOTYPE( int mini_senda, (struct proc *caller_ptr,
|
||||
FORWARD _PROTOTYPE( int deadlock, (int function,
|
||||
register struct proc *caller, int src_dst));
|
||||
FORWARD _PROTOTYPE( int try_async, (struct proc *caller_ptr));
|
||||
FORWARD _PROTOTYPE( int try_one, (struct proc *src_ptr, struct proc *dst_ptr));
|
||||
FORWARD _PROTOTYPE( int try_one, (struct proc *src_ptr, struct proc *dst_ptr,
|
||||
int *postponed));
|
||||
FORWARD _PROTOTYPE( void sched, (struct proc *rp, int *queue, int *front));
|
||||
FORWARD _PROTOTYPE( void pick_proc, (void));
|
||||
|
||||
@@ -137,21 +138,76 @@ PUBLIC void schedcheck(void)
|
||||
}
|
||||
vmassert(proc_ptr);
|
||||
vmassert(!proc_ptr->p_rts_flags);
|
||||
while(proc_ptr->p_misc_flags & MF_DELIVERMSG) {
|
||||
while (proc_ptr->p_misc_flags &
|
||||
(MF_DELIVERMSG | MF_SC_DEFER | MF_SC_TRACE | MF_SC_ACTIVE)) {
|
||||
|
||||
vmassert(!next_ptr);
|
||||
vmassert(!proc_ptr->p_rts_flags);
|
||||
TRACE(VF_SCHEDULING, printf("delivering to %s / %d\n",
|
||||
proc_ptr->p_name, proc_ptr->p_endpoint););
|
||||
if(delivermsg(proc_ptr) == VMSUSPEND) {
|
||||
vmassert(next_ptr);
|
||||
TRACE(VF_SCHEDULING, printf("suspending %s / %d\n",
|
||||
if (proc_ptr->p_misc_flags & MF_DELIVERMSG) {
|
||||
TRACE(VF_SCHEDULING, printf("delivering to %s / %d\n",
|
||||
proc_ptr->p_name, proc_ptr->p_endpoint););
|
||||
vmassert(proc_ptr->p_rts_flags);
|
||||
vmassert(next_ptr != proc_ptr);
|
||||
if(delivermsg(proc_ptr) == VMSUSPEND) {
|
||||
vmassert(next_ptr);
|
||||
TRACE(VF_SCHEDULING,
|
||||
printf("suspending %s / %d\n",
|
||||
proc_ptr->p_name,
|
||||
proc_ptr->p_endpoint););
|
||||
vmassert(proc_ptr->p_rts_flags);
|
||||
vmassert(next_ptr != proc_ptr);
|
||||
}
|
||||
}
|
||||
else if (proc_ptr->p_misc_flags & MF_SC_DEFER) {
|
||||
/* Perform the system call that we deferred earlier. */
|
||||
|
||||
#if DEBUG_SCHED_CHECK
|
||||
if (proc_ptr->p_misc_flags & MF_SC_ACTIVE)
|
||||
minix_panic("MF_SC_ACTIVE and MF_SC_DEFER set",
|
||||
NO_NUM);
|
||||
#endif
|
||||
|
||||
arch_do_syscall(proc_ptr);
|
||||
|
||||
/* If the process is stopped for signal delivery, and
|
||||
* not blocked sending a message after the system call,
|
||||
* inform PM.
|
||||
*/
|
||||
if ((proc_ptr->p_misc_flags & MF_SIG_DELAY) &&
|
||||
!RTS_ISSET(proc_ptr, SENDING))
|
||||
sig_delay_done(proc_ptr);
|
||||
}
|
||||
else if (proc_ptr->p_misc_flags & MF_SC_TRACE) {
|
||||
/* Trigger a system call leave event if this was a
|
||||
* system call. We must do this after processing the
|
||||
* other flags above, both for tracing correctness and
|
||||
* to be able to use 'break'.
|
||||
*/
|
||||
if (!(proc_ptr->p_misc_flags & MF_SC_ACTIVE))
|
||||
break;
|
||||
|
||||
proc_ptr->p_misc_flags &=
|
||||
~(MF_SC_TRACE | MF_SC_ACTIVE);
|
||||
|
||||
/* Signal the "leave system call" event.
|
||||
* Block the process.
|
||||
*/
|
||||
cause_sig(proc_nr(proc_ptr), SIGTRAP);
|
||||
}
|
||||
else if (proc_ptr->p_misc_flags & MF_SC_ACTIVE) {
|
||||
/* If MF_SC_ACTIVE was set, remove it now:
|
||||
* we're leaving the system call.
|
||||
*/
|
||||
proc_ptr->p_misc_flags &= ~MF_SC_ACTIVE;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
/* If proc_ptr is now descheduled,
|
||||
* continue with another process.
|
||||
*/
|
||||
if (next_ptr) {
|
||||
proc_ptr = next_ptr;
|
||||
vmassert(!proc_ptr->p_rts_flags);
|
||||
next_ptr = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
TRACE(VF_SCHEDULING, printf("starting %s / %d\n",
|
||||
proc_ptr->p_name, proc_ptr->p_endpoint););
|
||||
@@ -181,6 +237,37 @@ long bit_map; /* notification event set or flags */
|
||||
int src_dst_p; /* Process slot number */
|
||||
size_t msg_size;
|
||||
|
||||
/* If this process is subject to system call tracing, handle that first. */
|
||||
if (caller_ptr->p_misc_flags & (MF_SC_TRACE | MF_SC_DEFER)) {
|
||||
/* Are we tracing this process, and is it the first sys_call entry? */
|
||||
if ((caller_ptr->p_misc_flags & (MF_SC_TRACE | MF_SC_DEFER)) ==
|
||||
MF_SC_TRACE) {
|
||||
/* We must notify the tracer before processing the actual
|
||||
* system call. If we don't, the tracer could not obtain the
|
||||
* input message. Postpone the entire system call.
|
||||
*/
|
||||
caller_ptr->p_misc_flags &= ~MF_SC_TRACE;
|
||||
caller_ptr->p_misc_flags |= MF_SC_DEFER;
|
||||
|
||||
/* Signal the "enter system call" event. Block the process. */
|
||||
cause_sig(proc_nr(caller_ptr), SIGTRAP);
|
||||
|
||||
/* Preserve the return register's value. */
|
||||
return caller_ptr->p_reg.retreg;
|
||||
}
|
||||
|
||||
/* If the MF_SC_DEFER flag is set, the syscall is now being resumed. */
|
||||
caller_ptr->p_misc_flags &= ~MF_SC_DEFER;
|
||||
|
||||
#if DEBUG_SCHED_CHECK
|
||||
if (caller_ptr->p_misc_flags & MF_SC_ACTIVE)
|
||||
minix_panic("MF_SC_ACTIVE already set", NO_NUM);
|
||||
#endif
|
||||
|
||||
/* Set a flag to allow reliable tracing of leaving the system call. */
|
||||
caller_ptr->p_misc_flags |= MF_SC_ACTIVE;
|
||||
}
|
||||
|
||||
#if DEBUG_SCHED_CHECK
|
||||
if(caller_ptr->p_misc_flags & MF_DELIVERMSG) {
|
||||
kprintf("sys_call: MF_DELIVERMSG on for %s / %d\n",
|
||||
@@ -593,6 +680,8 @@ int flags;
|
||||
vmassert(!(caller_ptr->p_misc_flags & MF_DELIVERMSG));
|
||||
QueueMess((*xpp)->p_endpoint,
|
||||
vir2phys(&(*xpp)->p_sendmsg), caller_ptr);
|
||||
if ((*xpp)->p_misc_flags & MF_SIG_DELAY)
|
||||
sig_delay_done(*xpp);
|
||||
RTS_UNSET(*xpp, SENDING);
|
||||
*xpp = (*xpp)->p_q_link; /* remove from queue */
|
||||
return(OK); /* report success */
|
||||
@@ -603,16 +692,10 @@ int flags;
|
||||
if (caller_ptr->p_misc_flags & MF_ASYNMSG)
|
||||
{
|
||||
if (src_e != ANY)
|
||||
{
|
||||
#if 0
|
||||
kprintf("mini_receive: should try async from %d\n", src_e);
|
||||
#endif
|
||||
r= EAGAIN;
|
||||
}
|
||||
r= try_one(proc_addr(src_p), caller_ptr, NULL);
|
||||
else
|
||||
{
|
||||
r= try_async(caller_ptr);
|
||||
}
|
||||
|
||||
if (r == OK)
|
||||
return OK; /* Got a message */
|
||||
}
|
||||
@@ -772,7 +855,7 @@ size_t size;
|
||||
continue;
|
||||
|
||||
/* Check for reserved bits in the flags field */
|
||||
if (flags & ~(AMF_VALID|AMF_DONE|AMF_NOTIFY) ||
|
||||
if (flags & ~(AMF_VALID|AMF_DONE|AMF_NOTIFY|AMF_NOREPLY) ||
|
||||
!(flags & AMF_VALID))
|
||||
{
|
||||
return EINVAL;
|
||||
@@ -831,14 +914,13 @@ size_t size;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check if 'dst' is blocked waiting for this message. The
|
||||
* destination's SENDING flag may be set when its SENDREC call
|
||||
* blocked while sending.
|
||||
/* Check if 'dst' is blocked waiting for this message.
|
||||
* If AMF_NOREPLY is set, do not satisfy the receiving part of
|
||||
* a SENDREC.
|
||||
*/
|
||||
if ( (dst_ptr->p_rts_flags & (RECEIVING | SENDING)) ==
|
||||
RECEIVING &&
|
||||
(dst_ptr->p_getfrom_e == ANY ||
|
||||
dst_ptr->p_getfrom_e == caller_ptr->p_endpoint))
|
||||
if (WILLRECEIVE(dst_ptr, caller_ptr->p_endpoint) &&
|
||||
(!(flags & AMF_NOREPLY) ||
|
||||
!(dst_ptr->p_misc_flags & MF_REPLY_PEND)))
|
||||
{
|
||||
/* Destination is indeed waiting for this message. */
|
||||
m_ptr= &table[i].msg; /* Note: pointer in the
|
||||
@@ -887,25 +969,25 @@ struct proc *caller_ptr;
|
||||
int r;
|
||||
struct priv *privp;
|
||||
struct proc *src_ptr;
|
||||
|
||||
int postponed = FALSE;
|
||||
|
||||
/* Try all privilege structures */
|
||||
for (privp = BEG_PRIV_ADDR; privp < END_PRIV_ADDR; ++privp)
|
||||
{
|
||||
if (privp->s_proc_nr == NONE || privp->s_id == USER_PRIV_ID)
|
||||
continue;
|
||||
if (privp->s_asynsize == 0)
|
||||
if (privp->s_proc_nr == NONE)
|
||||
continue;
|
||||
|
||||
src_ptr= proc_addr(privp->s_proc_nr);
|
||||
if (!may_send_to(src_ptr, proc_nr(caller_ptr)))
|
||||
continue;
|
||||
|
||||
vmassert(!(caller_ptr->p_misc_flags & MF_DELIVERMSG));
|
||||
r= try_one(src_ptr, caller_ptr);
|
||||
r= try_one(src_ptr, caller_ptr, &postponed);
|
||||
if (r == OK)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Nothing found, clear MF_ASYNMSG */
|
||||
caller_ptr->p_misc_flags &= ~MF_ASYNMSG;
|
||||
/* Nothing found, clear MF_ASYNMSG unless messages were postponed */
|
||||
if (postponed == FALSE)
|
||||
caller_ptr->p_misc_flags &= ~MF_ASYNMSG;
|
||||
|
||||
return ESRCH;
|
||||
}
|
||||
@@ -914,9 +996,10 @@ struct proc *caller_ptr;
|
||||
/*===========================================================================*
|
||||
* try_one *
|
||||
*===========================================================================*/
|
||||
PRIVATE int try_one(src_ptr, dst_ptr)
|
||||
PRIVATE int try_one(src_ptr, dst_ptr, postponed)
|
||||
struct proc *src_ptr;
|
||||
struct proc *dst_ptr;
|
||||
int *postponed;
|
||||
{
|
||||
int i, do_notify, done;
|
||||
unsigned flags;
|
||||
@@ -931,6 +1014,12 @@ struct proc *dst_ptr;
|
||||
int r;
|
||||
|
||||
privp= priv(src_ptr);
|
||||
|
||||
/* Basic validity checks */
|
||||
if (privp->s_id == USER_PRIV_ID) return EAGAIN;
|
||||
if (privp->s_asynsize == 0) return EAGAIN;
|
||||
if (!may_send_to(src_ptr, proc_nr(dst_ptr))) return EAGAIN;
|
||||
|
||||
size= privp->s_asynsize;
|
||||
table_v = privp->s_asyntab;
|
||||
caller_ptr = src_ptr;
|
||||
@@ -953,7 +1042,7 @@ struct proc *dst_ptr;
|
||||
}
|
||||
|
||||
/* Check for reserved bits in the flags field */
|
||||
if (flags & ~(AMF_VALID|AMF_DONE|AMF_NOTIFY) ||
|
||||
if (flags & ~(AMF_VALID|AMF_DONE|AMF_NOTIFY|AMF_NOREPLY) ||
|
||||
!(flags & AMF_VALID))
|
||||
{
|
||||
kprintf("try_one: bad bits in table\n");
|
||||
@@ -980,6 +1069,19 @@ struct proc *dst_ptr;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If AMF_NOREPLY is set, do not satisfy the receiving part of
|
||||
* a SENDREC. Do not unset MF_ASYNMSG later because of this,
|
||||
* though: this message is still to be delivered later.
|
||||
*/
|
||||
if ((flags & AMF_NOREPLY) &&
|
||||
(dst_ptr->p_misc_flags & MF_REPLY_PEND))
|
||||
{
|
||||
if (postponed != NULL)
|
||||
*postponed = TRUE;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Deliver message */
|
||||
table_ptr= (asynmsg_t *)privp->s_asyntab;
|
||||
m_ptr= &table_ptr[i].msg; /* Note: pointer in the
|
||||
|
||||
+12
-7
@@ -106,7 +106,7 @@ struct proc {
|
||||
|
||||
/* Bits for the runtime flags. A process is runnable iff p_rts_flags == 0. */
|
||||
#define SLOT_FREE 0x01 /* process slot is free */
|
||||
#define NO_PRIORITY 0x02 /* process has been stopped */
|
||||
#define PROC_STOP 0x02 /* process has been stopped */
|
||||
#define SENDING 0x04 /* process blocked trying to send */
|
||||
#define RECEIVING 0x08 /* process blocked trying to receive */
|
||||
#define SIGNALED 0x10 /* set when new kernel signal arrives */
|
||||
@@ -118,6 +118,7 @@ struct proc {
|
||||
#define PAGEFAULT 0x400 /* process has unhandled pagefault */
|
||||
#define VMREQUEST 0x800 /* originator of vm memory request */
|
||||
#define VMREQTARGET 0x1000 /* target of vm memory request */
|
||||
#define SYS_LOCK 0x2000 /* temporary process lock flag for systask */
|
||||
|
||||
/* These runtime flags can be tested and manipulated by these macros. */
|
||||
|
||||
@@ -177,12 +178,16 @@ struct proc {
|
||||
} while(0)
|
||||
|
||||
/* Misc flags */
|
||||
#define MF_REPLY_PEND 0x01 /* reply to IPC_REQUEST is pending */
|
||||
#define MF_VIRT_TIMER 0x02 /* process-virtual timer is running */
|
||||
#define MF_PROF_TIMER 0x04 /* process-virtual profile timer is running */
|
||||
#define MF_ASYNMSG 0x10 /* Asynchrous message pending */
|
||||
#define MF_FULLVM 0x20
|
||||
#define MF_DELIVERMSG 0x40 /* Copy message for him before running */
|
||||
#define MF_REPLY_PEND 0x001 /* reply to IPC_REQUEST is pending */
|
||||
#define MF_VIRT_TIMER 0x002 /* process-virtual timer is running */
|
||||
#define MF_PROF_TIMER 0x004 /* process-virtual profile timer is running */
|
||||
#define MF_ASYNMSG 0x010 /* Asynchrous message pending */
|
||||
#define MF_FULLVM 0x020
|
||||
#define MF_DELIVERMSG 0x040 /* Copy message for him before running */
|
||||
#define MF_SIG_DELAY 0x080 /* Send signal when no longer sending */
|
||||
#define MF_SC_ACTIVE 0x100 /* Syscall tracing: in a system call now */
|
||||
#define MF_SC_DEFER 0x200 /* Syscall tracing: deferred system call */
|
||||
#define MF_SC_TRACE 0x400 /* Syscall tracing: trigger syscall events */
|
||||
|
||||
/* Scheduling priorities for p_priority. Values must start at zero (highest
|
||||
* priority) and increment. Priorities of the processes in the boot image
|
||||
|
||||
@@ -58,6 +58,7 @@ _PROTOTYPE( void set_sendto_bit, (struct proc *rc, int id) );
|
||||
_PROTOTYPE( void unset_sendto_bit, (struct proc *rc, int id) );
|
||||
_PROTOTYPE( void send_sig, (int proc_nr, int sig_nr) );
|
||||
_PROTOTYPE( void cause_sig, (int proc_nr, int sig_nr) );
|
||||
_PROTOTYPE( void sig_delay_done, (struct proc *rp) );
|
||||
_PROTOTYPE( void sys_task, (void) );
|
||||
#define numap_local(proc_nr, vir_addr, bytes) \
|
||||
umap_local(proc_addr(proc_nr), D, (vir_addr), (bytes))
|
||||
@@ -173,5 +174,6 @@ _PROTOTYPE( int vm_suspend, (struct proc *caller, struct proc *target,
|
||||
_PROTOTYPE( int delivermsg, (struct proc *target));
|
||||
_PROTOTYPE( phys_bytes arch_switch_copymsg, (struct proc *rp, message *m,
|
||||
phys_bytes lin));
|
||||
_PROTOTYPE( void arch_do_syscall, (struct proc *proc) );
|
||||
|
||||
#endif /* PROTO_H */
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
* unset_sendto_bit: disallow a process from sending messages to a target
|
||||
* send_sig: send a signal directly to a system process
|
||||
* cause_sig: take action to cause a signal to occur via PM
|
||||
* sig_delay_done: tell PM that a process is not sending
|
||||
* umap_bios: map virtual address in BIOS_SEG to physical
|
||||
* get_randomness: accumulate randomness in a buffer
|
||||
* clear_endpoint: remove a process' ability to send and receive messages
|
||||
@@ -178,6 +179,7 @@ PRIVATE void initialize(void)
|
||||
map(SYS_PRIVCTL, do_privctl); /* system privileges control */
|
||||
map(SYS_TRACE, do_trace); /* request a trace operation */
|
||||
map(SYS_SETGRANT, do_setgrant); /* get/set own parameters */
|
||||
map(SYS_RUNCTL, do_runctl); /* set/clear stop flag of a process */
|
||||
|
||||
/* Signal handling. */
|
||||
map(SYS_KILL, do_kill); /* cause a process to be signaled */
|
||||
@@ -365,6 +367,22 @@ int sig_nr; /* signal to be sent, 1 to _NSIG */
|
||||
}
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sig_delay_done *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sig_delay_done(rp)
|
||||
struct proc *rp;
|
||||
{
|
||||
/* A process is now known not to send any direct messages.
|
||||
* Tell PM by sending a signal to the process.
|
||||
* Used for actual signal delivery.
|
||||
*/
|
||||
|
||||
rp->p_misc_flags &= ~MF_SIG_DELAY;
|
||||
|
||||
cause_sig(proc_nr(rp), SIGKREADY);
|
||||
}
|
||||
|
||||
#if _MINIX_CHIP == _CHIP_INTEL
|
||||
|
||||
/*===========================================================================*
|
||||
|
||||
@@ -69,6 +69,11 @@ _PROTOTYPE( int do_nice, (message *m_ptr) );
|
||||
#define do_nice do_unused
|
||||
#endif
|
||||
|
||||
_PROTOTYPE( int do_runctl, (message *m_ptr) );
|
||||
#if ! USE_RUNCTL
|
||||
#define do_runctl do_unused
|
||||
#endif
|
||||
|
||||
_PROTOTYPE( int do_copy, (message *m_ptr) );
|
||||
#define do_vircopy do_copy
|
||||
#if ! (USE_VIRCOPY || USE_PHYSCOPY)
|
||||
|
||||
@@ -29,6 +29,7 @@ OBJECTS = \
|
||||
$(SYSTEM)(do_exit.o) \
|
||||
$(SYSTEM)(do_trace.o) \
|
||||
$(SYSTEM)(do_nice.o) \
|
||||
$(SYSTEM)(do_runctl.o) \
|
||||
$(SYSTEM)(do_times.o) \
|
||||
$(SYSTEM)(do_setalarm.o) \
|
||||
$(SYSTEM)(do_stime.o) \
|
||||
@@ -92,6 +93,9 @@ $(SYSTEM)(do_trace.o): do_trace.c
|
||||
$(SYSTEM)(do_nice.o): do_nice.c
|
||||
$(CC) do_nice.c
|
||||
|
||||
$(SYSTEM)(do_runctl.o): do_runctl.c
|
||||
$(CC) do_runctl.c
|
||||
|
||||
$(SYSTEM)(do_times.o): do_times.c
|
||||
$(CC) do_times.c
|
||||
|
||||
|
||||
@@ -74,8 +74,7 @@ register message *m_ptr; /* pointer to request message */
|
||||
rpc->p_sys_time = 0;
|
||||
|
||||
rpc->p_reg.psw &= ~TRACEBIT; /* clear trace bit */
|
||||
|
||||
rpc->p_misc_flags &= ~(MF_VIRT_TIMER | MF_PROF_TIMER);
|
||||
rpc->p_misc_flags &= ~(MF_VIRT_TIMER | MF_PROF_TIMER | MF_SC_TRACE);
|
||||
rpc->p_virt_left = 0; /* disable, clear the process-virtual timers */
|
||||
rpc->p_prof_left = 0;
|
||||
|
||||
|
||||
+16
-23
@@ -27,32 +27,25 @@ PUBLIC int do_nice(message *m_ptr)
|
||||
pri = m_ptr->PR_PRIORITY;
|
||||
rp = proc_addr(proc_nr);
|
||||
|
||||
if (pri == PRIO_STOP) {
|
||||
/* Take process off the scheduling queues. */
|
||||
RTS_LOCK_SET(rp, NO_PRIORITY);
|
||||
return(OK);
|
||||
}
|
||||
else if (pri >= PRIO_MIN && pri <= PRIO_MAX) {
|
||||
/* 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.
|
||||
*/
|
||||
if (pri < PRIO_MIN || pri > PRIO_MAX) return(EINVAL);
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
new_q = MAX_USER_Q + (pri-PRIO_MIN) * (MIN_USER_Q-MAX_USER_Q+1) /
|
||||
(PRIO_MAX-PRIO_MIN+1);
|
||||
if (new_q < MAX_USER_Q) new_q = MAX_USER_Q; /* shouldn't happen */
|
||||
if (new_q > MIN_USER_Q) new_q = MIN_USER_Q; /* shouldn't happen */
|
||||
new_q = MAX_USER_Q + (pri-PRIO_MIN) * (MIN_USER_Q-MAX_USER_Q+1) /
|
||||
(PRIO_MAX-PRIO_MIN+1);
|
||||
if (new_q < MAX_USER_Q) new_q = MAX_USER_Q; /* shouldn't happen */
|
||||
if (new_q > MIN_USER_Q) new_q = MIN_USER_Q; /* shouldn't happen */
|
||||
|
||||
/* Make sure the process is not running while changing its priority.
|
||||
* Put the process back in its new queue if it is runnable.
|
||||
*/
|
||||
RTS_LOCK_SET(rp, NO_PRIORITY);
|
||||
rp->p_max_priority = rp->p_priority = new_q;
|
||||
RTS_LOCK_UNSET(rp, NO_PRIORITY);
|
||||
/* Make sure the process is not running while changing its priority.
|
||||
* Put the process back in its new queue if it is runnable.
|
||||
*/
|
||||
RTS_LOCK_SET(rp, SYS_LOCK);
|
||||
rp->p_max_priority = rp->p_priority = new_q;
|
||||
RTS_LOCK_UNSET(rp, SYS_LOCK);
|
||||
|
||||
return(OK);
|
||||
}
|
||||
return(EINVAL);
|
||||
return(OK);
|
||||
}
|
||||
|
||||
#endif /* USE_NICE */
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/* The kernel call implemented in this file:
|
||||
* m_type: SYS_RUNCTL
|
||||
*
|
||||
* The parameters for this kernel call are:
|
||||
* m1_i1: RC_ENDPT process number to control
|
||||
* m1_i2: RC_ACTION stop or resume the process
|
||||
*/
|
||||
|
||||
#include "../system.h"
|
||||
#include <minix/type.h>
|
||||
|
||||
#if USE_RUNCTL
|
||||
|
||||
/*===========================================================================*
|
||||
* do_runctl *
|
||||
*===========================================================================*/
|
||||
PUBLIC int do_runctl(message *m_ptr)
|
||||
{
|
||||
/* Control a process's PROC_STOP flag. Used for process management.
|
||||
* If the process is queued sending a message or stopped for system call
|
||||
* tracing, set MF_SIG_DELAY instead of PROC_STOP, and send a SIGKREADY signal
|
||||
* later when the process is done sending. Used by PM for safe signal delivery.
|
||||
*/
|
||||
int proc_nr, action, delayed;
|
||||
register struct proc *rp;
|
||||
|
||||
/* Extract the message parameters and do sanity checking. */
|
||||
if (!isokendpt(m_ptr->RC_ENDPT, &proc_nr)) return(EINVAL);
|
||||
if (iskerneln(proc_nr)) return(EPERM);
|
||||
rp = proc_addr(proc_nr);
|
||||
|
||||
action = m_ptr->RC_ACTION;
|
||||
|
||||
/* Is the target sending or syscall-traced? Then set MF_SIG_DELAY instead.
|
||||
* The process will not become runnable before PM has called SYS_ENDKSIG.
|
||||
* Note that asynchronous messages are not covered: a process using SENDA
|
||||
* should not also install signal handlers *and* expect POSIX compliance.
|
||||
*/
|
||||
if (action == RC_STOP) {
|
||||
RTS_LOCK_SET(rp, SYS_LOCK);
|
||||
|
||||
if (RTS_ISSET(rp, SENDING) || (rp->p_misc_flags & MF_SC_DEFER))
|
||||
rp->p_misc_flags |= MF_SIG_DELAY;
|
||||
|
||||
delayed = (rp->p_misc_flags & MF_SIG_DELAY);
|
||||
|
||||
RTS_LOCK_UNSET(rp, SYS_LOCK);
|
||||
|
||||
if (delayed) return(EBUSY);
|
||||
}
|
||||
|
||||
/* Either set or clear the stop flag. */
|
||||
switch (action) {
|
||||
case RC_STOP:
|
||||
RTS_LOCK_SET(rp, PROC_STOP);
|
||||
break;
|
||||
case RC_RESUME:
|
||||
RTS_LOCK_UNSET(rp, PROC_STOP);
|
||||
break;
|
||||
default:
|
||||
return(EINVAL);
|
||||
}
|
||||
|
||||
return(OK);
|
||||
}
|
||||
|
||||
#endif /* USE_RUNCTL */
|
||||
|
||||
@@ -75,10 +75,7 @@ message *m_ptr; /* pointer to request message */
|
||||
rp->p_reg.sp = (reg_t) frp;
|
||||
rp->p_reg.pc = (reg_t) smsg.sm_sighandler;
|
||||
|
||||
/* Reschedule if necessary. */
|
||||
if(RTS_ISSET(rp, NO_PRIORITY))
|
||||
RTS_LOCK_UNSET(rp, NO_PRIORITY);
|
||||
else {
|
||||
if(!RTS_ISSET(rp, PROC_STOP)) {
|
||||
struct proc *caller;
|
||||
caller = proc_addr(who_p);
|
||||
kprintf("system: warning: sigsend a running process\n");
|
||||
|
||||
@@ -34,6 +34,7 @@ register message *m_ptr;
|
||||
* T_RESUME resume execution
|
||||
* T_EXIT exit
|
||||
* T_STEP set trace bit
|
||||
* T_SYSCALL trace system call
|
||||
*
|
||||
* The T_OK and T_EXIT commands are handled completely by the process manager,
|
||||
* all others come here.
|
||||
@@ -81,11 +82,12 @@ register message *m_ptr;
|
||||
if (iskerneln(tr_proc_nr)) return(EPERM);
|
||||
|
||||
rp = proc_addr(tr_proc_nr);
|
||||
if (isemptyp(rp)) return(EIO);
|
||||
if (isemptyp(rp)) return(EINVAL);
|
||||
switch (tr_request) {
|
||||
case T_STOP: /* stop process */
|
||||
RTS_LOCK_SET(rp, P_STOP);
|
||||
rp->p_reg.psw &= ~TRACEBIT; /* clear trace bit */
|
||||
rp->p_misc_flags &= ~MF_SC_TRACE; /* clear syscall trace flag */
|
||||
return(OK);
|
||||
|
||||
case T_GETINS: /* return value from instruction space */
|
||||
@@ -102,10 +104,22 @@ register message *m_ptr;
|
||||
break;
|
||||
|
||||
case T_GETUSER: /* return value from process table */
|
||||
if ((tr_addr & (sizeof(long) - 1)) != 0 ||
|
||||
tr_addr > sizeof(struct proc) - sizeof(long))
|
||||
return(EIO);
|
||||
m_ptr->CTL_DATA = *(long *) ((char *) rp + (int) tr_addr);
|
||||
if ((tr_addr & (sizeof(long) - 1)) != 0) return(EIO);
|
||||
|
||||
if (tr_addr <= sizeof(struct proc) - sizeof(long)) {
|
||||
m_ptr->CTL_DATA = *(long *) ((char *) rp + (int) tr_addr);
|
||||
break;
|
||||
}
|
||||
|
||||
/* The process's proc struct is followed by its priv struct.
|
||||
* The alignment here should be unnecessary, but better safe..
|
||||
*/
|
||||
i = sizeof(long) - 1;
|
||||
tr_addr -= (sizeof(struct proc) + i) & ~i;
|
||||
|
||||
if (tr_addr > sizeof(struct priv) - sizeof(long)) return(EIO);
|
||||
|
||||
m_ptr->CTL_DATA = *(long *) ((char *) rp->p_priv + (int) tr_addr);
|
||||
break;
|
||||
|
||||
case T_SETINS: /* set value in instruction space */
|
||||
@@ -160,6 +174,12 @@ register message *m_ptr;
|
||||
m_ptr->CTL_DATA = 0;
|
||||
break;
|
||||
|
||||
case T_SYSCALL: /* trace system call */
|
||||
rp->p_misc_flags |= MF_SC_TRACE;
|
||||
RTS_LOCK_UNSET(rp, P_STOP);
|
||||
m_ptr->CTL_DATA = 0;
|
||||
break;
|
||||
|
||||
case T_READB_INS: /* get value from instruction space */
|
||||
COPYFROMPROC(rp->p_memmap[T].mem_len > 0 ? T : D, tr_addr, (vir_bytes) &ub, 1);
|
||||
m_ptr->CTL_DATA = ub;
|
||||
@@ -171,7 +191,7 @@ register message *m_ptr;
|
||||
break;
|
||||
|
||||
default:
|
||||
return(EIO);
|
||||
return(EINVAL);
|
||||
}
|
||||
return(OK);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user