Non-locking I/O for panic()
This commit is contained in:
parent
0bdad29198
commit
887aa60973
|
@ -25,6 +25,7 @@
|
||||||
#include <kernel/buf.h>
|
#include <kernel/buf.h>
|
||||||
|
|
||||||
extern error_t bputc(Buffer_t *buf, uchar ch);
|
extern error_t bputc(Buffer_t *buf, uchar ch);
|
||||||
|
error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Prints formatted string on buf according to fmt
|
// Prints formatted string on buf according to fmt
|
||||||
|
@ -35,11 +36,25 @@ error_t BPrintOnBuf(Buffer_t *buf, const char *fmt, ...)
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
rc = BPrintOnBufV(buf, fmt, ap);
|
ExAcquireLock(&buf->lock);
|
||||||
|
rc = vbprintf(buf, fmt, ap);
|
||||||
|
ExReleaseLock(&buf->lock);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_t BPrintOnBufV(Buffer_t *buf, const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
error_t rc;
|
||||||
|
|
||||||
|
ExAcquireLock(&buf->lock);
|
||||||
|
rc = vbprintf(buf, fmt, ap);
|
||||||
|
ExReleaseLock(&buf->lock);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Prints 0 for octal, 0x for hexadecimal, 0b for binary
|
// Prints 0 for octal, 0x for hexadecimal, 0b for binary
|
||||||
//
|
//
|
||||||
|
@ -81,10 +96,10 @@ static error_t bdopadding(Buffer_t *buf, size_t width, size_t len,
|
||||||
#define fmtnext() do{fmt++;if(*fmt==0){rc=EINVAL;goto leave;}}while(0)
|
#define fmtnext() do{fmt++;if(*fmt==0){rc=EINVAL;goto leave;}}while(0)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Actually does BPrintOnBuf's job
|
// Actually does BPrintOnBuf's job; doesn't lock anything
|
||||||
// Quite a long function
|
// Quite a long function
|
||||||
//
|
//
|
||||||
error_t BPrintOnBufV(Buffer_t *buf, const char *fmt, va_list ap)
|
error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
error_t rc = EOK;
|
error_t rc = EOK;
|
||||||
int tmpwidth;
|
int tmpwidth;
|
||||||
|
@ -120,8 +135,6 @@ error_t BPrintOnBufV(Buffer_t *buf, const char *fmt, va_list ap)
|
||||||
return EBADF;
|
return EBADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExAcquireLock(&buf->lock);
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
// We come back here after dealing with a modifier
|
// We come back here after dealing with a modifier
|
||||||
|
@ -367,7 +380,6 @@ loop:
|
||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
leave:
|
leave:
|
||||||
ExReleaseLock(&buf->lock);
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,18 +147,18 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic)
|
||||||
// Sanity checks and hello world
|
// Sanity checks and hello world
|
||||||
BtInitSanity(mbMagic);
|
BtInitSanity(mbMagic);
|
||||||
|
|
||||||
//Memory mapping
|
// Memory mapping
|
||||||
MmInitMemoryMap();
|
MmInitMemoryMap();
|
||||||
|
|
||||||
|
// Heap initialization
|
||||||
MmInitHeap();
|
MmInitHeap();
|
||||||
|
|
||||||
//int i = 0;
|
|
||||||
//while(i < 512) { KernLog("%d\n", i++);}
|
|
||||||
//MmPrintMemoryMap();
|
|
||||||
|
|
||||||
PsInitSched();
|
PsInitSched();
|
||||||
|
|
||||||
// We're out
|
// We're out
|
||||||
PsFiniSched();
|
PsFiniSched();
|
||||||
KeCrashSystem(); //yay
|
|
||||||
|
KeStartPanic("Test Panic %d", 4);
|
||||||
|
|
||||||
|
KeCrashSystem();
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,9 +44,7 @@ error_t bvgaflusher(Buffer_t *buf)
|
||||||
ushort *fbp = BtGetBootInfo(video).framebufferAddr;
|
ushort *fbp = BtGetBootInfo(video).framebufferAddr;
|
||||||
const uchar color = 0xf;
|
const uchar color = 0xf;
|
||||||
|
|
||||||
assert(buf->lastLF == 0);
|
uchar *currentLine = buf->wp - buf->lineLen - buf->lastLF;
|
||||||
|
|
||||||
uchar *currentLine = buf->wp - buf->lineLen;
|
|
||||||
uchar *ptr = (uchar *)lmax((size_t)buf->buf,
|
uchar *ptr = (uchar *)lmax((size_t)buf->buf,
|
||||||
(size_t)currentLine
|
(size_t)currentLine
|
||||||
- (buf->nLines - 1) * buf->lineLen);
|
- (buf->nLines - 1) * buf->lineLen);
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
#include <kernel/sched.h>
|
#include <kernel/sched.h>
|
||||||
#include <kernel/panic.h>
|
#include <kernel/panic.h>
|
||||||
|
|
||||||
|
error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Failed assert() handler
|
// Failed assert() handler
|
||||||
//
|
//
|
||||||
|
@ -55,21 +57,29 @@ noreturn void KeStartPanic(const char *fmt, ...)
|
||||||
PsCurProc = NULL;
|
PsCurProc = NULL;
|
||||||
if (BStdOut == NULL) KeCrashSystem();
|
if (BStdOut == NULL) KeCrashSystem();
|
||||||
|
|
||||||
|
ExAttemptLock(&BStdOut->lock);
|
||||||
|
|
||||||
if (fmt == NULL) {
|
if (fmt == NULL) {
|
||||||
fmt = "(no message given)";
|
fmt = "(no message given)";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (KePanicStr[0] != 0) {
|
if (KePanicStr[0] != 0) {
|
||||||
KernLog("\nDouble panic!");
|
vbprintf(BStdOut, "\nDouble panic!", NULL);
|
||||||
KeHaltCPU();
|
KeHaltCPU();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KePanicStr[0] = 1;
|
||||||
|
|
||||||
|
// We don't check vbprintf's output
|
||||||
|
// If it fails, what could we do anyway?
|
||||||
|
|
||||||
|
vbprintf(BStdOut, "\nPanic!\n\n", NULL);
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vsnprintf((char *)KePanicStr, PANICSTR_SIZE, fmt, ap);
|
vbprintf(BStdOut, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
KernLog("\nPanic!\n\n");
|
BStdOut->flusher(BStdOut);
|
||||||
KernLog((char *)KePanicStr);
|
|
||||||
|
|
||||||
KeHaltCPU();
|
KeHaltCPU();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue