Remove the sys package

This commit is contained in:
2021-03-12 08:48:35 +01:00
parent f27f62b80a
commit 0fcc83d00e
30 changed files with 44 additions and 1450 deletions

View File

@ -5,8 +5,7 @@
"dependencies": {
"tanya:meta": "*",
"tanya:os": "*",
"tanya:sys": "*"
"tanya:os": "*"
},
"dependencies-linux": {

BIN
middle/middle-test-library Executable file

Binary file not shown.

View File

@ -15,11 +15,6 @@
*/
module tanya.memory.mallocator;
version (TanyaNative)
{
}
else:
import core.stdc.stdlib;
import tanya.memory.allocator;

View File

@ -14,32 +14,18 @@
*/
module tanya.memory.mmappool;
version (TanyaNative):
import mir.linux._asm.unistd;
import core.sys.linux.sys.mman;
import tanya.memory.allocator;
import tanya.memory.op;
import tanya.os.error;
import tanya.sys.linux.syscall;
import tanya.sys.posix.mman;
private void* mapMemory(const size_t length) @nogc nothrow pure @system
{
auto p = syscall_(0,
length,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS,
-1,
0,
NR_mmap);
return p == -ErrorCode.noMemory ? null : cast(void*) p;
}
extern(C) pragma(mangle, "mmap")
private void* mapMemory(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
@nogc nothrow pure @system;
private bool unmapMemory(shared void* addr, const size_t length)
@nogc nothrow pure @system
{
return syscall_(cast(ptrdiff_t) addr, length, NR_munmap) == 0;
}
extern(C) pragma(mangle, "munmap")
private bool unmapMemory(shared void* addr, size_t length)
@nogc nothrow pure @system;
/*
* This allocator allocates memory in regions (multiple of 64 KB for example).
@ -206,7 +192,7 @@ final class MmapPool : Allocator
{
block.region.next.prev = block.region.prev;
}
return unmapMemory(block.region, block.region.size);
return unmapMemory(block.region, block.region.size) == 0;
}
// Merge blocks if neigbours are free.
if (block.next !is null && block.next.free)
@ -394,9 +380,13 @@ final class MmapPool : Allocator
{
return null;
}
void* p = mapMemory(regionSize);
if (p is null)
void* p = mapMemory(null,
regionSize,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS,
-1,
0);
if (cast(ptrdiff_t) p == -1)
{
return null;
}
@ -506,10 +496,10 @@ final class MmapPool : Allocator
{
// allocate() check.
size_t tooMuchMemory = size_t.max
- MmapPool.alignment_
- BlockEntry.sizeof * 2
- RegionEntry.sizeof
- pageSize;
- MmapPool.alignment_
- MmapPool.BlockEntry.sizeof * 2
- MmapPool.RegionEntry.sizeof
- MmapPool.pageSize;
assert(MmapPool.instance.allocate(tooMuchMemory) is null);
assert(MmapPool.instance.allocate(size_t.max) is null);

View File

@ -14,23 +14,7 @@
*/
module tanya.memory.op;
version (TanyaNative)
{
extern private void fillMemory(void[], size_t) pure nothrow @system @nogc;
extern private void copyMemory(const void[], void[])
pure nothrow @system @nogc;
extern private void moveMemory(const void[], void[])
pure nothrow @system @nogc;
extern private bool equalMemory(const void[], const void[])
pure nothrow @system @nogc;
}
else
{
import core.stdc.string;
}
import core.stdc.string;
private enum alignMask = size_t.sizeof - 1;
@ -56,14 +40,7 @@ in (source.length <= target.length)
in (source.length == 0 || source.ptr !is null)
in (target.length == 0 || target.ptr !is null)
{
version (TanyaNative)
{
copyMemory(source, target);
}
else
{
memcpy(target.ptr, source.ptr, source.length);
}
memcpy(target.ptr, source.ptr, source.length);
}
///
@ -100,14 +77,7 @@ private template filledBytes(ubyte Byte, ubyte I = 0)
void fill(ubyte c = 0)(void[] memory) @trusted
in (memory.length == 0 || memory.ptr !is null)
{
version (TanyaNative)
{
fillMemory(memory, filledBytes!c);
}
else
{
memset(memory.ptr, c, memory.length);
}
memset(memory.ptr, c, memory.length);
}
///
@ -148,14 +118,7 @@ in (source.length <= target.length)
in (source.length == 0 || source.ptr !is null)
in (target.length == 0 || target.ptr !is null)
{
version (TanyaNative)
{
moveMemory(source, target);
}
else
{
memmove(target.ptr, source.ptr, source.length);
}
memmove(target.ptr, source.ptr, source.length);
}
///
@ -330,15 +293,7 @@ bool equal(const void[] r1, const void[] r2) @nogc nothrow pure @trusted
in (r1.length == 0 || r1.ptr !is null)
in (r2.length == 0 || r2.ptr !is null)
{
version (TanyaNative)
{
return equalMemory(r1, r2);
}
else
{
return r1.length == r2.length
&& memcmp(r1.ptr, r2.ptr, r1.length) == 0;
}
return r1.length == r2.length && memcmp(r1.ptr, r2.ptr, r1.length) == 0;
}
///