diff --git a/games/snake.cpp b/games/snake.cpp index dfc83bbf..5d3c1317 100644 --- a/games/snake.cpp +++ b/games/snake.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -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; } } diff --git a/libmaxsi/Makefile b/libmaxsi/Makefile index 60a9c4d6..9e41292b 100644 --- a/libmaxsi/Makefile +++ b/libmaxsi/Makefile @@ -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 \ diff --git a/libmaxsi/_assert.cpp b/libmaxsi/_assert.cpp index 90b30306..b191d88a 100644 --- a/libmaxsi/_assert.cpp +++ b/libmaxsi/_assert.cpp @@ -23,13 +23,25 @@ ******************************************************************************/ #include +#include +#if !defined(SORTIX_KERNEL) #include #include +#endif +#if defined(SORTIX_KERNEL) +#include +#include +#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 } diff --git a/libmaxsi/heap.cpp b/libmaxsi/heap.cpp index acea9df6..cf054fa9 100644 --- a/libmaxsi/heap.cpp +++ b/libmaxsi/heap.cpp @@ -35,11 +35,9 @@ #include #include #include -#include -#undef ASSERT -#define ASSERT(invariant) assert(invariant) #endif +#include #include #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); diff --git a/libmaxsi/include/libmaxsi/platform.h b/libmaxsi/include/libmaxsi/platform.h index 94adfb98..dc31e852 100644 --- a/libmaxsi/include/libmaxsi/platform.h +++ b/libmaxsi/include/libmaxsi/platform.h @@ -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" diff --git a/libmaxsi/include/libmaxsi/sortedlist.h b/libmaxsi/include/libmaxsi/sortedlist.h index a810257d..7b1415b7 100644 --- a/libmaxsi/include/libmaxsi/sortedlist.h +++ b/libmaxsi/include/libmaxsi/sortedlist.h @@ -30,6 +30,8 @@ #error Define __STDC_LIMIT_MACROS before including #endif +#include + namespace Maxsi { template 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. diff --git a/sortix/descriptors.cpp b/sortix/descriptors.cpp index 4fece4bb..1aa08c2e 100644 --- a/sortix/descriptors.cpp +++ b/sortix/descriptors.cpp @@ -24,6 +24,7 @@ #include #include +#include #include "descriptors.h" #include "device.h" #include @@ -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; } } diff --git a/sortix/directory.cpp b/sortix/directory.cpp index e1701b5b..fb7f4fad 100644 --- a/sortix/directory.cpp +++ b/sortix/directory.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #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 ); } diff --git a/sortix/elf.cpp b/sortix/elf.cpp index c2ff5da6..50e5ba9a 100644 --- a/sortix/elf.cpp +++ b/sortix/elf.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "elf.h" #include #include @@ -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; } diff --git a/sortix/fs/devfs.cpp b/sortix/fs/devfs.cpp index ae87572e..e1d22db1 100644 --- a/sortix/fs/devfs.cpp +++ b/sortix/fs/devfs.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #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) ) diff --git a/sortix/fs/ramfs.cpp b/sortix/fs/ramfs.cpp index ba19c580..5929f73e 100644 --- a/sortix/fs/ramfs.cpp +++ b/sortix/fs/ramfs.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #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; } diff --git a/sortix/include/sortix/kernel/decl.h b/sortix/include/sortix/kernel/decl.h index e61f1dd3..9513454b 100644 --- a/sortix/include/sortix/kernel/decl.h +++ b/sortix/include/sortix/kernel/decl.h @@ -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. diff --git a/sortix/interrupt.cpp b/sortix/interrupt.cpp index 9fad72df..8b593fb7 100644 --- a/sortix/interrupt.cpp +++ b/sortix/interrupt.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #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; diff --git a/sortix/kb/ps2.cpp b/sortix/kb/ps2.cpp index ebd77738..43f43486 100644 --- a/sortix/kb/ps2.cpp +++ b/sortix/kb/ps2.cpp @@ -24,6 +24,7 @@ #include #include +#include #include "../interrupt.h" #include "../keyboard.h" #include @@ -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); } diff --git a/sortix/pci.cpp b/sortix/pci.cpp index 6a2d717d..d0623a5d 100644 --- a/sortix/pci.cpp +++ b/sortix/pci.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "cpu.h" // TODO: Put this in some // 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); diff --git a/sortix/pipe.cpp b/sortix/pipe.cpp index 3eb57f98..b6673861 100644 --- a/sortix/pipe.cpp +++ b/sortix/pipe.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #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(); diff --git a/sortix/process.cpp b/sortix/process.cpp index 247c9a36..6bbbfbb9 100644 --- a/sortix/process.cpp +++ b/sortix/process.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #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); } diff --git a/sortix/refcount.cpp b/sortix/refcount.cpp index 575cfc8d..6621cd5c 100644 --- a/sortix/refcount.cpp +++ b/sortix/refcount.cpp @@ -25,6 +25,7 @@ #include #include #include +#include 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() diff --git a/sortix/scheduler.cpp b/sortix/scheduler.cpp index 652abc76..4a7ffcdc 100644 --- a/sortix/scheduler.cpp +++ b/sortix/scheduler.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #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); } diff --git a/sortix/signal.cpp b/sortix/signal.cpp index 665b37c0..399f9c1c 100644 --- a/sortix/signal.cpp +++ b/sortix/signal.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #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; } diff --git a/sortix/textbuffer.cpp b/sortix/textbuffer.cpp index 8dfff4db..7becc018 100644 --- a/sortix/textbuffer.cpp +++ b/sortix/textbuffer.cpp @@ -26,6 +26,7 @@ #include #include #include +#include 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); } diff --git a/sortix/thread.cpp b/sortix/thread.cpp index 4289385e..a00448a4 100644 --- a/sortix/thread.cpp +++ b/sortix/thread.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #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; } diff --git a/sortix/x86-family/float.cpp b/sortix/x86-family/float.cpp index b8e137c3..43360433 100644 --- a/sortix/x86-family/float.cpp +++ b/sortix/x86-family/float.cpp @@ -23,6 +23,7 @@ *******************************************************************************/ #include +#include #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); } diff --git a/sortix/x86-family/memorymanagement.cpp b/sortix/x86-family/memorymanagement.cpp index 60d3f3f1..53a7d8cd 100644 --- a/sortix/x86-family/memorymanagement.cpp +++ b/sortix/x86-family/memorymanagement.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #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; }