[+] NT IPC memory
This commit is contained in:
parent
371006c04e
commit
b424a3b434
@ -10,17 +10,153 @@
|
||||
#include "IPCHandle.hpp"
|
||||
#include "IPCMemory.NT.hpp"
|
||||
|
||||
#include <Source/IPC/IPC.hpp>
|
||||
#include <Source/IPC/IPCHandle.hpp>
|
||||
|
||||
namespace Aurora::IPC
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Shared memory
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct IPCSharedMemoryImpl : IPCSharedMemory
|
||||
{
|
||||
IPCSharedMemoryImpl(HANDLE handle, void *ptr, const IPC::IPCHandle &ipcHandle);
|
||||
~IPCSharedMemoryImpl();
|
||||
|
||||
virtual Memory::MemoryViewWrite GetMemory() override;
|
||||
virtual AuUInt GetLength() override;
|
||||
|
||||
virtual AuString ExportToString() override;
|
||||
|
||||
private:
|
||||
IPC::IPCHandle ipcHandle_;
|
||||
bool owns_;
|
||||
HANDLE handle_{};
|
||||
void *base_{};
|
||||
AuUInt len_ {};
|
||||
};
|
||||
|
||||
IPCSharedMemoryImpl::IPCSharedMemoryImpl(HANDLE handle, void *ptr, const IPC::IPCHandle &ipcHandle) :
|
||||
base_(ptr), len_(ipcHandle.word), handle_(handle), ipcHandle_(ipcHandle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
IPCSharedMemoryImpl::~IPCSharedMemoryImpl()
|
||||
{
|
||||
if (this->base_)
|
||||
{
|
||||
::UnmapViewOfFile(this->base_);
|
||||
}
|
||||
|
||||
AuWin32CloseHandle(this->handle_);
|
||||
}
|
||||
|
||||
Memory::MemoryViewWrite IPCSharedMemoryImpl::GetMemory()
|
||||
{
|
||||
return AuMemoryViewWrite(this->base_, this->len_);
|
||||
}
|
||||
|
||||
AuUInt IPCSharedMemoryImpl::GetLength()
|
||||
{
|
||||
return this->len_;
|
||||
}
|
||||
|
||||
AuString IPCSharedMemoryImpl::ExportToString()
|
||||
{
|
||||
return this->ipcHandle_.ToString();
|
||||
}
|
||||
|
||||
AUKN_SYM AuSPtr<IPCSharedMemory> NewSharedMemory(AuUInt length)
|
||||
{
|
||||
SysPushErrorUnimplemented();
|
||||
return {};
|
||||
IPC::IPCHandle handle;
|
||||
handle.NewId(length);
|
||||
|
||||
auto path = handle.ToNTPath();
|
||||
auto file = CreateFileMappingA(INVALID_HANDLE_VALUE,
|
||||
nullptr,
|
||||
PAGE_READWRITE,
|
||||
#if defined(AURORA_IS_64BIT)
|
||||
AuBitsToHigher(length),
|
||||
AuBitsToLower(length),
|
||||
#else
|
||||
0,
|
||||
length,
|
||||
#endif
|
||||
path.c_str());
|
||||
|
||||
if (file == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
auto map = MapViewOfFile(file,
|
||||
FILE_MAP_ALL_ACCESS,
|
||||
0,
|
||||
0,
|
||||
length);
|
||||
if (!map)
|
||||
{
|
||||
SysPushErrorIO();
|
||||
AuWin32CloseHandle(file);
|
||||
return {};
|
||||
}
|
||||
|
||||
auto object = AuMakeShared<IPCSharedMemoryImpl>(file, map, handle);
|
||||
if (!object)
|
||||
{
|
||||
SysPushErrorMem();
|
||||
::UnmapViewOfFile(map);
|
||||
AuWin32CloseHandle(file);
|
||||
return {};
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
AUKN_SYM AuSPtr<IPCSharedMemory> ImportSharedMemory(const AuString &handleString)
|
||||
{
|
||||
SysPushErrorUnimplemented();
|
||||
return {};
|
||||
IPC::IPCHandle handle;
|
||||
|
||||
if (!handle.FromString(handleString))
|
||||
{
|
||||
SysPushErrorParseError();
|
||||
return {};
|
||||
}
|
||||
|
||||
auto length = handle.word;
|
||||
auto path = handle.ToNTPath();
|
||||
auto file = OpenFileMappingA(FILE_MAP_ALL_ACCESS,
|
||||
FALSE,
|
||||
path.c_str());
|
||||
|
||||
if (file == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
auto map = MapViewOfFile(file,
|
||||
FILE_MAP_ALL_ACCESS,
|
||||
0,
|
||||
0,
|
||||
length);
|
||||
if (!map)
|
||||
{
|
||||
SysPushErrorIO();
|
||||
AuWin32CloseHandle(file);
|
||||
return {};
|
||||
}
|
||||
|
||||
auto object = AuMakeShared<IPCSharedMemoryImpl>(file, map, handle);
|
||||
if (!object)
|
||||
{
|
||||
SysPushErrorMem();
|
||||
::UnmapViewOfFile(map);
|
||||
AuWin32CloseHandle(file);
|
||||
return {};
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
}
|
@ -70,7 +70,6 @@ namespace Aurora::IPC
|
||||
bool bFirstTime {true};
|
||||
};
|
||||
|
||||
|
||||
IPCHasConnectionEvent::IPCHasConnectionEvent(AuSPtr<IPCPipeImpl> parent) : parent_(parent), LSEvent(false, false, true)
|
||||
{
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user