summaryrefslogtreecommitdiff
path: root/middle
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2021-03-12 08:48:35 +0100
committerEugen Wissner <belka@caraus.de>2021-03-12 08:48:35 +0100
commit0fcc83d00eb9d0699167bf105d522e7d23a44d32 (patch)
tree5cb0c97b04ec54cfba823e6c89dac99fbd5dcfdf /middle
parentf27f62b80abf8b237d5c4bf57427fd50aa17e2b0 (diff)
downloadtanya-0fcc83d00eb9d0699167bf105d522e7d23a44d32.tar.gz
Remove the sys package
Diffstat (limited to 'middle')
-rw-r--r--middle/dub.json3
-rwxr-xr-xmiddle/middle-test-librarybin0 -> 1169928 bytes
-rw-r--r--middle/tanya/memory/mallocator.d5
-rw-r--r--middle/tanya/memory/mmappool.d48
-rw-r--r--middle/tanya/memory/op.d55
5 files changed, 25 insertions, 86 deletions
diff --git a/middle/dub.json b/middle/dub.json
index d712f7f..0e91cd0 100644
--- a/middle/dub.json
+++ b/middle/dub.json
@@ -5,8 +5,7 @@
"dependencies": {
"tanya:meta": "*",
- "tanya:os": "*",
- "tanya:sys": "*"
+ "tanya:os": "*"
},
"dependencies-linux": {
diff --git a/middle/middle-test-library b/middle/middle-test-library
new file mode 100755
index 0000000..b8c40ab
--- /dev/null
+++ b/middle/middle-test-library
Binary files differ
diff --git a/middle/tanya/memory/mallocator.d b/middle/tanya/memory/mallocator.d
index e4c46d3..69a2876 100644
--- a/middle/tanya/memory/mallocator.d
+++ b/middle/tanya/memory/mallocator.d
@@ -15,11 +15,6 @@
*/
module tanya.memory.mallocator;
-version (TanyaNative)
-{
-}
-else:
-
import core.stdc.stdlib;
import tanya.memory.allocator;
diff --git a/middle/tanya/memory/mmappool.d b/middle/tanya/memory/mmappool.d
index 50142ce..5c25dd4 100644
--- a/middle/tanya/memory/mmappool.d
+++ b/middle/tanya/memory/mmappool.d
@@ -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);
diff --git a/middle/tanya/memory/op.d b/middle/tanya/memory/op.d
index 93a507f..fdbff38 100644
--- a/middle/tanya/memory/op.d
+++ b/middle/tanya/memory/op.d
@@ -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;
}
///