Skip to content

Commit

Permalink
Merge master into feature/device_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
kazssym committed Dec 25, 2020
2 parents 19ec8b6 + 7076200 commit 5dbfa01
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
22 changes: 22 additions & 0 deletions libvm68k/read_write_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,23 @@
#include <config.h>
#endif

#if _WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#endif

#include <bits/vm68k/read_write_memory.h>

#if HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
#include <new>
#include <cstdint>

using std::bad_alloc;
using std::declare_no_pointers;
using std::size_t;
using std::uint64_t;
using std::undeclare_no_pointers;
using std::unique_ptr;
using namespace vm68k;
Expand All @@ -42,6 +49,8 @@ void read_write_memory::bytes_delete::operator ()(byte_type *bytes) const
undeclare_no_pointers(reinterpret_cast<char *>(bytes), _size);
#if HAVE_SYS_MMAN_H && defined MAP_ANONYMOUS
munmap(bytes, _size);
#elif _WIN32
UnmapViewOfFile(bytes);
#else
delete[] bytes;
#endif
Expand All @@ -57,6 +66,19 @@ auto read_write_memory::allocate_bytes(const size_t size)
if (bytes == nullptr) {
throw bad_alloc();
}
#elif _WIN32
auto &&handle =
CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE,
(uint64_t)size >> 32, size, nullptr);
if (handle == nullptr) {
throw bad_alloc();
}
auto &&bytes = static_cast<byte_type *>(
MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, size));
CloseHandle(handle); // This handle is no longer needed.
if (bytes == nullptr) {
throw bad_alloc();
}
#else
auto bytes = new byte_type[size] {};
#endif
Expand Down
9 changes: 9 additions & 0 deletions libvm68kapi/bits/vm68k/device_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

namespace vm68k
{
#if _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251)
#endif

/**
* Device managers.
*/
Expand Down Expand Up @@ -119,6 +124,10 @@ namespace vm68k
void add_device(const std::shared_ptr<device> &device);
};

#if _MSC_VER
#pragma warning(pop)
#endif

/**
* Swaps the contents of two device managers.
*/
Expand Down
9 changes: 9 additions & 0 deletions libvm68kapi/bits/vm68k/memory_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ namespace vm68k
size_type size, const void *bytes) = 0;
};

#if _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251)
#endif

/**
* Paged memory maps.
*/
Expand Down Expand Up @@ -297,6 +302,10 @@ namespace vm68k
size_type size, const void *bytes) override;
};

#if _MSC_VER
#pragma warning(pop)
#endif

/**
* Swaps the contents of two paged memory maps.
*
Expand Down

0 comments on commit 5dbfa01

Please sign in to comment.