Cleaned up src/lib/utils library. Renamed server_ functions to more logical

names. All system processes can now either use panic() or report() from
libutils, or redefine their own function. Assertions are done via the standard
<assert.h> functionality.
This commit is contained in:
Jorrit Herder
2005-06-01 14:31:00 +00:00
parent 75689debe3
commit 6d23f072f3
58 changed files with 364 additions and 498 deletions
+3 -2
View File
@@ -108,7 +108,8 @@ phys_clicks clicks; /* number of clicks to free */
register struct hole *hp, *new_ptr, *prev_ptr;
if (clicks == 0) return;
if ( (new_ptr = free_slots) == NIL_HOLE) panic("Hole table full", NO_NUM);
if ( (new_ptr = free_slots) == NIL_HOLE)
panic(__FILE__,"hole table full", NO_NUM);
new_ptr->h_base = base;
new_ptr->h_len = clicks;
free_slots = new_ptr->h_next;
@@ -219,7 +220,7 @@ phys_clicks *free; /* memory size summaries */
/* Get a copy of the physical memory chunks found at the kernel. */
if ((i=sys_getmemchunks(mem)) != OK)
panic("PM couldn't get mem chunks",i);
panic(__FILE__,"couldn't get mem chunks",i);
/* Put all holes on the free list. */
for (hp = &hole[0]; hp < &hole[NR_HOLES]; hp++) hp->h_next = hp + 1;
+1 -1
View File
@@ -50,7 +50,7 @@ PUBLIC int do_brk()
}
new_clicks -= rmp->mp_seg[D].mem_vir;
if ((r=get_stack_ptr(who, &new_sp)) != OK) /* ask kernel for sp value */
panic("PM couldn't get stack pointer", r);
panic(__FILE__,"couldn't get stack pointer", r);
r = adjust(rmp, new_clicks, new_sp);
rmp->mp_reply.reply_ptr = (r == OK ? m_in.addr : (char *) -1);
return(r); /* return new address or -1 */
+2 -2
View File
@@ -129,7 +129,7 @@ PUBLIC int do_exec()
src = (vir_bytes) mbuf;
r = sys_datacopy(PM_PROC_NR, (vir_bytes) src,
who, (vir_bytes) vsp, (phys_bytes)stk_bytes);
if (r != OK) panic("do_exec stack copy err on", who);
if (r != OK) panic(__FILE__,"do_exec stack copy err on", who);
/* Read in text and data segments. */
if (sh_mp != NULL) {
@@ -381,7 +381,7 @@ phys_bytes tot_bytes; /* total memory to allocate, including gap */
count = MIN(bytes, (phys_bytes) sizeof(zero));
if ((s=sys_physcopy(PM_PROC_NR, D, (phys_bytes) zero,
NONE, PHYS_SEG, base, count)) != OK) {
panic("new_mem can't zero", s);
panic(__FILE__,"new_mem can't zero", s);
}
base += count;
bytes -= count;
+1 -1
View File
@@ -64,7 +64,7 @@ PUBLIC int do_fork()
child_abs = (phys_bytes) child_base << CLICK_SHIFT;
parent_abs = (phys_bytes) rmp->mp_seg[D].mem_phys << CLICK_SHIFT;
i = sys_abscopy(parent_abs, child_abs, prog_bytes);
if (i < 0) panic("do_fork can't copy", i);
if (i < 0) panic(__FILE__,"do_fork can't copy", i);
/* Find a slot in 'mproc' for the child process. A slot must exist. */
for (rmc = &mproc[0]; rmc < &mproc[NR_PROCS]; rmc++)
+6 -6
View File
@@ -77,7 +77,7 @@ PUBLIC void main()
for (proc_nr=0, rmp=mproc; proc_nr < NR_PROCS; proc_nr++, rmp++) {
if ((rmp->mp_flags & (REPLY | ONSWAP)) == REPLY) {
if ((s=send(proc_nr, &rmp->mp_reply)) != OK) {
panic("PM can't reply to", proc_nr);
panic(__FILE__,"PM can't reply to", proc_nr);
}
rmp->mp_flags &= ~REPLY;
}
@@ -92,7 +92,7 @@ PUBLIC void main()
PRIVATE void get_work()
{
/* Wait for the next message and extract useful information from it. */
if (receive(ANY, &m_in) != OK) panic("PM receive error", NO_NUM);
if (receive(ANY, &m_in) != OK) panic(__FILE__,"PM receive error", NO_NUM);
who = m_in.m_source; /* who sent the message */
call_nr = m_in.m_type; /* system call number */
@@ -156,7 +156,7 @@ PRIVATE void pm_init()
/* Get the memory map of the kernel to see how much memory it uses. */
if ((s=get_mem_map(SYSTASK, kernel_map)) != OK)
panic("PM couldn't get proc entry of SYSTASK",s);
panic(__FILE__,"PM couldn't get proc entry of SYSTASK",s);
minix_clicks = (kernel_map[S].mem_phys + kernel_map[S].mem_len)
- kernel_map[T].mem_phys;
@@ -185,7 +185,7 @@ PRIVATE void pm_init()
/* Get memory map for this process from the kernel. */
if ((s=get_mem_map(ip->proc_nr, rmp->mp_seg)) != OK)
panic("couldn't get process entry",s);
panic(__FILE__,"couldn't get process entry",s);
if (rmp->mp_seg[T].mem_len != 0) rmp->mp_flags |= SEPARATE;
minix_clicks += rmp->mp_seg[S].mem_phys +
rmp->mp_seg[S].mem_len - rmp->mp_seg[T].mem_phys;
@@ -194,14 +194,14 @@ PRIVATE void pm_init()
mess.PR_PROC_NR = ip->proc_nr;
mess.PR_PID = rmp->mp_pid;
if (OK != (s=send(FS_PROC_NR, &mess)))
panic("PM can't sync up with FS", s);
panic(__FILE__,"PM can't sync up with FS", s);
}
}
/* Tell FS no more SYSTEM processes follow and synchronize. */
mess.PR_PROC_NR = NONE;
if (sendrec(FS_PROC_NR, &mess) != OK || mess.m_type != OK)
panic("PM can't sync up with FS", NO_NUM);
panic(__FILE__,"PM can't sync up with FS", NO_NUM);
/* INIT process is somewhat special. */
sigemptyset(&mproc[INIT_PROC_NR].mp_ignore);
+4 -4
View File
@@ -67,7 +67,7 @@ _PROTOTYPE( void setreply, (int proc_nr, int result) );
/* signal.c */
_PROTOTYPE( int do_alarm, (void) );
_PROTOTYPE( int do_kill, (void) );
_PROTOTYPE( int ksig_pending, (void) );
_PROTOTYPE( int ksig_pending, (void) );
_PROTOTYPE( int do_pause, (void) );
_PROTOTYPE( int set_alarm, (int proc_nr, int sec) );
_PROTOTYPE( int check_sig, (pid_t proc_id, int signo) );
@@ -82,7 +82,7 @@ _PROTOTYPE( void check_pending, (struct mproc *rmp) );
/* time.c */
_PROTOTYPE( int do_stime, (void) );
_PROTOTYPE( int do_time, (void) );
_PROTOTYPE( int do_times, (void) );
_PROTOTYPE( int do_times, (void) );
/* trace.c */
_PROTOTYPE( int do_trace, (void) );
@@ -92,8 +92,8 @@ _PROTOTYPE( void stop_proc, (struct mproc *rmp, int sig_nr) );
_PROTOTYPE( pid_t get_free_pid, (void) );
_PROTOTYPE( int allowed, (char *name_buf, struct stat *s_buf, int mask) );
_PROTOTYPE( int no_sys, (void) );
_PROTOTYPE( void panic, (char *format, int num) );
_PROTOTYPE( void panic, (char *who, char *mess, int num) );
_PROTOTYPE( void tell_fs, (int what, int p1, int p2, int p3) );
_PROTOTYPE( int get_stack_ptr, (int proc_nr, vir_bytes *sp) );
_PROTOTYPE( int get_stack_ptr, (int proc_nr, vir_bytes *sp) );
_PROTOTYPE( int get_mem_map, (int proc_nr, struct mem_map *mem_map) );
+4 -4
View File
@@ -315,7 +315,7 @@ int sec; /* how many seconds delay before the signal */
ticks = LONG_MAX; /* eternity (really TMR_NEVER) */
if ((s=sys_signalrm(proc_nr, &ticks)) != OK)
panic("PM couldn't set signal alarm", s);
panic(__FILE__,"couldn't set signal alarm", s);
remaining = (int) ((ticks + (HZ-1))/HZ);
if (remaining < 0) remaining = INT_MAX; /* true value is too large */
@@ -364,7 +364,7 @@ int signo; /* signal to send to process (1 to _NSIG) */
if ((rmp->mp_flags & (IN_USE | ZOMBIE)) != IN_USE) {
printf("PM: signal %d sent to %s process %d\n",
(rmp->mp_flags & ZOMBIE) ? "zombie" : "dead", signo, slot);
panic("", NO_NUM);
panic(__FILE__,"", NO_NUM);
}
if ((rmp->mp_flags & TRACED) && signo != SIGKILL) {
/* A traced process has special handling. */
@@ -396,7 +396,7 @@ int signo; /* signal to send to process (1 to _NSIG) */
sm.sm_sighandler = (vir_bytes) rmp->mp_sigact[signo].sa_handler;
sm.sm_sigreturn = rmp->mp_sigreturn;
if ((s=get_stack_ptr(slot, &new_sp)) != OK)
panic("PM couldn't get new stack pointer",s);
panic(__FILE__,"couldn't get new stack pointer",s);
sm.sm_stkptr = new_sp;
/* Make room for the sigcontext and sigframe struct. */
@@ -600,7 +600,7 @@ register struct mproc *rmp; /* whose core is to be dumped */
* Maybe make SAFETY_BYTES a parameter.
*/
if ((s=get_stack_ptr(slot, &current_sp)) != OK)
panic("PM couldn't get new stack pointer",s);
panic(__FILE__,"couldn't get new stack pointer",s);
adjust(rmp, rmp->mp_seg[D].mem_len, current_sp);
/* Write the memory map of all segments to begin the core file. */
+3 -3
View File
@@ -30,7 +30,7 @@ PUBLIC int do_time()
int s;
if ( (s=sys_getuptime(&uptime)) != OK)
panic("PM: warning, do_time couldn't get uptime", s);
panic(__FILE__,"do_time couldn't get uptime", s);
mp->mp_reply.reply_time = (time_t) (boottime + (uptime/HZ));
return(OK);
@@ -53,7 +53,7 @@ PUBLIC int do_stime()
return(EPERM);
}
if ( (s=sys_getuptime(&uptime)) != OK)
panic("PM: warning, do_stime couldn't get uptime", s);
panic(__FILE__,"do_stime couldn't get uptime", s);
boottime = (long) m_in.stime - (uptime/HZ);
/* Also inform FS about the new system time. */
@@ -74,7 +74,7 @@ PUBLIC int do_times()
int s;
if (OK != (s=sys_times(who, t)))
panic("PM: warning, do_times couldn't get times", s);
panic(__FILE__,"do_times couldn't get times", s);
rmp->mp_reply.reply_t1 = t[0]; /* user time */
rmp->mp_reply.reply_t2 = t[1]; /* system time */
rmp->mp_reply.reply_t3 = rmp->mp_child_utime; /* child user time */
+6 -5
View File
@@ -78,7 +78,7 @@ int mask; /* R_BIT, W_BIT, or X_BIT */
save_errno = errno; /* open might fail, e.g. from ENFILE */
tell_fs(SETUID, PM_PROC_NR, (int) mp->mp_effuid, (int) mp->mp_effuid);
if (fd < 0) return(-save_errno);
if (fstat(fd, s_buf) < 0) panic("allowed: fstat failed", NO_NUM);
if (fstat(fd, s_buf) < 0) panic(__FILE__,"allowed: fstat failed", NO_NUM);
/* Only regular files can be executed. */
if (mask == X_BIT && (s_buf->st_mode & I_TYPE) != I_REGULAR) {
@@ -103,16 +103,17 @@ PUBLIC int no_sys()
/*===========================================================================*
* panic *
*===========================================================================*/
PUBLIC void panic(format, num)
char *format; /* format string */
int num; /* number to go with format string */
PUBLIC void panic(who, mess, num)
char *who; /* who caused the panic */
char *mess; /* panic message string */
int num; /* number to go with it */
{
/* An unrecoverable error has occurred. Panics are caused when an internal
* inconsistency is detected, e.g., a programming error or illegal value of a
* defined constant. The process manager decides to shut down. This results
* in a HARD_STOP notification to all system processes to allow local cleanup.
*/
printf("Process manager panic: %s", format);
printf("PM panic (%s): %s", who, mess);
if (num != NO_NUM) printf(": %d",num);
printf("\n");
sys_abort(RBT_PANIC);