2020301918-os/lib/user/assert.c
2022-10-29 19:48:58 +08:00

40 lines
723 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <assert.h>
#include <user/stdio.h>
/*
* 当发生不可挽回的错误时就打印错误信息并使进程死循环
*/
void
_panic(const char *file, int line, const char *fmt,...)
{
va_list ap;
va_start(ap, fmt);
printf("\x1b[0m\x1b[91muser panic at %s:%d: ", file, line);
vprintf(fmt, ap);
printf("\n\x1b[0m");
va_end(ap);
fflush();
// 休眠CPU核直接罢工
while(1)
/* do nothing */;
}
/*
* 很像panic但是不会休眠进程就是正常打印信息
*/
void
_warn(const char *file, int line, const char *fmt,...)
{
va_list ap;
va_start(ap, fmt);
printf("\x1b[0m\x1b[93muser warning at %s:%d: ", file, line);
vprintf(fmt, ap);
printf("\n\x1b[0m");
va_end(ap);
fflush();
}