[+] Linux build [again]
[+] ProcessSectionViewReserved.Unix.cpp [*] Fix missing ::Flush() member on ViewWriter
This commit is contained in:
parent
2b91302128
commit
766be57a46
@ -61,6 +61,11 @@ namespace Aurora::IO::Buffered
|
||||
this->pView_.reset();
|
||||
}
|
||||
|
||||
inline virtual void Flush() override
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
inline AuUInt &GetOffset()
|
||||
{
|
||||
return this->uOffset_;
|
||||
|
@ -58,9 +58,9 @@ static void Init()
|
||||
#endif
|
||||
|
||||
Aurora::Memory::Cache::InitCache();
|
||||
|
||||
Crypto::InitCrypto();
|
||||
Aurora::RNG::Init();
|
||||
|
||||
Crypto::InitCrypto();
|
||||
Aurora::IO::TLS::TLSInit();
|
||||
|
||||
Aurora::Threading::InitSleep();
|
||||
|
@ -34,7 +34,7 @@ namespace Aurora::Compression
|
||||
bool LimitHasHit() override;
|
||||
void LimitReset() override;
|
||||
void LimitSet(AuUInt uLength) override;
|
||||
bool LimitPassthroughOnOverflow(bool bPassthrough);
|
||||
bool LimitPassthroughOnOverflow(bool bPassthrough) override;
|
||||
AuUInt LimitGetIndex() override;
|
||||
|
||||
bool HasFailed() override;
|
||||
|
@ -1140,13 +1140,13 @@ namespace Aurora::Console::ConsoleTTY
|
||||
int XOffset {};
|
||||
XOffset = GetLeftBorder();
|
||||
|
||||
TTYSetPos({XOffset, Y});
|
||||
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
DWORD idc;
|
||||
auto line2 = AuLocale::ConvertFromUTF8(in);
|
||||
SetConsoleCursorPosition(GetTTYHandle(), COORD { AuStaticCast<short>(XOffset), AuStaticCast<short>(Y) });
|
||||
WriteConsoleW(GetTTYHandle(), line2.data(), AuUInt32(line2.size()), &idc, NULL);
|
||||
#else
|
||||
TTYSetPos({XOffset, Y});
|
||||
ConsoleStd::WriteStdOutBlocking2(in.data(), in.size());
|
||||
#endif
|
||||
}
|
||||
@ -1246,7 +1246,7 @@ namespace Aurora::Console::ConsoleTTY
|
||||
"";
|
||||
|
||||
writeLine = pAnsiCode + in + kAnsiColorForegroundToVirtualEscape[static_cast<AuUInt>(EAnsiColor::eReset)];
|
||||
x
|
||||
|
||||
ConsoleStd::WriteStdOutBlocking2(writeLine.data(), writeLine.size());
|
||||
#endif
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <Source/RuntimeInternal.hpp>
|
||||
#include "AuExit.hpp"
|
||||
#include "AuExit.Unix.hpp"
|
||||
#include <Source/Grug/Grug.hpp>
|
||||
#include <Source/Grug/AuGrug.hpp>
|
||||
|
||||
namespace Aurora::Exit
|
||||
{
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <fcntl.h>
|
||||
#include "FileStream.Unix.hpp"
|
||||
#include "Async.Linux.hpp"
|
||||
#include <Source/IO/IPC/IPCPipe.Unix.hpp>
|
||||
#include <Source/IO/IPC/AuIPCPipe.Unix.hpp>
|
||||
|
||||
namespace Aurora::IO::FS
|
||||
{
|
||||
|
@ -218,6 +218,7 @@ namespace Aurora::IO::FS
|
||||
auto file = OpenReadUnique(path, EFileAdvisoryLockLevel::eNoSafety);
|
||||
SysCheckReturn(file, false);
|
||||
|
||||
bool isZero = buffer.readPtr == buffer.base;
|
||||
auto len = file->GetLength();
|
||||
|
||||
// NOTE: Linux filesystems are such a cluster fuck of unimplemented interfaces and half-assed drivers
|
||||
@ -237,7 +238,7 @@ namespace Aurora::IO::FS
|
||||
}
|
||||
}
|
||||
|
||||
writeView = buffer.GetOrAllocateLinearWriteable(length);
|
||||
writeView = buffer.GetOrAllocateLinearWriteable(len);
|
||||
if (!writeView)
|
||||
{
|
||||
return {};
|
||||
@ -253,6 +254,12 @@ namespace Aurora::IO::FS
|
||||
// Do not entertain an arbitrarily large page length provided by non-regular fds
|
||||
|
||||
buffer.writePtr += read;
|
||||
|
||||
if (isZero)
|
||||
{
|
||||
AuTryDownsize(buffer, read);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <fcntl.h> /* For O_* constants */
|
||||
|
||||
#if defined(AURORA_IS_LINUX_DERIVED)
|
||||
#include "IPCMutexFutex.Linux.hpp" /* For import */
|
||||
#include "AuIPCMutexFutex.Linux.hpp" /* For import */
|
||||
#endif
|
||||
|
||||
namespace Aurora::IO::IPC
|
||||
@ -39,7 +39,7 @@ namespace Aurora::IO::IPC
|
||||
const IPC::IPCHandle &handle,
|
||||
bool bOwns) :
|
||||
fd_(fd),
|
||||
pBase_(ptr),
|
||||
pBase_(pBase),
|
||||
uLen_(handle.values[0].token.word),
|
||||
bOwns_(bOwns),
|
||||
handle_(handle)
|
||||
|
@ -8,7 +8,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Source/IO/IPC/IPC.hpp>
|
||||
#include <Source/IO/IPC/IPCHandle.hpp>
|
||||
#include <Source/IO/IPC/AuIPCHandle.hpp>
|
||||
|
||||
namespace Aurora::IO::IPC
|
||||
{
|
||||
|
@ -14,11 +14,11 @@
|
||||
#if defined(AURORA_IS_LINUX_DERIVED)
|
||||
#include <Source/IO/UNIX/IOSubmit.Linux.hpp>
|
||||
#include <Source/IO/FS/Async.Linux.hpp>
|
||||
#include "IPCPrimitives.Linux.hpp"
|
||||
#include "IPCMutexFutex.Linux.hpp"
|
||||
#include "AuIPCPrimitives.Linux.hpp"
|
||||
#include "AuIPCMutexFutex.Linux.hpp"
|
||||
#endif
|
||||
|
||||
#include "IPCMemory.Unix.hpp" // required for handle
|
||||
#include "AuIPCMemory.Unix.hpp" // required for handle
|
||||
|
||||
namespace Aurora::IO::IPC
|
||||
{
|
||||
|
@ -7,9 +7,9 @@
|
||||
***/
|
||||
#include <Source/RuntimeInternal.hpp>
|
||||
#include "IPC.hpp"
|
||||
#include "IPCHandle.hpp"
|
||||
#include "AuIPCHandle.hpp"
|
||||
|
||||
#include "IPCPrimitives.Linux.hpp"
|
||||
#include "AuIPCPrimitives.Linux.hpp"
|
||||
|
||||
#include <Source/IO/UNIX/FDIpcServer.hpp>
|
||||
|
||||
|
@ -8,14 +8,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "IPC.hpp"
|
||||
#include "IPCHandle.hpp"
|
||||
#include "AuIPCHandle.hpp"
|
||||
|
||||
#include <Source/IO/Loop/LSEvent.hpp>
|
||||
#include <Source/IO/Loop/LSSemaphore.hpp>
|
||||
#include <Source/IO/Loop/LSMutex.hpp>
|
||||
|
||||
#include <Source/IO/IPC/IPC.hpp>
|
||||
#include <Source/IO/IPC/IPCHandle.hpp>
|
||||
#include <Source/IO/IPC/AuIPCHandle.hpp>
|
||||
|
||||
namespace Aurora::IO::IPC
|
||||
{
|
||||
|
@ -220,7 +220,7 @@ namespace Aurora::IO::Loop
|
||||
|
||||
if (ms)
|
||||
{
|
||||
src->timeoutAbs = (AuUInt64)ms + AuTime::CurrentClockSteadyMS();
|
||||
src->timeoutAbs = (AuUInt64)ms + AuTime::SteadyClockMS();
|
||||
}
|
||||
|
||||
if (!AuTryInsert(this->sources_, src))
|
||||
@ -426,7 +426,7 @@ namespace Aurora::IO::Loop
|
||||
AuUInt64 timeout {timeoutIn};
|
||||
if (timeout)
|
||||
{
|
||||
timeout += AuTime::CurrentClockSteadyMS();
|
||||
timeout += AuTime::SteadyClockMS();
|
||||
}
|
||||
|
||||
{
|
||||
@ -461,7 +461,7 @@ namespace Aurora::IO::Loop
|
||||
// but this hack should apply to wait any as well, so i'm moving it to the DoTick function
|
||||
|
||||
anythingLeft = epollReference.startingWorkRead.size() || epollReference.startingWorkWrite.size();
|
||||
bTimeout = timeout ? AuTime::CurrentClockSteadyMS() >= timeout : false;
|
||||
bTimeout = timeout ? AuTime::SteadyClockMS() >= timeout : false;
|
||||
} while (anythingLeft && !bTimeout);
|
||||
|
||||
{
|
||||
@ -478,7 +478,7 @@ namespace Aurora::IO::Loop
|
||||
|
||||
if (timeout)
|
||||
{
|
||||
timeout += AuTime::CurrentClockSteadyMS();
|
||||
timeout += AuTime::SteadyClockMS();
|
||||
}
|
||||
|
||||
AuUInt32 cTicked {};
|
||||
@ -532,7 +532,7 @@ namespace Aurora::IO::Loop
|
||||
|
||||
if (timeout)
|
||||
{
|
||||
timeout += AuTime::CurrentClockSteadyMS();
|
||||
timeout += AuTime::SteadyClockMS();
|
||||
}
|
||||
|
||||
bool bTryAgain {};
|
||||
@ -674,7 +674,7 @@ namespace Aurora::IO::Loop
|
||||
AuInt64 deltaMS = 0;
|
||||
if (time)
|
||||
{
|
||||
deltaMS = AuMin(AuInt64(4), (AuInt64)time - (AuInt64)AuTime::CurrentClockSteadyMS());
|
||||
deltaMS = AuMin(AuInt64(4), (AuInt64)time - (AuInt64)AuTime::SteadyClockMS());
|
||||
if (deltaMS < 0)
|
||||
{
|
||||
deltaMS = 0;
|
||||
@ -753,7 +753,7 @@ namespace Aurora::IO::Loop
|
||||
}
|
||||
}
|
||||
|
||||
now = AuTime::CurrentClockSteadyMS();
|
||||
now = AuTime::SteadyClockMS();
|
||||
|
||||
if (!bTicked)
|
||||
{
|
||||
@ -768,7 +768,7 @@ namespace Aurora::IO::Loop
|
||||
|
||||
if (!now)
|
||||
{
|
||||
now = AuTime::CurrentClockSteadyMS();
|
||||
now = AuTime::SteadyClockMS();
|
||||
}
|
||||
|
||||
for (auto itr = this->sources_.begin(); itr != this->sources_.end(); )
|
||||
|
@ -0,0 +1,34 @@
|
||||
/***
|
||||
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: AuNetAdapter.Linux.cpp
|
||||
Date: 2022-11-15
|
||||
Author: Reece
|
||||
***/
|
||||
#include "Networking.hpp"
|
||||
#include "AuNetAdapter.hpp"
|
||||
#include "AuNetEndpoint.hpp"
|
||||
|
||||
namespace Aurora::IO::Net
|
||||
{
|
||||
AuString NetAdapter::GetHostname()
|
||||
{
|
||||
char name[128];
|
||||
if (::gethostname(name, AuArraySize(name)) != 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
AuList<AuSPtr<INetAdapter>> NetAdapter::GetIPv4s()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
AuList<AuSPtr<INetAdapter>> NetAdapter::GetIPv6s()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
/***
|
||||
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: AuNetAdapter.Linux.hpp
|
||||
Date: 2022-11-15
|
||||
Author: Reece
|
||||
***/
|
||||
#pragma once
|
||||
|
||||
namespace Aurora::IO::Net
|
||||
{
|
||||
|
||||
}
|
@ -21,7 +21,8 @@ namespace Aurora::IO::Net
|
||||
pWorker,
|
||||
{},
|
||||
{},
|
||||
4096),
|
||||
4096,
|
||||
true),
|
||||
Socket(pInterface, pWorker, {}, -1)
|
||||
{
|
||||
}
|
||||
|
@ -72,7 +72,12 @@ namespace Aurora::IO::Net
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
auto pTransaction = AuMakeShared<NtAsyncNetworkTransaction>(this);
|
||||
#else
|
||||
auto pTransaction = AuMakeShared<LinuxAsyncNetworkTransaction>(this);
|
||||
#endif
|
||||
if (!pTransaction || (pCalback2 && !pCallback))
|
||||
{
|
||||
SysPushErrorMemory("Dropping datagram");
|
||||
|
@ -199,9 +199,24 @@ namespace Aurora::IO::Net
|
||||
return ::fcntl(this->osHandle_, F_SETFL, flags) == 0;
|
||||
}
|
||||
|
||||
void Socket::Shutdown()
|
||||
void Socket::Shutdown(bool bNow)
|
||||
{
|
||||
this->SendEnd();
|
||||
::shutdown(this->osHandle_, SHUT_RDWR);
|
||||
if (bNow)
|
||||
{
|
||||
this->SendEnd();
|
||||
::shutdown(this->osHandle_, SHUT_RDWR);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!this->socketChannel_.outputChannel.AsWritableByteBuffer()->RemainingBytes())
|
||||
{
|
||||
this->Shutdown(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->socketChannel_.outputChannel.bShutdownOnComplete = true;
|
||||
this->socketChannel_.ScheduleOutOfFrameWrite();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -58,7 +58,7 @@ namespace Aurora::IO::Net
|
||||
|
||||
virtual bool MakeNonblocking() override;
|
||||
|
||||
virtual void Shutdown() override;
|
||||
virtual void Shutdown(bool bNow) override;
|
||||
|
||||
virtual void CloseSocket() override;
|
||||
};
|
||||
|
@ -98,7 +98,6 @@ namespace Aurora::IO::Net
|
||||
return;
|
||||
}
|
||||
|
||||
AuLogDbg("On tick");
|
||||
auto pTemp = AuExchange(this->pSocket, {});
|
||||
|
||||
if (this->HasFailed())
|
||||
|
@ -16,12 +16,14 @@ namespace Aurora::IO::Net
|
||||
NetWorker *pWorker,
|
||||
const AuSPtr<ISocketServerDriver> &pDriver,
|
||||
const AuSPtr<ISocketDriverFactory> &pSocketDriverFactory,
|
||||
AuUInt32 maxConnections) :
|
||||
AuUInt32 maxConnections,
|
||||
bool bMultiThreaded) :
|
||||
SocketServer(pInterface,
|
||||
pWorker,
|
||||
pDriver,
|
||||
pSocketDriverFactory,
|
||||
maxConnections),
|
||||
maxConnections,
|
||||
bMultiThreaded),
|
||||
Socket(pInterface,
|
||||
pWorker,
|
||||
AuSPtr<ISocketDriver>{},
|
||||
|
@ -17,7 +17,8 @@ namespace Aurora::IO::Net
|
||||
struct NetWorker *pWorker,
|
||||
const AuSPtr<ISocketServerDriver> &pDriver,
|
||||
const AuSPtr<ISocketDriverFactory> &pSocketDriverFactory,
|
||||
AuUInt32 maxConnections);
|
||||
AuUInt32 maxConnections,
|
||||
bool bMultiThreaded);
|
||||
|
||||
|
||||
virtual void DoNonblockingReadTick() override;
|
||||
|
@ -9,6 +9,9 @@
|
||||
#include "AuNetSocketServer.hpp"
|
||||
#include "AuNetSocket.hpp"
|
||||
#include "AuNetEndpoint.hpp"
|
||||
#include "AuNetInterface.hpp"
|
||||
#include "AuNetWorker.hpp"
|
||||
#include "AuNetEndpoint.hpp"
|
||||
|
||||
namespace Aurora::IO::Net
|
||||
{
|
||||
@ -81,7 +84,7 @@ namespace Aurora::IO::Net
|
||||
}
|
||||
|
||||
NetWorker *pWorker;
|
||||
if (this->pParent_->bMultiThreadTCP)
|
||||
if (this->pParent_->bMultiThreaded)
|
||||
{
|
||||
pWorker = this->pInterface_->TryScheduleEx().get();
|
||||
}
|
||||
@ -111,7 +114,7 @@ namespace Aurora::IO::Net
|
||||
// Deoptimize (sockaddr -> binary) endpoints
|
||||
UpdateNextSocketAddresses();
|
||||
|
||||
if (this->pParent_->bMultiThreadTCP)
|
||||
if (this->pParent_->bMultiThreaded)
|
||||
{
|
||||
auto pCallback = AuMakeShared<IIOProcessorWorkUnitFunctional>([=]()
|
||||
{
|
||||
|
@ -81,7 +81,7 @@ namespace Aurora::IO::Net
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (gRuntimeConfig.bFIODisableBatching)
|
||||
if (gRuntimeConfig.bFIODisableBatching)
|
||||
{
|
||||
UNIX::SendIOBuffers();
|
||||
}
|
||||
@ -149,7 +149,7 @@ namespace Aurora::IO::Net
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (gRuntimeConfig.bFIODisableBatching)
|
||||
if (gRuntimeConfig.bFIODisableBatching)
|
||||
{
|
||||
UNIX::SendIOBuffers();
|
||||
}
|
||||
@ -159,7 +159,19 @@ namespace Aurora::IO::Net
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
if (::sendto(this->GetSocket(),
|
||||
memoryView->ptr,
|
||||
memoryView->length,
|
||||
0,
|
||||
(struct sockaddr *)netEndpoint.hint,
|
||||
this->iSocketLength) != memoryView->length)
|
||||
{
|
||||
LIOS_SendProcess(0, false, errno);
|
||||
return true;
|
||||
}
|
||||
|
||||
LIOS_SendProcess(memoryView->length, true, errno);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace Aurora::IO::Net
|
||||
|
||||
AuBST<AuSPtr<NetWorker>, AuList<AuSPtr<NetDatagramSocketServerSession>>> abortions;
|
||||
|
||||
for (const auto &pSession : sessions)
|
||||
for (auto pSession : sessions)
|
||||
{
|
||||
auto uLastRecv = pSession->channel.GetRecvStatsEx().uLastTimeSteadyMS;
|
||||
auto uLastSend = pSession->channel.GetSendStatsEx().uLastTimeSteadyMS;
|
||||
@ -39,11 +39,11 @@ namespace Aurora::IO::Net
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &[pWorker, list] : abortions)
|
||||
for (const auto [pWorker, list] : abortions)
|
||||
{
|
||||
pWorker->TryScheduleInternalTemplate<AuNullS>([=](const AuSPtr<AuAsync::PromiseCallback<AuNullS>> &info)
|
||||
pWorker->TryScheduleInternalTemplate<AuNullS>([list = list](const AuSPtr<AuAsync::PromiseCallback<AuNullS>> &info)
|
||||
{
|
||||
for (const auto pDriver : list)
|
||||
for (auto pDriver : list)
|
||||
{
|
||||
pDriver->Shutdown(false);
|
||||
}
|
||||
@ -63,9 +63,9 @@ namespace Aurora::IO::Net
|
||||
|
||||
for (const auto &[pWorker, list] : abortions)
|
||||
{
|
||||
pWorker->TryScheduleInternalTemplate<AuNullS>([=](const AuSPtr<AuAsync::PromiseCallback<AuNullS>> &info)
|
||||
pWorker->TryScheduleInternalTemplate<AuNullS>([list = list](const AuSPtr<AuAsync::PromiseCallback<AuNullS>> &info)
|
||||
{
|
||||
for (const auto pDriver : list)
|
||||
for (auto pDriver : list)
|
||||
{
|
||||
pDriver->Shutdown(false);
|
||||
}
|
||||
|
@ -41,7 +41,11 @@ namespace Aurora::IO::Net
|
||||
|
||||
AuSPtr<IAsyncTransaction> NetDatagramSocketServerChannel::ToWriteTransaction()
|
||||
{
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
auto pTransaction = AuMakeShared<NtAsyncNetworkTransaction>(AuDynamicCast<AuNet::DatagramServerImpl>(this->pParent_->ToParent()->ToServer()).get());
|
||||
#else
|
||||
auto pTransaction = AuMakeShared<LinuxAsyncNetworkTransaction>(AuDynamicCast<AuNet::DatagramServerImpl>(this->pParent_->ToParent()->ToServer()).get());
|
||||
#endif
|
||||
if (!pTransaction)
|
||||
{
|
||||
SysPushErrorMemory();
|
||||
@ -227,7 +231,7 @@ namespace Aurora::IO::Net
|
||||
if (this->pRecvProtocol)
|
||||
{
|
||||
AuStaticCast<AuIO::Protocol::ProtocolStack>(this->pRecvProtocol)->bOwnsSource = false;
|
||||
AuStaticCast<AuIO::Protocol::ProtocolStack>(this->pRecvProtocol)->pSourceBufer = {};
|
||||
AuStaticCast<AuIO::Protocol::ProtocolStack>(this->pRecvProtocol)->pSourceBufer.reset();
|
||||
}
|
||||
|
||||
this->pRecvProtocol = pRecvProtocol;
|
||||
|
@ -12,8 +12,7 @@ namespace Aurora::IO::Net
|
||||
NetDatagramSocketServerSession::NetDatagramSocketServerSession(AuSPtr<NetDatagramSocketServer> pParentServer) :
|
||||
pParentServer(pParentServer),
|
||||
emulator(this),
|
||||
channel(this),
|
||||
pDriver(pDriver)
|
||||
channel(this)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,6 @@ namespace Aurora::IO::TLS
|
||||
bool Precache();
|
||||
|
||||
mbedtls_x509_crt *pCertificate;
|
||||
mbedtls_x509_crt ownCertificate;
|
||||
mbedtls_x509_crt ownCertificate {};
|
||||
};
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
***/
|
||||
#pragma once
|
||||
|
||||
#include <Source/IO/IPC/IPCHandle.hpp>
|
||||
#include <Source/IO/IPC/AuIPCHandle.hpp>
|
||||
|
||||
namespace Aurora::IO::UNIX
|
||||
{
|
||||
|
@ -157,6 +157,8 @@ namespace Aurora::IO::UNIX
|
||||
}
|
||||
}
|
||||
|
||||
UNIX::SendIOBuffers();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -505,7 +507,6 @@ namespace Aurora::IO::UNIX
|
||||
int temp;
|
||||
int dwApcsSent {};
|
||||
|
||||
|
||||
auto io = GetTls();
|
||||
if (!io)
|
||||
{
|
||||
@ -516,7 +517,7 @@ namespace Aurora::IO::UNIX
|
||||
AuInt64 iTargetTime {};
|
||||
if (timeout)
|
||||
{
|
||||
iStartTime = AuTime::CurrentClockSteadyMS();
|
||||
iStartTime = AuTime::SteadyClockMS();
|
||||
iTargetTime = iStartTime + timeout;
|
||||
}
|
||||
|
||||
@ -531,7 +532,7 @@ namespace Aurora::IO::UNIX
|
||||
{
|
||||
if (timeout)
|
||||
{
|
||||
auto delta = iTargetTime - AuTime::CurrentClockSteadyMS();
|
||||
auto delta = iTargetTime - AuTime::SteadyClockMS();
|
||||
if (delta <= 0)
|
||||
{
|
||||
return dwApcsSent;
|
||||
@ -618,7 +619,7 @@ namespace Aurora::IO::UNIX
|
||||
AuInt64 iTargetTime {};
|
||||
if (timeout)
|
||||
{
|
||||
iStartTime = AuTime::CurrentClockSteadyMS();
|
||||
iStartTime = AuTime::SteadyClockMS();
|
||||
iTargetTime = iStartTime + timeout;
|
||||
}
|
||||
|
||||
@ -659,10 +660,11 @@ namespace Aurora::IO::UNIX
|
||||
{
|
||||
if (timeout)
|
||||
{
|
||||
auto delta = iTargetTime - AuTime::CurrentClockSteadyMS();
|
||||
auto delta = iTargetTime - AuTime::SteadyClockMS();
|
||||
if (delta <= 0)
|
||||
{
|
||||
return dwApcsSent;
|
||||
errno = EINTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
AuTime::ns2ts(&targetTime, delta);
|
||||
@ -771,7 +773,7 @@ namespace Aurora::IO::UNIX
|
||||
AuInt64 iTargetTime {};
|
||||
if (timeout)
|
||||
{
|
||||
iStartTime = AuTime::CurrentClockSteadyMS();
|
||||
iStartTime = AuTime::SteadyClockMS();
|
||||
iTargetTime = iStartTime + timeout;
|
||||
}
|
||||
|
||||
@ -827,10 +829,10 @@ namespace Aurora::IO::UNIX
|
||||
{
|
||||
if (timeout)
|
||||
{
|
||||
auto delta = iTargetTime - AuTime::CurrentClockSteadyMS();
|
||||
auto delta = iTargetTime - AuTime::SteadyClockMS();
|
||||
if (delta <= 0)
|
||||
{
|
||||
return dwApcsSent;
|
||||
return false;
|
||||
}
|
||||
|
||||
AuTime::ns2ts(&targetTime, delta);
|
||||
@ -945,6 +947,7 @@ namespace Aurora::IO::UNIX
|
||||
{
|
||||
io_event ioEvents[512];
|
||||
int temp;
|
||||
int iTicks {};
|
||||
timespec targetTime {};
|
||||
auto io = GetTls();
|
||||
|
||||
@ -990,6 +993,7 @@ namespace Aurora::IO::UNIX
|
||||
}
|
||||
|
||||
handle->LIOS_SendProcess(bytesTransacted, bError, errNo);
|
||||
iTicks++;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1018,6 +1022,6 @@ namespace Aurora::IO::UNIX
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return iTicks;
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
|
||||
namespace Aurora::Memory::Cache
|
||||
{
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
struct WIN32_MEMORY_RANGE_ENTRY2 {
|
||||
PVOID VirtualAddress;
|
||||
SIZE_T NumberOfBytes;
|
||||
@ -36,6 +37,7 @@ namespace Aurora::Memory::Cache
|
||||
WIN32_MEMORY_RANGE_ENTRY2* VirtualAddresses,
|
||||
ULONG Flags
|
||||
);
|
||||
#endif
|
||||
|
||||
AUKN_SYM void OptimizeAddressRangeOnCore(const AuList<AuPair<AuUInt, AuUInt>> &addressRanges)
|
||||
{
|
||||
|
@ -106,4 +106,24 @@ namespace Aurora::Process
|
||||
uAddressOut = uFoundAddress;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProcessSectionAllocations::IsAddressValid(AuUInt uOffset)
|
||||
{
|
||||
if (AuUInt(-1) == uOffset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
AU_LOCK_GUARD(this->spinlock);
|
||||
|
||||
for (const auto & [uCmpOffset, uCmpLength] : this->allocations)
|
||||
{
|
||||
if ((uOffset >= uCmpOffset) &&
|
||||
(uOffset <= (uCmpOffset + uCmpOffset)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -17,5 +17,6 @@ namespace Aurora::Process
|
||||
|
||||
bool GetAddress(AuUInt uOffset, AuUInt uLength, AuUInt &uAddressOut, bool &bCompleteBlock);
|
||||
void ReleaseAddress(AuUInt uOffset);
|
||||
bool IsAddressValid(AuUInt uOffset);
|
||||
};
|
||||
}
|
@ -7,6 +7,7 @@
|
||||
***/
|
||||
#include <Source/RuntimeInternal.hpp>
|
||||
#include "ProcessSectionFileMapView.Unix.hpp"
|
||||
#include "ProcessSectionViewReserved.Unix.hpp"
|
||||
#include "ProcessSectionView.Unix.hpp"
|
||||
#include <sys/mman.h>
|
||||
|
||||
@ -33,9 +34,25 @@ namespace Aurora::Process
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->uAddress && this->bShouldUnmap_)
|
||||
if (this->uAddress)
|
||||
{
|
||||
::munmap(this->GetBasePointer(), this->uLength_);
|
||||
if (this->pSharedSectionHint)
|
||||
{
|
||||
AuStaticCast<ProcessSectionViewReserved>(this->pSharedSectionHint)->Release(this->uAddress);
|
||||
}
|
||||
|
||||
if (this->bShouldUnmap_)
|
||||
{
|
||||
::munmap(this->GetBasePointer(), this->uLength_);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!::mmap(this->GetBasePointer(), this->uLength_, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, 0, 0))
|
||||
{
|
||||
::mmap(this->GetBasePointer(), this->uLength_, PROT_READ /*coping*/, MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
this->uAddress = 0;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,8 @@ namespace Aurora::Process
|
||||
AuUInt8 *GetBasePointer() override;
|
||||
AuUInt8 *GetPointer(AuUInt offset) override;
|
||||
|
||||
AuSPtr<IProcessSectionView> pSharedSectionHint {};
|
||||
|
||||
private:
|
||||
AuUInt uAddress {};
|
||||
AuUInt uLength_ {};
|
||||
|
@ -38,7 +38,6 @@ namespace Aurora::Process
|
||||
|
||||
AuSPtr<IProcessSectionMapView> AllocateEx2(AuUInt uLength, AuUInt uOffset, PageTable permissions) override;
|
||||
|
||||
|
||||
AuSPtr<IProcessSectionMapView> MapFileByPathEx(AuUInt viewOffset,
|
||||
const AuString &str,
|
||||
AuUInt64 uOffset,
|
||||
|
@ -10,23 +10,23 @@
|
||||
#include "Process.hpp"
|
||||
#include <Source/IO/FS/FileStream.Unix.hpp>
|
||||
#include "ProcessSectionFileMapView.Unix.hpp"
|
||||
#include <Source/IO/IPC/IPCHandle.hpp>
|
||||
#include <Source/IO/IPC/IPCMemory.Unix.hpp>
|
||||
#include <Source/IO/IPC/AuIPCHandle.hpp>
|
||||
#include <Source/IO/IPC/AuIPCMemory.Unix.hpp>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
namespace Aurora::Process
|
||||
{
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionView::Allocate(AuUInt length)
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionView::Allocate(AuUInt uLength)
|
||||
{
|
||||
if (!length)
|
||||
if (!uLength)
|
||||
{
|
||||
SysPushErrorArg("invalid length");
|
||||
SysPushErrorArg("invalid uLength");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto map = ::mmap(nullptr, length, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
|
||||
auto map = ::mmap(nullptr, uLength, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
|
||||
if (map == MAP_FAILED)
|
||||
{
|
||||
SysPushErrorIO();
|
||||
@ -34,12 +34,12 @@ namespace Aurora::Process
|
||||
}
|
||||
|
||||
auto newObject = AuMakeShared<ProcessSectionFileMapView>(AuUInt(map),
|
||||
length,
|
||||
uLength,
|
||||
false);
|
||||
if (!newObject)
|
||||
{
|
||||
SysPushErrorMem();
|
||||
::munmap(map, length);
|
||||
::munmap(map, uLength);
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -47,33 +47,116 @@ namespace Aurora::Process
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionView::MapFileByPath(const AuString &str,
|
||||
AuUInt64 offset,
|
||||
AuUInt length,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
AuFS::EFileOpenMode mode,
|
||||
AuFS::EFileAdvisoryLockLevel sectionLock)
|
||||
{
|
||||
auto file = AuFS::OpenShared(str, mode, AuFS::EFileAdvisoryLockLevel::eNoSafety);
|
||||
return file ? this->MapFileByObject(file, offset, length, mode, sectionLock) : AuSPtr<IProcessSectionMapView> {};
|
||||
return file ? this->MapFileByObject(file, uOffset, uLength, mode, sectionLock) : AuSPtr<IProcessSectionMapView> {};
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionView::MapFileByObject(const AuSPtr<AuFS::IFileStream> &stream,
|
||||
AuUInt64 offset,
|
||||
AuUInt length,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
AuFS::EFileOpenMode mode,
|
||||
AuFS::EFileAdvisoryLockLevel processLockLevel)
|
||||
{
|
||||
if (!stream)
|
||||
return this->MapFileByObjectEx(0, stream, uOffset, uLength, mode, processLockLevel);
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionView::MapIPCMemory(const AuString &handleString,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
AuFS::EFileOpenMode mode)
|
||||
{
|
||||
return this->MapIPCMemoryEx(0, handleString, uOffset, uLength, mode);
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionView::AllocateEx(AuUInt uLength, AuUInt uOffset)
|
||||
{
|
||||
PageTable table {};
|
||||
table.NX = true;
|
||||
table.readable = true;
|
||||
table.writable = true;
|
||||
return this->AllocateEx2(uLength, uOffset, table);
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionView::AllocateEx2(AuUInt uLength, AuUInt uOffset, PageTable permissions)
|
||||
{
|
||||
if (!uLength)
|
||||
{
|
||||
SysPushErrorArg("invalid uLength");
|
||||
return {};
|
||||
}
|
||||
|
||||
AuUInt32 uProtFlags {};
|
||||
|
||||
if (!permissions.NX)
|
||||
{
|
||||
uProtFlags |= PROT_EXEC;
|
||||
}
|
||||
|
||||
if (permissions.writable)
|
||||
{
|
||||
uProtFlags |= PROT_WRITE;
|
||||
}
|
||||
|
||||
if (permissions.readable)
|
||||
{
|
||||
uProtFlags |= PROT_READ;
|
||||
}
|
||||
|
||||
auto map = ::mmap((void *)uOffset, uLength, uProtFlags, MAP_ANONYMOUS | MAP_PRIVATE | (uOffset ? MAP_FIXED : 0), 0, 0);
|
||||
if (map == MAP_FAILED)
|
||||
{
|
||||
SysPushErrorIO();
|
||||
return {};
|
||||
}
|
||||
|
||||
auto newObject = AuMakeShared<ProcessSectionFileMapView>(AuUInt(map),
|
||||
uLength,
|
||||
false);
|
||||
if (!newObject)
|
||||
{
|
||||
SysPushErrorMem();
|
||||
::munmap(map, uLength);
|
||||
return {};
|
||||
}
|
||||
|
||||
return newObject;
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionView::MapFileByPathEx(AuUInt viewOffset,
|
||||
const AuString &str,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
Aurora::IO::FS::EFileOpenMode mode,
|
||||
Aurora::IO::FS::EFileAdvisoryLockLevel processLockLevel)
|
||||
{
|
||||
auto file = AuFS::OpenShared(str, mode, AuFS::EFileAdvisoryLockLevel::eNoSafety);
|
||||
return file ? this->MapFileByObjectEx(viewOffset, file, uOffset, uLength, mode, processLockLevel) : AuSPtr<IProcessSectionMapView> {};
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionView::MapFileByObjectEx(AuUInt viewOffset,
|
||||
const AuSPtr<Aurora::IO::FS::IFileStream> &pStream,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
Aurora::IO::FS::EFileOpenMode mode,
|
||||
Aurora::IO::FS::EFileAdvisoryLockLevel processLockLevel)
|
||||
{
|
||||
if (!pStream)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!length)
|
||||
if (!uLength)
|
||||
{
|
||||
SysPushErrorArg("invalid length");
|
||||
SysPushErrorArg("invalid uLength");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto ok = AuStaticCast<AuFS::PosixFileStream>(stream);
|
||||
auto ok = AuStaticCast<AuFS::PosixFileStream>(pStream);
|
||||
int fd = ::dup(ok->GetHandle());
|
||||
if (fd == -1)
|
||||
{
|
||||
@ -102,7 +185,7 @@ namespace Aurora::Process
|
||||
return {};
|
||||
};
|
||||
|
||||
auto map = ::mmap(nullptr, length, prot, MAP_SHARED, fd, offset);
|
||||
auto map = ::mmap((void *)viewOffset, uLength, prot, MAP_SHARED | (viewOffset ? MAP_FIXED : 0), fd, uOffset);
|
||||
if (map == MAP_FAILED)
|
||||
{
|
||||
SysPushErrorIO();
|
||||
@ -111,30 +194,31 @@ namespace Aurora::Process
|
||||
}
|
||||
|
||||
auto newObject = AuMakeShared<ProcessSectionFileMapView>(AuUInt(map),
|
||||
length,
|
||||
uLength,
|
||||
true,
|
||||
fd);
|
||||
if (!newObject)
|
||||
{
|
||||
SysPushErrorMem();
|
||||
::close(fd);
|
||||
::munmap(map, length);
|
||||
::munmap(map, uLength);
|
||||
return {};
|
||||
}
|
||||
|
||||
return newObject;
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionView::MapIPCMemory(const AuString &handleString,
|
||||
AuUInt64 offset,
|
||||
AuUInt length,
|
||||
AuFS::EFileOpenMode mode)
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionView::MapIPCMemoryEx(AuUInt viewOffset,
|
||||
const AuString &handleString,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
Aurora::IO::FS::EFileOpenMode mode)
|
||||
{
|
||||
AuIPC::IPCHandle handle;
|
||||
|
||||
if (!length)
|
||||
if (!uLength)
|
||||
{
|
||||
SysPushErrorArg("invalid length");
|
||||
SysPushErrorArg("invalid uLength");
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -154,7 +238,7 @@ namespace Aurora::Process
|
||||
auto actualLength = val->token.word;
|
||||
auto path = AuIPC::GetServerPath(val->token);
|
||||
|
||||
if (actualLength < offset + length)
|
||||
if (actualLength < uOffset + uLength)
|
||||
{
|
||||
SysPushErrorIO("Out of range");
|
||||
return {};
|
||||
@ -188,7 +272,7 @@ namespace Aurora::Process
|
||||
return {};
|
||||
};
|
||||
|
||||
auto map = ::mmap(nullptr, length, prot, MAP_SHARED, fd, offset);
|
||||
auto map = ::mmap((void *)viewOffset, uLength, prot, MAP_SHARED | (viewOffset ? MAP_FIXED : 0), fd, uOffset);
|
||||
if (map == MAP_FAILED)
|
||||
{
|
||||
SysPushErrorIO();
|
||||
@ -197,7 +281,7 @@ namespace Aurora::Process
|
||||
}
|
||||
|
||||
auto newObject = AuMakeShared<ProcessSectionFileMapView>(AuUInt(map),
|
||||
length,
|
||||
uLength,
|
||||
true,
|
||||
fd);
|
||||
if (!newObject)
|
||||
@ -211,6 +295,12 @@ namespace Aurora::Process
|
||||
return newObject;
|
||||
}
|
||||
|
||||
AuList<AuPair<AuUInt, AuUInt>> ProcessSectionView::GetAllocations()
|
||||
{
|
||||
AU_LOCK_GUARD(this->spinlock);
|
||||
return allocations;
|
||||
}
|
||||
|
||||
AUKN_SYM AuSPtr<IProcessSectionView> GetGlobalProcessSpace()
|
||||
{
|
||||
static ProcessSectionView gSingleton;
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace Aurora::Process
|
||||
{
|
||||
struct ProcessSectionView : IProcessSectionView
|
||||
struct ProcessSectionView : IProcessSectionView, AuEnableSharedFromThis<ProcessSectionView>
|
||||
{
|
||||
AuSPtr<IProcessSectionMapView> Allocate(AuUInt length) override;
|
||||
|
||||
@ -30,5 +30,36 @@ namespace Aurora::Process
|
||||
AuUInt length,
|
||||
AuFS::EFileOpenMode mode) override;
|
||||
|
||||
AuSPtr<IProcessSectionMapView> AllocateEx(AuUInt uLength, AuUInt uOffset) override;
|
||||
|
||||
AuSPtr<IProcessSectionMapView> AllocateEx2(AuUInt uLength, AuUInt uOffset, PageTable permissions) override;
|
||||
|
||||
AuSPtr<IProcessSectionMapView> MapFileByPathEx(AuUInt viewOffset,
|
||||
const AuString &str,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
Aurora::IO::FS::EFileOpenMode mode,
|
||||
Aurora::IO::FS::EFileAdvisoryLockLevel processLockLevel) override;
|
||||
|
||||
AuSPtr<IProcessSectionMapView> MapFileByObjectEx(AuUInt viewOffset,
|
||||
const AuSPtr<Aurora::IO::FS::IFileStream> &pStream,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
Aurora::IO::FS::EFileOpenMode mode,
|
||||
Aurora::IO::FS::EFileAdvisoryLockLevel processLockLevel) override;
|
||||
|
||||
AuSPtr<IProcessSectionMapView> MapIPCMemoryEx(AuUInt viewOffset,
|
||||
const AuString &handle,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
Aurora::IO::FS::EFileOpenMode mode) override;
|
||||
|
||||
AuList<AuPair<AuUInt, AuUInt>> GetAllocations() override;
|
||||
|
||||
AuThreadPrimitives::SpinLock spinlock;
|
||||
AuList<AuPair<AuUInt, AuUInt>> allocations;
|
||||
void *MapAddress(AuUInt uOffset, AuUInt uLength,
|
||||
AuUInt prot, AuUInt share, int fd, AuUInt offset);
|
||||
|
||||
};
|
||||
}
|
367
Source/Process/ProcessSectionViewReserved.Unix.cpp
Executable file
367
Source/Process/ProcessSectionViewReserved.Unix.cpp
Executable file
@ -0,0 +1,367 @@
|
||||
/***
|
||||
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: ProcessSectionViewReserved.Unix.cpp
|
||||
Date: 2022-11-15
|
||||
Author: Reece
|
||||
***/
|
||||
#include <Source/RuntimeInternal.hpp>
|
||||
#include "ProcessSectionViewReserved.Unix.hpp"
|
||||
#include "Process.hpp"
|
||||
#include <Source/IO/FS/FileStream.Unix.hpp>
|
||||
#include "ProcessSectionFileMapView.Unix.hpp"
|
||||
#include <Source/IO/IPC/AuIPCHandle.hpp>
|
||||
#include <Source/IO/IPC/AuIPCMemory.Unix.hpp>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
namespace Aurora::Process
|
||||
{
|
||||
ProcessSectionViewReserved::~ProcessSectionViewReserved()
|
||||
{
|
||||
if (this->pBaseAddress)
|
||||
{
|
||||
::munmap(this->pBaseAddress, this->uMaxLength);
|
||||
}
|
||||
}
|
||||
|
||||
bool ProcessSectionViewReserved::Init(AuUInt uLength)
|
||||
{
|
||||
this->uMaxLength = uLength;
|
||||
|
||||
if (!(this->pBaseAddress = (char *)::mmap(0, uLength, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0)))
|
||||
{
|
||||
this->pBaseAddress = (char *)::mmap(0, uLength, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
|
||||
}
|
||||
|
||||
return bool(this->pBaseAddress);
|
||||
}
|
||||
|
||||
void ProcessSectionViewReserved::Release(AuUInt address)
|
||||
{
|
||||
auto uOffset = address - (AuUInt)this->pBaseAddress;
|
||||
this->ReleaseAddress(uOffset);
|
||||
}
|
||||
|
||||
void *ProcessSectionViewReserved::MapAddress(AuUInt uOffset, AuUInt uLength,
|
||||
AuUInt prot, AuUInt share, int fd, AuUInt offset)
|
||||
{
|
||||
bool bCompleteBlock {};
|
||||
AuUInt uFoundOffset {};
|
||||
|
||||
if (!this->GetAddress(uOffset, uLength, uFoundOffset, bCompleteBlock))
|
||||
{
|
||||
SysPushErrorMemory("Reserved address space has no available space");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto pRet = ::mmap(this->pBaseAddress + uFoundOffset,
|
||||
uLength,
|
||||
prot,
|
||||
share | MAP_FIXED,
|
||||
fd,
|
||||
offset);
|
||||
|
||||
if (!pRet)
|
||||
{
|
||||
SysPushErrorMemory("mmap failed");
|
||||
ReleaseAddress(uFoundOffset);
|
||||
return {};
|
||||
}
|
||||
|
||||
return pRet;
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::Allocate(AuUInt uLength)
|
||||
{
|
||||
return this->AllocateEx(uLength, -1);
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapFileByPath(const AuString &str,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
AuFS::EFileOpenMode mode,
|
||||
AuFS::EFileAdvisoryLockLevel sectionLock)
|
||||
{
|
||||
auto file = AuFS::OpenShared(str, mode, AuFS::EFileAdvisoryLockLevel::eNoSafety);
|
||||
return file ? this->MapFileByObject(file, uOffset, uLength, mode, sectionLock) : AuSPtr<IProcessSectionMapView> {};
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapFileByObject(const AuSPtr<AuFS::IFileStream> &stream,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
AuFS::EFileOpenMode mode,
|
||||
AuFS::EFileAdvisoryLockLevel processLockLevel)
|
||||
{
|
||||
return this->MapFileByObjectEx(-1, stream, uOffset, uLength, mode, processLockLevel);
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapIPCMemory(const AuString &handleString,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
AuFS::EFileOpenMode mode)
|
||||
{
|
||||
return this->MapIPCMemoryEx(-1, handleString, uOffset, uLength, mode);
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::AllocateEx(AuUInt uLength, AuUInt uOffset)
|
||||
{
|
||||
PageTable table {};
|
||||
table.NX = true;
|
||||
table.readable = true;
|
||||
table.writable = true;
|
||||
return this->AllocateEx2(uLength, uOffset, table);
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::AllocateEx2(AuUInt uLength, AuUInt uOffset, PageTable permissions)
|
||||
{
|
||||
if (!uLength)
|
||||
{
|
||||
SysPushErrorArg("invalid uLength");
|
||||
return {};
|
||||
}
|
||||
|
||||
AuUInt32 uProtFlags {};
|
||||
|
||||
if (!permissions.NX)
|
||||
{
|
||||
uProtFlags |= PROT_EXEC;
|
||||
}
|
||||
|
||||
if (permissions.writable)
|
||||
{
|
||||
uProtFlags |= PROT_WRITE;
|
||||
}
|
||||
|
||||
if (permissions.readable)
|
||||
{
|
||||
uProtFlags |= PROT_READ;
|
||||
}
|
||||
|
||||
auto map = this->MapAddress(uOffset, uLength, uProtFlags, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
|
||||
if (map == MAP_FAILED)
|
||||
{
|
||||
SysPushErrorIO();
|
||||
return {};
|
||||
}
|
||||
|
||||
auto pNewObject = AuMakeShared<ProcessSectionFileMapView>(AuUInt(map),
|
||||
uLength,
|
||||
false);
|
||||
if (!pNewObject)
|
||||
{
|
||||
SysPushErrorMem();
|
||||
return {};
|
||||
}
|
||||
|
||||
pNewObject->pSharedSectionHint = AuSharedFromThis();
|
||||
return pNewObject;
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapFileByPathEx(AuUInt viewOffset,
|
||||
const AuString &str,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
Aurora::IO::FS::EFileOpenMode mode,
|
||||
Aurora::IO::FS::EFileAdvisoryLockLevel processLockLevel)
|
||||
{
|
||||
auto file = AuFS::OpenShared(str, mode, AuFS::EFileAdvisoryLockLevel::eNoSafety);
|
||||
return file ? this->MapFileByObjectEx(viewOffset, file, uOffset, uLength, mode, processLockLevel) : AuSPtr<IProcessSectionMapView> {};
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapFileByObjectEx(AuUInt viewOffset,
|
||||
const AuSPtr<Aurora::IO::FS::IFileStream> &pStream,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
Aurora::IO::FS::EFileOpenMode mode,
|
||||
Aurora::IO::FS::EFileAdvisoryLockLevel processLockLevel)
|
||||
{
|
||||
if (!pStream)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!uLength)
|
||||
{
|
||||
SysPushErrorArg("invalid uLength");
|
||||
return {};
|
||||
}
|
||||
|
||||
if (this->IsAddressValid(viewOffset))
|
||||
{
|
||||
SysPushErrorMemory("Address space is in use");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto ok = AuStaticCast<AuFS::PosixFileStream>(pStream);
|
||||
int fd = ::dup(ok->GetHandle());
|
||||
if (fd == -1)
|
||||
{
|
||||
SysPushErrorIO();
|
||||
return {};
|
||||
}
|
||||
|
||||
// TODO (Reece): lock garbage
|
||||
|
||||
int prot {};
|
||||
switch (mode)
|
||||
{
|
||||
case AuFS::EFileOpenMode::eRead:
|
||||
{
|
||||
prot = PROT_READ;
|
||||
break;
|
||||
}
|
||||
case AuFS::EFileOpenMode::eWrite:
|
||||
case AuFS::EFileOpenMode::eReadWrite:
|
||||
{
|
||||
prot = PROT_READ | PROT_WRITE;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
SysPushErrorGeneric();
|
||||
return {};
|
||||
};
|
||||
|
||||
auto map = this->MapAddress(viewOffset, uLength, prot, MAP_SHARED, fd, uOffset);
|
||||
if (map == MAP_FAILED)
|
||||
{
|
||||
SysPushErrorIO();
|
||||
::close(fd);
|
||||
return {};
|
||||
}
|
||||
|
||||
auto pNewObject = AuMakeShared<ProcessSectionFileMapView>(AuUInt(map),
|
||||
uLength,
|
||||
false,
|
||||
fd);
|
||||
if (!pNewObject)
|
||||
{
|
||||
SysPushErrorMem();
|
||||
::close(fd);
|
||||
return {};
|
||||
}
|
||||
|
||||
pNewObject->pSharedSectionHint = AuSharedFromThis();
|
||||
return pNewObject;
|
||||
}
|
||||
|
||||
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapIPCMemoryEx(AuUInt viewOffset,
|
||||
const AuString &handleString,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
Aurora::IO::FS::EFileOpenMode mode)
|
||||
{
|
||||
AuIPC::IPCHandle handle;
|
||||
|
||||
if (!uLength)
|
||||
{
|
||||
SysPushErrorArg("invalid uLength");
|
||||
return {};
|
||||
}
|
||||
|
||||
if (this->IsAddressValid(viewOffset))
|
||||
{
|
||||
SysPushErrorMemory("Address space is in use");
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!handle.FromString(handleString))
|
||||
{
|
||||
SysPushErrorParseError("Invalid handle: {}", handleString);
|
||||
return {};
|
||||
}
|
||||
|
||||
auto val = handle.GetToken(AuIPC::EIPCHandleType::eIPCMemory, 0);
|
||||
if (!val)
|
||||
{
|
||||
SysPushErrorParseError("Invalid handle: {}", handleString);
|
||||
return {};
|
||||
}
|
||||
|
||||
auto actualLength = val->token.word;
|
||||
auto path = AuIPC::GetServerPath(val->token);
|
||||
|
||||
if (actualLength < uOffset + uLength)
|
||||
{
|
||||
SysPushErrorIO("Out of range");
|
||||
return {};
|
||||
}
|
||||
|
||||
int fd = ::shm_open(path.c_str(), O_RDWR, S_IRUSR | S_IWUSR);
|
||||
if (fd == -1)
|
||||
{
|
||||
SysPushErrorIO();
|
||||
return {};
|
||||
}
|
||||
|
||||
// TODO (Reece): lock garbage ( ??? )
|
||||
|
||||
int prot {};
|
||||
switch (mode)
|
||||
{
|
||||
case AuFS::EFileOpenMode::eRead:
|
||||
{
|
||||
prot = PROT_READ;
|
||||
break;
|
||||
}
|
||||
case AuFS::EFileOpenMode::eWrite:
|
||||
case AuFS::EFileOpenMode::eReadWrite:
|
||||
{
|
||||
prot = PROT_READ | PROT_WRITE;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
SysPushErrorGeneric();
|
||||
return {};
|
||||
};
|
||||
|
||||
auto map = this->MapAddress(viewOffset, uLength, prot, MAP_SHARED, fd, uOffset);
|
||||
if (map == MAP_FAILED)
|
||||
{
|
||||
SysPushErrorIO();
|
||||
::close(fd);
|
||||
return {};
|
||||
}
|
||||
|
||||
auto pNewObject = AuMakeShared<ProcessSectionFileMapView>(AuUInt(map),
|
||||
uLength,
|
||||
false,
|
||||
fd);
|
||||
if (!pNewObject)
|
||||
{
|
||||
SysPushErrorMem();
|
||||
::close(fd);
|
||||
return {};
|
||||
}
|
||||
|
||||
pNewObject->pSharedSectionHint = AuSharedFromThis();
|
||||
return pNewObject;
|
||||
}
|
||||
|
||||
AuList<AuPair<AuUInt, AuUInt>> ProcessSectionViewReserved::GetAllocations()
|
||||
{
|
||||
AU_LOCK_GUARD(this->spinlock);
|
||||
return this->allocations;
|
||||
}
|
||||
|
||||
AUKN_SYM AuSPtr<IProcessSectionView> ReserveAddressSpace(AuUInt uLength)
|
||||
{
|
||||
auto &platform = AuSwInfo::GetPlatformInfo();
|
||||
|
||||
auto pSectionView = AuMakeShared<ProcessSectionViewReserved>();
|
||||
if (!pSectionView)
|
||||
{
|
||||
SysPushErrorMemory();
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!pSectionView->Init(uLength))
|
||||
{
|
||||
SysPushErrorMemory();
|
||||
return {};
|
||||
}
|
||||
|
||||
return pSectionView;
|
||||
}
|
||||
}
|
71
Source/Process/ProcessSectionViewReserved.Unix.hpp
Executable file
71
Source/Process/ProcessSectionViewReserved.Unix.hpp
Executable file
@ -0,0 +1,71 @@
|
||||
/***
|
||||
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: ProcessSectionViewReserved.Unix.hpp
|
||||
Date: 2022-11-15
|
||||
Author: Reece
|
||||
***/
|
||||
#pragma once
|
||||
|
||||
#include "ProcessSectionAllocations.hpp"
|
||||
|
||||
namespace Aurora::Process
|
||||
{
|
||||
struct ProcessSectionViewReserved : IProcessSectionView, ProcessSectionAllocations, AuEnableSharedFromThis<ProcessSectionViewReserved>
|
||||
{
|
||||
~ProcessSectionViewReserved();
|
||||
bool Init(AuUInt uLength);
|
||||
|
||||
char *pBaseAddress {};
|
||||
|
||||
AuSPtr<IProcessSectionMapView> Allocate(AuUInt length) override;
|
||||
|
||||
AuSPtr<IProcessSectionMapView> MapFileByPath(const AuString &str,
|
||||
AuUInt64 offset,
|
||||
AuUInt length,
|
||||
AuFS::EFileOpenMode mode,
|
||||
AuFS::EFileAdvisoryLockLevel sectionLock) override;
|
||||
|
||||
AuSPtr<IProcessSectionMapView> MapFileByObject(const AuSPtr<Aurora::IO::FS::IFileStream> &stream,
|
||||
AuUInt64 offset,
|
||||
AuUInt length,
|
||||
Aurora::IO::FS::EFileOpenMode mode,
|
||||
AuFS::EFileAdvisoryLockLevel processLockLevel) override;
|
||||
|
||||
AuSPtr<IProcessSectionMapView> MapIPCMemory(const AuString &handle,
|
||||
AuUInt64 offset,
|
||||
AuUInt length,
|
||||
AuFS::EFileOpenMode mode) override;
|
||||
|
||||
AuSPtr<IProcessSectionMapView> AllocateEx(AuUInt uLength, AuUInt uOffset) override;
|
||||
|
||||
AuSPtr<IProcessSectionMapView> AllocateEx2(AuUInt uLength, AuUInt uOffset, PageTable permissions) override;
|
||||
|
||||
AuSPtr<IProcessSectionMapView> MapFileByPathEx(AuUInt viewOffset,
|
||||
const AuString &str,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
Aurora::IO::FS::EFileOpenMode mode,
|
||||
Aurora::IO::FS::EFileAdvisoryLockLevel processLockLevel) override;
|
||||
|
||||
AuSPtr<IProcessSectionMapView> MapFileByObjectEx(AuUInt viewOffset,
|
||||
const AuSPtr<Aurora::IO::FS::IFileStream> &pStream,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
Aurora::IO::FS::EFileOpenMode mode,
|
||||
Aurora::IO::FS::EFileAdvisoryLockLevel processLockLevel) override;
|
||||
|
||||
AuSPtr<IProcessSectionMapView> MapIPCMemoryEx(AuUInt viewOffset,
|
||||
const AuString &handle,
|
||||
AuUInt64 uOffset,
|
||||
AuUInt uLength,
|
||||
Aurora::IO::FS::EFileOpenMode mode) override;
|
||||
|
||||
AuList<AuPair<AuUInt, AuUInt>> GetAllocations() override;
|
||||
|
||||
void *MapAddress(AuUInt uOffset, AuUInt uLength,
|
||||
AuUInt prot, AuUInt share, int fd, AuUInt offset);
|
||||
void Release(AuUInt address);
|
||||
|
||||
};
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
/***
|
||||
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: Process.Unix.cpp
|
||||
File: AuProcess.Unix.cpp
|
||||
File: Process.Linux.cpp
|
||||
Date: 2021-6-12
|
||||
Author: Reece
|
||||
***/
|
||||
#include <RuntimeInternal.hpp>
|
||||
#include "Processes.hpp"
|
||||
#include "Process.Unix.hpp"
|
||||
#include "AuProcesses.hpp"
|
||||
#include "AuProcess.Unix.hpp"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
@ -16,7 +16,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <Source/Threading/Primitives/Semaphore.Unix.hpp>
|
||||
#include <Source/Threading/Primitives/AuSemaphore.Unix.hpp>
|
||||
|
||||
#if defined(AURORA_IS_LINUX_DERIVED)
|
||||
#include <sys/prctl.h>
|
||||
|
@ -14,7 +14,7 @@
|
||||
#endif
|
||||
|
||||
#if defined(AURORA_IS_POSIX_DERIVED)
|
||||
#include "Process.Unix.hpp"
|
||||
#include "AuProcess.Unix.hpp"
|
||||
#endif
|
||||
|
||||
namespace Aurora::Processes
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#if defined(AURORA_IS_POSIX_DERIVED)
|
||||
#include <cstdio>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#include "AuWELL.hpp"
|
||||
@ -169,7 +170,7 @@ namespace Aurora::RNG
|
||||
return x;
|
||||
}
|
||||
#elif defined(AURORA_IS_POSIX_DERIVED)
|
||||
x = RngUnix(out, uBytes);
|
||||
x = RngUnix(pBuffer, uBytes);
|
||||
if (x != 0)
|
||||
{
|
||||
return x;
|
||||
|
@ -1,12 +1,12 @@
|
||||
/***
|
||||
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: ConditionMutex.Unix.cpp
|
||||
File: AuConditionMutex.Unix.cpp
|
||||
Date: 2021-6-12
|
||||
Author: Reece
|
||||
***/
|
||||
#include <Source/RuntimeInternal.hpp>
|
||||
#include "ConditionMutex.Generic.hpp"
|
||||
#include "AuConditionMutex.Generic.hpp"
|
||||
|
||||
#if !defined(_AURUNTIME_GENERICCM)
|
||||
#include <Source/Time/Time.hpp>
|
||||
|
@ -1,14 +1,14 @@
|
||||
/***
|
||||
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: ConditionMutex.Unix.hpp
|
||||
File: AuConditionMutex.Unix.hpp
|
||||
Date: 2021-6-12
|
||||
Author: Reece
|
||||
***/
|
||||
#pragma once
|
||||
|
||||
#include "IConditionMutexEx.hpp"
|
||||
#include "Mutex.Generic.hpp"
|
||||
#include "AuIConditionMutexEx.hpp"
|
||||
#include "AuMutex.Generic.hpp"
|
||||
|
||||
namespace Aurora::Threading::Primitives
|
||||
{
|
||||
|
@ -168,7 +168,7 @@ namespace Aurora::Time
|
||||
{
|
||||
#if defined(AURORA_IS_POSIX_DERIVED)
|
||||
::timespec spec {};
|
||||
if (::clock_getclock(CLOCK_MONOTONIC, &spec) == 0)
|
||||
if (::clock_gettime(CLOCK_MONOTONIC, &spec) == 0)
|
||||
{
|
||||
return AuSToMS<AuUInt64>(spec.tv_sec) + AuNSToMS<AuUInt64>(spec.tv_nsec);
|
||||
}
|
||||
@ -185,7 +185,7 @@ namespace Aurora::Time
|
||||
{
|
||||
#if defined(AURORA_IS_POSIX_DERIVED)
|
||||
::timespec spec {};
|
||||
if (::clock_getclock(CLOCK_MONOTONIC, &spec) == 0)
|
||||
if (::clock_gettime(CLOCK_MONOTONIC, &spec) == 0)
|
||||
{
|
||||
return AuMSToNS<AuUInt64>(AuSToMS<AuUInt64>(spec.tv_sec)) + (AuUInt64)spec.tv_nsec;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user