2005-04-21 16:53:53 +02:00
|
|
|
/* This file contains essentially all of the process and message handling.
|
2005-05-30 13:05:42 +02:00
|
|
|
* Together with "mpx.s" it forms the lowest layer of the MINIX kernel.
|
|
|
|
* There is one entry point from the outside:
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
2005-08-29 18:47:18 +02:00
|
|
|
* sys_call: a system call, i.e., the kernel is trapped with an INT
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
2005-05-30 13:05:42 +02:00
|
|
|
* As well as several entry points used from the interrupt and task level:
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
2005-06-17 15:00:04 +02:00
|
|
|
* lock_notify: notify a process of a system event
|
2005-05-18 12:36:23 +02:00
|
|
|
* lock_send: send a message to a process
|
2005-08-19 18:43:28 +02:00
|
|
|
* lock_enqueue: put a process on one of the scheduling queues
|
|
|
|
* lock_dequeue: remove a process from the scheduling queues
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
|
|
|
* Changes:
|
2005-08-22 17:14:11 +02:00
|
|
|
* Aug 19, 2005 rewrote scheduling code (Jorrit N. Herder)
|
|
|
|
* Jul 25, 2005 rewrote system call handling (Jorrit N. Herder)
|
2005-08-19 18:43:28 +02:00
|
|
|
* May 26, 2005 rewrote message passing functions (Jorrit N. Herder)
|
|
|
|
* May 24, 2005 new notification system call (Jorrit N. Herder)
|
|
|
|
* Oct 28, 2004 nonblocking send and receive calls (Jorrit N. Herder)
|
2005-05-30 13:05:42 +02:00
|
|
|
*
|
|
|
|
* The code here is critical to make everything work and is important for the
|
|
|
|
* overall performance of the system. A large fraction of the code deals with
|
|
|
|
* list manipulation. To make this both easy to understand and fast to execute
|
|
|
|
* pointer pointers are used throughout the code. Pointer pointers prevent
|
|
|
|
* exceptions for the head or tail of a linked list.
|
|
|
|
*
|
|
|
|
* node_t *queue, *new_node; // assume these as global variables
|
|
|
|
* node_t **xpp = &queue; // get pointer pointer to head of queue
|
|
|
|
* while (*xpp != NULL) // find last pointer of the linked list
|
|
|
|
* xpp = &(*xpp)->next; // get pointer to next pointer
|
|
|
|
* *xpp = new_node; // now replace the end (the NULL pointer)
|
|
|
|
* new_node->next = NULL; // and mark the new end of the list
|
|
|
|
*
|
|
|
|
* For example, when adding a new node to the end of the list, one normally
|
|
|
|
* makes an exception for an empty list and looks up the end of the list for
|
|
|
|
* nonempty lists. As shown above, this is not required with pointer pointers.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <minix/com.h>
|
2005-07-14 17:12:12 +02:00
|
|
|
#include <minix/callnr.h>
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
#include <minix/endpoint.h>
|
2007-04-23 16:24:30 +02:00
|
|
|
#include <stddef.h>
|
2006-03-15 13:01:59 +01:00
|
|
|
#include <signal.h>
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
#include <minix/portio.h>
|
2008-02-22 13:36:46 +01:00
|
|
|
#include <minix/u64.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
#include "debug.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "proc.h"
|
|
|
|
#include "vm.h"
|
|
|
|
|
2005-05-24 12:06:17 +02:00
|
|
|
/* Scheduling and message passing functions. The functions are available to
|
|
|
|
* other parts of the kernel through lock_...(). The lock temporarily disables
|
|
|
|
* interrupts to prevent race conditions.
|
|
|
|
*/
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
FORWARD _PROTOTYPE( int mini_send, (struct proc *caller_ptr, int dst_e,
|
2008-11-19 13:26:10 +01:00
|
|
|
message *m_ptr, int flags));
|
2005-06-07 14:34:25 +02:00
|
|
|
FORWARD _PROTOTYPE( int mini_receive, (struct proc *caller_ptr, int src,
|
2008-11-19 13:26:10 +01:00
|
|
|
message *m_ptr, int flags));
|
2005-10-12 17:08:23 +02:00
|
|
|
FORWARD _PROTOTYPE( int mini_notify, (struct proc *caller_ptr, int dst));
|
2007-04-23 16:24:30 +02:00
|
|
|
FORWARD _PROTOTYPE( int mini_senda, (struct proc *caller_ptr,
|
|
|
|
asynmsg_t *table, size_t size));
|
2005-10-12 17:08:23 +02:00
|
|
|
FORWARD _PROTOTYPE( int deadlock, (int function,
|
|
|
|
register struct proc *caller, int src_dst));
|
2007-04-23 16:24:30 +02:00
|
|
|
FORWARD _PROTOTYPE( int try_async, (struct proc *caller_ptr));
|
|
|
|
FORWARD _PROTOTYPE( int try_one, (struct proc *src_ptr, struct proc *dst_ptr));
|
2005-10-12 17:08:23 +02:00
|
|
|
FORWARD _PROTOTYPE( void sched, (struct proc *rp, int *queue, int *front));
|
|
|
|
FORWARD _PROTOTYPE( void pick_proc, (void));
|
2005-07-14 17:12:12 +02:00
|
|
|
|
|
|
|
#define BuildMess(m_ptr, src, dst_ptr) \
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
(m_ptr)->m_source = proc_addr(src)->p_endpoint; \
|
2005-07-14 17:12:12 +02:00
|
|
|
(m_ptr)->m_type = NOTIFY_FROM(src); \
|
|
|
|
(m_ptr)->NOTIFY_TIMESTAMP = get_uptime(); \
|
2005-07-19 14:21:36 +02:00
|
|
|
switch (src) { \
|
|
|
|
case HARDWARE: \
|
2005-07-14 17:12:12 +02:00
|
|
|
(m_ptr)->NOTIFY_ARG = priv(dst_ptr)->s_int_pending; \
|
|
|
|
priv(dst_ptr)->s_int_pending = 0; \
|
2005-07-19 14:21:36 +02:00
|
|
|
break; \
|
|
|
|
case SYSTEM: \
|
|
|
|
(m_ptr)->NOTIFY_ARG = priv(dst_ptr)->s_sig_pending; \
|
|
|
|
priv(dst_ptr)->s_sig_pending = 0; \
|
|
|
|
break; \
|
2005-07-14 17:12:12 +02:00
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
#define CopyMess(s,sp,sm,dp,dm) do { \
|
|
|
|
vir_bytes dstlin; \
|
|
|
|
endpoint_t e = proc_addr(s)->p_endpoint; \
|
|
|
|
struct vir_addr src, dst; \
|
|
|
|
int r; \
|
|
|
|
timer_start(0, "copymess"); \
|
|
|
|
if((dstlin = umap_local((dp), D, (vir_bytes) dm, sizeof(message))) == 0){\
|
|
|
|
minix_panic("CopyMess: umap_local failed", __LINE__); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
if(vm_running && \
|
|
|
|
(r=vm_checkrange((dp), (dp), dstlin, sizeof(message), 1, 0)) != OK) { \
|
|
|
|
if(r != VMSUSPEND) \
|
|
|
|
minix_panic("CopyMess: vm_checkrange error", __LINE__); \
|
|
|
|
(dp)->p_vmrequest.saved.msgcopy.dst = (dp); \
|
|
|
|
(dp)->p_vmrequest.saved.msgcopy.dst_v = (vir_bytes) dm; \
|
|
|
|
if(data_copy((sp)->p_endpoint, \
|
|
|
|
(vir_bytes) (sm), SYSTEM, \
|
|
|
|
(vir_bytes) &(dp)->p_vmrequest.saved.msgcopy.msgbuf, \
|
|
|
|
sizeof(message)) != OK) { \
|
|
|
|
minix_panic("CopyMess: data_copy failed", __LINE__);\
|
|
|
|
} \
|
|
|
|
(dp)->p_vmrequest.saved.msgcopy.msgbuf.m_source = e; \
|
|
|
|
(dp)->p_vmrequest.type = VMSTYPE_MSGCOPY; \
|
|
|
|
} else { \
|
|
|
|
src.proc_nr_e = (sp)->p_endpoint; \
|
|
|
|
dst.proc_nr_e = (dp)->p_endpoint; \
|
|
|
|
src.segment = dst.segment = D; \
|
|
|
|
src.offset = (vir_bytes) (sm); \
|
|
|
|
dst.offset = (vir_bytes) (dm); \
|
|
|
|
if(virtual_copy(&src, &dst, sizeof(message)) != OK) { \
|
|
|
|
kprintf("copymess: copy %d:%lx to %d:%lx failed\n",\
|
|
|
|
(sp)->p_endpoint, (sm), (dp)->p_endpoint, dm);\
|
|
|
|
minix_panic("CopyMess: virtual_copy (1) failed", __LINE__); \
|
|
|
|
} \
|
|
|
|
src.proc_nr_e = SYSTEM; \
|
|
|
|
src.offset = (vir_bytes) &e; \
|
|
|
|
if(virtual_copy(&src, &dst, sizeof(e)) != OK) { \
|
|
|
|
kprintf("copymess: copy %d:%lx to %d:%lx\n", \
|
|
|
|
(sp)->p_endpoint, (sm), (dp)->p_endpoint, dm);\
|
|
|
|
minix_panic("CopyMess: virtual_copy (2) failed", __LINE__); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
timer_end(0); \
|
|
|
|
} while(0)
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* sys_call *
|
|
|
|
*===========================================================================*/
|
2006-03-10 17:10:05 +01:00
|
|
|
PUBLIC int sys_call(call_nr, src_dst_e, m_ptr, bit_map)
|
2005-05-30 13:05:42 +02:00
|
|
|
int call_nr; /* system call number and flags */
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
int src_dst_e; /* src to receive from or dst to send to */
|
2005-04-21 16:53:53 +02:00
|
|
|
message *m_ptr; /* pointer to message in the caller's space */
|
2006-03-10 17:10:05 +01:00
|
|
|
long bit_map; /* notification event set or flags */
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
/* System calls are done by trapping to the kernel with an INT instruction.
|
|
|
|
* The trap is caught and sys_call() is called to send or receive a message
|
|
|
|
* (or both). The caller is always given by 'proc_ptr'.
|
|
|
|
*/
|
|
|
|
register struct proc *caller_ptr = proc_ptr; /* get pointer to caller */
|
|
|
|
int mask_entry; /* bit to check in send mask */
|
2005-10-12 17:08:23 +02:00
|
|
|
int group_size; /* used for deadlock check */
|
2005-04-21 16:53:53 +02:00
|
|
|
int result; /* the system call's result */
|
2007-04-23 16:24:30 +02:00
|
|
|
int src_dst_p; /* Process slot number */
|
2008-11-19 13:26:10 +01:00
|
|
|
size_t msg_size;
|
2006-03-08 13:06:33 +01:00
|
|
|
|
2008-02-22 13:36:46 +01:00
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.total= add64u(ipc_stats.total, 1);
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
|
|
|
if(src_dst_e != 4 && src_dst_e != 5 &&
|
|
|
|
caller_ptr->p_endpoint != 4 && caller_ptr->p_endpoint != 5) {
|
|
|
|
if(call_nr == SEND)
|
|
|
|
kprintf("(%d SEND to %d) ", caller_ptr->p_endpoint, src_dst_e);
|
|
|
|
else if(call_nr == RECEIVE)
|
|
|
|
kprintf("(%d RECEIVE from %d) ", caller_ptr->p_endpoint, src_dst_e);
|
|
|
|
else if(call_nr == SENDREC)
|
|
|
|
kprintf("(%d SENDREC to %d) ", caller_ptr->p_endpoint, src_dst_e);
|
|
|
|
else
|
|
|
|
kprintf("(%d %d to/from %d) ", caller_ptr->p_endpoint, call_nr, src_dst_e);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
#if 1
|
Mostly bugfixes of bugs triggered by the test set.
bugfixes:
SYSTEM:
. removed
rc->p_priv->s_flags = 0;
for the priv struct shared by all user processes in get_priv(). this
should only be done once. doing a SYS_PRIV_USER in sys_privctl()
caused the flags of all user processes to be reset, so they were no
longer PREEMPTIBLE. this happened when RS executed a policy script.
(this broke test1 in the test set)
VFS/MFS:
. chown can change the mode of a file, and chmod arguments are only
part of the full file mode so the full filemode is slightly magic.
changed these calls so that the final modes are returned to VFS, so
that the vnode can be kept up-to-date.
(this broke test11 in the test set)
MFS:
. lookup() checked for sizeof(string) instead of sizeof(user_path),
truncating long path names
(caught by test 23)
. truncate functions neglected to update ctime
(this broke test16)
VFS:
. corner case of an empty filename lookup caused fields of a request
not to be filled in in the lookup functions, not making it clear
that the lookup had failed, causing messages to garbage processes,
causing strange failures.
(caught by test 30)
. trust v_size in vnode when doing reads or writes on non-special
files, truncating i/o where necessary; this is necessary for pipes,
as MFS can't tell when a pipe has been truncated without it being
told explicitly each time.
when the last reader/writer on a pipe closes, tell FS about
the new size using truncate_vn().
(this broke test 25, among others)
. permission check for chdir() had disappeared; added a
forbidden() call
(caught by test 23)
new code, shouldn't change anything:
. introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their
LOCK variants. These macros set and clear the p_rts_flags field,
causing a lot of duplicated logic like
old_flags = rp->p_rts_flags; /* save value of the flags */
rp->p_rts_flags &= ~NO_PRIV;
if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp);
to change into the simpler
RTS_LOCK_UNSET(rp, NO_PRIV);
so the macros take care of calling dequeue() and enqueue() (or lock_*()),
as the case may be). This makes the code a bit more readable and a
bit less fragile.
. removed return code from do_clocktick in CLOCK as it currently
never replies
. removed some debug code from VFS
. fixed grant debug message in device.c
preemptive checks, tests, changes:
. added return code checks of receive() to SYSTEM and CLOCK
. O_TRUNC should never arrive at MFS (added sanity check and removed
O_TRUNC code)
. user_path declared with PATH_MAX+1 to let it be null-terminated
. checks in MFS to see if strings passed by VFS are null-terminated
IS:
. static irq name table thrown out
2007-02-01 18:50:02 +01:00
|
|
|
if (RTS_ISSET(caller_ptr, SLOT_FREE))
|
2006-03-08 13:06:33 +01:00
|
|
|
{
|
|
|
|
kprintf("called by the dead?!?\n");
|
2008-02-22 13:36:46 +01:00
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.deadproc++;
|
2006-03-08 13:06:33 +01:00
|
|
|
return EINVAL;
|
|
|
|
}
|
2006-03-08 13:30:43 +01:00
|
|
|
#endif
|
2007-04-23 16:24:30 +02:00
|
|
|
|
|
|
|
/* Check destination. SENDA is special because its argument is a table and
|
|
|
|
* not a single destination. RECEIVE is the only call that accepts ANY (in
|
2008-11-19 13:26:10 +01:00
|
|
|
* addition to a real endpoint). The other calls (SEND, SENDREC,
|
2007-04-23 16:24:30 +02:00
|
|
|
* and NOTIFY) require an endpoint to corresponds to a process. In addition,
|
2008-11-19 13:26:10 +01:00
|
|
|
* it is necessary to check whether a process is allowed to send to a given
|
|
|
|
* destination. For SENDREC we check s_ipc_sendrec, and for SEND,
|
2007-04-23 16:24:30 +02:00
|
|
|
* and NOTIFY we check s_ipc_to.
|
|
|
|
*/
|
|
|
|
if (call_nr == SENDA)
|
|
|
|
{
|
|
|
|
/* No destination argument */
|
|
|
|
}
|
|
|
|
else if (src_dst_e == ANY)
|
|
|
|
{
|
|
|
|
if (call_nr != RECEIVE)
|
|
|
|
{
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
#if DEBUG_ENABLE_IPC_WARNINGS
|
2007-04-23 16:24:30 +02:00
|
|
|
kprintf("sys_call: trap %d by %d with bad endpoint %d\n",
|
|
|
|
call_nr, proc_nr(caller_ptr), src_dst_e);
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
#endif
|
2008-02-22 13:36:46 +01:00
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.bad_endpoint++;
|
2007-04-23 16:24:30 +02:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
src_dst_p = src_dst_e;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Require a valid source and/or destination process. */
|
|
|
|
if(!isokendpt(src_dst_e, &src_dst_p)) {
|
|
|
|
#if DEBUG_ENABLE_IPC_WARNINGS
|
|
|
|
kprintf("sys_call: trap %d by %d with bad endpoint %d\n",
|
|
|
|
call_nr, proc_nr(caller_ptr), src_dst_e);
|
|
|
|
#endif
|
2008-02-22 13:36:46 +01:00
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.bad_endpoint++;
|
2007-04-23 16:24:30 +02:00
|
|
|
return EDEADSRCDST;
|
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
/* If the call is to send to a process, i.e., for SEND,
|
2007-04-23 16:24:30 +02:00
|
|
|
* SENDREC or NOTIFY, verify that the caller is allowed to send to
|
|
|
|
* the given destination.
|
|
|
|
*/
|
|
|
|
if (call_nr == SENDREC)
|
|
|
|
{
|
|
|
|
if (! get_sys_bit(priv(caller_ptr)->s_ipc_sendrec,
|
|
|
|
nr_to_id(src_dst_p))) {
|
|
|
|
#if DEBUG_ENABLE_IPC_WARNINGS
|
|
|
|
kprintf(
|
2008-02-22 13:36:46 +01:00
|
|
|
"sys_call: ipc sendrec mask denied trap %d from %d ('%s') to %d\n",
|
|
|
|
call_nr, proc_nr(caller_ptr),
|
|
|
|
caller_ptr->p_name, src_dst_p);
|
2007-04-23 16:24:30 +02:00
|
|
|
#endif
|
2008-02-22 13:36:46 +01:00
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.dst_not_allowed++;
|
2007-04-23 16:24:30 +02:00
|
|
|
return(ECALLDENIED); /* call denied by ipc mask */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (call_nr == SEND || call_nr == SENDNB || call_nr == NOTIFY)
|
|
|
|
{
|
|
|
|
if (! get_sys_bit(priv(caller_ptr)->s_ipc_to,
|
|
|
|
nr_to_id(src_dst_p))) {
|
|
|
|
#if DEBUG_ENABLE_IPC_WARNINGS
|
|
|
|
kprintf(
|
|
|
|
"sys_call: ipc mask denied trap %d from %d to %d\n",
|
|
|
|
call_nr, proc_nr(caller_ptr), src_dst_p);
|
|
|
|
#endif
|
2008-02-22 13:36:46 +01:00
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.dst_not_allowed++;
|
2007-04-23 16:24:30 +02:00
|
|
|
return(ECALLDENIED); /* call denied by ipc mask */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only allow non-negative call_nr values less than 32 */
|
|
|
|
if (call_nr < 0 || call_nr >= 32)
|
|
|
|
{
|
|
|
|
#if DEBUG_ENABLE_IPC_WARNINGS
|
|
|
|
kprintf("sys_call: trap %d not allowed, caller %d, src_dst %d\n",
|
|
|
|
call_nr, proc_nr(caller_ptr), src_dst_p);
|
|
|
|
#endif
|
2008-02-22 13:36:46 +01:00
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.bad_call++;
|
|
|
|
return(ETRAPDENIED); /* trap denied by mask or kernel */
|
2007-04-23 16:24:30 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-05-31 11:50:51 +02:00
|
|
|
/* Check if the process has privileges for the requested call. Calls to the
|
|
|
|
* kernel may only be SENDREC, because tasks always reply and may not block
|
|
|
|
* if the caller doesn't do receive().
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2007-04-23 16:24:30 +02:00
|
|
|
if (!(priv(caller_ptr)->s_trap_mask & (1 << call_nr))) {
|
2005-10-18 18:13:12 +02:00
|
|
|
#if DEBUG_ENABLE_IPC_WARNINGS
|
2005-08-10 11:51:29 +02:00
|
|
|
kprintf("sys_call: trap %d not allowed, caller %d, src_dst %d\n",
|
2007-04-23 16:24:30 +02:00
|
|
|
call_nr, proc_nr(caller_ptr), src_dst_p);
|
2005-10-18 18:13:12 +02:00
|
|
|
#endif
|
2008-02-22 13:36:46 +01:00
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.call_not_allowed++;
|
|
|
|
return(ETRAPDENIED); /* trap denied by mask or kernel */
|
2005-08-05 20:57:20 +02:00
|
|
|
}
|
2005-05-26 15:17:57 +02:00
|
|
|
|
2008-02-25 15:35:11 +01:00
|
|
|
if ((iskerneln(src_dst_p) && call_nr != SENDREC && call_nr != RECEIVE)) {
|
2005-10-18 18:13:12 +02:00
|
|
|
#if DEBUG_ENABLE_IPC_WARNINGS
|
2007-04-23 16:24:30 +02:00
|
|
|
kprintf("sys_call: trap %d not allowed, caller %d, src_dst %d\n",
|
2008-11-19 13:26:10 +01:00
|
|
|
call_nr, proc_nr(caller_ptr), src_dst_e);
|
2005-10-18 18:13:12 +02:00
|
|
|
#endif
|
2008-02-22 13:36:46 +01:00
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.call_not_allowed++;
|
|
|
|
return(ETRAPDENIED); /* trap denied by mask or kernel */
|
2005-07-26 14:48:34 +02:00
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
/* Get and check the size of the argument in bytes.
|
|
|
|
* Normally this is just the size of a regular message, but in the
|
|
|
|
* case of SENDA the argument is a table.
|
|
|
|
*/
|
|
|
|
if(call_nr == SENDA) {
|
|
|
|
msg_size = (size_t) src_dst_e;
|
|
|
|
|
|
|
|
/* Limit size to something reasonable. An arbitrary choice is 16
|
|
|
|
* times the number of process table entries.
|
|
|
|
*/
|
|
|
|
if (msg_size > 16*(NR_TASKS + NR_PROCS))
|
|
|
|
return EDOM;
|
|
|
|
msg_size *= sizeof(asynmsg_t); /* convert to bytes */
|
|
|
|
} else {
|
|
|
|
msg_size = sizeof(*m_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the call involves a message buffer, i.e., for SEND, SENDREC,
|
2007-04-23 16:24:30 +02:00
|
|
|
* or RECEIVE, check the message pointer. This check allows a message to be
|
|
|
|
* anywhere in data or stack or gap. It will have to be made more elaborate
|
|
|
|
* for machines which don't have the gap mapped.
|
2008-11-19 13:26:10 +01:00
|
|
|
*
|
|
|
|
* We use msg_size decided above.
|
2005-07-26 14:48:34 +02:00
|
|
|
*/
|
2008-11-19 13:26:10 +01:00
|
|
|
if (call_nr == SEND || call_nr == SENDREC ||
|
|
|
|
call_nr == RECEIVE || call_nr == SENDA || call_nr == SENDNB) {
|
|
|
|
int r;
|
|
|
|
phys_bytes lin;
|
|
|
|
|
|
|
|
/* Map to linear address. */
|
|
|
|
if((lin = umap_local(caller_ptr, D, (vir_bytes) m_ptr, msg_size)) == 0)
|
|
|
|
return EFAULT;
|
|
|
|
|
|
|
|
/* Check if message pages in calling process are mapped.
|
|
|
|
* We don't have to check the recipient if this is a send,
|
|
|
|
* because this code will do that before its receive() starts.
|
|
|
|
*
|
|
|
|
* It is important the range is verified as _writable_, because
|
|
|
|
* the kernel will want to write to the SENDA buffer in the future,
|
|
|
|
* and those pages may not be shared between processes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(vm_running &&
|
|
|
|
(r=vm_checkrange(caller_ptr, caller_ptr, lin, msg_size, 1, 0)) != OK) {
|
|
|
|
if(r != VMSUSPEND) {
|
|
|
|
kprintf("SYSTEM:sys_call:vm_checkrange: err %d\n", r);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
minix_panic("vmsuspend", __LINE__);
|
|
|
|
|
|
|
|
/* We can't go ahead with this call. Caller is suspended
|
|
|
|
* and we have to save the state in its process struct.
|
|
|
|
*/
|
|
|
|
caller_ptr->p_vmrequest.saved.sys_call.call_nr = call_nr;
|
|
|
|
caller_ptr->p_vmrequest.saved.sys_call.m_ptr = m_ptr;
|
|
|
|
caller_ptr->p_vmrequest.saved.sys_call.src_dst_e = src_dst_e;
|
|
|
|
caller_ptr->p_vmrequest.saved.sys_call.bit_map = bit_map;
|
|
|
|
caller_ptr->p_vmrequest.type = VMSTYPE_SYS_CALL;
|
|
|
|
|
|
|
|
kprintf("SYSTEM: %s:%d: suspending call 0x%lx on ipc buffer 0x%lx\n",
|
|
|
|
caller_ptr->p_name, caller_ptr->p_endpoint, call_nr, m_ptr);
|
|
|
|
|
|
|
|
/* vm_checkrange() will have suspended caller with VMREQUEST. */
|
|
|
|
return OK;
|
2007-04-23 16:24:30 +02:00
|
|
|
}
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-10-12 17:08:23 +02:00
|
|
|
/* Check for a possible deadlock for blocking SEND(REC) and RECEIVE. */
|
2007-04-23 16:24:30 +02:00
|
|
|
if (call_nr == SEND || call_nr == SENDREC || call_nr == RECEIVE) {
|
|
|
|
if (group_size = deadlock(call_nr, caller_ptr, src_dst_p)) {
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
2005-10-12 17:08:23 +02:00
|
|
|
kprintf("sys_call: trap %d from %d to %d deadlocked, group size %d\n",
|
2007-04-23 16:24:30 +02:00
|
|
|
call_nr, proc_nr(caller_ptr), src_dst_p, group_size);
|
2005-10-18 18:13:12 +02:00
|
|
|
#endif
|
2008-02-22 13:36:46 +01:00
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.deadlock++;
|
|
|
|
return(ELOCKED);
|
2005-10-12 17:08:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Now check if the call is known and try to perform the request. The only
|
|
|
|
* system calls that exist in MINIX are sending and receiving messages.
|
2005-05-30 13:05:42 +02:00
|
|
|
* - SENDREC: combines SEND and RECEIVE in a single system call
|
|
|
|
* - SEND: sender blocks until its message has been delivered
|
|
|
|
* - RECEIVE: receiver blocks until an acceptable message has arrived
|
2007-04-23 16:24:30 +02:00
|
|
|
* - NOTIFY: asynchronous call; deliver notification or mark pending
|
|
|
|
* - SENDA: list of asynchronous send requests
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2007-04-23 16:24:30 +02:00
|
|
|
switch(call_nr) {
|
2005-07-27 16:08:59 +02:00
|
|
|
case SENDREC:
|
2007-04-23 16:24:30 +02:00
|
|
|
/* A flag is set so that notifications cannot interrupt SENDREC. */
|
|
|
|
caller_ptr->p_misc_flags |= REPLY_PENDING;
|
|
|
|
/* fall through */
|
2005-05-27 14:44:14 +02:00
|
|
|
case SEND:
|
2008-11-19 13:26:10 +01:00
|
|
|
result = mini_send(caller_ptr, src_dst_e, m_ptr, 0);
|
2007-04-23 16:24:30 +02:00
|
|
|
if (call_nr == SEND || result != OK)
|
|
|
|
break; /* done, or SEND failed */
|
|
|
|
/* fall through for SENDREC */
|
2005-05-26 15:17:57 +02:00
|
|
|
case RECEIVE:
|
2007-04-23 16:24:30 +02:00
|
|
|
if (call_nr == RECEIVE)
|
|
|
|
caller_ptr->p_misc_flags &= ~REPLY_PENDING;
|
2008-11-19 13:26:10 +01:00
|
|
|
result = mini_receive(caller_ptr, src_dst_e, m_ptr, 0);
|
2007-04-23 16:24:30 +02:00
|
|
|
break;
|
2005-05-26 15:17:57 +02:00
|
|
|
case NOTIFY:
|
2007-04-23 16:24:30 +02:00
|
|
|
result = mini_notify(caller_ptr, src_dst_p);
|
|
|
|
break;
|
2008-11-19 13:26:10 +01:00
|
|
|
case SENDNB:
|
|
|
|
result = mini_send(caller_ptr, src_dst_e, m_ptr, NON_BLOCKING);
|
|
|
|
break;
|
2007-04-23 16:24:30 +02:00
|
|
|
case SENDA:
|
|
|
|
result = mini_senda(caller_ptr, (asynmsg_t *)m_ptr, (size_t)src_dst_e);
|
|
|
|
break;
|
2005-05-26 15:17:57 +02:00
|
|
|
default:
|
2007-04-23 16:24:30 +02:00
|
|
|
result = EBADCALL; /* illegal system call */
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, return the result of the system call to the caller. */
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2005-10-12 17:08:23 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* deadlock *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE int deadlock(function, cp, src_dst)
|
|
|
|
int function; /* trap number */
|
|
|
|
register struct proc *cp; /* pointer to caller */
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
int src_dst; /* src or dst process */
|
2005-10-12 17:08:23 +02:00
|
|
|
{
|
|
|
|
/* Check for deadlock. This can happen if 'caller_ptr' and 'src_dst' have
|
|
|
|
* a cyclic dependency of blocking send and receive calls. The only cyclic
|
|
|
|
* depency that is not fatal is if the caller and target directly SEND(REC)
|
|
|
|
* and RECEIVE to each other. If a deadlock is found, the group size is
|
|
|
|
* returned. Otherwise zero is returned.
|
|
|
|
*/
|
|
|
|
register struct proc *xp; /* process pointer */
|
|
|
|
int group_size = 1; /* start with only caller */
|
|
|
|
int trap_flags;
|
2008-11-19 13:26:10 +01:00
|
|
|
#if DEBUG_ENABLE_IPC_WARNINGS
|
|
|
|
static struct proc *processes[NR_PROCS + NR_TASKS];
|
|
|
|
processes[0] = cp;
|
|
|
|
#endif
|
2005-10-12 17:08:23 +02:00
|
|
|
|
|
|
|
while (src_dst != ANY) { /* check while process nr */
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
int src_dst_e;
|
2005-10-12 17:08:23 +02:00
|
|
|
xp = proc_addr(src_dst); /* follow chain of processes */
|
2008-11-19 13:26:10 +01:00
|
|
|
#if DEBUG_ENABLE_IPC_WARNINGS
|
|
|
|
processes[group_size] = xp;
|
|
|
|
#endif
|
2005-10-12 17:08:23 +02:00
|
|
|
group_size ++; /* extra process in group */
|
|
|
|
|
2006-03-09 14:59:59 +01:00
|
|
|
/* Check whether the last process in the chain has a dependency. If it
|
2005-10-12 17:08:23 +02:00
|
|
|
* has not, the cycle cannot be closed and we are done.
|
|
|
|
*/
|
Mostly bugfixes of bugs triggered by the test set.
bugfixes:
SYSTEM:
. removed
rc->p_priv->s_flags = 0;
for the priv struct shared by all user processes in get_priv(). this
should only be done once. doing a SYS_PRIV_USER in sys_privctl()
caused the flags of all user processes to be reset, so they were no
longer PREEMPTIBLE. this happened when RS executed a policy script.
(this broke test1 in the test set)
VFS/MFS:
. chown can change the mode of a file, and chmod arguments are only
part of the full file mode so the full filemode is slightly magic.
changed these calls so that the final modes are returned to VFS, so
that the vnode can be kept up-to-date.
(this broke test11 in the test set)
MFS:
. lookup() checked for sizeof(string) instead of sizeof(user_path),
truncating long path names
(caught by test 23)
. truncate functions neglected to update ctime
(this broke test16)
VFS:
. corner case of an empty filename lookup caused fields of a request
not to be filled in in the lookup functions, not making it clear
that the lookup had failed, causing messages to garbage processes,
causing strange failures.
(caught by test 30)
. trust v_size in vnode when doing reads or writes on non-special
files, truncating i/o where necessary; this is necessary for pipes,
as MFS can't tell when a pipe has been truncated without it being
told explicitly each time.
when the last reader/writer on a pipe closes, tell FS about
the new size using truncate_vn().
(this broke test 25, among others)
. permission check for chdir() had disappeared; added a
forbidden() call
(caught by test 23)
new code, shouldn't change anything:
. introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their
LOCK variants. These macros set and clear the p_rts_flags field,
causing a lot of duplicated logic like
old_flags = rp->p_rts_flags; /* save value of the flags */
rp->p_rts_flags &= ~NO_PRIV;
if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp);
to change into the simpler
RTS_LOCK_UNSET(rp, NO_PRIV);
so the macros take care of calling dequeue() and enqueue() (or lock_*()),
as the case may be). This makes the code a bit more readable and a
bit less fragile.
. removed return code from do_clocktick in CLOCK as it currently
never replies
. removed some debug code from VFS
. fixed grant debug message in device.c
preemptive checks, tests, changes:
. added return code checks of receive() to SYSTEM and CLOCK
. O_TRUNC should never arrive at MFS (added sanity check and removed
O_TRUNC code)
. user_path declared with PATH_MAX+1 to let it be null-terminated
. checks in MFS to see if strings passed by VFS are null-terminated
IS:
. static irq name table thrown out
2007-02-01 18:50:02 +01:00
|
|
|
if (RTS_ISSET(xp, RECEIVING)) { /* xp has dependency */
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
if(xp->p_getfrom_e == ANY) src_dst = ANY;
|
|
|
|
else okendpt(xp->p_getfrom_e, &src_dst);
|
Mostly bugfixes of bugs triggered by the test set.
bugfixes:
SYSTEM:
. removed
rc->p_priv->s_flags = 0;
for the priv struct shared by all user processes in get_priv(). this
should only be done once. doing a SYS_PRIV_USER in sys_privctl()
caused the flags of all user processes to be reset, so they were no
longer PREEMPTIBLE. this happened when RS executed a policy script.
(this broke test1 in the test set)
VFS/MFS:
. chown can change the mode of a file, and chmod arguments are only
part of the full file mode so the full filemode is slightly magic.
changed these calls so that the final modes are returned to VFS, so
that the vnode can be kept up-to-date.
(this broke test11 in the test set)
MFS:
. lookup() checked for sizeof(string) instead of sizeof(user_path),
truncating long path names
(caught by test 23)
. truncate functions neglected to update ctime
(this broke test16)
VFS:
. corner case of an empty filename lookup caused fields of a request
not to be filled in in the lookup functions, not making it clear
that the lookup had failed, causing messages to garbage processes,
causing strange failures.
(caught by test 30)
. trust v_size in vnode when doing reads or writes on non-special
files, truncating i/o where necessary; this is necessary for pipes,
as MFS can't tell when a pipe has been truncated without it being
told explicitly each time.
when the last reader/writer on a pipe closes, tell FS about
the new size using truncate_vn().
(this broke test 25, among others)
. permission check for chdir() had disappeared; added a
forbidden() call
(caught by test 23)
new code, shouldn't change anything:
. introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their
LOCK variants. These macros set and clear the p_rts_flags field,
causing a lot of duplicated logic like
old_flags = rp->p_rts_flags; /* save value of the flags */
rp->p_rts_flags &= ~NO_PRIV;
if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp);
to change into the simpler
RTS_LOCK_UNSET(rp, NO_PRIV);
so the macros take care of calling dequeue() and enqueue() (or lock_*()),
as the case may be). This makes the code a bit more readable and a
bit less fragile.
. removed return code from do_clocktick in CLOCK as it currently
never replies
. removed some debug code from VFS
. fixed grant debug message in device.c
preemptive checks, tests, changes:
. added return code checks of receive() to SYSTEM and CLOCK
. O_TRUNC should never arrive at MFS (added sanity check and removed
O_TRUNC code)
. user_path declared with PATH_MAX+1 to let it be null-terminated
. checks in MFS to see if strings passed by VFS are null-terminated
IS:
. static irq name table thrown out
2007-02-01 18:50:02 +01:00
|
|
|
} else if (RTS_ISSET(xp, SENDING)) { /* xp has dependency */
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
okendpt(xp->p_sendto_e, &src_dst);
|
2005-10-12 17:08:23 +02:00
|
|
|
} else {
|
|
|
|
return(0); /* not a deadlock */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now check if there is a cyclic dependency. For group sizes of two,
|
|
|
|
* a combination of SEND(REC) and RECEIVE is not fatal. Larger groups
|
|
|
|
* or other combinations indicate a deadlock.
|
|
|
|
*/
|
|
|
|
if (src_dst == proc_nr(cp)) { /* possible deadlock */
|
|
|
|
if (group_size == 2) { /* caller and src_dst */
|
|
|
|
/* The function number is magically converted to flags. */
|
|
|
|
if ((xp->p_rts_flags ^ (function << 2)) & SENDING) {
|
|
|
|
return(0); /* not a deadlock */
|
|
|
|
}
|
|
|
|
}
|
2008-11-19 13:26:10 +01:00
|
|
|
#if DEBUG_ENABLE_IPC_WARNINGS
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
kprintf("deadlock between these processes:\n");
|
|
|
|
for(i = 0; i < group_size; i++) {
|
|
|
|
kprintf(" %10s ", processes[i]->p_name);
|
|
|
|
proc_stacktrace(processes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2005-10-12 17:08:23 +02:00
|
|
|
return(group_size); /* deadlock found */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(0); /* not a deadlock */
|
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* sys_call_restart *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void sys_call_restart(caller)
|
|
|
|
struct proc *caller;
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
minix_panic("sys_call_restart", NO_NUM);
|
|
|
|
kprintf("restarting sys_call code 0x%lx, "
|
|
|
|
"m_ptr 0x%lx, srcdst %d, bitmap 0x%lx, but not really\n",
|
|
|
|
caller->p_vmrequest.saved.sys_call.call_nr,
|
|
|
|
caller->p_vmrequest.saved.sys_call.m_ptr,
|
|
|
|
caller->p_vmrequest.saved.sys_call.src_dst_e,
|
|
|
|
caller->p_vmrequest.saved.sys_call.bit_map);
|
|
|
|
caller->p_reg.retreg = r;
|
|
|
|
}
|
2007-04-23 16:24:30 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* mini_send *
|
|
|
|
*===========================================================================*/
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
PRIVATE int mini_send(caller_ptr, dst_e, m_ptr, flags)
|
2005-04-21 16:53:53 +02:00
|
|
|
register struct proc *caller_ptr; /* who is trying to send a message? */
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
int dst_e; /* to whom is message being sent? */
|
2005-04-21 16:53:53 +02:00
|
|
|
message *m_ptr; /* pointer to message buffer */
|
2008-11-19 13:26:10 +01:00
|
|
|
int flags;
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2005-05-24 12:06:17 +02:00
|
|
|
/* Send a message from 'caller_ptr' to 'dst'. If 'dst' is blocked waiting
|
|
|
|
* for this message, copy the message to it and unblock 'dst'. If 'dst' is
|
2005-04-21 16:53:53 +02:00
|
|
|
* not waiting at all, or is waiting for another source, queue 'caller_ptr'.
|
|
|
|
*/
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
register struct proc *dst_ptr;
|
2005-05-26 15:17:57 +02:00
|
|
|
register struct proc **xpp;
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
int dst_p;
|
|
|
|
|
|
|
|
dst_p = _ENDPOINT_P(dst_e);
|
|
|
|
dst_ptr = proc_addr(dst_p);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2008-02-22 13:36:46 +01:00
|
|
|
if (RTS_ISSET(dst_ptr, NO_ENDPOINT))
|
|
|
|
{
|
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.dst_died++;
|
|
|
|
return EDSTDIED;
|
|
|
|
}
|
2006-03-15 13:01:59 +01:00
|
|
|
|
2005-05-26 15:17:57 +02:00
|
|
|
/* Check if 'dst' is blocked waiting for this message. The destination's
|
2005-05-30 13:05:42 +02:00
|
|
|
* SENDING flag may be set when its SENDREC call blocked while sending.
|
2005-05-26 15:17:57 +02:00
|
|
|
*/
|
2008-11-19 13:26:10 +01:00
|
|
|
if (WILLRECEIVE(dst_ptr, caller_ptr->p_endpoint)) {
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Destination is indeed waiting for this message. */
|
2005-05-26 15:17:57 +02:00
|
|
|
CopyMess(caller_ptr->p_nr, caller_ptr, m_ptr, dst_ptr,
|
2005-05-24 12:06:17 +02:00
|
|
|
dst_ptr->p_messbuf);
|
Mostly bugfixes of bugs triggered by the test set.
bugfixes:
SYSTEM:
. removed
rc->p_priv->s_flags = 0;
for the priv struct shared by all user processes in get_priv(). this
should only be done once. doing a SYS_PRIV_USER in sys_privctl()
caused the flags of all user processes to be reset, so they were no
longer PREEMPTIBLE. this happened when RS executed a policy script.
(this broke test1 in the test set)
VFS/MFS:
. chown can change the mode of a file, and chmod arguments are only
part of the full file mode so the full filemode is slightly magic.
changed these calls so that the final modes are returned to VFS, so
that the vnode can be kept up-to-date.
(this broke test11 in the test set)
MFS:
. lookup() checked for sizeof(string) instead of sizeof(user_path),
truncating long path names
(caught by test 23)
. truncate functions neglected to update ctime
(this broke test16)
VFS:
. corner case of an empty filename lookup caused fields of a request
not to be filled in in the lookup functions, not making it clear
that the lookup had failed, causing messages to garbage processes,
causing strange failures.
(caught by test 30)
. trust v_size in vnode when doing reads or writes on non-special
files, truncating i/o where necessary; this is necessary for pipes,
as MFS can't tell when a pipe has been truncated without it being
told explicitly each time.
when the last reader/writer on a pipe closes, tell FS about
the new size using truncate_vn().
(this broke test 25, among others)
. permission check for chdir() had disappeared; added a
forbidden() call
(caught by test 23)
new code, shouldn't change anything:
. introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their
LOCK variants. These macros set and clear the p_rts_flags field,
causing a lot of duplicated logic like
old_flags = rp->p_rts_flags; /* save value of the flags */
rp->p_rts_flags &= ~NO_PRIV;
if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp);
to change into the simpler
RTS_LOCK_UNSET(rp, NO_PRIV);
so the macros take care of calling dequeue() and enqueue() (or lock_*()),
as the case may be). This makes the code a bit more readable and a
bit less fragile.
. removed return code from do_clocktick in CLOCK as it currently
never replies
. removed some debug code from VFS
. fixed grant debug message in device.c
preemptive checks, tests, changes:
. added return code checks of receive() to SYSTEM and CLOCK
. O_TRUNC should never arrive at MFS (added sanity check and removed
O_TRUNC code)
. user_path declared with PATH_MAX+1 to let it be null-terminated
. checks in MFS to see if strings passed by VFS are null-terminated
IS:
. static irq name table thrown out
2007-02-01 18:50:02 +01:00
|
|
|
RTS_UNSET(dst_ptr, RECEIVING);
|
2008-11-19 13:26:10 +01:00
|
|
|
} else {
|
|
|
|
if(flags & NON_BLOCKING) {
|
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.not_ready++;
|
|
|
|
return(ENOTREADY);
|
|
|
|
}
|
|
|
|
|
2005-10-07 15:23:18 +02:00
|
|
|
/* Destination is not waiting. Block and dequeue caller. */
|
2005-04-21 16:53:53 +02:00
|
|
|
caller_ptr->p_messbuf = m_ptr;
|
Mostly bugfixes of bugs triggered by the test set.
bugfixes:
SYSTEM:
. removed
rc->p_priv->s_flags = 0;
for the priv struct shared by all user processes in get_priv(). this
should only be done once. doing a SYS_PRIV_USER in sys_privctl()
caused the flags of all user processes to be reset, so they were no
longer PREEMPTIBLE. this happened when RS executed a policy script.
(this broke test1 in the test set)
VFS/MFS:
. chown can change the mode of a file, and chmod arguments are only
part of the full file mode so the full filemode is slightly magic.
changed these calls so that the final modes are returned to VFS, so
that the vnode can be kept up-to-date.
(this broke test11 in the test set)
MFS:
. lookup() checked for sizeof(string) instead of sizeof(user_path),
truncating long path names
(caught by test 23)
. truncate functions neglected to update ctime
(this broke test16)
VFS:
. corner case of an empty filename lookup caused fields of a request
not to be filled in in the lookup functions, not making it clear
that the lookup had failed, causing messages to garbage processes,
causing strange failures.
(caught by test 30)
. trust v_size in vnode when doing reads or writes on non-special
files, truncating i/o where necessary; this is necessary for pipes,
as MFS can't tell when a pipe has been truncated without it being
told explicitly each time.
when the last reader/writer on a pipe closes, tell FS about
the new size using truncate_vn().
(this broke test 25, among others)
. permission check for chdir() had disappeared; added a
forbidden() call
(caught by test 23)
new code, shouldn't change anything:
. introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their
LOCK variants. These macros set and clear the p_rts_flags field,
causing a lot of duplicated logic like
old_flags = rp->p_rts_flags; /* save value of the flags */
rp->p_rts_flags &= ~NO_PRIV;
if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp);
to change into the simpler
RTS_LOCK_UNSET(rp, NO_PRIV);
so the macros take care of calling dequeue() and enqueue() (or lock_*()),
as the case may be). This makes the code a bit more readable and a
bit less fragile.
. removed return code from do_clocktick in CLOCK as it currently
never replies
. removed some debug code from VFS
. fixed grant debug message in device.c
preemptive checks, tests, changes:
. added return code checks of receive() to SYSTEM and CLOCK
. O_TRUNC should never arrive at MFS (added sanity check and removed
O_TRUNC code)
. user_path declared with PATH_MAX+1 to let it be null-terminated
. checks in MFS to see if strings passed by VFS are null-terminated
IS:
. static irq name table thrown out
2007-02-01 18:50:02 +01:00
|
|
|
RTS_SET(caller_ptr, SENDING);
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
caller_ptr->p_sendto_e = dst_e;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Process is now blocked. Put in on the destination's queue. */
|
2005-05-30 13:05:42 +02:00
|
|
|
xpp = &dst_ptr->p_caller_q; /* find end of list */
|
2005-08-19 18:43:28 +02:00
|
|
|
while (*xpp != NIL_PROC) xpp = &(*xpp)->p_q_link;
|
2005-05-30 13:05:42 +02:00
|
|
|
*xpp = caller_ptr; /* add caller to end */
|
|
|
|
caller_ptr->p_q_link = NIL_PROC; /* mark new end of list */
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
2005-06-07 14:34:25 +02:00
|
|
|
* mini_receive *
|
2005-04-21 16:53:53 +02:00
|
|
|
*===========================================================================*/
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
PRIVATE int mini_receive(caller_ptr, src_e, m_ptr, flags)
|
2005-04-21 16:53:53 +02:00
|
|
|
register struct proc *caller_ptr; /* process trying to get message */
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
int src_e; /* which message source is wanted */
|
2005-04-21 16:53:53 +02:00
|
|
|
message *m_ptr; /* pointer to message buffer */
|
2008-11-19 13:26:10 +01:00
|
|
|
int flags;
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2005-05-30 13:05:42 +02:00
|
|
|
/* A process or task wants to get a message. If a message is already queued,
|
2005-04-21 16:53:53 +02:00
|
|
|
* acquire it and deblock the sender. If no message from the desired source
|
2008-11-19 13:26:10 +01:00
|
|
|
* is available block the caller.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2005-05-26 15:17:57 +02:00
|
|
|
register struct proc **xpp;
|
2005-05-19 16:05:51 +02:00
|
|
|
register struct notification **ntf_q_pp;
|
2005-04-21 16:53:53 +02:00
|
|
|
message m;
|
2005-05-26 15:17:57 +02:00
|
|
|
int bit_nr;
|
2005-07-14 17:12:12 +02:00
|
|
|
sys_map_t *map;
|
|
|
|
bitchunk_t *chunk;
|
2007-04-23 16:24:30 +02:00
|
|
|
int i, r, src_id, src_proc_nr, src_p;
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
|
|
|
|
if(src_e == ANY) src_p = ANY;
|
2006-03-15 13:01:59 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
okendpt(src_e, &src_p);
|
2008-02-22 13:36:46 +01:00
|
|
|
if (RTS_ISSET(proc_addr(src_p), NO_ENDPOINT))
|
|
|
|
{
|
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.src_died++;
|
|
|
|
return ESRCDIED;
|
|
|
|
}
|
2006-03-15 13:01:59 +01:00
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-05-26 15:17:57 +02:00
|
|
|
/* Check to see if a message from desired source is already available.
|
2005-05-27 14:44:14 +02:00
|
|
|
* The caller's SENDING flag may be set if SENDREC couldn't send. If it is
|
2005-05-26 15:17:57 +02:00
|
|
|
* set, the process should be blocked.
|
|
|
|
*/
|
Mostly bugfixes of bugs triggered by the test set.
bugfixes:
SYSTEM:
. removed
rc->p_priv->s_flags = 0;
for the priv struct shared by all user processes in get_priv(). this
should only be done once. doing a SYS_PRIV_USER in sys_privctl()
caused the flags of all user processes to be reset, so they were no
longer PREEMPTIBLE. this happened when RS executed a policy script.
(this broke test1 in the test set)
VFS/MFS:
. chown can change the mode of a file, and chmod arguments are only
part of the full file mode so the full filemode is slightly magic.
changed these calls so that the final modes are returned to VFS, so
that the vnode can be kept up-to-date.
(this broke test11 in the test set)
MFS:
. lookup() checked for sizeof(string) instead of sizeof(user_path),
truncating long path names
(caught by test 23)
. truncate functions neglected to update ctime
(this broke test16)
VFS:
. corner case of an empty filename lookup caused fields of a request
not to be filled in in the lookup functions, not making it clear
that the lookup had failed, causing messages to garbage processes,
causing strange failures.
(caught by test 30)
. trust v_size in vnode when doing reads or writes on non-special
files, truncating i/o where necessary; this is necessary for pipes,
as MFS can't tell when a pipe has been truncated without it being
told explicitly each time.
when the last reader/writer on a pipe closes, tell FS about
the new size using truncate_vn().
(this broke test 25, among others)
. permission check for chdir() had disappeared; added a
forbidden() call
(caught by test 23)
new code, shouldn't change anything:
. introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their
LOCK variants. These macros set and clear the p_rts_flags field,
causing a lot of duplicated logic like
old_flags = rp->p_rts_flags; /* save value of the flags */
rp->p_rts_flags &= ~NO_PRIV;
if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp);
to change into the simpler
RTS_LOCK_UNSET(rp, NO_PRIV);
so the macros take care of calling dequeue() and enqueue() (or lock_*()),
as the case may be). This makes the code a bit more readable and a
bit less fragile.
. removed return code from do_clocktick in CLOCK as it currently
never replies
. removed some debug code from VFS
. fixed grant debug message in device.c
preemptive checks, tests, changes:
. added return code checks of receive() to SYSTEM and CLOCK
. O_TRUNC should never arrive at MFS (added sanity check and removed
O_TRUNC code)
. user_path declared with PATH_MAX+1 to let it be null-terminated
. checks in MFS to see if strings passed by VFS are null-terminated
IS:
. static irq name table thrown out
2007-02-01 18:50:02 +01:00
|
|
|
if (!RTS_ISSET(caller_ptr, SENDING)) {
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-05-30 13:05:42 +02:00
|
|
|
/* Check if there are pending notifications, except for SENDREC. */
|
2006-03-10 17:10:05 +01:00
|
|
|
if (! (caller_ptr->p_misc_flags & REPLY_PENDING)) {
|
2005-05-27 14:44:14 +02:00
|
|
|
|
2005-07-14 17:12:12 +02:00
|
|
|
map = &priv(caller_ptr)->s_notify_pending;
|
|
|
|
for (chunk=&map->chunk[0]; chunk<&map->chunk[NR_SYS_CHUNKS]; chunk++) {
|
|
|
|
|
|
|
|
/* Find a pending notification from the requested source. */
|
|
|
|
if (! *chunk) continue; /* no bits in chunk */
|
|
|
|
for (i=0; ! (*chunk & (1<<i)); ++i) {} /* look up the bit */
|
|
|
|
src_id = (chunk - &map->chunk[0]) * BITCHUNK_BITS + i;
|
|
|
|
if (src_id >= NR_SYS_PROCS) break; /* out of range */
|
|
|
|
src_proc_nr = id_to_nr(src_id); /* get source proc */
|
2005-10-20 22:59:02 +02:00
|
|
|
#if DEBUG_ENABLE_IPC_WARNINGS
|
|
|
|
if(src_proc_nr == NONE) {
|
|
|
|
kprintf("mini_receive: sending notify from NONE\n");
|
|
|
|
}
|
|
|
|
#endif
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
if (src_e!=ANY && src_p != src_proc_nr) continue;/* source not ok */
|
2005-07-14 17:12:12 +02:00
|
|
|
*chunk &= ~(1 << i); /* no longer pending */
|
|
|
|
|
|
|
|
/* Found a suitable source, deliver the notification message. */
|
|
|
|
BuildMess(&m, src_proc_nr, caller_ptr); /* assemble message */
|
|
|
|
CopyMess(src_proc_nr, proc_addr(HARDWARE), &m, caller_ptr, m_ptr);
|
|
|
|
return(OK); /* report success */
|
|
|
|
}
|
2005-05-19 16:05:51 +02:00
|
|
|
}
|
2005-07-14 17:12:12 +02:00
|
|
|
|
|
|
|
/* Check caller queue. Use pointer pointers to keep code simple. */
|
|
|
|
xpp = &caller_ptr->p_caller_q;
|
|
|
|
while (*xpp != NIL_PROC) {
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
if (src_e == ANY || src_p == proc_nr(*xpp)) {
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
#if 1
|
Mostly bugfixes of bugs triggered by the test set.
bugfixes:
SYSTEM:
. removed
rc->p_priv->s_flags = 0;
for the priv struct shared by all user processes in get_priv(). this
should only be done once. doing a SYS_PRIV_USER in sys_privctl()
caused the flags of all user processes to be reset, so they were no
longer PREEMPTIBLE. this happened when RS executed a policy script.
(this broke test1 in the test set)
VFS/MFS:
. chown can change the mode of a file, and chmod arguments are only
part of the full file mode so the full filemode is slightly magic.
changed these calls so that the final modes are returned to VFS, so
that the vnode can be kept up-to-date.
(this broke test11 in the test set)
MFS:
. lookup() checked for sizeof(string) instead of sizeof(user_path),
truncating long path names
(caught by test 23)
. truncate functions neglected to update ctime
(this broke test16)
VFS:
. corner case of an empty filename lookup caused fields of a request
not to be filled in in the lookup functions, not making it clear
that the lookup had failed, causing messages to garbage processes,
causing strange failures.
(caught by test 30)
. trust v_size in vnode when doing reads or writes on non-special
files, truncating i/o where necessary; this is necessary for pipes,
as MFS can't tell when a pipe has been truncated without it being
told explicitly each time.
when the last reader/writer on a pipe closes, tell FS about
the new size using truncate_vn().
(this broke test 25, among others)
. permission check for chdir() had disappeared; added a
forbidden() call
(caught by test 23)
new code, shouldn't change anything:
. introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their
LOCK variants. These macros set and clear the p_rts_flags field,
causing a lot of duplicated logic like
old_flags = rp->p_rts_flags; /* save value of the flags */
rp->p_rts_flags &= ~NO_PRIV;
if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp);
to change into the simpler
RTS_LOCK_UNSET(rp, NO_PRIV);
so the macros take care of calling dequeue() and enqueue() (or lock_*()),
as the case may be). This makes the code a bit more readable and a
bit less fragile.
. removed return code from do_clocktick in CLOCK as it currently
never replies
. removed some debug code from VFS
. fixed grant debug message in device.c
preemptive checks, tests, changes:
. added return code checks of receive() to SYSTEM and CLOCK
. O_TRUNC should never arrive at MFS (added sanity check and removed
O_TRUNC code)
. user_path declared with PATH_MAX+1 to let it be null-terminated
. checks in MFS to see if strings passed by VFS are null-terminated
IS:
. static irq name table thrown out
2007-02-01 18:50:02 +01:00
|
|
|
if (RTS_ISSET(*xpp, SLOT_FREE))
|
2006-03-08 13:06:33 +01:00
|
|
|
{
|
2008-11-19 13:26:10 +01:00
|
|
|
kprintf("%d: receive from %d; found dead %d (%s)?\n",
|
|
|
|
caller_ptr->p_endpoint, src_e, (*xpp)->p_endpoint,
|
|
|
|
(*xpp)->p_name);
|
2008-02-22 13:36:46 +01:00
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.deadproc++;
|
2006-03-08 13:06:33 +01:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-07-14 17:12:12 +02:00
|
|
|
/* Found acceptable message. Copy it and update status. */
|
|
|
|
CopyMess((*xpp)->p_nr, *xpp, (*xpp)->p_messbuf, caller_ptr, m_ptr);
|
Mostly bugfixes of bugs triggered by the test set.
bugfixes:
SYSTEM:
. removed
rc->p_priv->s_flags = 0;
for the priv struct shared by all user processes in get_priv(). this
should only be done once. doing a SYS_PRIV_USER in sys_privctl()
caused the flags of all user processes to be reset, so they were no
longer PREEMPTIBLE. this happened when RS executed a policy script.
(this broke test1 in the test set)
VFS/MFS:
. chown can change the mode of a file, and chmod arguments are only
part of the full file mode so the full filemode is slightly magic.
changed these calls so that the final modes are returned to VFS, so
that the vnode can be kept up-to-date.
(this broke test11 in the test set)
MFS:
. lookup() checked for sizeof(string) instead of sizeof(user_path),
truncating long path names
(caught by test 23)
. truncate functions neglected to update ctime
(this broke test16)
VFS:
. corner case of an empty filename lookup caused fields of a request
not to be filled in in the lookup functions, not making it clear
that the lookup had failed, causing messages to garbage processes,
causing strange failures.
(caught by test 30)
. trust v_size in vnode when doing reads or writes on non-special
files, truncating i/o where necessary; this is necessary for pipes,
as MFS can't tell when a pipe has been truncated without it being
told explicitly each time.
when the last reader/writer on a pipe closes, tell FS about
the new size using truncate_vn().
(this broke test 25, among others)
. permission check for chdir() had disappeared; added a
forbidden() call
(caught by test 23)
new code, shouldn't change anything:
. introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their
LOCK variants. These macros set and clear the p_rts_flags field,
causing a lot of duplicated logic like
old_flags = rp->p_rts_flags; /* save value of the flags */
rp->p_rts_flags &= ~NO_PRIV;
if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp);
to change into the simpler
RTS_LOCK_UNSET(rp, NO_PRIV);
so the macros take care of calling dequeue() and enqueue() (or lock_*()),
as the case may be). This makes the code a bit more readable and a
bit less fragile.
. removed return code from do_clocktick in CLOCK as it currently
never replies
. removed some debug code from VFS
. fixed grant debug message in device.c
preemptive checks, tests, changes:
. added return code checks of receive() to SYSTEM and CLOCK
. O_TRUNC should never arrive at MFS (added sanity check and removed
O_TRUNC code)
. user_path declared with PATH_MAX+1 to let it be null-terminated
. checks in MFS to see if strings passed by VFS are null-terminated
IS:
. static irq name table thrown out
2007-02-01 18:50:02 +01:00
|
|
|
RTS_UNSET(*xpp, SENDING);
|
2005-07-14 17:12:12 +02:00
|
|
|
*xpp = (*xpp)->p_q_link; /* remove from queue */
|
|
|
|
return(OK); /* report success */
|
|
|
|
}
|
|
|
|
xpp = &(*xpp)->p_q_link; /* proceed to next */
|
|
|
|
}
|
2007-04-23 16:24:30 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
caller_ptr->p_messbuf = m_ptr;
|
|
|
|
r= try_async(caller_ptr);
|
|
|
|
}
|
|
|
|
if (r == OK)
|
|
|
|
return OK; /* Got a message */
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2005-05-27 14:44:14 +02:00
|
|
|
/* No suitable message is available or the caller couldn't send in SENDREC.
|
2005-05-26 15:17:57 +02:00
|
|
|
* Block the process trying to receive, unless the flags tell otherwise.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2005-05-27 14:44:14 +02:00
|
|
|
if ( ! (flags & NON_BLOCKING)) {
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
caller_ptr->p_getfrom_e = src_e;
|
2005-04-21 16:53:53 +02:00
|
|
|
caller_ptr->p_messbuf = m_ptr;
|
Mostly bugfixes of bugs triggered by the test set.
bugfixes:
SYSTEM:
. removed
rc->p_priv->s_flags = 0;
for the priv struct shared by all user processes in get_priv(). this
should only be done once. doing a SYS_PRIV_USER in sys_privctl()
caused the flags of all user processes to be reset, so they were no
longer PREEMPTIBLE. this happened when RS executed a policy script.
(this broke test1 in the test set)
VFS/MFS:
. chown can change the mode of a file, and chmod arguments are only
part of the full file mode so the full filemode is slightly magic.
changed these calls so that the final modes are returned to VFS, so
that the vnode can be kept up-to-date.
(this broke test11 in the test set)
MFS:
. lookup() checked for sizeof(string) instead of sizeof(user_path),
truncating long path names
(caught by test 23)
. truncate functions neglected to update ctime
(this broke test16)
VFS:
. corner case of an empty filename lookup caused fields of a request
not to be filled in in the lookup functions, not making it clear
that the lookup had failed, causing messages to garbage processes,
causing strange failures.
(caught by test 30)
. trust v_size in vnode when doing reads or writes on non-special
files, truncating i/o where necessary; this is necessary for pipes,
as MFS can't tell when a pipe has been truncated without it being
told explicitly each time.
when the last reader/writer on a pipe closes, tell FS about
the new size using truncate_vn().
(this broke test 25, among others)
. permission check for chdir() had disappeared; added a
forbidden() call
(caught by test 23)
new code, shouldn't change anything:
. introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their
LOCK variants. These macros set and clear the p_rts_flags field,
causing a lot of duplicated logic like
old_flags = rp->p_rts_flags; /* save value of the flags */
rp->p_rts_flags &= ~NO_PRIV;
if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp);
to change into the simpler
RTS_LOCK_UNSET(rp, NO_PRIV);
so the macros take care of calling dequeue() and enqueue() (or lock_*()),
as the case may be). This makes the code a bit more readable and a
bit less fragile.
. removed return code from do_clocktick in CLOCK as it currently
never replies
. removed some debug code from VFS
. fixed grant debug message in device.c
preemptive checks, tests, changes:
. added return code checks of receive() to SYSTEM and CLOCK
. O_TRUNC should never arrive at MFS (added sanity check and removed
O_TRUNC code)
. user_path declared with PATH_MAX+1 to let it be null-terminated
. checks in MFS to see if strings passed by VFS are null-terminated
IS:
. static irq name table thrown out
2007-02-01 18:50:02 +01:00
|
|
|
RTS_SET(caller_ptr, RECEIVING);
|
2005-04-21 16:53:53 +02:00
|
|
|
return(OK);
|
|
|
|
} else {
|
2008-02-22 13:36:46 +01:00
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.not_ready++;
|
|
|
|
return(ENOTREADY);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-14 17:12:12 +02:00
|
|
|
/*===========================================================================*
|
2005-07-27 16:32:16 +02:00
|
|
|
* mini_notify *
|
2005-07-14 17:12:12 +02:00
|
|
|
*===========================================================================*/
|
2005-07-27 16:32:16 +02:00
|
|
|
PRIVATE int mini_notify(caller_ptr, dst)
|
2005-07-14 17:12:12 +02:00
|
|
|
register struct proc *caller_ptr; /* sender of the notification */
|
|
|
|
int dst; /* which process to notify */
|
|
|
|
{
|
|
|
|
register struct proc *dst_ptr = proc_addr(dst);
|
|
|
|
int src_id; /* source id for late delivery */
|
|
|
|
message m; /* the notification message */
|
|
|
|
|
|
|
|
/* Check to see if target is blocked waiting for this message. A process
|
|
|
|
* can be both sending and receiving during a SENDREC system call.
|
|
|
|
*/
|
Mostly bugfixes of bugs triggered by the test set.
bugfixes:
SYSTEM:
. removed
rc->p_priv->s_flags = 0;
for the priv struct shared by all user processes in get_priv(). this
should only be done once. doing a SYS_PRIV_USER in sys_privctl()
caused the flags of all user processes to be reset, so they were no
longer PREEMPTIBLE. this happened when RS executed a policy script.
(this broke test1 in the test set)
VFS/MFS:
. chown can change the mode of a file, and chmod arguments are only
part of the full file mode so the full filemode is slightly magic.
changed these calls so that the final modes are returned to VFS, so
that the vnode can be kept up-to-date.
(this broke test11 in the test set)
MFS:
. lookup() checked for sizeof(string) instead of sizeof(user_path),
truncating long path names
(caught by test 23)
. truncate functions neglected to update ctime
(this broke test16)
VFS:
. corner case of an empty filename lookup caused fields of a request
not to be filled in in the lookup functions, not making it clear
that the lookup had failed, causing messages to garbage processes,
causing strange failures.
(caught by test 30)
. trust v_size in vnode when doing reads or writes on non-special
files, truncating i/o where necessary; this is necessary for pipes,
as MFS can't tell when a pipe has been truncated without it being
told explicitly each time.
when the last reader/writer on a pipe closes, tell FS about
the new size using truncate_vn().
(this broke test 25, among others)
. permission check for chdir() had disappeared; added a
forbidden() call
(caught by test 23)
new code, shouldn't change anything:
. introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their
LOCK variants. These macros set and clear the p_rts_flags field,
causing a lot of duplicated logic like
old_flags = rp->p_rts_flags; /* save value of the flags */
rp->p_rts_flags &= ~NO_PRIV;
if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp);
to change into the simpler
RTS_LOCK_UNSET(rp, NO_PRIV);
so the macros take care of calling dequeue() and enqueue() (or lock_*()),
as the case may be). This makes the code a bit more readable and a
bit less fragile.
. removed return code from do_clocktick in CLOCK as it currently
never replies
. removed some debug code from VFS
. fixed grant debug message in device.c
preemptive checks, tests, changes:
. added return code checks of receive() to SYSTEM and CLOCK
. O_TRUNC should never arrive at MFS (added sanity check and removed
O_TRUNC code)
. user_path declared with PATH_MAX+1 to let it be null-terminated
. checks in MFS to see if strings passed by VFS are null-terminated
IS:
. static irq name table thrown out
2007-02-01 18:50:02 +01:00
|
|
|
if ( (RTS_ISSET(dst_ptr, RECEIVING) && !RTS_ISSET(dst_ptr, SENDING)) &&
|
2006-03-10 17:10:05 +01:00
|
|
|
! (dst_ptr->p_misc_flags & REPLY_PENDING) &&
|
|
|
|
(dst_ptr->p_getfrom_e == ANY ||
|
|
|
|
dst_ptr->p_getfrom_e == caller_ptr->p_endpoint)) {
|
2005-07-14 17:12:12 +02:00
|
|
|
|
|
|
|
/* Destination is indeed waiting for a message. Assemble a notification
|
|
|
|
* message and deliver it. Copy from pseudo-source HARDWARE, since the
|
|
|
|
* message is in the kernel's address space.
|
|
|
|
*/
|
|
|
|
BuildMess(&m, proc_nr(caller_ptr), dst_ptr);
|
|
|
|
CopyMess(proc_nr(caller_ptr), proc_addr(HARDWARE), &m,
|
|
|
|
dst_ptr, dst_ptr->p_messbuf);
|
Mostly bugfixes of bugs triggered by the test set.
bugfixes:
SYSTEM:
. removed
rc->p_priv->s_flags = 0;
for the priv struct shared by all user processes in get_priv(). this
should only be done once. doing a SYS_PRIV_USER in sys_privctl()
caused the flags of all user processes to be reset, so they were no
longer PREEMPTIBLE. this happened when RS executed a policy script.
(this broke test1 in the test set)
VFS/MFS:
. chown can change the mode of a file, and chmod arguments are only
part of the full file mode so the full filemode is slightly magic.
changed these calls so that the final modes are returned to VFS, so
that the vnode can be kept up-to-date.
(this broke test11 in the test set)
MFS:
. lookup() checked for sizeof(string) instead of sizeof(user_path),
truncating long path names
(caught by test 23)
. truncate functions neglected to update ctime
(this broke test16)
VFS:
. corner case of an empty filename lookup caused fields of a request
not to be filled in in the lookup functions, not making it clear
that the lookup had failed, causing messages to garbage processes,
causing strange failures.
(caught by test 30)
. trust v_size in vnode when doing reads or writes on non-special
files, truncating i/o where necessary; this is necessary for pipes,
as MFS can't tell when a pipe has been truncated without it being
told explicitly each time.
when the last reader/writer on a pipe closes, tell FS about
the new size using truncate_vn().
(this broke test 25, among others)
. permission check for chdir() had disappeared; added a
forbidden() call
(caught by test 23)
new code, shouldn't change anything:
. introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their
LOCK variants. These macros set and clear the p_rts_flags field,
causing a lot of duplicated logic like
old_flags = rp->p_rts_flags; /* save value of the flags */
rp->p_rts_flags &= ~NO_PRIV;
if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp);
to change into the simpler
RTS_LOCK_UNSET(rp, NO_PRIV);
so the macros take care of calling dequeue() and enqueue() (or lock_*()),
as the case may be). This makes the code a bit more readable and a
bit less fragile.
. removed return code from do_clocktick in CLOCK as it currently
never replies
. removed some debug code from VFS
. fixed grant debug message in device.c
preemptive checks, tests, changes:
. added return code checks of receive() to SYSTEM and CLOCK
. O_TRUNC should never arrive at MFS (added sanity check and removed
O_TRUNC code)
. user_path declared with PATH_MAX+1 to let it be null-terminated
. checks in MFS to see if strings passed by VFS are null-terminated
IS:
. static irq name table thrown out
2007-02-01 18:50:02 +01:00
|
|
|
RTS_UNSET(dst_ptr, RECEIVING);
|
2005-07-14 17:12:12 +02:00
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Destination is not ready to receive the notification. Add it to the
|
|
|
|
* bit map with pending notifications. Note the indirectness: the system id
|
|
|
|
* instead of the process number is used in the pending bit map.
|
|
|
|
*/
|
|
|
|
src_id = priv(caller_ptr)->s_id;
|
|
|
|
set_sys_bit(priv(dst_ptr)->s_notify_pending, src_id);
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
#define ASCOMPLAIN(caller, entry, field) \
|
|
|
|
kprintf("kernel:%s:%d: asyn failed for %s in %s " \
|
|
|
|
"(%d/%d, tab 0x%lx)\n",__FILE__,__LINE__, \
|
|
|
|
field, caller->p_name, entry, priv(caller)->s_asynsize, priv(caller)->s_asyntab)
|
|
|
|
|
|
|
|
#define A_RETRIEVE(entry, field) \
|
|
|
|
if(data_copy(caller_ptr->p_endpoint, \
|
|
|
|
table_v + (entry)*sizeof(asynmsg_t) + offsetof(struct asynmsg,field),\
|
|
|
|
SYSTEM, (vir_bytes) &tabent.field, \
|
|
|
|
sizeof(tabent.field)) != OK) {\
|
|
|
|
ASCOMPLAIN(caller_ptr, entry, #field); \
|
|
|
|
return EFAULT; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define A_INSERT(entry, field) \
|
|
|
|
if(data_copy(SYSTEM, (vir_bytes) &tabent.field, \
|
|
|
|
caller_ptr->p_endpoint, \
|
|
|
|
table_v + (entry)*sizeof(asynmsg_t) + offsetof(struct asynmsg,field),\
|
|
|
|
sizeof(tabent.field)) != OK) {\
|
|
|
|
ASCOMPLAIN(caller_ptr, entry, #field); \
|
|
|
|
return EFAULT; \
|
|
|
|
}
|
2007-04-23 16:24:30 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* mini_senda *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE int mini_senda(caller_ptr, table, size)
|
|
|
|
struct proc *caller_ptr;
|
|
|
|
asynmsg_t *table;
|
|
|
|
size_t size;
|
|
|
|
{
|
|
|
|
int i, dst_p, done, do_notify;
|
|
|
|
unsigned flags;
|
|
|
|
struct proc *dst_ptr;
|
|
|
|
struct priv *privp;
|
|
|
|
message *m_ptr;
|
|
|
|
asynmsg_t tabent;
|
2008-11-19 13:26:10 +01:00
|
|
|
vir_bytes table_v = (vir_bytes) table;
|
2007-04-23 16:24:30 +02:00
|
|
|
|
|
|
|
privp= priv(caller_ptr);
|
|
|
|
if (!(privp->s_flags & SYS_PROC))
|
|
|
|
{
|
|
|
|
kprintf(
|
|
|
|
"mini_senda: warning caller has no privilege structure\n");
|
2008-02-22 13:36:46 +01:00
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.no_priv++;
|
2007-04-23 16:24:30 +02:00
|
|
|
return EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear table */
|
|
|
|
privp->s_asyntab= -1;
|
|
|
|
privp->s_asynsize= 0;
|
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
{
|
|
|
|
/* Nothing to do, just return */
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Limit size to something reasonable. An arbitrary choice is 16
|
|
|
|
* times the number of process table entries.
|
2008-11-19 13:26:10 +01:00
|
|
|
*
|
|
|
|
* (this check has been duplicated in sys_call but is left here
|
|
|
|
* as a sanity check)
|
2007-04-23 16:24:30 +02:00
|
|
|
*/
|
|
|
|
if (size > 16*(NR_TASKS + NR_PROCS))
|
2008-02-22 13:36:46 +01:00
|
|
|
{
|
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.bad_size++;
|
2007-04-23 16:24:30 +02:00
|
|
|
return EDOM;
|
2008-02-22 13:36:46 +01:00
|
|
|
}
|
2007-04-23 16:24:30 +02:00
|
|
|
|
|
|
|
/* Scan the table */
|
|
|
|
do_notify= FALSE;
|
|
|
|
done= TRUE;
|
|
|
|
for (i= 0; i<size; i++)
|
|
|
|
{
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2007-04-23 16:24:30 +02:00
|
|
|
/* Read status word */
|
2008-11-19 13:26:10 +01:00
|
|
|
A_RETRIEVE(i, flags);
|
2007-04-23 16:24:30 +02:00
|
|
|
flags= tabent.flags;
|
|
|
|
|
|
|
|
/* Skip empty entries */
|
|
|
|
if (flags == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Check for reserved bits in the flags field */
|
|
|
|
if (flags & ~(AMF_VALID|AMF_DONE|AMF_NOTIFY) ||
|
|
|
|
!(flags & AMF_VALID))
|
|
|
|
{
|
2008-02-22 13:36:46 +01:00
|
|
|
if (caller_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.bad_senda++;
|
2007-04-23 16:24:30 +02:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
/* Skip entry if AMF_DONE is already set */
|
2007-04-23 16:24:30 +02:00
|
|
|
if (flags & AMF_DONE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Get destination */
|
2008-11-19 13:26:10 +01:00
|
|
|
A_RETRIEVE(i, dst);
|
2007-04-23 16:24:30 +02:00
|
|
|
|
|
|
|
if (!isokendpt(tabent.dst, &dst_p))
|
|
|
|
{
|
|
|
|
/* Bad destination, report the error */
|
|
|
|
tabent.result= EDEADSRCDST;
|
2008-11-19 13:26:10 +01:00
|
|
|
A_INSERT(i, result);
|
2007-04-23 16:24:30 +02:00
|
|
|
tabent.flags= flags | AMF_DONE;
|
2008-11-19 13:26:10 +01:00
|
|
|
A_INSERT(i, flags);
|
2007-04-23 16:24:30 +02:00
|
|
|
|
|
|
|
if (flags & AMF_NOTIFY)
|
|
|
|
do_notify= 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
kprintf("mini_senda: entry[%d]: flags 0x%x dst %d/%d\n",
|
|
|
|
i, tabent.flags, tabent.dst, dst_p);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
dst_ptr = proc_addr(dst_p);
|
|
|
|
|
|
|
|
/* NO_ENDPOINT should be removed */
|
|
|
|
if (dst_ptr->p_rts_flags & NO_ENDPOINT)
|
|
|
|
{
|
|
|
|
tabent.result= EDSTDIED;
|
2008-11-19 13:26:10 +01:00
|
|
|
A_INSERT(i, result);
|
2007-04-23 16:24:30 +02:00
|
|
|
tabent.flags= flags | AMF_DONE;
|
2008-11-19 13:26:10 +01:00
|
|
|
A_INSERT(i, flags);
|
2007-04-23 16:24:30 +02:00
|
|
|
|
|
|
|
if (flags & AMF_NOTIFY)
|
|
|
|
do_notify= TRUE;
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
if ( (dst_ptr->p_rts_flags & (RECEIVING | SENDING)) ==
|
|
|
|
RECEIVING &&
|
|
|
|
(dst_ptr->p_getfrom_e == ANY ||
|
|
|
|
dst_ptr->p_getfrom_e == caller_ptr->p_endpoint))
|
|
|
|
{
|
|
|
|
/* Destination is indeed waiting for this message. */
|
|
|
|
m_ptr= &table[i].msg; /* Note: pointer in the
|
|
|
|
* caller's address space.
|
|
|
|
*/
|
|
|
|
CopyMess(caller_ptr->p_nr, caller_ptr, m_ptr, dst_ptr,
|
|
|
|
dst_ptr->p_messbuf);
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
RTS_UNSET(dst_ptr, RECEIVING);
|
2007-04-23 16:24:30 +02:00
|
|
|
|
|
|
|
tabent.result= OK;
|
2008-11-19 13:26:10 +01:00
|
|
|
A_INSERT(i, result);
|
2007-04-23 16:24:30 +02:00
|
|
|
tabent.flags= flags | AMF_DONE;
|
2008-11-19 13:26:10 +01:00
|
|
|
A_INSERT(i, flags);
|
2007-04-23 16:24:30 +02:00
|
|
|
|
|
|
|
if (flags & AMF_NOTIFY)
|
|
|
|
do_notify= 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Should inform receiver that something is pending */
|
|
|
|
dst_ptr->p_misc_flags |= MF_ASYNMSG;
|
|
|
|
done= FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (do_notify)
|
2008-11-19 13:26:10 +01:00
|
|
|
kprintf("mini_senda: should notify caller\n");
|
2007-04-23 16:24:30 +02:00
|
|
|
if (!done)
|
|
|
|
{
|
|
|
|
privp->s_asyntab= (vir_bytes)table;
|
|
|
|
privp->s_asynsize= size;
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
|
|
|
if(caller_ptr->p_endpoint > INIT_PROC_NR) {
|
|
|
|
kprintf("kernel: %s (%d) asynsend table at 0x%lx, %d\n",
|
|
|
|
caller_ptr->p_name, caller_ptr->p_endpoint,
|
|
|
|
table, size);
|
|
|
|
}
|
|
|
|
#endif
|
2007-04-23 16:24:30 +02:00
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* try_async *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE int try_async(caller_ptr)
|
|
|
|
struct proc *caller_ptr;
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct priv *privp;
|
|
|
|
struct proc *src_ptr;
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
continue;
|
|
|
|
#if 0
|
|
|
|
kprintf("try_async: found asyntable for proc %d\n",
|
|
|
|
privp->s_proc_nr);
|
|
|
|
#endif
|
|
|
|
src_ptr= proc_addr(privp->s_proc_nr);
|
|
|
|
r= try_one(src_ptr, caller_ptr);
|
|
|
|
if (r == OK)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Nothing found, clear MF_ASYNMSG */
|
|
|
|
caller_ptr->p_misc_flags &= ~MF_ASYNMSG;
|
|
|
|
|
|
|
|
return ESRCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* try_one *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE int try_one(src_ptr, dst_ptr)
|
|
|
|
struct proc *src_ptr;
|
|
|
|
struct proc *dst_ptr;
|
|
|
|
{
|
|
|
|
int i, do_notify, done;
|
|
|
|
unsigned flags;
|
|
|
|
size_t size;
|
|
|
|
endpoint_t dst_e;
|
|
|
|
asynmsg_t *table_ptr;
|
|
|
|
message *m_ptr;
|
|
|
|
struct priv *privp;
|
|
|
|
asynmsg_t tabent;
|
2008-11-19 13:26:10 +01:00
|
|
|
vir_bytes table_v;
|
|
|
|
struct proc *caller_ptr;
|
2007-04-23 16:24:30 +02:00
|
|
|
|
|
|
|
privp= priv(src_ptr);
|
|
|
|
size= privp->s_asynsize;
|
2008-11-19 13:26:10 +01:00
|
|
|
table_v = privp->s_asyntab;
|
|
|
|
caller_ptr = src_ptr;
|
2007-04-23 16:24:30 +02:00
|
|
|
|
|
|
|
dst_e= dst_ptr->p_endpoint;
|
|
|
|
|
|
|
|
/* Scan the table */
|
|
|
|
do_notify= FALSE;
|
|
|
|
done= TRUE;
|
|
|
|
for (i= 0; i<size; i++)
|
|
|
|
{
|
|
|
|
/* Read status word */
|
2008-11-19 13:26:10 +01:00
|
|
|
A_RETRIEVE(i, flags);
|
2007-04-23 16:24:30 +02:00
|
|
|
flags= tabent.flags;
|
|
|
|
|
|
|
|
/* Skip empty entries */
|
|
|
|
if (flags == 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for reserved bits in the flags field */
|
|
|
|
if (flags & ~(AMF_VALID|AMF_DONE|AMF_NOTIFY) ||
|
|
|
|
!(flags & AMF_VALID))
|
|
|
|
{
|
|
|
|
kprintf("try_one: bad bits in table\n");
|
|
|
|
privp->s_asynsize= 0;
|
2008-02-22 13:36:46 +01:00
|
|
|
if (src_ptr->p_endpoint == ipc_stats_target)
|
|
|
|
ipc_stats.bad_senda++;
|
2007-04-23 16:24:30 +02:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip entry is AMF_DONE is already set */
|
|
|
|
if (flags & AMF_DONE)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear done. We are done when all entries are either empty
|
|
|
|
* or done at the start of the call.
|
|
|
|
*/
|
|
|
|
done= FALSE;
|
|
|
|
|
|
|
|
/* Get destination */
|
2008-11-19 13:26:10 +01:00
|
|
|
A_RETRIEVE(i, dst);
|
2007-04-23 16:24:30 +02:00
|
|
|
|
|
|
|
if (tabent.dst != dst_e)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Deliver message */
|
|
|
|
table_ptr= (asynmsg_t *)privp->s_asyntab;
|
|
|
|
m_ptr= &table_ptr[i].msg; /* Note: pointer in the
|
|
|
|
* caller's address space.
|
|
|
|
*/
|
|
|
|
CopyMess(src_ptr->p_nr, src_ptr, m_ptr, dst_ptr,
|
|
|
|
dst_ptr->p_messbuf);
|
|
|
|
|
|
|
|
tabent.result= OK;
|
2008-11-19 13:26:10 +01:00
|
|
|
A_INSERT(i, result);
|
2007-04-23 16:24:30 +02:00
|
|
|
tabent.flags= flags | AMF_DONE;
|
2008-11-19 13:26:10 +01:00
|
|
|
A_INSERT(i, flags);
|
2007-04-23 16:24:30 +02:00
|
|
|
|
|
|
|
if (flags & AMF_NOTIFY)
|
|
|
|
{
|
|
|
|
kprintf("try_one: should notify caller\n");
|
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
if (done)
|
|
|
|
privp->s_asynsize= 0;
|
|
|
|
return EAGAIN;
|
|
|
|
}
|
|
|
|
|
2005-09-11 18:44:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* lock_notify *
|
|
|
|
*===========================================================================*/
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
PUBLIC int lock_notify(src_e, dst_e)
|
|
|
|
int src_e; /* (endpoint) sender of the notification */
|
|
|
|
int dst_e; /* (endpoint) who is to be notified */
|
2005-05-24 12:06:17 +02:00
|
|
|
{
|
2005-07-14 17:12:12 +02:00
|
|
|
/* Safe gateway to mini_notify() for tasks and interrupt handlers. The sender
|
|
|
|
* is explicitely given to prevent confusion where the call comes from. MINIX
|
2005-06-17 15:00:04 +02:00
|
|
|
* kernel is not reentrant, which means to interrupts are disabled after
|
|
|
|
* the first kernel entry (hardware interrupt, trap, or exception). Locking
|
2005-07-14 17:12:12 +02:00
|
|
|
* is done by temporarily disabling interrupts.
|
2005-05-24 16:35:58 +02:00
|
|
|
*/
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
int result, src, dst;
|
|
|
|
|
|
|
|
if(!isokendpt(src_e, &src) || !isokendpt(dst_e, &dst))
|
|
|
|
return EDEADSRCDST;
|
2005-05-18 12:36:23 +02:00
|
|
|
|
2005-06-17 15:00:04 +02:00
|
|
|
/* Exception or interrupt occurred, thus already locked. */
|
|
|
|
if (k_reenter >= 0) {
|
2005-07-27 16:32:16 +02:00
|
|
|
result = mini_notify(proc_addr(src), dst);
|
2005-06-17 15:00:04 +02:00
|
|
|
}
|
2005-06-17 11:09:54 +02:00
|
|
|
|
2005-06-17 15:00:04 +02:00
|
|
|
/* Call from task level, locking is required. */
|
|
|
|
else {
|
2008-11-19 13:26:10 +01:00
|
|
|
lock;
|
2005-07-27 16:32:16 +02:00
|
|
|
result = mini_notify(proc_addr(src), dst);
|
2008-11-19 13:26:10 +01:00
|
|
|
unlock;
|
2005-06-17 15:00:04 +02:00
|
|
|
}
|
2005-06-17 11:09:54 +02:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* soft_notify *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int soft_notify(dst_e)
|
|
|
|
int dst_e; /* (endpoint) who is to be notified */
|
|
|
|
{
|
|
|
|
int dst, u = 0;
|
|
|
|
struct proc *dstp, *sys = proc_addr(SYSTEM);
|
|
|
|
|
|
|
|
/* Delayed interface to notify() from SYSTEM that is safe/easy to call
|
|
|
|
* from more places than notify().
|
|
|
|
*/
|
|
|
|
if(!intr_disabled()) { lock; u = 1; }
|
|
|
|
|
|
|
|
{
|
|
|
|
if(!isokendpt(dst_e, &dst))
|
|
|
|
minix_panic("soft_notify to dead ep", dst_e);
|
|
|
|
|
|
|
|
dstp = proc_addr(dst);
|
|
|
|
|
|
|
|
if(!dstp->p_softnotified) {
|
|
|
|
dstp->next_soft_notify = softnotify;
|
|
|
|
softnotify = dstp;
|
|
|
|
dstp->p_softnotified = 1;
|
|
|
|
|
|
|
|
if (RTS_ISSET(sys, RECEIVING)) {
|
|
|
|
sys->p_messbuf->m_source = SYSTEM;
|
|
|
|
RTS_UNSET(sys, RECEIVING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(u) { unlock; }
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
2005-08-19 18:43:28 +02:00
|
|
|
* enqueue *
|
2005-04-21 16:53:53 +02:00
|
|
|
*===========================================================================*/
|
2008-11-19 13:26:10 +01:00
|
|
|
PUBLIC void enqueue(rp)
|
2005-04-21 16:53:53 +02:00
|
|
|
register struct proc *rp; /* this process is now runnable */
|
|
|
|
{
|
2005-08-22 17:14:11 +02:00
|
|
|
/* Add 'rp' to one of the queues of runnable processes. This function is
|
|
|
|
* responsible for inserting a process into one of the scheduling queues.
|
|
|
|
* The mechanism is implemented here. The actual scheduling policy is
|
|
|
|
* defined in sched() and pick_proc().
|
2005-08-19 18:43:28 +02:00
|
|
|
*/
|
2005-08-22 17:14:11 +02:00
|
|
|
int q; /* scheduling queue to use */
|
|
|
|
int front; /* add to front or back */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-07-14 17:12:12 +02:00
|
|
|
#if DEBUG_SCHED_CHECK
|
2008-11-19 13:26:10 +01:00
|
|
|
if(!intr_disabled()) { minix_panic("enqueue with interrupts enabled", NO_NUM); }
|
|
|
|
CHECK_RUNQUEUES;
|
|
|
|
if (rp->p_ready) minix_panic("enqueue already ready process", NO_NUM);
|
2005-05-24 14:32:34 +02:00
|
|
|
#endif
|
|
|
|
|
2005-08-22 17:14:11 +02:00
|
|
|
/* Determine where to insert to process. */
|
|
|
|
sched(rp, &q, &front);
|
|
|
|
|
2005-08-19 18:43:28 +02:00
|
|
|
/* Now add the process to the queue. */
|
2005-06-20 13:26:48 +02:00
|
|
|
if (rdy_head[q] == NIL_PROC) { /* add to empty queue */
|
|
|
|
rdy_head[q] = rdy_tail[q] = rp; /* create a new queue */
|
|
|
|
rp->p_nextready = NIL_PROC; /* mark new end */
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2005-08-22 17:14:11 +02:00
|
|
|
else if (front) { /* add to head of queue */
|
2005-06-20 13:26:48 +02:00
|
|
|
rp->p_nextready = rdy_head[q]; /* chain head of queue */
|
|
|
|
rdy_head[q] = rp; /* set new queue head */
|
|
|
|
}
|
|
|
|
else { /* add to tail of queue */
|
|
|
|
rdy_tail[q]->p_nextready = rp; /* chain tail of queue */
|
|
|
|
rdy_tail[q] = rp; /* set new queue tail */
|
|
|
|
rp->p_nextready = NIL_PROC; /* mark new end */
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2005-08-22 17:14:11 +02:00
|
|
|
|
2007-03-21 10:45:01 +01:00
|
|
|
/* Now select the next process to run, if there isn't a current
|
|
|
|
* process yet or current process isn't ready any more, or
|
|
|
|
* it's PREEMPTIBLE.
|
|
|
|
*/
|
|
|
|
if(!proc_ptr || proc_ptr->p_rts_flags ||
|
|
|
|
(priv(proc_ptr)->s_flags & PREEMPTIBLE)) {
|
|
|
|
pick_proc();
|
|
|
|
}
|
2005-07-14 17:12:12 +02:00
|
|
|
|
|
|
|
#if DEBUG_SCHED_CHECK
|
|
|
|
rp->p_ready = 1;
|
2008-11-19 13:26:10 +01:00
|
|
|
CHECK_RUNQUEUES;
|
2005-07-14 17:12:12 +02:00
|
|
|
#endif
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
2005-08-19 18:43:28 +02:00
|
|
|
* dequeue *
|
2005-04-21 16:53:53 +02:00
|
|
|
*===========================================================================*/
|
2008-11-19 13:26:10 +01:00
|
|
|
PUBLIC void dequeue(rp)
|
2005-04-21 16:53:53 +02:00
|
|
|
register struct proc *rp; /* this process is no longer runnable */
|
|
|
|
{
|
2005-08-22 17:14:11 +02:00
|
|
|
/* A process must be removed from the scheduling queues, for example, because
|
|
|
|
* it has blocked. If the currently active process is removed, a new process
|
|
|
|
* is picked to run by calling pick_proc().
|
|
|
|
*/
|
2005-05-30 13:05:42 +02:00
|
|
|
register int q = rp->p_priority; /* queue to use */
|
|
|
|
register struct proc **xpp; /* iterate over queue */
|
2005-06-20 13:26:48 +02:00
|
|
|
register struct proc *prev_xp;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-06-24 18:24:40 +02:00
|
|
|
/* Side-effect for kernel: check if the task's stack still is ok? */
|
|
|
|
if (iskernelp(rp)) {
|
2005-07-14 17:12:12 +02:00
|
|
|
if (*priv(rp)->s_stack_guard != STACK_GUARD)
|
2008-11-19 13:26:10 +01:00
|
|
|
minix_panic("stack overrun by task", proc_nr(rp));
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2005-07-14 17:12:12 +02:00
|
|
|
#if DEBUG_SCHED_CHECK
|
2008-11-19 13:26:10 +01:00
|
|
|
CHECK_RUNQUEUES;
|
|
|
|
if(!intr_disabled()) { minix_panic("dequeue with interrupts enabled", NO_NUM); }
|
|
|
|
if (! rp->p_ready) minix_panic("dequeue() already unready process", NO_NUM);
|
2005-07-14 17:12:12 +02:00
|
|
|
#endif
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Now make sure that the process is not in its ready queue. Remove the
|
2005-05-20 11:37:43 +02:00
|
|
|
* process if it is found. A process can be made unready even if it is not
|
|
|
|
* running by being sent a signal that kills it.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2005-06-20 13:26:48 +02:00
|
|
|
prev_xp = NIL_PROC;
|
|
|
|
for (xpp = &rdy_head[q]; *xpp != NIL_PROC; xpp = &(*xpp)->p_nextready) {
|
|
|
|
|
|
|
|
if (*xpp == rp) { /* found process to remove */
|
|
|
|
*xpp = (*xpp)->p_nextready; /* replace with next chain */
|
|
|
|
if (rp == rdy_tail[q]) /* queue tail removed */
|
|
|
|
rdy_tail[q] = prev_xp; /* set new tail */
|
|
|
|
if (rp == proc_ptr || rp == next_ptr) /* active process removed */
|
2005-05-26 15:17:57 +02:00
|
|
|
pick_proc(); /* pick new process to run */
|
|
|
|
break;
|
|
|
|
}
|
2005-06-20 13:26:48 +02:00
|
|
|
prev_xp = *xpp; /* save previous in chain */
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2005-11-14 16:50:46 +01:00
|
|
|
|
2005-07-14 17:12:12 +02:00
|
|
|
#if DEBUG_SCHED_CHECK
|
|
|
|
rp->p_ready = 0;
|
2008-11-19 13:26:10 +01:00
|
|
|
CHECK_RUNQUEUES;
|
2005-07-14 17:12:12 +02:00
|
|
|
#endif
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* sched *
|
|
|
|
*===========================================================================*/
|
2005-08-22 17:14:11 +02:00
|
|
|
PRIVATE void sched(rp, queue, front)
|
|
|
|
register struct proc *rp; /* process to be scheduled */
|
2005-08-19 18:43:28 +02:00
|
|
|
int *queue; /* return: queue to use */
|
|
|
|
int *front; /* return: front or back */
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2005-08-23 12:25:01 +02:00
|
|
|
/* This function determines the scheduling policy. It is called whenever a
|
2005-08-22 17:14:11 +02:00
|
|
|
* process must be added to one of the scheduling queues to decide where to
|
2005-08-23 12:25:01 +02:00
|
|
|
* insert it. As a side-effect the process' priority may be updated.
|
2005-08-22 17:14:11 +02:00
|
|
|
*/
|
2005-08-23 12:25:01 +02:00
|
|
|
int time_left = (rp->p_ticks_left > 0); /* quantum fully consumed */
|
|
|
|
|
|
|
|
/* Check whether the process has time left. Otherwise give a new quantum
|
2006-03-10 17:10:05 +01:00
|
|
|
* and lower the process' priority, unless the process already is in the
|
|
|
|
* lowest queue.
|
2005-08-22 17:14:11 +02:00
|
|
|
*/
|
2006-03-10 17:10:05 +01:00
|
|
|
if (! time_left) { /* quantum consumed ? */
|
2005-08-22 17:14:11 +02:00
|
|
|
rp->p_ticks_left = rp->p_quantum_size; /* give new quantum */
|
2006-03-10 17:10:05 +01:00
|
|
|
if (rp->p_priority < (IDLE_Q-1)) {
|
|
|
|
rp->p_priority += 1; /* lower priority */
|
|
|
|
}
|
2005-08-23 12:25:01 +02:00
|
|
|
}
|
2005-08-22 17:14:11 +02:00
|
|
|
|
|
|
|
/* If there is time left, the process is added to the front of its queue,
|
|
|
|
* so that it can immediately run. The queue to use simply is always the
|
|
|
|
* process' current priority.
|
|
|
|
*/
|
|
|
|
*queue = rp->p_priority;
|
|
|
|
*front = time_left;
|
2005-06-30 17:55:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* pick_proc *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void pick_proc()
|
|
|
|
{
|
|
|
|
/* Decide who to run now. A new process is selected by setting 'next_ptr'.
|
|
|
|
* When a billable process is selected, record it in 'bill_ptr', so that the
|
|
|
|
* clock task can tell who to bill for system time.
|
|
|
|
*/
|
|
|
|
register struct proc *rp; /* process to run */
|
|
|
|
int q; /* iterate over queues */
|
|
|
|
|
|
|
|
/* Check each of the scheduling queues for ready processes. The number of
|
|
|
|
* queues is defined in proc.h, and priorities are set in the task table.
|
|
|
|
* The lowest queue contains IDLE, which is always ready.
|
|
|
|
*/
|
|
|
|
for (q=0; q < NR_SCHED_QUEUES; q++) {
|
|
|
|
if ( (rp = rdy_head[q]) != NIL_PROC) {
|
|
|
|
next_ptr = rp; /* run process 'rp' next */
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
|
|
|
if(rp->p_endpoint != 4 && rp->p_endpoint != 5 && rp->p_endpoint != IDLE && rp->p_endpoint != SYSTEM)
|
|
|
|
kprintf("[run %s]", rp->p_name);
|
|
|
|
#endif
|
2005-07-14 17:12:12 +02:00
|
|
|
if (priv(rp)->s_flags & BILLABLE)
|
2005-06-30 17:55:19 +02:00
|
|
|
bill_ptr = rp; /* bill for system time */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-11-19 13:26:10 +01:00
|
|
|
minix_panic("no ready process", NO_NUM);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2006-03-10 17:10:05 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* balance_queues *
|
|
|
|
*===========================================================================*/
|
|
|
|
#define Q_BALANCE_TICKS 100
|
|
|
|
PUBLIC void balance_queues(tp)
|
|
|
|
timer_t *tp; /* watchdog timer pointer */
|
|
|
|
{
|
|
|
|
/* Check entire process table and give all process a higher priority. This
|
|
|
|
* effectively means giving a new quantum. If a process already is at its
|
|
|
|
* maximum priority, its quantum will be renewed.
|
|
|
|
*/
|
|
|
|
static timer_t queue_timer; /* timer structure to use */
|
|
|
|
register struct proc* rp; /* process table pointer */
|
|
|
|
clock_t next_period; /* time of next period */
|
|
|
|
int ticks_added = 0; /* total time added */
|
|
|
|
|
|
|
|
for (rp=BEG_PROC_ADDR; rp<END_PROC_ADDR; rp++) {
|
|
|
|
if (! isemptyp(rp)) { /* check slot use */
|
2008-11-19 13:26:10 +01:00
|
|
|
lock;
|
2006-03-10 17:10:05 +01:00
|
|
|
if (rp->p_priority > rp->p_max_priority) { /* update priority? */
|
|
|
|
if (rp->p_rts_flags == 0) dequeue(rp); /* take off queue */
|
|
|
|
ticks_added += rp->p_quantum_size; /* do accounting */
|
|
|
|
rp->p_priority -= 1; /* raise priority */
|
|
|
|
if (rp->p_rts_flags == 0) enqueue(rp); /* put on queue */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ticks_added += rp->p_quantum_size - rp->p_ticks_left;
|
|
|
|
rp->p_ticks_left = rp->p_quantum_size; /* give new quantum */
|
|
|
|
}
|
2008-11-19 13:26:10 +01:00
|
|
|
unlock;
|
2006-03-10 17:10:05 +01:00
|
|
|
}
|
|
|
|
}
|
2006-03-10 17:50:27 +01:00
|
|
|
#if DEBUG
|
2006-03-10 17:10:05 +01:00
|
|
|
kprintf("ticks_added: %d\n", ticks_added);
|
2006-03-10 17:50:27 +01:00
|
|
|
#endif
|
2006-03-10 17:10:05 +01:00
|
|
|
|
|
|
|
/* Now schedule a new watchdog timer to balance the queues again. The
|
|
|
|
* period depends on the total amount of quantum ticks added.
|
|
|
|
*/
|
|
|
|
next_period = MAX(Q_BALANCE_TICKS, ticks_added); /* calculate next */
|
|
|
|
set_timer(&queue_timer, get_uptime() + next_period, balance_queues);
|
|
|
|
}
|
|
|
|
|
2005-09-11 18:44:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* lock_send *
|
|
|
|
*===========================================================================*/
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
PUBLIC int lock_send(dst_e, m_ptr)
|
|
|
|
int dst_e; /* to whom is message being sent? */
|
2005-05-24 12:06:17 +02:00
|
|
|
message *m_ptr; /* pointer to message buffer */
|
2005-05-18 12:36:23 +02:00
|
|
|
{
|
|
|
|
/* Safe gateway to mini_send() for tasks. */
|
|
|
|
int result;
|
2008-11-19 13:26:10 +01:00
|
|
|
lock;
|
|
|
|
result = mini_send(proc_ptr, dst_e, m_ptr, 0);
|
|
|
|
unlock;
|
2005-05-18 12:36:23 +02:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2005-09-11 18:44:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* lock_enqueue *
|
|
|
|
*===========================================================================*/
|
2005-08-19 18:43:28 +02:00
|
|
|
PUBLIC void lock_enqueue(rp)
|
2005-04-21 16:53:53 +02:00
|
|
|
struct proc *rp; /* this process is now runnable */
|
|
|
|
{
|
2005-08-19 18:43:28 +02:00
|
|
|
/* Safe gateway to enqueue() for tasks. */
|
2008-11-19 13:26:10 +01:00
|
|
|
lock;
|
2005-08-19 18:43:28 +02:00
|
|
|
enqueue(rp);
|
2008-11-19 13:26:10 +01:00
|
|
|
unlock;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2005-09-11 18:44:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* lock_dequeue *
|
|
|
|
*===========================================================================*/
|
2005-08-19 18:43:28 +02:00
|
|
|
PUBLIC void lock_dequeue(rp)
|
2005-04-21 16:53:53 +02:00
|
|
|
struct proc *rp; /* this process is no longer runnable */
|
|
|
|
{
|
2005-08-19 18:43:28 +02:00
|
|
|
/* Safe gateway to dequeue() for tasks. */
|
2006-02-10 17:53:51 +01:00
|
|
|
if (k_reenter >= 0) {
|
2006-03-10 17:10:05 +01:00
|
|
|
/* We're in an exception or interrupt, so don't lock (and ...
|
2006-02-10 17:53:51 +01:00
|
|
|
* don't unlock).
|
|
|
|
*/
|
|
|
|
dequeue(rp);
|
|
|
|
} else {
|
2008-11-19 13:26:10 +01:00
|
|
|
lock;
|
2006-02-10 17:53:51 +01:00
|
|
|
dequeue(rp);
|
2008-11-19 13:26:10 +01:00
|
|
|
unlock;
|
2006-02-10 17:53:51 +01:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* endpoint_lookup *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC struct proc *endpoint_lookup(endpoint_t e)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if(!isokendpt(e, &n)) return NULL;
|
|
|
|
|
|
|
|
return proc_addr(n);
|
|
|
|
}
|
|
|
|
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* isokendpt_f *
|
|
|
|
*===========================================================================*/
|
|
|
|
#if DEBUG_ENABLE_IPC_WARNINGS
|
|
|
|
PUBLIC int isokendpt_f(file, line, e, p, fatalflag)
|
|
|
|
char *file;
|
|
|
|
int line;
|
|
|
|
#else
|
|
|
|
PUBLIC int isokendpt_f(e, p, fatalflag)
|
|
|
|
#endif
|
2006-06-20 11:57:00 +02:00
|
|
|
endpoint_t e;
|
|
|
|
int *p, fatalflag;
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
{
|
|
|
|
int ok = 0;
|
|
|
|
/* Convert an endpoint number into a process number.
|
|
|
|
* Return nonzero if the process is alive with the corresponding
|
|
|
|
* generation number, zero otherwise.
|
|
|
|
*
|
|
|
|
* This function is called with file and line number by the
|
|
|
|
* isokendpt_d macro if DEBUG_ENABLE_IPC_WARNINGS is defined,
|
|
|
|
* otherwise without. This allows us to print the where the
|
|
|
|
* conversion was attempted, making the errors verbose without
|
|
|
|
* adding code for that at every call.
|
|
|
|
*
|
|
|
|
* If fatalflag is nonzero, we must panic if the conversion doesn't
|
|
|
|
* succeed.
|
|
|
|
*/
|
|
|
|
*p = _ENDPOINT_P(e);
|
|
|
|
if(!isokprocn(*p)) {
|
|
|
|
#if DEBUG_ENABLE_IPC_WARNINGS
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
kprintf("kernel:%s:%d: bad endpoint %d: proc %d out of range\n",
|
|
|
|
file, line, e, *p);
|
2008-11-19 13:26:10 +01:00
|
|
|
#endif
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
#endif
|
|
|
|
} else if(isemptyn(*p)) {
|
|
|
|
#if DEBUG_ENABLE_IPC_WARNINGS
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
kprintf("kernel:%s:%d: bad endpoint %d: proc %d empty\n", file, line, e, *p);
|
2008-11-19 13:26:10 +01:00
|
|
|
#endif
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
#endif
|
|
|
|
} else if(proc_addr(*p)->p_endpoint != e) {
|
|
|
|
#if DEBUG_ENABLE_IPC_WARNINGS
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
kprintf("kernel:%s:%d: bad endpoint %d: proc %d has ept %d (generation %d vs. %d)\n", file, line,
|
|
|
|
e, *p, proc_addr(*p)->p_endpoint,
|
|
|
|
_ENDPOINT_G(e), _ENDPOINT_G(proc_addr(*p)->p_endpoint));
|
2008-11-19 13:26:10 +01:00
|
|
|
#endif
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
#endif
|
|
|
|
} else ok = 1;
|
|
|
|
if(!ok && fatalflag) {
|
2008-11-19 13:26:10 +01:00
|
|
|
minix_panic("invalid endpoint ", e);
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
2008-11-19 13:26:10 +01:00
|
|
|
|