1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Replace ASSERT with assert of <assert.h>.

This commit is contained in:
Jonas 'Sortie' Termansen 2012-09-22 14:57:20 +02:00
parent b685b7a9eb
commit 42754f1728
24 changed files with 135 additions and 116 deletions

View file

@ -24,6 +24,7 @@
#include <libmaxsi/sortix-vga.h>
#include <sys/keycodes.h>
#include <sys/termmode.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
@ -204,8 +205,8 @@ void Update()
tailmax++;
animalx = 2 + (rand() % (width-4));
animaly = 2 + (rand() % (height-4));
ASSERT(0 <= animalx && animalx < width);
ASSERT(0 <= animaly && animaly < height);
assert(0 <= animalx && animalx < width);
assert(0 <= animaly && animaly < height);
if ( maxspeed < speed ) { speed += speedincrease; }
}

View file

@ -32,6 +32,7 @@ ASFLAGS=$(CPUASFLAGS)
FREEOBJS=\
abort.o \
abs.o \
_assert.o \
bsearch.o \
clearerr.o \
c++.o \
@ -106,7 +107,6 @@ vsscanf.o \
HOSTEDOBJS=\
access.o \
_assert.o \
chdir.o \
chmod.o \
close.o \

View file

@ -23,13 +23,25 @@
******************************************************************************/
#include <assert.h>
#include <stdint.h>
#if !defined(SORTIX_KERNEL)
#include <stdio.h>
#include <stdlib.h>
#endif
#if defined(SORTIX_KERNEL)
#include <sortix/kernel/decl.h>
#include <sortix/kernel/panic.h>
#endif
void _assert(const char* filename, unsigned int line, const char* functionname,
const char* expression)
{
#if !defined(SORTIX_KERNEL)
fprintf(stderr, "Assertion failure: %s:%u: %s: %s\n", filename, line,
functionname, expression);
abort();
#else
Sortix::PanicF("Assertion failure: %s:%u: %s: %s\n", filename, line,
functionname, expression);
#endif
}

View file

@ -35,11 +35,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#undef ASSERT
#define ASSERT(invariant) assert(invariant)
#endif
#include <assert.h>
#include <malloc.h>
#define PARANOIA 1
@ -87,7 +85,7 @@ namespace Maxsi
void FreeMemory(addr_t where, size_t bytes)
{
ASSERT(Sortix::Page::IsAligned(where + bytes));
assert(Sortix::Page::IsAligned(where + bytes));
while ( bytes )
{
@ -101,7 +99,7 @@ namespace Maxsi
bool AllocateMemory(addr_t where, size_t bytes)
{
ASSERT(Sortix::Page::IsAligned(where + bytes));
assert(Sortix::Page::IsAligned(where + bytes));
addr_t pos = where;
@ -172,7 +170,7 @@ namespace Maxsi
inline size_t BSR(size_t Value)
{
#if 1
ASSERT(Value > 0);
assert(Value > 0);
for ( size_t I = 8*sizeof(size_t); I > 0; I-- )
{
if ( Value & ( 1UL << (I-1) ) ) { return I-1; }
@ -189,7 +187,7 @@ namespace Maxsi
inline size_t BSF(size_t Value)
{
#if 1
ASSERT(Value > 0);
assert(Value > 0);
for ( size_t I = 0; I < 8*sizeof(size_t); I++ )
{
if ( Value & ( 1UL << I ) ) { return I; }
@ -369,12 +367,12 @@ namespace Maxsi
chunk->nextunused = bins[binindex];
if ( chunk->nextunused )
{
ASSERT(chunk->nextunused->IsSane());
assert(chunk->nextunused->IsSane());
chunk->nextunused->GetTrailer()->prevunused = chunk;
}
bins[binindex] = chunk;
bincontainschunks |= (1UL << binindex);
ASSERT(chunk->IsSane());
assert(chunk->IsSane());
}
bool ValidateHeap()
@ -451,7 +449,7 @@ namespace Maxsi
const size_t PAGEMASK = ~(PAGESIZE - 1UL);
bytesneeded = ( bytesneeded + PAGESIZE - 1UL ) & PAGEMASK;
ASSERT(bytesneeded >= PAGESIZE);
assert(bytesneeded >= PAGESIZE);
// TODO: Overflow MAY happen here!
if ( heapmaxsize <= heapsize + wildernesssize + bytesneeded )
@ -482,7 +480,7 @@ namespace Maxsi
#endif
#if 2 <= PARANOIA
ASSERT(ValidateHeap());
assert(ValidateHeap());
#endif
// The size field keeps both the allocation and meta information.
@ -506,7 +504,7 @@ namespace Maxsi
size_t binindex = BSF(availablebins);
Chunk* chunk = bins[binindex];
ASSERT(chunk->IsSane());
assert(chunk->IsSane());
bins[binindex] = chunk->nextunused;
size_t binsize = 1UL << binindex;
@ -522,7 +520,7 @@ namespace Maxsi
trailer->prevunused = NULL;
}
ASSERT(!bins[binindex] || bins[binindex]->IsSane());
assert(!bins[binindex] || bins[binindex]->IsSane());
// If we don't use the entire chunk.
if ( OVERHEAD <= binsize - size )
@ -544,7 +542,7 @@ namespace Maxsi
chunk->GetTrailer()->magic = MAGIC;
#if 2 <= PARANOIA
ASSERT(ValidateHeap());
assert(ValidateHeap());
#endif
addr_t result = ((addr_t) chunk) + sizeof(Chunk);
@ -566,19 +564,19 @@ namespace Maxsi
#else
Chunk* chunk = (Chunk*) (wilderness - wildernesssize);
#endif
ASSERT(size <= wildernesssize);
assert(size <= wildernesssize);
wildernesssize -= size;
heapsize += size;
ASSERT(IsGoodHeapPointer(chunk, sizeof(*chunk)));
assert(IsGoodHeapPointer(chunk, sizeof(*chunk)));
chunk->size = size;
Trailer* trailer = chunk->GetTrailer();
ASSERT(IsGoodHeapPointer(trailer, sizeof(*trailer)));
assert(IsGoodHeapPointer(trailer, sizeof(*trailer)));
trailer->size = size;
chunk->magic = MAGIC;
trailer->magic = MAGIC;
#if 2 <= PARANOIA
ASSERT(ValidateHeap());
assert(ValidateHeap());
#endif
addr_t result = ((addr_t) chunk) + sizeof(Chunk);
@ -606,15 +604,15 @@ namespace Maxsi
// Removes a chunk from its bin.
void UnlinkChunk(Chunk* chunk)
{
ASSERT(chunk->IsSane());
assert(chunk->IsSane());
Trailer* trailer = chunk->GetTrailer();
if ( trailer->prevunused )
{
ASSERT(trailer->prevunused->IsSane());
assert(trailer->prevunused->IsSane());
trailer->prevunused->nextunused = chunk->nextunused;
if ( chunk->nextunused )
{
ASSERT(chunk->nextunused->IsSane());
assert(chunk->nextunused->IsSane());
chunk->nextunused->GetTrailer()->prevunused = trailer->prevunused;
}
}
@ -622,14 +620,14 @@ namespace Maxsi
{
if ( chunk->nextunused )
{
ASSERT(chunk->nextunused->IsSane());
assert(chunk->nextunused->IsSane());
chunk->nextunused->GetTrailer()->prevunused = NULL;
}
size_t binindex = BSR(chunk->size);
ASSERT(bins[binindex] == chunk);
assert(bins[binindex] == chunk);
bins[binindex] = chunk->nextunused;
if ( !bins[binindex] ) { bincontainschunks ^= 1UL << binindex; }
else { ASSERT(bins[binindex]->IsSane()); }
else { assert(bins[binindex]->IsSane()); }
}
}
@ -669,13 +667,13 @@ namespace Maxsi
#endif
#if 2 <= PARANOIA
ASSERT(ValidateHeap());
assert(ValidateHeap());
#endif
if ( !addr) { return; }
Chunk* chunk = (Chunk*) ((addr_t) addr - sizeof(Chunk));
ASSERT(chunk->IsUsed());
ASSERT(chunk->IsSane());
assert(chunk->IsUsed());
assert(chunk->IsSane());
UnifyNeighbors(&chunk);
@ -696,7 +694,7 @@ namespace Maxsi
InsertChunk(chunk);
#if 2 <= PARANOIA
ASSERT(ValidateHeap());
assert(ValidateHeap());
#endif
}
@ -714,8 +712,8 @@ namespace Maxsi
{
if ( !ptr ) { return Allocate(size); }
Chunk* chunk = (Chunk*) ((addr_t) ptr - sizeof(Chunk));
ASSERT(chunk->IsUsed());
ASSERT(chunk->IsSane());
assert(chunk->IsUsed());
assert(chunk->IsSane());
size_t allocsize = chunk->size - OVERHEAD;
if ( size < allocsize ) { return ptr; }
void* newptr = Allocate(size);

View file

@ -52,10 +52,6 @@
extern "C" Type CName Parameters
#endif
#if !defined(SORTIX_KERNEL) && !defined(ASSERT)
#define ASSERT(invariant)
#endif
// Define common datatypes.
#include "types.h"

View file

@ -30,6 +30,8 @@
#error Define __STDC_LIMIT_MACROS before including <stdint.h>
#endif
#include <assert.h>
namespace Maxsi
{
template <class T> class SortedList
@ -147,7 +149,7 @@ namespace Maxsi
T Remove(size_t index)
{
if ( !(flags & FLAG_SORTED) ) { Sort(); }
ASSERT(index < listused);
assert(index < listused);
// TODO: It may be possible to further speed up removal by delaying
// the expensive memory copy operation.

View file

@ -24,6 +24,7 @@
#include <sortix/kernel/platform.h>
#include <libmaxsi/memory.h>
#include <assert.h>
#include "descriptors.h"
#include "device.h"
#include <sortix/fcntl.h>
@ -99,8 +100,8 @@ namespace Sortix
void DescriptorTable::Free(int index)
{
ASSERT(index < numdevices);
ASSERT(devices[index].dev);
assert(index < numdevices);
assert(devices[index].dev);
if ( devices[index].dev != RESERVED_DEVICE )
{
@ -118,9 +119,9 @@ namespace Sortix
void DescriptorTable::UseReservation(int index, Device* object)
{
ASSERT(index < index);
ASSERT(devices[index].dev != NULL);
ASSERT(devices[index].dev == RESERVED_DEVICE);
assert(index < index);
assert(devices[index].dev != NULL);
assert(devices[index].dev == RESERVED_DEVICE);
object->Refer();
devices[index].dev = object;
@ -143,7 +144,7 @@ namespace Sortix
newlist[i].dev->Refer();
}
ASSERT(!forkinto->devices);
assert(!forkinto->devices);
forkinto->devices = newlist;
forkinto->numdevices = numdevices;
@ -161,15 +162,15 @@ namespace Sortix
void DescriptorTable::SetFlags(int index, int flags)
{
ASSERT(0 <= index && index < numdevices);
ASSERT(devices[index].dev);
assert(0 <= index && index < numdevices);
assert(devices[index].dev);
devices[index].flags = flags;
}
int DescriptorTable::GetFlags(int index)
{
ASSERT(0 <= index && index < numdevices);
ASSERT(devices[index].dev);
assert(0 <= index && index < numdevices);
assert(devices[index].dev);
return devices[index].flags;
}
}

View file

@ -26,6 +26,7 @@
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h>
#include <libmaxsi/string.h>
#include <assert.h>
#include "syscall.h"
#include "process.h"
#include "device.h"
@ -81,7 +82,7 @@ namespace Sortix
// another one (provide as many as we can).
prev = dirent;
size_t bytesused = sizeof(sortix_dirent) + dirent->d_namelen + 1;
ASSERT(bytesused <= size);
assert(bytesused <= size);
size -= bytesused;
dirent = (sortix_dirent*) ( ((uint8_t*) dirent) + bytesused );
}

View file

@ -26,6 +26,7 @@
#include <sortix/mman.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h>
#include <assert.h>
#include "elf.h"
#include <sortix/kernel/memorymanagement.h>
#include <sortix/kernel/panic.h>
@ -95,9 +96,9 @@ namespace Sortix
addr_t virtualaddr = pht->virtualaddr;
addr_t mapto = Page::AlignDown(virtualaddr);
addr_t mapbytes = virtualaddr - mapto + pht->memorysize;
ASSERT(pht->offset % pht->align == virtualaddr % pht->align);
ASSERT(pht->offset + pht->filesize < filelen);
ASSERT(pht->filesize <= pht->memorysize);
assert(pht->offset % pht->align == virtualaddr % pht->align);
assert(pht->offset + pht->filesize < filelen);
assert(pht->filesize <= pht->memorysize);
ProcessSegment* segment = new ProcessSegment;
if ( segment == NULL ) { return 0; }
@ -181,9 +182,9 @@ namespace Sortix
addr_t virtualaddr = pht->virtualaddr;
addr_t mapto = Page::AlignDown(virtualaddr);
addr_t mapbytes = virtualaddr - mapto + pht->memorysize;
ASSERT(pht->offset % pht->align == virtualaddr % pht->align);
ASSERT(pht->offset + pht->filesize < filelen);
ASSERT(pht->filesize <= pht->memorysize);
assert(pht->offset % pht->align == virtualaddr % pht->align);
assert(pht->offset + pht->filesize < filelen);
assert(pht->filesize <= pht->memorysize);
ProcessSegment* segment = new ProcessSegment;
if ( segment == NULL ) { return 0; }

View file

@ -26,6 +26,7 @@
#include <libmaxsi/error.h>
#include <libmaxsi/string.h>
#include <libmaxsi/memory.h>
#include <assert.h>
#include "../filesystem.h"
#include "../directory.h"
#include "../stream.h"
@ -256,7 +257,7 @@ namespace Sortix
DevATA* ata = new DevATA(drive);
if ( !ata ) { Panic("Cannot allocate ATA device"); }
ata->Refer();
ASSERT(ataid < 10);
assert(ataid < 10);
char name[5] = "ataN";
name[3] = '0' + ataid;
if ( !RegisterDevice(name, ata) )

View file

@ -26,6 +26,7 @@
#include <libmaxsi/error.h>
#include <libmaxsi/string.h>
#include <libmaxsi/memory.h>
#include <assert.h>
#include "../filesystem.h"
#include "../directory.h"
#include "../stream.h"
@ -332,7 +333,7 @@ namespace Sortix
if ( index == SIZE_MAX ) { Error::Set(ENOENT); return false; }
Device* dev = files->Remove(index);
ASSERT(dev);
assert(dev);
dev->Unref();
return true;
}

View file

@ -38,13 +38,6 @@ typedef uintptr_t addr_t;
#define unlikely(x) __builtin_expect((x),0)
#define STATIC_ASSERT(condition) static_assert(condition, #condition)
#define ASSERT(invariant) \
if ( unlikely(!(invariant)) ) \
{ \
Sortix::PanicF("Assertion failure: %s:%u: %s: %s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #invariant); \
while ( true ) { } \
}
// The following declarations should not be used if possible. They were part of
// what libmaxsi's old platform.h header declared and the kernel continues to
// depend on it.

View file

@ -25,6 +25,7 @@
#include <sortix/kernel/platform.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h>
#include <assert.h>
#include "x86-family/idt.h"
#include "interrupt.h"
#include "scheduler.h"
@ -384,7 +385,7 @@ out:
void WorkerThread(void* /*user*/)
{
ASSERT(Interrupt::IsEnabled());
assert(Interrupt::IsEnabled());
uint8_t* payload = NULL;
Package* package = NULL;
while ( true )
@ -398,7 +399,7 @@ void WorkerThread(void* /*user*/)
bool ScheduleWork(WorkHandler handler, void* payload, size_t payloadsize)
{
ASSERT(!Interrupt::IsEnabled());
assert(!Interrupt::IsEnabled());
Package package;
package.size = sizeof(package) + payloadsize;

View file

@ -24,6 +24,7 @@
#include <sortix/kernel/platform.h>
#include <libmaxsi/memory.h>
#include <assert.h>
#include "../interrupt.h"
#include "../keyboard.h"
#include <sortix/keycodes.h>
@ -80,7 +81,7 @@ namespace Sortix
static void PS2Keyboard__InterruptWork(void* payload, size_t size)
{
ASSERT(size == sizeof(PS2KeyboardWork));
assert(size == sizeof(PS2KeyboardWork));
PS2KeyboardWork* work = (PS2KeyboardWork*) payload;
work->kb->InterruptWork(work->scancode);
}

View file

@ -25,6 +25,7 @@
#include <sortix/kernel/platform.h>
#include <sortix/kernel/endian.h>
#include <sortix/kernel/pci.h>
#include <assert.h>
#include "cpu.h" // TODO: Put this in some <sortix/kernel/cpu.h>
// TODO: Verify that the endian conversions in this file actually works. I have
@ -38,9 +39,9 @@ const uint16_t CONFIG_DATA = 0xCFC;
uint32_t MakeDevAddr(uint8_t bus, uint8_t slot, uint8_t func)
{
//ASSERT(bus < 1UL<<8UL); // bus is 8 bit anyways.
ASSERT(slot < 1UL<<5UL);
ASSERT(func < 1UL<<3UL);
//assert(bus < 1UL<<8UL); // bus is 8 bit anyways.
assert(slot < 1UL<<5UL);
assert(func < 1UL<<3UL);
return func << 8U | slot << 11U | bus << 16U | 1 << 31U;
}
@ -75,7 +76,7 @@ void Write32(uint32_t devaddr, uint8_t off, uint32_t val)
uint16_t Read16(uint32_t devaddr, uint8_t off)
{
ASSERT((off & 0x1) == 0);
assert((off & 0x1) == 0);
uint8_t alignedoff = off & ~0x3;
union { uint16_t val16[2]; uint32_t val32; };
val32 = ReadRaw32(devaddr, alignedoff);

View file

@ -27,6 +27,7 @@
#include <sortix/signal.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h>
#include <assert.h>
#ifdef GOT_FAKE_KTHREAD
#include "event.h"
#endif
@ -116,7 +117,7 @@ namespace Sortix
size_t amount = count;
size_t linear = buffersize - bufferoffset;
if ( linear < amount ) { amount = linear; }
ASSERT(amount);
assert(amount);
Memory::Copy(dest, buffer + bufferoffset, amount);
bufferoffset = (bufferoffset + amount) % buffersize;
bufferused -= amount;
@ -129,7 +130,7 @@ namespace Sortix
size_t amount = count;
size_t linear = buffersize - bufferoffset;
if ( linear < amount ) { amount = linear; }
ASSERT(amount);
assert(amount);
Memory::Copy(dest, buffer + bufferoffset, amount);
bufferoffset = (bufferoffset + amount) % buffersize;
bufferused -= amount;
@ -170,7 +171,7 @@ namespace Sortix
size_t amount = count;
size_t linear = buffersize - writeoffset;
if ( linear < amount ) { amount = linear; }
ASSERT(amount);
assert(amount);
Memory::Copy(buffer + writeoffset, src, amount);
bufferused += amount;
kthread_cond_broadcast(&readcond);
@ -183,7 +184,7 @@ namespace Sortix
size_t amount = count;
size_t linear = buffersize - writeoffset;
if ( linear < amount ) { amount = linear; }
ASSERT(amount);
assert(amount);
Memory::Copy(buffer + writeoffset, src, amount);
bufferused += amount;
readevent.Signal();

View file

@ -35,6 +35,7 @@
#include <libmaxsi/memory.h>
#include <libmaxsi/string.h>
#include <libmaxsi/sortedlist.h>
#include <assert.h>
#include "thread.h"
#include "process.h"
#include "device.h"
@ -123,10 +124,10 @@ namespace Sortix
Process::~Process()
{
ASSERT(!zombiechild);
ASSERT(!firstchild);
ASSERT(!addrspace);
ASSERT(!segments);
assert(!zombiechild);
assert(!firstchild);
assert(!addrspace);
assert(!segments);
Remove(this);
delete[] workingdir;
@ -136,7 +137,7 @@ namespace Sortix
void Process::OnThreadDestruction(Thread* thread)
{
ASSERT(thread->process == this);
assert(thread->process == this);
kthread_mutex_lock(&threadlock);
if ( thread->prevsibling )
thread->prevsibling->nextsibling = thread->nextsibling;
@ -159,7 +160,7 @@ namespace Sortix
void Process::ScheduleDeath()
{
// All our threads must have exited at this point.
ASSERT(!firstthread);
assert(!firstthread);
Worker::Schedule(Process__OnLastThreadExit, this);
}
@ -189,17 +190,17 @@ namespace Sortix
void Process::LastPrayer()
{
ASSERT(this);
assert(this);
// This must never be called twice.
ASSERT(!iszombie);
assert(!iszombie);
// This must be called from a thread using another address space as the
// address space of this process is about to be destroyed.
Thread* curthread = CurrentThread();
ASSERT(curthread->process != this);
assert(curthread->process != this);
// This can't be called if the process is still alive.
ASSERT(!firstthread);
assert(!firstthread);
// We need to temporarily reload the correct addrese space of the dying
// process such that we can unmap and free its memory.
@ -217,7 +218,7 @@ namespace Sortix
// Init is nice and will gladly raise our orphaned children and zombies.
Process* init = Scheduler::GetInitProcess();
ASSERT(init);
assert(init);
kthread_mutex_lock(&childlock);
while ( firstchild )
{
@ -272,7 +273,7 @@ namespace Sortix
void Process::ResetAddressSpace()
{
ASSERT(Memory::GetAddressSpace() == addrspace);
assert(Memory::GetAddressSpace() == addrspace);
ProcessSegment* tmp = segments;
while ( tmp != NULL )
{
@ -425,9 +426,9 @@ namespace Sortix
{
ScopedLock mylock(&childlock);
ScopedLock itslock(&child->parentlock);
ASSERT(!child->parent);
ASSERT(!child->nextsibling);
ASSERT(!child->prevsibling);
assert(!child->parent);
assert(!child->nextsibling);
assert(!child->prevsibling);
child->parent = this;
child->nextsibling = firstchild;
child->prevsibling = NULL;
@ -438,7 +439,7 @@ namespace Sortix
Process* Process::Fork()
{
ASSERT(CurrentProcess() == this);
assert(CurrentProcess() == this);
Process* clone = new Process;
if ( !clone ) { return NULL; }
@ -510,7 +511,7 @@ namespace Sortix
int envc, const char* const* envp,
CPU::InterruptRegisters* regs)
{
ASSERT(CurrentProcess() == this);
assert(CurrentProcess() == this);
addr_t entry = ELF::Construct(CurrentProcess(), program, programsize);
if ( !entry ) { return -1; }
@ -783,7 +784,7 @@ namespace Sortix
{
ScopedLock lock(&pidalloclock);
size_t index = pidlist->Search(process);
ASSERT(index != SIZE_MAX);
assert(index != SIZE_MAX);
pidlist->Remove(index);
}

View file

@ -25,6 +25,7 @@
#include <sortix/kernel/platform.h>
#include <sortix/kernel/kthread.h>
#include <sortix/kernel/refcount.h>
#include <assert.h>
namespace Sortix {
@ -38,7 +39,7 @@ Refcounted::~Refcounted()
{
// It's OK to be deleted if our refcount is 1, it won't mess with any
// other owners that might need us.
ASSERT(refcount <= 1);
assert(refcount <= 1);
}
void Refcounted::Refer()

View file

@ -26,6 +26,7 @@
#include <sortix/kernel/memorymanagement.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h>
#include <assert.h>
#include "x86-family/gdt.h"
#include "x86-family/float.h"
#include "syscall.h"
@ -114,7 +115,7 @@ static void DoActualSwitch(CPU::InterruptRegisters* regs)
addr_t stacklower = next->kernelstackpos;
size_t stacksize = next->kernelstacksize;
addr_t stackhigher = stacklower + stacksize;
ASSERT(stacklower && stacksize && stackhigher);
assert(stacklower && stacksize && stackhigher);
GDT::SetKernelStack(stacklower, stacksize, stackhigher);
LogEndSwitch(next, regs);
@ -186,7 +187,7 @@ static void ThreadExitCPU(CPU::InterruptRegisters* regs, void* /*user*/)
// nothing, which is only run when the system has nothing to do.
void SetIdleThread(Thread* thread)
{
ASSERT(!idlethread);
assert(!idlethread);
idlethread = thread;
SetThreadState(thread, Thread::State::NONE);
SetCurrentThread(thread);
@ -217,8 +218,8 @@ void SetThreadState(Thread* thread, Thread::State state)
{
if ( thread == firstrunnablethread ) { firstrunnablethread = thread->schedulerlistnext; }
if ( thread == firstrunnablethread ) { firstrunnablethread = NULL; }
ASSERT(thread->schedulerlistprev);
ASSERT(thread->schedulerlistnext);
assert(thread->schedulerlistprev);
assert(thread->schedulerlistnext);
thread->schedulerlistprev->schedulerlistnext = thread->schedulerlistnext;
thread->schedulerlistnext->schedulerlistprev = thread->schedulerlistprev;
thread->schedulerlistprev = NULL;
@ -238,8 +239,8 @@ void SetThreadState(Thread* thread, Thread::State state)
thread->state = state;
ASSERT(thread->state != Thread::State::RUNNABLE || thread->schedulerlistprev);
ASSERT(thread->state != Thread::State::RUNNABLE || thread->schedulerlistnext);
assert(thread->state != Thread::State::RUNNABLE || thread->schedulerlistprev);
assert(thread->state != Thread::State::RUNNABLE || thread->schedulerlistnext);
Interrupt::SetEnabled(wasenabled);
}

View file

@ -26,6 +26,7 @@
#include <sortix/kernel/panic.h>
#include <sortix/signal.h>
#include <libmaxsi/memory.h>
#include <assert.h>
#include "interrupt.h"
#include "thread.h"
#include "signal.h"
@ -80,7 +81,7 @@ const int PRIORITIES[SIG__NUM_DECLARED] =
int Priority(int signum)
{
ASSERT(0 <= signum && signum < SIG_MAX_NUM);
assert(0 <= signum && signum < SIG_MAX_NUM);
if ( !signum )
return -1;
if ( SIG__NUM_DECLARED <= signum )
@ -96,7 +97,7 @@ Queue::Queue()
void Queue::Push(int signum)
{
ASSERT(0 < signum && signum < SIG_MAX_NUM);
assert(0 < signum && signum < SIG_MAX_NUM);
pending[signum] = true;
}

View file

@ -26,6 +26,7 @@
#include <sortix/kernel/kthread.h>
#include <sortix/kernel/refcount.h>
#include <sortix/kernel/textbuffer.h>
#include <assert.h>
namespace Sortix {
@ -62,9 +63,9 @@ TextBuffer* TextBufferHandle::Acquire()
void TextBufferHandle::Release(TextBuffer* textbuf)
{
ASSERT(textbuf);
assert(textbuf);
ScopedLock lock(&mutex);
ASSERT(numused);
assert(numused);
if ( !--numused )
kthread_cond_signal(&unusedcond);
}

View file

@ -29,6 +29,7 @@
#include <sortix/signal.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h>
#include <assert.h>
#include "process.h"
#include "thread.h"
#include "scheduler.h"
@ -70,7 +71,7 @@ namespace Sortix
{
if ( process )
process->OnThreadDestruction(this);
ASSERT(CurrentThread() != this);
assert(CurrentThread() != this);
if ( kernelstackmalloced )
delete[] (uint8_t*) kernelstackpos;
terminated = true;
@ -101,7 +102,7 @@ namespace Sortix
Thread* CreateKernelThread(Process* process, CPU::InterruptRegisters* regs)
{
ASSERT(process && regs && process->addrspace);
assert(process && regs && process->addrspace);
Thread* thread = new Thread;
if ( !thread ) { return NULL; }

View file

@ -23,6 +23,7 @@
*******************************************************************************/
#include <sortix/kernel/platform.h>
#include <assert.h>
#include "../interrupt.h"
#include "../thread.h"
#include "float.h"
@ -39,13 +40,13 @@ static inline void InitFPU()
static inline void SaveState(uint8_t* dest)
{
ASSERT( (((unsigned long) dest) & (16UL-1UL)) == 0 );
assert( (((unsigned long) dest) & (16UL-1UL)) == 0 );
asm volatile ("fxsave (%0)" : : "r"(dest));
}
static inline void LoadState(const uint8_t* src)
{
ASSERT( (((unsigned long) src) & (16UL-1UL)) == 0 );
assert( (((unsigned long) src) & (16UL-1UL)) == 0 );
asm volatile ("fxrstor (%0)" : : "r"(src));
}
@ -70,7 +71,7 @@ static void OnFPUAccess(CPU::InterruptRegisters* /*regs*/, void* /*user*/)
void Init()
{
fputhread = CurrentThread();
ASSERT(fputhread);
assert(fputhread);
Interrupt::RegisterHandler(7, OnFPUAccess, NULL);
}

View file

@ -29,6 +29,7 @@
#include <sortix/mman.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h>
#include <assert.h>
#include "multiboot.h"
#include "memorymanagement.h"
#include "syscall.h"
@ -286,7 +287,7 @@ namespace Sortix
bool ReserveUnlocked(size_t* counter, size_t least, size_t ideal)
{
ASSERT(least < ideal);
assert(least < ideal);
size_t available = stackused - stackreserved;
if ( least < available ) { Error::Set(ENOMEM); return false; }
if ( available < ideal ) { ideal = available; }
@ -315,9 +316,9 @@ namespace Sortix
addr_t GetReservedUnlocked(size_t* counter)
{
if ( !*counter ) { return 0; }
ASSERT(stackused); // After all, we did _reserve_ the memory.
assert(stackused); // After all, we did _reserve_ the memory.
addr_t result = STACK[--stackused];
ASSERT(result == AlignDown(result));
assert(result == AlignDown(result));
stackreserved--;
(*counter)--;
return result;
@ -331,14 +332,14 @@ namespace Sortix
addr_t GetUnlocked()
{
ASSERT(stackreserved <= stackused);
assert(stackreserved <= stackused);
if ( unlikely(stackreserved == stackused) )
{
Error::Set(ENOMEM);
return 0;
}
addr_t result = STACK[--stackused];
ASSERT(result == AlignDown(result));
assert(result == AlignDown(result));
return result;
}
@ -350,8 +351,8 @@ namespace Sortix
void PutUnlocked(addr_t page)
{
ASSERT(page == AlignDown(page));
ASSERT(stackused < MAXSTACKLENGTH);
assert(page == AlignDown(page));
assert(stackused < MAXSTACKLENGTH);
STACK[stackused++] = page;
}