summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt6
-rw-r--r--rttest.cc16
-rw-r--r--test.cc6
-rw-r--r--zp/GNUmakefile2
-rw-r--r--zp/include/zp/str.d/strcpy.ii4
-rw-r--r--zp/source/amd64/bs/syscl.s2
-rw-r--r--zp/source/ia32/bs/syscl.s61
7 files changed, 53 insertions, 44 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index c0e56a1..4c44127 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -53,6 +53,12 @@
* Update target detection script;
* Update gitingore;
+* Use NASM on IA-32;
+* Don't use libfmt in rttest;
+* Fix uninitialised variable in rttest;
+* Make test support C++20;
+* Fix out-of-bounds write in strcpy;
+
# 0.0.2
* Migrate to CMake;
diff --git a/rttest.cc b/rttest.cc
index c0df7ab..0f3142f 100644
--- a/rttest.cc
+++ b/rttest.cc
@@ -1,6 +1,6 @@
#include <cstdlib>
#include <exception>
-#include <fmt/core.h>
+#include <iostream>
#include <source_location>
#include <typeinfo>
#include <zp/mem>
@@ -9,10 +9,10 @@
int main() {
int unsigned num;
- int unsigned numerr;
+ int unsigned numerr = 0x0u;
auto const tst = [&num](char const * const cmp) noexcept {
- ::fmt::print("\n\x1B[38;5;75mtesting\x1B[0m {}\n\n",cmp);
+ ::std::cout << "\n\x1B[38;5;75mtesting\x1B[0m " << cmp << "\n\n";
num = 0x0;
};
@@ -30,20 +30,20 @@ int main() {
auto const lval = getval(lvalref);
auto const rval = getval(rvalref);
- ::fmt::print(" {}. comparing {} ({}) vs. {} ({})... ",num++,ltypnm,lval,rtypnm,rval);
+ ::std::cout << " " << num++ << ". comparing " << ltypnm << " (" << lval << ") vs. " << rtypnm << " (" << rval << ")... ";
if (lval != rval) {
- ::fmt::print("\x1B[38;5;161munequal\x1B[0m (at #{})\n",srcloc.line());
+ ::std::cout << "\x1B[38;5;161munequal\x1B[0m (at #" << srcloc.line() << ")\n";
//throw ::std::exception {};
++numerr;
return;
}
- ::fmt::print("\x1B[38;5;77mequal\x1B[0m\n");
+ ::std::cout << "\x1B[38;5;77mequal\x1B[0m\n";
};
- ::fmt::print("zp test {}.{}\n",::zp::ver,::zp::extver);
+ ::std::cout << "zp test " << ::zp::ver << "." << ::zp::extver << "\n";
try {
[&] {
@@ -207,7 +207,7 @@ int main() {
return EXIT_FAILURE;
}
- ::fmt::print("\nDone - {} error(s)\n",numerr);
+ ::std::cout << "\nDone \u2212 " << numerr << " error(s)\n";
return EXIT_SUCCESS;
}
diff --git a/test.cc b/test.cc
index 00990b6..83580f0 100644
--- a/test.cc
+++ b/test.cc
@@ -7,7 +7,7 @@
#include <zp/str>
int main() {
- [] consteval {
+ static_assert([] {
static_assert(::zp::isptr<int> == false);
static_assert(::zp::isptr<int *> == true);
static_assert(::zp::isptr<int const *> == true);
@@ -130,5 +130,7 @@ int main() {
static_assert(::zp::maxval<long unsigned> == ::std::numeric_limits<long unsigned>::max());
static_assert(::zp::maxval<long long unsigned> == ::std::numeric_limits<long long unsigned>::max());
static_assert(::zp::maxval<wchar_t> == ::std::numeric_limits<wchar_t>::max());
- }();
+
+ return true;
+ }());
}
diff --git a/zp/GNUmakefile b/zp/GNUmakefile
index 291729c..6316845 100644
--- a/zp/GNUmakefile
+++ b/zp/GNUmakefile
@@ -12,6 +12,8 @@ endif
ifeq "$(targ)" "amd64"
AS := nasm -felf64
+else ifeq "$(targ)" "ia32"
+AS := nasm -felf32
endif
ifeq "$(stdc)" ""
diff --git a/zp/include/zp/str.d/strcpy.ii b/zp/include/zp/str.d/strcpy.ii
index 3691e8e..6f373a6 100644
--- a/zp/include/zp/str.d/strcpy.ii
+++ b/zp/include/zp/str.d/strcpy.ii
@@ -9,7 +9,7 @@ template<typename typ> constexpr auto ::zp::strcpy(typ * dst,typ const * src) no
auto const dstsrt = dst;
- while ((*dst++ = *src++) != typ {0x0}) {}
+ while (*src != typ {0x0}) {*dst++ = *src++;}
- return static_cast<::zp::sz>(dst-dstsrt)-0x1u; // Number of values copied.
+ return static_cast<::zp::sz>(dst-dstsrt); // Number of values copied.
}
diff --git a/zp/source/amd64/bs/syscl.s b/zp/source/amd64/bs/syscl.s
index af0bf1a..4842577 100644
--- a/zp/source/amd64/bs/syscl.s
+++ b/zp/source/amd64/bs/syscl.s
@@ -21,7 +21,7 @@ zp_syscl:
mov rdx,rcx
mov r10,r8 ; System calls use r10 instead of rcx.
mov r8,r9
- mov r9,[rsp + 0x8] ; Extract the sixth argument from the stack.
+ mov r9,[rsp+0x8] ; Extract the sixth argument from the stack.
syscall ; Slime incident
; No need to move the return value.
ret
diff --git a/zp/source/ia32/bs/syscl.s b/zp/source/ia32/bs/syscl.s
index 9dd3195..9fe18e2 100644
--- a/zp/source/ia32/bs/syscl.s
+++ b/zp/source/ia32/bs/syscl.s
@@ -1,34 +1,33 @@
-# Copyright 2022-2023 Gabriel Jensen.
-# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
+; Copyright 2022-2023 Gabriel Jensen.
+; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+; If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
-.globl zp_syscl
+global zp_syscl
zp_syscl:
- # System calls on IA-32 use the following registers:
- # eax : System call identifier
- # ebx : First parameter
- # ecx : Second parameter
- # edx : Third parameter
- # esi : Fourth parameter
- # edi : Fifth parameter
- # ebp : Sixth parameter
- # eax : Return value
- pushl %ebx # Remember to save the registers.
- pushl %esi
- pushl %edi
- pushl %ebp # Remember that the provided paramters are now further up the stack.
- movl 0x14(%esp),%eax # Move the first parameter (the identifier) to eax.
- movl 0x18(%esp),%ebx # Move the remaining parameters into their designated registers. This will read "out of bounds" memory if the number of passed parameters is less than six, but this shouldn't matter as long as the data isn't being used, which it won't be as long as the expected ammount of parameters have been passed.
- movl 0x1C(%esp),%ecx
- movl 0x20(%esp),%edx
- movl 0x24(%esp),%esi
- movl 0x28(%esp),%edi
- movl 0x2C(%esp),%ebp
- int $0x80 # Flying city
- popl %ebp # Restore the registers.
- popl %edi
- popl %esi
- popl %ebx
- # No need to move the return value.
- ret
+ ; System calls on IA-32 use the following registers:
+ ; eax : System call identifier
+ ; ebx : First parameter
+ ; ecx : Second parameter
+ ; edx : Third parameter
+ ; esi : Fourth parameter
+ ; edi : Fifth parameter
+ ; ebp : Sixth parameter
+ ; eax : Return value
+ push ebx ; Remember to save the registers.
+ push esi
+ push edi
+ push ebp ; Remember that the provided paramters are now further up the stack.
+ mov eax,[esp+0x14] ; Move the first parameter (the identifier) to eax.
+ mov ebx,[esp+0x18] ; Move the remaining parameters into their designated registers. This will read "out of bounds" memory if the number of passed parameters is less than six, but this shouldn't matter as long as the data isn't being used, which it won't be as long as the expected ammount of parameters have been passed.
+ mov ecx,[esp+0x1C]
+ mov edx,[esp+0x20]
+ mov esi,[esp+0x24]
+ mov edi,[esp+0x28]
+ mov ebp,[esp+0x2C]
+ int 0x80 ; Flying city
+ pop ebp ; Restore the registers.
+ pop edi
+ pop esi
+ pop ebx
+ ret ; No need to move the return value.