summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/asmjit/test/asmjit_test_execute.cpp
diff options
context:
space:
mode:
author Patrick Mackinlay <pmackinlay@hotmail.com>2024-04-11 00:16:51 +0700
committer GitHub <noreply@github.com>2024-04-11 03:16:51 +1000
commit2c566627a1fc0ab21cc0399e8ad0ce134e36b53f (patch)
tree8eb19fad727675c673de8e59a7fd6137e14f2cfd /3rdparty/asmjit/test/asmjit_test_execute.cpp
parent4bcbfac11f352eabcae33b203c026ce02b3fd4ba (diff)
3rdparty/asmjit: Updated to upstream version 1.13.0. (#12228)
From revision asmjit/asmjit@e5d7c0bd5d9aec44d68830187138149e6a8c4e32
Diffstat (limited to '3rdparty/asmjit/test/asmjit_test_execute.cpp')
-rw-r--r--3rdparty/asmjit/test/asmjit_test_execute.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/3rdparty/asmjit/test/asmjit_test_execute.cpp b/3rdparty/asmjit/test/asmjit_test_execute.cpp
new file mode 100644
index 00000000000..ce002dc5a6b
--- /dev/null
+++ b/3rdparty/asmjit/test/asmjit_test_execute.cpp
@@ -0,0 +1,103 @@
+// This file is part of AsmJit project <https://asmjit.com>
+//
+// See asmjit.h or LICENSE.md for license and copyright information
+// SPDX-License-Identifier: Zlib
+
+#include <asmjit/core.h>
+
+static void printInfo() noexcept {
+ printf("AsmJit Execute Test-Suite v%u.%u.%u\n",
+ unsigned((ASMJIT_LIBRARY_VERSION >> 16) ),
+ unsigned((ASMJIT_LIBRARY_VERSION >> 8) & 0xFF),
+ unsigned((ASMJIT_LIBRARY_VERSION ) & 0xFF));
+}
+
+#if !defined(ASMJIT_NO_JIT) && ( \
+ (ASMJIT_ARCH_X86 != 0 && !defined(ASMJIT_NO_X86 )) || \
+ (ASMJIT_ARCH_ARM == 64 && !defined(ASMJIT_NO_AARCH64)) )
+
+#if ASMJIT_ARCH_X86 != 0
+#include <asmjit/x86.h>
+#endif
+
+#if ASMJIT_ARCH_ARM == 64
+#include <asmjit/a64.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+using namespace asmjit;
+
+// Signature of the generated function.
+typedef void (*EmptyFunc)(void);
+
+// Generate Empty Function
+// -----------------------
+
+#if ASMJIT_ARCH_X86 != 0
+static void generateEmptyFunc(CodeHolder& code) noexcept {
+ x86::Assembler a(&code);
+ a.ret();
+}
+#endif
+
+#if ASMJIT_ARCH_ARM == 64
+static void generateEmptyFunc(CodeHolder& code) noexcept {
+ a64::Assembler a(&code);
+ a.ret(a64::x30);
+}
+#endif
+
+// Testing
+// -------
+
+static void executeEmptyFunc(JitRuntime& rt) noexcept {
+ CodeHolder code;
+ code.init(rt.environment(), rt.cpuFeatures());
+
+ EmptyFunc fn;
+
+ generateEmptyFunc(code);
+ Error err = rt.add(&fn, &code);
+
+ if (err) {
+ printf("** FAILURE: JitRuntime::add() failed: %s **\n", DebugUtils::errorAsString(err));
+ exit(1);
+ }
+
+ fn();
+
+ rt.release(&fn);
+}
+
+int main() {
+ printInfo();
+ printf("\n");
+
+ {
+ printf("Trying to execute empty function with JitRuntime (default settings)\n");
+ JitRuntime rt;
+ executeEmptyFunc(rt);
+ }
+
+ if (VirtMem::hardenedRuntimeInfo().hasFlag(VirtMem::HardenedRuntimeFlags::kDualMapping)) {
+ printf("Trying to execute empty function with JitRuntime (dual-mapped)\n");
+ JitAllocator::CreateParams params {};
+ params.options |= JitAllocatorOptions::kUseDualMapping;
+ JitRuntime rt;
+ executeEmptyFunc(rt);
+ }
+
+ // If we are here we were successful, otherwise the process would crash.
+ printf("** SUCCESS **\n");
+ return 0;
+}
+#else
+int main() {
+ printInfo();
+ printf("\nThis test is currently disabled - no JIT or no support for the target architecture\n");
+ return 0;
+}
+#endif // ASMJIT_ARCH_X86 && !ASMJIT_NO_X86 && !ASMJIT_NO_JIT