Skip to content

Commit acf2b39

Browse files
authored
Merge pull request #1206 from fwsGonzo/dev
kernel: Use panic instead of assert for sanity checks
2 parents ac0ce41 + af444ec commit acf2b39

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/drivers/vmxnet3.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ vmxnet3::vmxnet3(hw::PCI_Device& d) :
118118
INFO2("[x] Device has %u MSI-X vectors", msix_vectors);
119119
assert(msix_vectors >= 3);
120120
if (msix_vectors > 3) msix_vectors = 3;
121-
std::vector<uint8_t> irqs;
122121

123122
for (int i = 0; i < msix_vectors; i++)
124123
{
@@ -144,10 +143,12 @@ vmxnet3::vmxnet3(hw::PCI_Device& d) :
144143
assert(this->ptbase);
145144

146145
// verify and select version
147-
assert(check_version());
146+
bool ok = check_version();
147+
assert(ok);
148148

149149
// reset device
150-
assert(reset());
150+
ok = reset();
151+
assert(ok);
151152

152153
// get mac address
153154
retrieve_hwaddr();

src/hw/pci_device.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ namespace hw {
183183

184184
// enable MSI-x if its supported
185185
if (this->msix_cap()) {
186-
assert(this->init_msix());
186+
int vectors = this->init_msix();
187+
assert(vectors > 0);
187188
}
188189
}
189190

src/kernel/sanity_checks.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <kprint>
2222
#include <util/crc32.hpp>
2323
#include <kernel/elf.hpp>
24+
#include <kernel/syscalls.hpp>
2425

2526
// NOTE: crc_to MUST NOT be initialized to zero
2627
static uint32_t crc_ro = CRC32_BEGIN();
@@ -54,14 +55,16 @@ void kernel_sanity_checks()
5455
uint32_t new_ro = generate_ro_crc();
5556
if (crc_ro != new_ro) {
5657
kprintf("CRC mismatch %#x vs %#x\n", crc_ro, new_ro);
57-
assert(0 && "CRC of kernel read-only area failed");
58+
panic("Sanity checks: CRC of kernel read-only area failed");
5859
}
5960
// verify that first page is zeroes only
6061
for (volatile int* lowmem = NULL; lowmem < LOW_CHECK_SIZE; lowmem++)
6162
if (UNLIKELY(*lowmem != 0)) {
6263
kprintf("Memory at %p was not zeroed: %#x\n", lowmem, *lowmem);
63-
assert(0 && "Low-memory zero test");
64+
panic("Sanity checks: Low-memory zero test");
6465
}
6566
// verify that Elf symbols were not overwritten
66-
assert(Elf::verify_symbols() && "Check consistency of Elf symbols and string areas");
67+
bool symbols_verified = Elf::verify_symbols();
68+
if (!symbols_verified)
69+
panic("Sanity checks: Consistency of Elf symbols and string areas");
6770
}

0 commit comments

Comments
 (0)