summaryrefslogtreecommitdiffstats
path: root/src/common/virtual_buffer.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2020-04-17 22:33:08 +0200
committerGitHub <noreply@github.com>2020-04-17 22:33:08 +0200
commitb8f5c71f2d7f819821acf036175cce65ab1ae12c (patch)
tree151d7ed4e47536dc0e149a7117387b6a502d7da6 /src/common/virtual_buffer.cpp
parentMerge pull request #3682 from lioncash/uam (diff)
parentcore: hle: Address various feedback & code cleanup. (diff)
downloadyuzu-b8f5c71f2d7f819821acf036175cce65ab1ae12c.tar
yuzu-b8f5c71f2d7f819821acf036175cce65ab1ae12c.tar.gz
yuzu-b8f5c71f2d7f819821acf036175cce65ab1ae12c.tar.bz2
yuzu-b8f5c71f2d7f819821acf036175cce65ab1ae12c.tar.lz
yuzu-b8f5c71f2d7f819821acf036175cce65ab1ae12c.tar.xz
yuzu-b8f5c71f2d7f819821acf036175cce65ab1ae12c.tar.zst
yuzu-b8f5c71f2d7f819821acf036175cce65ab1ae12c.zip
Diffstat (limited to 'src/common/virtual_buffer.cpp')
-rw-r--r--src/common/virtual_buffer.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/common/virtual_buffer.cpp b/src/common/virtual_buffer.cpp
new file mode 100644
index 000000000..b426f4747
--- /dev/null
+++ b/src/common/virtual_buffer.cpp
@@ -0,0 +1,52 @@
+// Copyright 2020 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#ifdef _WIN32
+#include <windows.h>
+#else
+#include <stdio.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#if defined __APPLE__ || defined __FreeBSD__ || defined __OpenBSD__
+#include <sys/sysctl.h>
+#elif defined __HAIKU__
+#include <OS.h>
+#else
+#include <sys/sysinfo.h>
+#endif
+#endif
+
+#include "common/assert.h"
+#include "common/virtual_buffer.h"
+
+namespace Common {
+
+void* AllocateMemoryPages(std::size_t size) {
+#ifdef _WIN32
+ void* base{VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE)};
+#else
+ void* base{mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0)};
+
+ if (base == MAP_FAILED) {
+ base = nullptr;
+ }
+#endif
+
+ ASSERT(base);
+
+ return base;
+}
+
+void FreeMemoryPages(void* base, std::size_t size) {
+ if (!base) {
+ return;
+ }
+#ifdef _WIN32
+ ASSERT(VirtualFree(base, 0, MEM_RELEASE));
+#else
+ ASSERT(munmap(base, size) == 0);
+#endif
+}
+
+} // namespace Common