
Now that clock_t is an unsigned value, we can also allow the system uptime to wrap. Essentially, instead of using (a <= b) to see if time a occurs no later than time b, we use (b - a <= CLOCK_MAX / 2). The latter value does not exist, so instead we add TMRDIFF_MAX for that purpose. We must therefore also avoid using values like 0 and LONG_MAX as special values for absolute times. This patch extends the libtimers interface so that it no longer uses 0 to indicate "no timeout". Similarly, TMR_NEVER is now used as special value only when otherwise a relative time difference would be used. A minix_timer structure is now considered in use when it has a watchdog function set, rather than when the absolute expiry time is not TMR_NEVER. A few new macros in <minix/timers.h> help with timer comparison and obtaining properties from a minix_timer structure. This patch also eliminates the union of timer arguments, instead using the only union element that is only used (the integer). This prevents potential problems with e.g. live update. The watchdog function prototype is changed to pass in the argument value rather than a pointer to the timer structure, since obtaining the argument value was the only current use of the timer structure anyway. The result is a somewhat friendlier timers API. The VFS select code required a few more invasive changes to restrict the timer value to the new maximum, effectively matching the timer code in PM. As a side effect, select(2) has been changed to reject invalid timeout values. That required a change to the test set, which relied on the previous, erroneous behavior. Finally, while we're rewriting significant chunks of the timer code anyway, also covert it to KNF and add a few more explanatory comments. Change-Id: Id43165c3fbb140b32b90be2cca7f68dd646ea72e
93 lines
2.5 KiB
C
93 lines
2.5 KiB
C
/* This file contains a collection of miscellaneous procedures:
|
|
* panic: abort MINIX due to a fatal error
|
|
* kputc: buffered putc used by kernel printf
|
|
*/
|
|
|
|
#include "kernel/kernel.h"
|
|
#include "arch_proto.h"
|
|
|
|
#include <minix/syslib.h>
|
|
#include <unistd.h>
|
|
#include <stdarg.h>
|
|
#include <signal.h>
|
|
#include <string.h>
|
|
|
|
#include <minix/sys_config.h>
|
|
|
|
#define ARE_PANICING 0xDEADC0FF
|
|
|
|
/*===========================================================================*
|
|
* panic *
|
|
*===========================================================================*/
|
|
void panic(const char *fmt, ...)
|
|
{
|
|
va_list arg;
|
|
/* The system has run aground of a fatal kernel error. Terminate execution. */
|
|
if (kinfo.minix_panicing == ARE_PANICING) {
|
|
reset();
|
|
}
|
|
kinfo.minix_panicing = ARE_PANICING;
|
|
if (fmt != NULL) {
|
|
printf("kernel panic: ");
|
|
va_start(arg, fmt);
|
|
vprintf(fmt, arg);
|
|
printf("\n");
|
|
}
|
|
|
|
printf("kernel on CPU %d: ", cpuid);
|
|
util_stacktrace();
|
|
|
|
#if 0
|
|
if(get_cpulocal_var(proc_ptr)) {
|
|
printf("current process : ");
|
|
proc_stacktrace(get_cpulocal_var(proc_ptr));
|
|
}
|
|
#endif
|
|
|
|
/* Abort MINIX. */
|
|
minix_shutdown(0);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* kputc *
|
|
*===========================================================================*/
|
|
void kputc(
|
|
int c /* character to append */
|
|
)
|
|
{
|
|
/* Accumulate a single character for a kernel message. Send a notification
|
|
* to the output drivers if an END_OF_KMESS is encountered.
|
|
*/
|
|
if (c != END_OF_KMESS) {
|
|
int maxblpos = sizeof(kmess.kmess_buf) - 2;
|
|
#ifdef DEBUG_SERIAL
|
|
if (kinfo.do_serial_debug) {
|
|
if(c == '\n')
|
|
ser_putc('\r');
|
|
ser_putc(c);
|
|
}
|
|
#endif
|
|
kmess.km_buf[kmess.km_next] = c; /* put normal char in buffer */
|
|
kmess.kmess_buf[kmess.blpos] = c;
|
|
if (kmess.km_size < sizeof(kmess.km_buf))
|
|
kmess.km_size += 1;
|
|
kmess.km_next = (kmess.km_next + 1) % _KMESS_BUF_SIZE;
|
|
if(kmess.blpos == maxblpos) {
|
|
memmove(kmess.kmess_buf,
|
|
kmess.kmess_buf+1, sizeof(kmess.kmess_buf)-1);
|
|
} else kmess.blpos++;
|
|
} else if (!(kinfo.minix_panicing || kinfo.do_serial_debug)) {
|
|
send_diag_sig();
|
|
}
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* _exit *
|
|
*===========================================================================*/
|
|
void _exit(
|
|
int e /* error code */
|
|
)
|
|
{
|
|
panic("_exit called from within the kernel, should not happen. (err %i)", e);
|
|
}
|