[kernel] Move kassert out of kutil
Continuing moving things out of kutil. The assert as implemented could only ever work in the kernel, so remaining kutil uses of kassert have been moved to including standard C assert instead. Along the way, kassert was broken out into panic::panic and kassert, and the panic.serial namespace was renamed panicking.
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
#include "kutil/assert.h"
|
||||
|
||||
namespace kutil {
|
||||
namespace assert {
|
||||
|
||||
uint32_t *apic_icr = reinterpret_cast<uint32_t*>(0xffffc000fee00300);
|
||||
uintptr_t symbol_table = 0;
|
||||
|
||||
} // namespace assert
|
||||
} // namespace kutil
|
||||
@@ -1,4 +1,9 @@
|
||||
#include "kutil/assert.h"
|
||||
#if __has_include(<assert.h>)
|
||||
#include <assert.h>
|
||||
#else
|
||||
#define assert(x) ((void)0)
|
||||
#endif
|
||||
|
||||
#include "kutil/bip_buffer.h"
|
||||
|
||||
namespace kutil {
|
||||
@@ -61,14 +66,14 @@ size_t bip_buffer::reserve(size_t size, void **area)
|
||||
|
||||
void bip_buffer::commit(size_t size)
|
||||
{
|
||||
kassert(size <= m_size_r, "Tried to commit more than reserved");
|
||||
assert(size <= m_size_r && "Tried to commit more than reserved");
|
||||
|
||||
if (m_start_r == m_start_a + m_size_a) {
|
||||
// We were adding to A
|
||||
m_size_a += size;
|
||||
} else {
|
||||
// We were adding to B
|
||||
kassert(m_start_r == m_start_b + m_size_b, "Bad m_start_r!");
|
||||
assert(m_start_r == m_start_b + m_size_b && "Bad m_start_r!");
|
||||
m_size_b += size;
|
||||
}
|
||||
|
||||
@@ -83,7 +88,7 @@ size_t bip_buffer::get_block(void **area) const
|
||||
|
||||
void bip_buffer::consume(size_t size)
|
||||
{
|
||||
kassert(size <= m_size_a, "Consumed more bytes than exist in A");
|
||||
assert(size <= m_size_a && "Consumed more bytes than exist in A");
|
||||
if (size >= m_size_a) {
|
||||
m_size_a = m_size_b;
|
||||
m_start_a = m_start_b;
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace kutil {
|
||||
namespace assert {
|
||||
|
||||
constexpr uint32_t send_nmi_command =
|
||||
(4 << 8) | // Delivery mode NMI
|
||||
(1 << 14) | // assert level high
|
||||
(1 << 18); // destination self
|
||||
|
||||
extern uint32_t *apic_icr;
|
||||
extern uintptr_t symbol_table;
|
||||
|
||||
} // namespace assert
|
||||
} // namespace kutil
|
||||
|
||||
__attribute__ ((always_inline))
|
||||
inline void kassert(
|
||||
bool check,
|
||||
const char *message = nullptr,
|
||||
const char *function = __builtin_FUNCTION(),
|
||||
const char *file = __builtin_FILE(),
|
||||
uint64_t line = __builtin_LINE())
|
||||
{
|
||||
if (!check) {
|
||||
register uintptr_t syms asm("rdi");
|
||||
register const char *m asm("rsi");
|
||||
register const char *fn asm("rdx");
|
||||
register const char *fi asm("rcx");
|
||||
register uint64_t l asm("r8");
|
||||
|
||||
asm volatile ("mov %1, %0" : "=r"(syms) : "r"(kutil::assert::symbol_table));
|
||||
asm volatile ("mov %1, %0" : "=r"(m) : "r"(message));
|
||||
asm volatile ("mov %1, %0" : "=r"(fn) : "r"(function));
|
||||
asm volatile ("mov %1, %0" : "=r"(fi) : "r"(file));
|
||||
asm volatile ("mov %1, %0" : "=r"(l) : "r"(line));
|
||||
|
||||
*kutil::assert::apic_icr = kutil::assert::send_nmi_command;
|
||||
|
||||
while (1) asm ("hlt");
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
/// http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/
|
||||
|
||||
#include <new>
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "kutil/hash.h"
|
||||
@@ -145,7 +146,7 @@ protected:
|
||||
}
|
||||
|
||||
void set_capacity(size_t capacity) {
|
||||
kassert((capacity & (capacity - 1)) == 0,
|
||||
assert((capacity & (capacity - 1)) == 0 &&
|
||||
"Map capacity must be a power of two");
|
||||
|
||||
m_capacity = capacity;
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
/// \file vector.h
|
||||
/// Definition of a simple dynamic vector collection for use in kernel space
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <utility>
|
||||
#include "kutil/assert.h"
|
||||
#include "kutil/util.h"
|
||||
|
||||
namespace kutil {
|
||||
@@ -158,7 +158,7 @@ public:
|
||||
/// Remove an item from the end of the array.
|
||||
void remove()
|
||||
{
|
||||
kassert(m_size, "Called remove() on an empty array");
|
||||
assert(m_size && "Called remove() on an empty array");
|
||||
|
||||
m_size -= 1;
|
||||
m_elements[m_size].~T();
|
||||
@@ -167,14 +167,14 @@ public:
|
||||
/// Remove an item from the front of the array, preserving order.
|
||||
void remove_front()
|
||||
{
|
||||
kassert(m_size, "Called remove_front() on an empty array");
|
||||
assert(m_size && "Called remove_front() on an empty array");
|
||||
remove_at(0);
|
||||
}
|
||||
|
||||
/// Remove an item from the array.
|
||||
void remove(const T &item)
|
||||
{
|
||||
kassert(m_size, "Called remove() on an empty array");
|
||||
assert(m_size && "Called remove() on an empty array");
|
||||
for (count_t i = 0; i < m_size; ++i) {
|
||||
if (m_elements[i] == item) {
|
||||
remove_at(i);
|
||||
@@ -224,7 +224,7 @@ public:
|
||||
/// Remove an item from the end of the array and return it.
|
||||
T pop()
|
||||
{
|
||||
kassert(m_size, "Called pop() on an empty array");
|
||||
assert(m_size && "Called pop() on an empty array");
|
||||
|
||||
T temp = m_elements[m_size - 1];
|
||||
remove();
|
||||
@@ -234,7 +234,7 @@ public:
|
||||
/// Remove an item from the beginning of the array and return it.
|
||||
T pop_front()
|
||||
{
|
||||
kassert(m_size, "Called pop_front() on an empty array");
|
||||
assert(m_size && "Called pop_front() on an empty array");
|
||||
|
||||
T temp = m_elements[0];
|
||||
remove_front();
|
||||
|
||||
@@ -4,7 +4,6 @@ module("kutil",
|
||||
kind = "lib",
|
||||
includes = [ "include" ],
|
||||
sources = [
|
||||
"assert.cpp",
|
||||
"bip_buffer.cpp",
|
||||
"spinlock.cpp",
|
||||
])
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
CPP_CHECK_BEGIN
|
||||
|
||||
void _PDCLIB_assert( const char * const, const char * const, const char * const );
|
||||
void _PDCLIB_assert( const char * const, const char * const, const char * const, unsigned );
|
||||
|
||||
/* If NDEBUG is set, assert() is a null operation. */
|
||||
#undef assert
|
||||
@@ -19,11 +19,7 @@ void _PDCLIB_assert( const char * const, const char * const, const char * const
|
||||
#define assert( ignore ) ( (void) 0 )
|
||||
#else
|
||||
#define assert( expression ) ( ( expression ) ? (void) 0 \
|
||||
: _PDCLIB_assert( "Assertion failed: " #expression \
|
||||
", function ", __func__, \
|
||||
", file " __FILE__ \
|
||||
", line " _PDCLIB_symbol2string( __LINE__ ) \
|
||||
"." _PDCLIB_endl ) )
|
||||
: _PDCLIB_assert( #expression, __func__, __FILE__, __LINE__ ) )
|
||||
#endif
|
||||
|
||||
CPP_CHECK_END
|
||||
|
||||
@@ -10,10 +10,9 @@
|
||||
|
||||
#include "j6libc/aux.h"
|
||||
|
||||
void _PDCLIB_assert( const char * const message1, const char * const function, const char * const message2 )
|
||||
void _PDCLIB_assert( const char * const message, const char * const function, const char * const file, unsigned line )
|
||||
{
|
||||
fputs( message1, stderr );
|
||||
fputs( function, stderr );
|
||||
fputs( message2, stderr );
|
||||
fprintf( stderr, "Assertion failed: %s, function %s, file %s, line %d.%s",
|
||||
message, function, file, line, _PDCLIB_endl );
|
||||
abort();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user