Replace ASSERT with assert of <assert.h>.
This commit is contained in:
parent
b685b7a9eb
commit
42754f1728
|
@ -24,6 +24,7 @@
|
||||||
#include <libmaxsi/sortix-vga.h>
|
#include <libmaxsi/sortix-vga.h>
|
||||||
#include <sys/keycodes.h>
|
#include <sys/keycodes.h>
|
||||||
#include <sys/termmode.h>
|
#include <sys/termmode.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -204,8 +205,8 @@ void Update()
|
||||||
tailmax++;
|
tailmax++;
|
||||||
animalx = 2 + (rand() % (width-4));
|
animalx = 2 + (rand() % (width-4));
|
||||||
animaly = 2 + (rand() % (height-4));
|
animaly = 2 + (rand() % (height-4));
|
||||||
ASSERT(0 <= animalx && animalx < width);
|
assert(0 <= animalx && animalx < width);
|
||||||
ASSERT(0 <= animaly && animaly < height);
|
assert(0 <= animaly && animaly < height);
|
||||||
if ( maxspeed < speed ) { speed += speedincrease; }
|
if ( maxspeed < speed ) { speed += speedincrease; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ ASFLAGS=$(CPUASFLAGS)
|
||||||
FREEOBJS=\
|
FREEOBJS=\
|
||||||
abort.o \
|
abort.o \
|
||||||
abs.o \
|
abs.o \
|
||||||
|
_assert.o \
|
||||||
bsearch.o \
|
bsearch.o \
|
||||||
clearerr.o \
|
clearerr.o \
|
||||||
c++.o \
|
c++.o \
|
||||||
|
@ -106,7 +107,6 @@ vsscanf.o \
|
||||||
|
|
||||||
HOSTEDOBJS=\
|
HOSTEDOBJS=\
|
||||||
access.o \
|
access.o \
|
||||||
_assert.o \
|
|
||||||
chdir.o \
|
chdir.o \
|
||||||
chmod.o \
|
chmod.o \
|
||||||
close.o \
|
close.o \
|
||||||
|
|
|
@ -23,13 +23,25 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#if !defined(SORTIX_KERNEL)
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.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,
|
void _assert(const char* filename, unsigned int line, const char* functionname,
|
||||||
const char* expression)
|
const char* expression)
|
||||||
{
|
{
|
||||||
|
#if !defined(SORTIX_KERNEL)
|
||||||
fprintf(stderr, "Assertion failure: %s:%u: %s: %s\n", filename, line,
|
fprintf(stderr, "Assertion failure: %s:%u: %s: %s\n", filename, line,
|
||||||
functionname, expression);
|
functionname, expression);
|
||||||
abort();
|
abort();
|
||||||
|
#else
|
||||||
|
Sortix::PanicF("Assertion failure: %s:%u: %s: %s\n", filename, line,
|
||||||
|
functionname, expression);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <assert.h>
|
|
||||||
#undef ASSERT
|
|
||||||
#define ASSERT(invariant) assert(invariant)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
|
||||||
#define PARANOIA 1
|
#define PARANOIA 1
|
||||||
|
@ -87,7 +85,7 @@ namespace Maxsi
|
||||||
|
|
||||||
void FreeMemory(addr_t where, size_t bytes)
|
void FreeMemory(addr_t where, size_t bytes)
|
||||||
{
|
{
|
||||||
ASSERT(Sortix::Page::IsAligned(where + bytes));
|
assert(Sortix::Page::IsAligned(where + bytes));
|
||||||
|
|
||||||
while ( bytes )
|
while ( bytes )
|
||||||
{
|
{
|
||||||
|
@ -101,7 +99,7 @@ namespace Maxsi
|
||||||
|
|
||||||
bool AllocateMemory(addr_t where, size_t bytes)
|
bool AllocateMemory(addr_t where, size_t bytes)
|
||||||
{
|
{
|
||||||
ASSERT(Sortix::Page::IsAligned(where + bytes));
|
assert(Sortix::Page::IsAligned(where + bytes));
|
||||||
|
|
||||||
addr_t pos = where;
|
addr_t pos = where;
|
||||||
|
|
||||||
|
@ -172,7 +170,7 @@ namespace Maxsi
|
||||||
inline size_t BSR(size_t Value)
|
inline size_t BSR(size_t Value)
|
||||||
{
|
{
|
||||||
#if 1
|
#if 1
|
||||||
ASSERT(Value > 0);
|
assert(Value > 0);
|
||||||
for ( size_t I = 8*sizeof(size_t); I > 0; I-- )
|
for ( size_t I = 8*sizeof(size_t); I > 0; I-- )
|
||||||
{
|
{
|
||||||
if ( Value & ( 1UL << (I-1) ) ) { return I-1; }
|
if ( Value & ( 1UL << (I-1) ) ) { return I-1; }
|
||||||
|
@ -189,7 +187,7 @@ namespace Maxsi
|
||||||
inline size_t BSF(size_t Value)
|
inline size_t BSF(size_t Value)
|
||||||
{
|
{
|
||||||
#if 1
|
#if 1
|
||||||
ASSERT(Value > 0);
|
assert(Value > 0);
|
||||||
for ( size_t I = 0; I < 8*sizeof(size_t); I++ )
|
for ( size_t I = 0; I < 8*sizeof(size_t); I++ )
|
||||||
{
|
{
|
||||||
if ( Value & ( 1UL << I ) ) { return I; }
|
if ( Value & ( 1UL << I ) ) { return I; }
|
||||||
|
@ -369,12 +367,12 @@ namespace Maxsi
|
||||||
chunk->nextunused = bins[binindex];
|
chunk->nextunused = bins[binindex];
|
||||||
if ( chunk->nextunused )
|
if ( chunk->nextunused )
|
||||||
{
|
{
|
||||||
ASSERT(chunk->nextunused->IsSane());
|
assert(chunk->nextunused->IsSane());
|
||||||
chunk->nextunused->GetTrailer()->prevunused = chunk;
|
chunk->nextunused->GetTrailer()->prevunused = chunk;
|
||||||
}
|
}
|
||||||
bins[binindex] = chunk;
|
bins[binindex] = chunk;
|
||||||
bincontainschunks |= (1UL << binindex);
|
bincontainschunks |= (1UL << binindex);
|
||||||
ASSERT(chunk->IsSane());
|
assert(chunk->IsSane());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ValidateHeap()
|
bool ValidateHeap()
|
||||||
|
@ -451,7 +449,7 @@ namespace Maxsi
|
||||||
const size_t PAGEMASK = ~(PAGESIZE - 1UL);
|
const size_t PAGEMASK = ~(PAGESIZE - 1UL);
|
||||||
bytesneeded = ( bytesneeded + PAGESIZE - 1UL ) & PAGEMASK;
|
bytesneeded = ( bytesneeded + PAGESIZE - 1UL ) & PAGEMASK;
|
||||||
|
|
||||||
ASSERT(bytesneeded >= PAGESIZE);
|
assert(bytesneeded >= PAGESIZE);
|
||||||
|
|
||||||
// TODO: Overflow MAY happen here!
|
// TODO: Overflow MAY happen here!
|
||||||
if ( heapmaxsize <= heapsize + wildernesssize + bytesneeded )
|
if ( heapmaxsize <= heapsize + wildernesssize + bytesneeded )
|
||||||
|
@ -482,7 +480,7 @@ namespace Maxsi
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 2 <= PARANOIA
|
#if 2 <= PARANOIA
|
||||||
ASSERT(ValidateHeap());
|
assert(ValidateHeap());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// The size field keeps both the allocation and meta information.
|
// The size field keeps both the allocation and meta information.
|
||||||
|
@ -506,7 +504,7 @@ namespace Maxsi
|
||||||
size_t binindex = BSF(availablebins);
|
size_t binindex = BSF(availablebins);
|
||||||
|
|
||||||
Chunk* chunk = bins[binindex];
|
Chunk* chunk = bins[binindex];
|
||||||
ASSERT(chunk->IsSane());
|
assert(chunk->IsSane());
|
||||||
bins[binindex] = chunk->nextunused;
|
bins[binindex] = chunk->nextunused;
|
||||||
|
|
||||||
size_t binsize = 1UL << binindex;
|
size_t binsize = 1UL << binindex;
|
||||||
|
@ -522,7 +520,7 @@ namespace Maxsi
|
||||||
trailer->prevunused = NULL;
|
trailer->prevunused = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(!bins[binindex] || bins[binindex]->IsSane());
|
assert(!bins[binindex] || bins[binindex]->IsSane());
|
||||||
|
|
||||||
// If we don't use the entire chunk.
|
// If we don't use the entire chunk.
|
||||||
if ( OVERHEAD <= binsize - size )
|
if ( OVERHEAD <= binsize - size )
|
||||||
|
@ -544,7 +542,7 @@ namespace Maxsi
|
||||||
chunk->GetTrailer()->magic = MAGIC;
|
chunk->GetTrailer()->magic = MAGIC;
|
||||||
|
|
||||||
#if 2 <= PARANOIA
|
#if 2 <= PARANOIA
|
||||||
ASSERT(ValidateHeap());
|
assert(ValidateHeap());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
addr_t result = ((addr_t) chunk) + sizeof(Chunk);
|
addr_t result = ((addr_t) chunk) + sizeof(Chunk);
|
||||||
|
@ -566,19 +564,19 @@ namespace Maxsi
|
||||||
#else
|
#else
|
||||||
Chunk* chunk = (Chunk*) (wilderness - wildernesssize);
|
Chunk* chunk = (Chunk*) (wilderness - wildernesssize);
|
||||||
#endif
|
#endif
|
||||||
ASSERT(size <= wildernesssize);
|
assert(size <= wildernesssize);
|
||||||
wildernesssize -= size;
|
wildernesssize -= size;
|
||||||
heapsize += size;
|
heapsize += size;
|
||||||
ASSERT(IsGoodHeapPointer(chunk, sizeof(*chunk)));
|
assert(IsGoodHeapPointer(chunk, sizeof(*chunk)));
|
||||||
chunk->size = size;
|
chunk->size = size;
|
||||||
Trailer* trailer = chunk->GetTrailer();
|
Trailer* trailer = chunk->GetTrailer();
|
||||||
ASSERT(IsGoodHeapPointer(trailer, sizeof(*trailer)));
|
assert(IsGoodHeapPointer(trailer, sizeof(*trailer)));
|
||||||
trailer->size = size;
|
trailer->size = size;
|
||||||
chunk->magic = MAGIC;
|
chunk->magic = MAGIC;
|
||||||
trailer->magic = MAGIC;
|
trailer->magic = MAGIC;
|
||||||
|
|
||||||
#if 2 <= PARANOIA
|
#if 2 <= PARANOIA
|
||||||
ASSERT(ValidateHeap());
|
assert(ValidateHeap());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
addr_t result = ((addr_t) chunk) + sizeof(Chunk);
|
addr_t result = ((addr_t) chunk) + sizeof(Chunk);
|
||||||
|
@ -606,15 +604,15 @@ namespace Maxsi
|
||||||
// Removes a chunk from its bin.
|
// Removes a chunk from its bin.
|
||||||
void UnlinkChunk(Chunk* chunk)
|
void UnlinkChunk(Chunk* chunk)
|
||||||
{
|
{
|
||||||
ASSERT(chunk->IsSane());
|
assert(chunk->IsSane());
|
||||||
Trailer* trailer = chunk->GetTrailer();
|
Trailer* trailer = chunk->GetTrailer();
|
||||||
if ( trailer->prevunused )
|
if ( trailer->prevunused )
|
||||||
{
|
{
|
||||||
ASSERT(trailer->prevunused->IsSane());
|
assert(trailer->prevunused->IsSane());
|
||||||
trailer->prevunused->nextunused = chunk->nextunused;
|
trailer->prevunused->nextunused = chunk->nextunused;
|
||||||
if ( chunk->nextunused )
|
if ( chunk->nextunused )
|
||||||
{
|
{
|
||||||
ASSERT(chunk->nextunused->IsSane());
|
assert(chunk->nextunused->IsSane());
|
||||||
chunk->nextunused->GetTrailer()->prevunused = trailer->prevunused;
|
chunk->nextunused->GetTrailer()->prevunused = trailer->prevunused;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -622,14 +620,14 @@ namespace Maxsi
|
||||||
{
|
{
|
||||||
if ( chunk->nextunused )
|
if ( chunk->nextunused )
|
||||||
{
|
{
|
||||||
ASSERT(chunk->nextunused->IsSane());
|
assert(chunk->nextunused->IsSane());
|
||||||
chunk->nextunused->GetTrailer()->prevunused = NULL;
|
chunk->nextunused->GetTrailer()->prevunused = NULL;
|
||||||
}
|
}
|
||||||
size_t binindex = BSR(chunk->size);
|
size_t binindex = BSR(chunk->size);
|
||||||
ASSERT(bins[binindex] == chunk);
|
assert(bins[binindex] == chunk);
|
||||||
bins[binindex] = chunk->nextunused;
|
bins[binindex] = chunk->nextunused;
|
||||||
if ( !bins[binindex] ) { bincontainschunks ^= 1UL << binindex; }
|
if ( !bins[binindex] ) { bincontainschunks ^= 1UL << binindex; }
|
||||||
else { ASSERT(bins[binindex]->IsSane()); }
|
else { assert(bins[binindex]->IsSane()); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -669,13 +667,13 @@ namespace Maxsi
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 2 <= PARANOIA
|
#if 2 <= PARANOIA
|
||||||
ASSERT(ValidateHeap());
|
assert(ValidateHeap());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( !addr) { return; }
|
if ( !addr) { return; }
|
||||||
Chunk* chunk = (Chunk*) ((addr_t) addr - sizeof(Chunk));
|
Chunk* chunk = (Chunk*) ((addr_t) addr - sizeof(Chunk));
|
||||||
ASSERT(chunk->IsUsed());
|
assert(chunk->IsUsed());
|
||||||
ASSERT(chunk->IsSane());
|
assert(chunk->IsSane());
|
||||||
|
|
||||||
UnifyNeighbors(&chunk);
|
UnifyNeighbors(&chunk);
|
||||||
|
|
||||||
|
@ -696,7 +694,7 @@ namespace Maxsi
|
||||||
InsertChunk(chunk);
|
InsertChunk(chunk);
|
||||||
|
|
||||||
#if 2 <= PARANOIA
|
#if 2 <= PARANOIA
|
||||||
ASSERT(ValidateHeap());
|
assert(ValidateHeap());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -714,8 +712,8 @@ namespace Maxsi
|
||||||
{
|
{
|
||||||
if ( !ptr ) { return Allocate(size); }
|
if ( !ptr ) { return Allocate(size); }
|
||||||
Chunk* chunk = (Chunk*) ((addr_t) ptr - sizeof(Chunk));
|
Chunk* chunk = (Chunk*) ((addr_t) ptr - sizeof(Chunk));
|
||||||
ASSERT(chunk->IsUsed());
|
assert(chunk->IsUsed());
|
||||||
ASSERT(chunk->IsSane());
|
assert(chunk->IsSane());
|
||||||
size_t allocsize = chunk->size - OVERHEAD;
|
size_t allocsize = chunk->size - OVERHEAD;
|
||||||
if ( size < allocsize ) { return ptr; }
|
if ( size < allocsize ) { return ptr; }
|
||||||
void* newptr = Allocate(size);
|
void* newptr = Allocate(size);
|
||||||
|
|
|
@ -52,10 +52,6 @@
|
||||||
extern "C" Type CName Parameters
|
extern "C" Type CName Parameters
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(SORTIX_KERNEL) && !defined(ASSERT)
|
|
||||||
#define ASSERT(invariant)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Define common datatypes.
|
// Define common datatypes.
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
#error Define __STDC_LIMIT_MACROS before including <stdint.h>
|
#error Define __STDC_LIMIT_MACROS before including <stdint.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
namespace Maxsi
|
namespace Maxsi
|
||||||
{
|
{
|
||||||
template <class T> class SortedList
|
template <class T> class SortedList
|
||||||
|
@ -147,7 +149,7 @@ namespace Maxsi
|
||||||
T Remove(size_t index)
|
T Remove(size_t index)
|
||||||
{
|
{
|
||||||
if ( !(flags & FLAG_SORTED) ) { Sort(); }
|
if ( !(flags & FLAG_SORTED) ) { Sort(); }
|
||||||
ASSERT(index < listused);
|
assert(index < listused);
|
||||||
|
|
||||||
// TODO: It may be possible to further speed up removal by delaying
|
// TODO: It may be possible to further speed up removal by delaying
|
||||||
// the expensive memory copy operation.
|
// the expensive memory copy operation.
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include <sortix/kernel/platform.h>
|
#include <sortix/kernel/platform.h>
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "descriptors.h"
|
#include "descriptors.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include <sortix/fcntl.h>
|
#include <sortix/fcntl.h>
|
||||||
|
@ -99,8 +100,8 @@ namespace Sortix
|
||||||
|
|
||||||
void DescriptorTable::Free(int index)
|
void DescriptorTable::Free(int index)
|
||||||
{
|
{
|
||||||
ASSERT(index < numdevices);
|
assert(index < numdevices);
|
||||||
ASSERT(devices[index].dev);
|
assert(devices[index].dev);
|
||||||
|
|
||||||
if ( devices[index].dev != RESERVED_DEVICE )
|
if ( devices[index].dev != RESERVED_DEVICE )
|
||||||
{
|
{
|
||||||
|
@ -118,9 +119,9 @@ namespace Sortix
|
||||||
|
|
||||||
void DescriptorTable::UseReservation(int index, Device* object)
|
void DescriptorTable::UseReservation(int index, Device* object)
|
||||||
{
|
{
|
||||||
ASSERT(index < index);
|
assert(index < index);
|
||||||
ASSERT(devices[index].dev != NULL);
|
assert(devices[index].dev != NULL);
|
||||||
ASSERT(devices[index].dev == RESERVED_DEVICE);
|
assert(devices[index].dev == RESERVED_DEVICE);
|
||||||
|
|
||||||
object->Refer();
|
object->Refer();
|
||||||
devices[index].dev = object;
|
devices[index].dev = object;
|
||||||
|
@ -143,7 +144,7 @@ namespace Sortix
|
||||||
newlist[i].dev->Refer();
|
newlist[i].dev->Refer();
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(!forkinto->devices);
|
assert(!forkinto->devices);
|
||||||
|
|
||||||
forkinto->devices = newlist;
|
forkinto->devices = newlist;
|
||||||
forkinto->numdevices = numdevices;
|
forkinto->numdevices = numdevices;
|
||||||
|
@ -161,15 +162,15 @@ namespace Sortix
|
||||||
|
|
||||||
void DescriptorTable::SetFlags(int index, int flags)
|
void DescriptorTable::SetFlags(int index, int flags)
|
||||||
{
|
{
|
||||||
ASSERT(0 <= index && index < numdevices);
|
assert(0 <= index && index < numdevices);
|
||||||
ASSERT(devices[index].dev);
|
assert(devices[index].dev);
|
||||||
devices[index].flags = flags;
|
devices[index].flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DescriptorTable::GetFlags(int index)
|
int DescriptorTable::GetFlags(int index)
|
||||||
{
|
{
|
||||||
ASSERT(0 <= index && index < numdevices);
|
assert(0 <= index && index < numdevices);
|
||||||
ASSERT(devices[index].dev);
|
assert(devices[index].dev);
|
||||||
return devices[index].flags;
|
return devices[index].flags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <libmaxsi/error.h>
|
#include <libmaxsi/error.h>
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
#include <libmaxsi/string.h>
|
#include <libmaxsi/string.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "syscall.h"
|
#include "syscall.h"
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
@ -81,7 +82,7 @@ namespace Sortix
|
||||||
// another one (provide as many as we can).
|
// another one (provide as many as we can).
|
||||||
prev = dirent;
|
prev = dirent;
|
||||||
size_t bytesused = sizeof(sortix_dirent) + dirent->d_namelen + 1;
|
size_t bytesused = sizeof(sortix_dirent) + dirent->d_namelen + 1;
|
||||||
ASSERT(bytesused <= size);
|
assert(bytesused <= size);
|
||||||
size -= bytesused;
|
size -= bytesused;
|
||||||
dirent = (sortix_dirent*) ( ((uint8_t*) dirent) + bytesused );
|
dirent = (sortix_dirent*) ( ((uint8_t*) dirent) + bytesused );
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <sortix/mman.h>
|
#include <sortix/mman.h>
|
||||||
#include <libmaxsi/error.h>
|
#include <libmaxsi/error.h>
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "elf.h"
|
#include "elf.h"
|
||||||
#include <sortix/kernel/memorymanagement.h>
|
#include <sortix/kernel/memorymanagement.h>
|
||||||
#include <sortix/kernel/panic.h>
|
#include <sortix/kernel/panic.h>
|
||||||
|
@ -95,9 +96,9 @@ namespace Sortix
|
||||||
addr_t virtualaddr = pht->virtualaddr;
|
addr_t virtualaddr = pht->virtualaddr;
|
||||||
addr_t mapto = Page::AlignDown(virtualaddr);
|
addr_t mapto = Page::AlignDown(virtualaddr);
|
||||||
addr_t mapbytes = virtualaddr - mapto + pht->memorysize;
|
addr_t mapbytes = virtualaddr - mapto + pht->memorysize;
|
||||||
ASSERT(pht->offset % pht->align == virtualaddr % pht->align);
|
assert(pht->offset % pht->align == virtualaddr % pht->align);
|
||||||
ASSERT(pht->offset + pht->filesize < filelen);
|
assert(pht->offset + pht->filesize < filelen);
|
||||||
ASSERT(pht->filesize <= pht->memorysize);
|
assert(pht->filesize <= pht->memorysize);
|
||||||
|
|
||||||
ProcessSegment* segment = new ProcessSegment;
|
ProcessSegment* segment = new ProcessSegment;
|
||||||
if ( segment == NULL ) { return 0; }
|
if ( segment == NULL ) { return 0; }
|
||||||
|
@ -181,9 +182,9 @@ namespace Sortix
|
||||||
addr_t virtualaddr = pht->virtualaddr;
|
addr_t virtualaddr = pht->virtualaddr;
|
||||||
addr_t mapto = Page::AlignDown(virtualaddr);
|
addr_t mapto = Page::AlignDown(virtualaddr);
|
||||||
addr_t mapbytes = virtualaddr - mapto + pht->memorysize;
|
addr_t mapbytes = virtualaddr - mapto + pht->memorysize;
|
||||||
ASSERT(pht->offset % pht->align == virtualaddr % pht->align);
|
assert(pht->offset % pht->align == virtualaddr % pht->align);
|
||||||
ASSERT(pht->offset + pht->filesize < filelen);
|
assert(pht->offset + pht->filesize < filelen);
|
||||||
ASSERT(pht->filesize <= pht->memorysize);
|
assert(pht->filesize <= pht->memorysize);
|
||||||
|
|
||||||
ProcessSegment* segment = new ProcessSegment;
|
ProcessSegment* segment = new ProcessSegment;
|
||||||
if ( segment == NULL ) { return 0; }
|
if ( segment == NULL ) { return 0; }
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <libmaxsi/error.h>
|
#include <libmaxsi/error.h>
|
||||||
#include <libmaxsi/string.h>
|
#include <libmaxsi/string.h>
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "../filesystem.h"
|
#include "../filesystem.h"
|
||||||
#include "../directory.h"
|
#include "../directory.h"
|
||||||
#include "../stream.h"
|
#include "../stream.h"
|
||||||
|
@ -256,7 +257,7 @@ namespace Sortix
|
||||||
DevATA* ata = new DevATA(drive);
|
DevATA* ata = new DevATA(drive);
|
||||||
if ( !ata ) { Panic("Cannot allocate ATA device"); }
|
if ( !ata ) { Panic("Cannot allocate ATA device"); }
|
||||||
ata->Refer();
|
ata->Refer();
|
||||||
ASSERT(ataid < 10);
|
assert(ataid < 10);
|
||||||
char name[5] = "ataN";
|
char name[5] = "ataN";
|
||||||
name[3] = '0' + ataid;
|
name[3] = '0' + ataid;
|
||||||
if ( !RegisterDevice(name, ata) )
|
if ( !RegisterDevice(name, ata) )
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <libmaxsi/error.h>
|
#include <libmaxsi/error.h>
|
||||||
#include <libmaxsi/string.h>
|
#include <libmaxsi/string.h>
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "../filesystem.h"
|
#include "../filesystem.h"
|
||||||
#include "../directory.h"
|
#include "../directory.h"
|
||||||
#include "../stream.h"
|
#include "../stream.h"
|
||||||
|
@ -332,7 +333,7 @@ namespace Sortix
|
||||||
if ( index == SIZE_MAX ) { Error::Set(ENOENT); return false; }
|
if ( index == SIZE_MAX ) { Error::Set(ENOENT); return false; }
|
||||||
|
|
||||||
Device* dev = files->Remove(index);
|
Device* dev = files->Remove(index);
|
||||||
ASSERT(dev);
|
assert(dev);
|
||||||
dev->Unref();
|
dev->Unref();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,13 +38,6 @@ typedef uintptr_t addr_t;
|
||||||
#define unlikely(x) __builtin_expect((x),0)
|
#define unlikely(x) __builtin_expect((x),0)
|
||||||
#define STATIC_ASSERT(condition) static_assert(condition, #condition)
|
#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
|
// 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
|
// what libmaxsi's old platform.h header declared and the kernel continues to
|
||||||
// depend on it.
|
// depend on it.
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <sortix/kernel/platform.h>
|
#include <sortix/kernel/platform.h>
|
||||||
#include <libmaxsi/error.h>
|
#include <libmaxsi/error.h>
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "x86-family/idt.h"
|
#include "x86-family/idt.h"
|
||||||
#include "interrupt.h"
|
#include "interrupt.h"
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
|
@ -384,7 +385,7 @@ out:
|
||||||
|
|
||||||
void WorkerThread(void* /*user*/)
|
void WorkerThread(void* /*user*/)
|
||||||
{
|
{
|
||||||
ASSERT(Interrupt::IsEnabled());
|
assert(Interrupt::IsEnabled());
|
||||||
uint8_t* payload = NULL;
|
uint8_t* payload = NULL;
|
||||||
Package* package = NULL;
|
Package* package = NULL;
|
||||||
while ( true )
|
while ( true )
|
||||||
|
@ -398,7 +399,7 @@ void WorkerThread(void* /*user*/)
|
||||||
|
|
||||||
bool ScheduleWork(WorkHandler handler, void* payload, size_t payloadsize)
|
bool ScheduleWork(WorkHandler handler, void* payload, size_t payloadsize)
|
||||||
{
|
{
|
||||||
ASSERT(!Interrupt::IsEnabled());
|
assert(!Interrupt::IsEnabled());
|
||||||
|
|
||||||
Package package;
|
Package package;
|
||||||
package.size = sizeof(package) + payloadsize;
|
package.size = sizeof(package) + payloadsize;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include <sortix/kernel/platform.h>
|
#include <sortix/kernel/platform.h>
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "../interrupt.h"
|
#include "../interrupt.h"
|
||||||
#include "../keyboard.h"
|
#include "../keyboard.h"
|
||||||
#include <sortix/keycodes.h>
|
#include <sortix/keycodes.h>
|
||||||
|
@ -80,7 +81,7 @@ namespace Sortix
|
||||||
|
|
||||||
static void PS2Keyboard__InterruptWork(void* payload, size_t size)
|
static void PS2Keyboard__InterruptWork(void* payload, size_t size)
|
||||||
{
|
{
|
||||||
ASSERT(size == sizeof(PS2KeyboardWork));
|
assert(size == sizeof(PS2KeyboardWork));
|
||||||
PS2KeyboardWork* work = (PS2KeyboardWork*) payload;
|
PS2KeyboardWork* work = (PS2KeyboardWork*) payload;
|
||||||
work->kb->InterruptWork(work->scancode);
|
work->kb->InterruptWork(work->scancode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <sortix/kernel/platform.h>
|
#include <sortix/kernel/platform.h>
|
||||||
#include <sortix/kernel/endian.h>
|
#include <sortix/kernel/endian.h>
|
||||||
#include <sortix/kernel/pci.h>
|
#include <sortix/kernel/pci.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "cpu.h" // TODO: Put this in some <sortix/kernel/cpu.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
|
// 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)
|
uint32_t MakeDevAddr(uint8_t bus, uint8_t slot, uint8_t func)
|
||||||
{
|
{
|
||||||
//ASSERT(bus < 1UL<<8UL); // bus is 8 bit anyways.
|
//assert(bus < 1UL<<8UL); // bus is 8 bit anyways.
|
||||||
ASSERT(slot < 1UL<<5UL);
|
assert(slot < 1UL<<5UL);
|
||||||
ASSERT(func < 1UL<<3UL);
|
assert(func < 1UL<<3UL);
|
||||||
return func << 8U | slot << 11U | bus << 16U | 1 << 31U;
|
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)
|
uint16_t Read16(uint32_t devaddr, uint8_t off)
|
||||||
{
|
{
|
||||||
ASSERT((off & 0x1) == 0);
|
assert((off & 0x1) == 0);
|
||||||
uint8_t alignedoff = off & ~0x3;
|
uint8_t alignedoff = off & ~0x3;
|
||||||
union { uint16_t val16[2]; uint32_t val32; };
|
union { uint16_t val16[2]; uint32_t val32; };
|
||||||
val32 = ReadRaw32(devaddr, alignedoff);
|
val32 = ReadRaw32(devaddr, alignedoff);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <sortix/signal.h>
|
#include <sortix/signal.h>
|
||||||
#include <libmaxsi/error.h>
|
#include <libmaxsi/error.h>
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
|
#include <assert.h>
|
||||||
#ifdef GOT_FAKE_KTHREAD
|
#ifdef GOT_FAKE_KTHREAD
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -116,7 +117,7 @@ namespace Sortix
|
||||||
size_t amount = count;
|
size_t amount = count;
|
||||||
size_t linear = buffersize - bufferoffset;
|
size_t linear = buffersize - bufferoffset;
|
||||||
if ( linear < amount ) { amount = linear; }
|
if ( linear < amount ) { amount = linear; }
|
||||||
ASSERT(amount);
|
assert(amount);
|
||||||
Memory::Copy(dest, buffer + bufferoffset, amount);
|
Memory::Copy(dest, buffer + bufferoffset, amount);
|
||||||
bufferoffset = (bufferoffset + amount) % buffersize;
|
bufferoffset = (bufferoffset + amount) % buffersize;
|
||||||
bufferused -= amount;
|
bufferused -= amount;
|
||||||
|
@ -129,7 +130,7 @@ namespace Sortix
|
||||||
size_t amount = count;
|
size_t amount = count;
|
||||||
size_t linear = buffersize - bufferoffset;
|
size_t linear = buffersize - bufferoffset;
|
||||||
if ( linear < amount ) { amount = linear; }
|
if ( linear < amount ) { amount = linear; }
|
||||||
ASSERT(amount);
|
assert(amount);
|
||||||
Memory::Copy(dest, buffer + bufferoffset, amount);
|
Memory::Copy(dest, buffer + bufferoffset, amount);
|
||||||
bufferoffset = (bufferoffset + amount) % buffersize;
|
bufferoffset = (bufferoffset + amount) % buffersize;
|
||||||
bufferused -= amount;
|
bufferused -= amount;
|
||||||
|
@ -170,7 +171,7 @@ namespace Sortix
|
||||||
size_t amount = count;
|
size_t amount = count;
|
||||||
size_t linear = buffersize - writeoffset;
|
size_t linear = buffersize - writeoffset;
|
||||||
if ( linear < amount ) { amount = linear; }
|
if ( linear < amount ) { amount = linear; }
|
||||||
ASSERT(amount);
|
assert(amount);
|
||||||
Memory::Copy(buffer + writeoffset, src, amount);
|
Memory::Copy(buffer + writeoffset, src, amount);
|
||||||
bufferused += amount;
|
bufferused += amount;
|
||||||
kthread_cond_broadcast(&readcond);
|
kthread_cond_broadcast(&readcond);
|
||||||
|
@ -183,7 +184,7 @@ namespace Sortix
|
||||||
size_t amount = count;
|
size_t amount = count;
|
||||||
size_t linear = buffersize - writeoffset;
|
size_t linear = buffersize - writeoffset;
|
||||||
if ( linear < amount ) { amount = linear; }
|
if ( linear < amount ) { amount = linear; }
|
||||||
ASSERT(amount);
|
assert(amount);
|
||||||
Memory::Copy(buffer + writeoffset, src, amount);
|
Memory::Copy(buffer + writeoffset, src, amount);
|
||||||
bufferused += amount;
|
bufferused += amount;
|
||||||
readevent.Signal();
|
readevent.Signal();
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
#include <libmaxsi/string.h>
|
#include <libmaxsi/string.h>
|
||||||
#include <libmaxsi/sortedlist.h>
|
#include <libmaxsi/sortedlist.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
@ -123,10 +124,10 @@ namespace Sortix
|
||||||
|
|
||||||
Process::~Process()
|
Process::~Process()
|
||||||
{
|
{
|
||||||
ASSERT(!zombiechild);
|
assert(!zombiechild);
|
||||||
ASSERT(!firstchild);
|
assert(!firstchild);
|
||||||
ASSERT(!addrspace);
|
assert(!addrspace);
|
||||||
ASSERT(!segments);
|
assert(!segments);
|
||||||
|
|
||||||
Remove(this);
|
Remove(this);
|
||||||
delete[] workingdir;
|
delete[] workingdir;
|
||||||
|
@ -136,7 +137,7 @@ namespace Sortix
|
||||||
|
|
||||||
void Process::OnThreadDestruction(Thread* thread)
|
void Process::OnThreadDestruction(Thread* thread)
|
||||||
{
|
{
|
||||||
ASSERT(thread->process == this);
|
assert(thread->process == this);
|
||||||
kthread_mutex_lock(&threadlock);
|
kthread_mutex_lock(&threadlock);
|
||||||
if ( thread->prevsibling )
|
if ( thread->prevsibling )
|
||||||
thread->prevsibling->nextsibling = thread->nextsibling;
|
thread->prevsibling->nextsibling = thread->nextsibling;
|
||||||
|
@ -159,7 +160,7 @@ namespace Sortix
|
||||||
void Process::ScheduleDeath()
|
void Process::ScheduleDeath()
|
||||||
{
|
{
|
||||||
// All our threads must have exited at this point.
|
// All our threads must have exited at this point.
|
||||||
ASSERT(!firstthread);
|
assert(!firstthread);
|
||||||
Worker::Schedule(Process__OnLastThreadExit, this);
|
Worker::Schedule(Process__OnLastThreadExit, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,17 +190,17 @@ namespace Sortix
|
||||||
|
|
||||||
void Process::LastPrayer()
|
void Process::LastPrayer()
|
||||||
{
|
{
|
||||||
ASSERT(this);
|
assert(this);
|
||||||
// This must never be called twice.
|
// This must never be called twice.
|
||||||
ASSERT(!iszombie);
|
assert(!iszombie);
|
||||||
|
|
||||||
// This must be called from a thread using another address space as the
|
// This must be called from a thread using another address space as the
|
||||||
// address space of this process is about to be destroyed.
|
// address space of this process is about to be destroyed.
|
||||||
Thread* curthread = CurrentThread();
|
Thread* curthread = CurrentThread();
|
||||||
ASSERT(curthread->process != this);
|
assert(curthread->process != this);
|
||||||
|
|
||||||
// This can't be called if the process is still alive.
|
// 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
|
// We need to temporarily reload the correct addrese space of the dying
|
||||||
// process such that we can unmap and free its memory.
|
// 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.
|
// Init is nice and will gladly raise our orphaned children and zombies.
|
||||||
Process* init = Scheduler::GetInitProcess();
|
Process* init = Scheduler::GetInitProcess();
|
||||||
ASSERT(init);
|
assert(init);
|
||||||
kthread_mutex_lock(&childlock);
|
kthread_mutex_lock(&childlock);
|
||||||
while ( firstchild )
|
while ( firstchild )
|
||||||
{
|
{
|
||||||
|
@ -272,7 +273,7 @@ namespace Sortix
|
||||||
|
|
||||||
void Process::ResetAddressSpace()
|
void Process::ResetAddressSpace()
|
||||||
{
|
{
|
||||||
ASSERT(Memory::GetAddressSpace() == addrspace);
|
assert(Memory::GetAddressSpace() == addrspace);
|
||||||
ProcessSegment* tmp = segments;
|
ProcessSegment* tmp = segments;
|
||||||
while ( tmp != NULL )
|
while ( tmp != NULL )
|
||||||
{
|
{
|
||||||
|
@ -425,9 +426,9 @@ namespace Sortix
|
||||||
{
|
{
|
||||||
ScopedLock mylock(&childlock);
|
ScopedLock mylock(&childlock);
|
||||||
ScopedLock itslock(&child->parentlock);
|
ScopedLock itslock(&child->parentlock);
|
||||||
ASSERT(!child->parent);
|
assert(!child->parent);
|
||||||
ASSERT(!child->nextsibling);
|
assert(!child->nextsibling);
|
||||||
ASSERT(!child->prevsibling);
|
assert(!child->prevsibling);
|
||||||
child->parent = this;
|
child->parent = this;
|
||||||
child->nextsibling = firstchild;
|
child->nextsibling = firstchild;
|
||||||
child->prevsibling = NULL;
|
child->prevsibling = NULL;
|
||||||
|
@ -438,7 +439,7 @@ namespace Sortix
|
||||||
|
|
||||||
Process* Process::Fork()
|
Process* Process::Fork()
|
||||||
{
|
{
|
||||||
ASSERT(CurrentProcess() == this);
|
assert(CurrentProcess() == this);
|
||||||
|
|
||||||
Process* clone = new Process;
|
Process* clone = new Process;
|
||||||
if ( !clone ) { return NULL; }
|
if ( !clone ) { return NULL; }
|
||||||
|
@ -510,7 +511,7 @@ namespace Sortix
|
||||||
int envc, const char* const* envp,
|
int envc, const char* const* envp,
|
||||||
CPU::InterruptRegisters* regs)
|
CPU::InterruptRegisters* regs)
|
||||||
{
|
{
|
||||||
ASSERT(CurrentProcess() == this);
|
assert(CurrentProcess() == this);
|
||||||
|
|
||||||
addr_t entry = ELF::Construct(CurrentProcess(), program, programsize);
|
addr_t entry = ELF::Construct(CurrentProcess(), program, programsize);
|
||||||
if ( !entry ) { return -1; }
|
if ( !entry ) { return -1; }
|
||||||
|
@ -783,7 +784,7 @@ namespace Sortix
|
||||||
{
|
{
|
||||||
ScopedLock lock(&pidalloclock);
|
ScopedLock lock(&pidalloclock);
|
||||||
size_t index = pidlist->Search(process);
|
size_t index = pidlist->Search(process);
|
||||||
ASSERT(index != SIZE_MAX);
|
assert(index != SIZE_MAX);
|
||||||
|
|
||||||
pidlist->Remove(index);
|
pidlist->Remove(index);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <sortix/kernel/platform.h>
|
#include <sortix/kernel/platform.h>
|
||||||
#include <sortix/kernel/kthread.h>
|
#include <sortix/kernel/kthread.h>
|
||||||
#include <sortix/kernel/refcount.h>
|
#include <sortix/kernel/refcount.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
namespace Sortix {
|
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
|
// It's OK to be deleted if our refcount is 1, it won't mess with any
|
||||||
// other owners that might need us.
|
// other owners that might need us.
|
||||||
ASSERT(refcount <= 1);
|
assert(refcount <= 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Refcounted::Refer()
|
void Refcounted::Refer()
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <sortix/kernel/memorymanagement.h>
|
#include <sortix/kernel/memorymanagement.h>
|
||||||
#include <libmaxsi/error.h>
|
#include <libmaxsi/error.h>
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "x86-family/gdt.h"
|
#include "x86-family/gdt.h"
|
||||||
#include "x86-family/float.h"
|
#include "x86-family/float.h"
|
||||||
#include "syscall.h"
|
#include "syscall.h"
|
||||||
|
@ -114,7 +115,7 @@ static void DoActualSwitch(CPU::InterruptRegisters* regs)
|
||||||
addr_t stacklower = next->kernelstackpos;
|
addr_t stacklower = next->kernelstackpos;
|
||||||
size_t stacksize = next->kernelstacksize;
|
size_t stacksize = next->kernelstacksize;
|
||||||
addr_t stackhigher = stacklower + stacksize;
|
addr_t stackhigher = stacklower + stacksize;
|
||||||
ASSERT(stacklower && stacksize && stackhigher);
|
assert(stacklower && stacksize && stackhigher);
|
||||||
GDT::SetKernelStack(stacklower, stacksize, stackhigher);
|
GDT::SetKernelStack(stacklower, stacksize, stackhigher);
|
||||||
|
|
||||||
LogEndSwitch(next, regs);
|
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.
|
// nothing, which is only run when the system has nothing to do.
|
||||||
void SetIdleThread(Thread* thread)
|
void SetIdleThread(Thread* thread)
|
||||||
{
|
{
|
||||||
ASSERT(!idlethread);
|
assert(!idlethread);
|
||||||
idlethread = thread;
|
idlethread = thread;
|
||||||
SetThreadState(thread, Thread::State::NONE);
|
SetThreadState(thread, Thread::State::NONE);
|
||||||
SetCurrentThread(thread);
|
SetCurrentThread(thread);
|
||||||
|
@ -217,8 +218,8 @@ void SetThreadState(Thread* thread, Thread::State state)
|
||||||
{
|
{
|
||||||
if ( thread == firstrunnablethread ) { firstrunnablethread = thread->schedulerlistnext; }
|
if ( thread == firstrunnablethread ) { firstrunnablethread = thread->schedulerlistnext; }
|
||||||
if ( thread == firstrunnablethread ) { firstrunnablethread = NULL; }
|
if ( thread == firstrunnablethread ) { firstrunnablethread = NULL; }
|
||||||
ASSERT(thread->schedulerlistprev);
|
assert(thread->schedulerlistprev);
|
||||||
ASSERT(thread->schedulerlistnext);
|
assert(thread->schedulerlistnext);
|
||||||
thread->schedulerlistprev->schedulerlistnext = thread->schedulerlistnext;
|
thread->schedulerlistprev->schedulerlistnext = thread->schedulerlistnext;
|
||||||
thread->schedulerlistnext->schedulerlistprev = thread->schedulerlistprev;
|
thread->schedulerlistnext->schedulerlistprev = thread->schedulerlistprev;
|
||||||
thread->schedulerlistprev = NULL;
|
thread->schedulerlistprev = NULL;
|
||||||
|
@ -238,8 +239,8 @@ void SetThreadState(Thread* thread, Thread::State state)
|
||||||
|
|
||||||
thread->state = state;
|
thread->state = state;
|
||||||
|
|
||||||
ASSERT(thread->state != Thread::State::RUNNABLE || thread->schedulerlistprev);
|
assert(thread->state != Thread::State::RUNNABLE || thread->schedulerlistprev);
|
||||||
ASSERT(thread->state != Thread::State::RUNNABLE || thread->schedulerlistnext);
|
assert(thread->state != Thread::State::RUNNABLE || thread->schedulerlistnext);
|
||||||
|
|
||||||
Interrupt::SetEnabled(wasenabled);
|
Interrupt::SetEnabled(wasenabled);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <sortix/kernel/panic.h>
|
#include <sortix/kernel/panic.h>
|
||||||
#include <sortix/signal.h>
|
#include <sortix/signal.h>
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "interrupt.h"
|
#include "interrupt.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "signal.h"
|
#include "signal.h"
|
||||||
|
@ -80,7 +81,7 @@ const int PRIORITIES[SIG__NUM_DECLARED] =
|
||||||
|
|
||||||
int Priority(int signum)
|
int Priority(int signum)
|
||||||
{
|
{
|
||||||
ASSERT(0 <= signum && signum < SIG_MAX_NUM);
|
assert(0 <= signum && signum < SIG_MAX_NUM);
|
||||||
if ( !signum )
|
if ( !signum )
|
||||||
return -1;
|
return -1;
|
||||||
if ( SIG__NUM_DECLARED <= signum )
|
if ( SIG__NUM_DECLARED <= signum )
|
||||||
|
@ -96,7 +97,7 @@ Queue::Queue()
|
||||||
|
|
||||||
void Queue::Push(int signum)
|
void Queue::Push(int signum)
|
||||||
{
|
{
|
||||||
ASSERT(0 < signum && signum < SIG_MAX_NUM);
|
assert(0 < signum && signum < SIG_MAX_NUM);
|
||||||
pending[signum] = true;
|
pending[signum] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <sortix/kernel/kthread.h>
|
#include <sortix/kernel/kthread.h>
|
||||||
#include <sortix/kernel/refcount.h>
|
#include <sortix/kernel/refcount.h>
|
||||||
#include <sortix/kernel/textbuffer.h>
|
#include <sortix/kernel/textbuffer.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
namespace Sortix {
|
namespace Sortix {
|
||||||
|
|
||||||
|
@ -62,9 +63,9 @@ TextBuffer* TextBufferHandle::Acquire()
|
||||||
|
|
||||||
void TextBufferHandle::Release(TextBuffer* textbuf)
|
void TextBufferHandle::Release(TextBuffer* textbuf)
|
||||||
{
|
{
|
||||||
ASSERT(textbuf);
|
assert(textbuf);
|
||||||
ScopedLock lock(&mutex);
|
ScopedLock lock(&mutex);
|
||||||
ASSERT(numused);
|
assert(numused);
|
||||||
if ( !--numused )
|
if ( !--numused )
|
||||||
kthread_cond_signal(&unusedcond);
|
kthread_cond_signal(&unusedcond);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <sortix/signal.h>
|
#include <sortix/signal.h>
|
||||||
#include <libmaxsi/error.h>
|
#include <libmaxsi/error.h>
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
|
@ -70,7 +71,7 @@ namespace Sortix
|
||||||
{
|
{
|
||||||
if ( process )
|
if ( process )
|
||||||
process->OnThreadDestruction(this);
|
process->OnThreadDestruction(this);
|
||||||
ASSERT(CurrentThread() != this);
|
assert(CurrentThread() != this);
|
||||||
if ( kernelstackmalloced )
|
if ( kernelstackmalloced )
|
||||||
delete[] (uint8_t*) kernelstackpos;
|
delete[] (uint8_t*) kernelstackpos;
|
||||||
terminated = true;
|
terminated = true;
|
||||||
|
@ -101,7 +102,7 @@ namespace Sortix
|
||||||
|
|
||||||
Thread* CreateKernelThread(Process* process, CPU::InterruptRegisters* regs)
|
Thread* CreateKernelThread(Process* process, CPU::InterruptRegisters* regs)
|
||||||
{
|
{
|
||||||
ASSERT(process && regs && process->addrspace);
|
assert(process && regs && process->addrspace);
|
||||||
Thread* thread = new Thread;
|
Thread* thread = new Thread;
|
||||||
if ( !thread ) { return NULL; }
|
if ( !thread ) { return NULL; }
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#include <sortix/kernel/platform.h>
|
#include <sortix/kernel/platform.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "../interrupt.h"
|
#include "../interrupt.h"
|
||||||
#include "../thread.h"
|
#include "../thread.h"
|
||||||
#include "float.h"
|
#include "float.h"
|
||||||
|
@ -39,13 +40,13 @@ static inline void InitFPU()
|
||||||
|
|
||||||
static inline void SaveState(uint8_t* dest)
|
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));
|
asm volatile ("fxsave (%0)" : : "r"(dest));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void LoadState(const uint8_t* src)
|
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));
|
asm volatile ("fxrstor (%0)" : : "r"(src));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ static void OnFPUAccess(CPU::InterruptRegisters* /*regs*/, void* /*user*/)
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
fputhread = CurrentThread();
|
fputhread = CurrentThread();
|
||||||
ASSERT(fputhread);
|
assert(fputhread);
|
||||||
Interrupt::RegisterHandler(7, OnFPUAccess, NULL);
|
Interrupt::RegisterHandler(7, OnFPUAccess, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <sortix/mman.h>
|
#include <sortix/mman.h>
|
||||||
#include <libmaxsi/error.h>
|
#include <libmaxsi/error.h>
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "multiboot.h"
|
#include "multiboot.h"
|
||||||
#include "memorymanagement.h"
|
#include "memorymanagement.h"
|
||||||
#include "syscall.h"
|
#include "syscall.h"
|
||||||
|
@ -286,7 +287,7 @@ namespace Sortix
|
||||||
|
|
||||||
bool ReserveUnlocked(size_t* counter, size_t least, size_t ideal)
|
bool ReserveUnlocked(size_t* counter, size_t least, size_t ideal)
|
||||||
{
|
{
|
||||||
ASSERT(least < ideal);
|
assert(least < ideal);
|
||||||
size_t available = stackused - stackreserved;
|
size_t available = stackused - stackreserved;
|
||||||
if ( least < available ) { Error::Set(ENOMEM); return false; }
|
if ( least < available ) { Error::Set(ENOMEM); return false; }
|
||||||
if ( available < ideal ) { ideal = available; }
|
if ( available < ideal ) { ideal = available; }
|
||||||
|
@ -315,9 +316,9 @@ namespace Sortix
|
||||||
addr_t GetReservedUnlocked(size_t* counter)
|
addr_t GetReservedUnlocked(size_t* counter)
|
||||||
{
|
{
|
||||||
if ( !*counter ) { return 0; }
|
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];
|
addr_t result = STACK[--stackused];
|
||||||
ASSERT(result == AlignDown(result));
|
assert(result == AlignDown(result));
|
||||||
stackreserved--;
|
stackreserved--;
|
||||||
(*counter)--;
|
(*counter)--;
|
||||||
return result;
|
return result;
|
||||||
|
@ -331,14 +332,14 @@ namespace Sortix
|
||||||
|
|
||||||
addr_t GetUnlocked()
|
addr_t GetUnlocked()
|
||||||
{
|
{
|
||||||
ASSERT(stackreserved <= stackused);
|
assert(stackreserved <= stackused);
|
||||||
if ( unlikely(stackreserved == stackused) )
|
if ( unlikely(stackreserved == stackused) )
|
||||||
{
|
{
|
||||||
Error::Set(ENOMEM);
|
Error::Set(ENOMEM);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
addr_t result = STACK[--stackused];
|
addr_t result = STACK[--stackused];
|
||||||
ASSERT(result == AlignDown(result));
|
assert(result == AlignDown(result));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,8 +351,8 @@ namespace Sortix
|
||||||
|
|
||||||
void PutUnlocked(addr_t page)
|
void PutUnlocked(addr_t page)
|
||||||
{
|
{
|
||||||
ASSERT(page == AlignDown(page));
|
assert(page == AlignDown(page));
|
||||||
ASSERT(stackused < MAXSTACKLENGTH);
|
assert(stackused < MAXSTACKLENGTH);
|
||||||
STACK[stackused++] = page;
|
STACK[stackused++] = page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue