[*] NT regression and fixes

This commit is contained in:
Reece Wilson 2022-04-15 19:20:12 +01:00
parent 9f2ff9de19
commit 7a0d9701b5
7 changed files with 70 additions and 60 deletions

View File

@ -28,7 +28,6 @@ namespace Aurora::Compression
bool Init(const AuSPtr<IO::IStreamReader> &reader)
{
size_t ret;
this->reader_ = reader;
this->dctx_ = ZSTD_createDCtx();

View File

@ -55,18 +55,18 @@ namespace Aurora::IO::FS
bool Wait(AuUInt32 timeout) override;
AuSPtr<Loop::ILoopSource> NewLoopSource() override;
void DispatchCb();
void DispatchCb(AuUInt32 len);
HANDLE GetHandle();
AuSPtr<FileHandle> GetFileHandle();
// Required for a very evil hack
OVERLAPPED overlap_ {};
HANDLE event_ = INVALID_HANDLE_VALUE;
AuSPtr<NtAsyncFileTransaction> pin_;
AuUInt32 lastAbstractStat_ {}, lastAbstractOffset_ {};
private:
AuSPtr<void> memoryHold_;
AuSPtr<FileHandle> handle_;
HANDLE event_ = INVALID_HANDLE_VALUE;
AuUInt32 lastAbstractStat_ {}, lastAbstractOffset_ {};
bool latch_ {};
AuSPtr<IAsyncFinishedSubscriber> sub_;
};
@ -97,7 +97,7 @@ namespace Aurora::IO::FS
bool NtAsyncFileTransactionLoopSource::IsSignaled()
{
auto lock = caller_.lock();
if (!lock) return LSEvent::IsSignaled();
if (!lock) return LSHandle::IsSignaled();
return lock->Complete();
}
@ -193,7 +193,7 @@ namespace Aurora::IO::FS
bool NtAsyncFileTransaction::Init(const AuSPtr<FileHandle> &handle)
{
this->handle_ = handle;
this->overlap_.hEvent = this->event_ = CreateEvent(NULL, true, 0, NULL);
this->overlap_.hEvent = this->event_ = CreateEventW(nullptr, true, false, nullptr);
return this->overlap_.hEvent != INVALID_HANDLE_VALUE;
}
@ -204,15 +204,15 @@ namespace Aurora::IO::FS
{
if (val)
{
that->DispatchCb();
that->pin_.reset();
SetEvent(that->event_);
that->DispatchCb(that->lastAbstractStat_);
}
return true;
}
else
{
that->pin_.reset();
SysPushErrorFIO("Async FIO error: {}", that->GetFileHandle()->path);
SysPushErrorFIO("Async FIO error: {} {}", that->GetFileHandle()->path, GetLastError());
return false;
}
}
@ -235,7 +235,7 @@ namespace Aurora::IO::FS
}
this->latch_ = false;
::ResetEvent(this->this->event_);
::ResetEvent(this->event_);
this->memoryHold_ = memoryView;
@ -257,7 +257,7 @@ namespace Aurora::IO::FS
}
this->latch_ = false;
::ResetEvent(this->this->event_);
::ResetEvent(this->event_);
this->memoryHold_ = memoryView;
@ -270,32 +270,37 @@ namespace Aurora::IO::FS
return TranslateNtStatus(this, ret);
}
void NtAsyncFileTransaction::DispatchCb()
void NtAsyncFileTransaction::DispatchCb(AuUInt32 read)
{
if (AuExchange(this->latch_, true))
{
return;
}
this->memoryHold_.reset();
auto hold = AuExchange(this->pin_, {});
if (hold->sub_)
if (this->sub_)
{
DWORD read {};
GetOverlappedResult(hold->handle_->handle, &hold->overlap_, &read, false);
hold->sub_->OnAsyncFileOpFinished(hold->lastAbstractOffset_, read);
this->sub_->OnAsyncFileOpFinished(this->lastAbstractOffset_, read);
}
this->memoryHold_.reset();
}
bool NtAsyncFileTransaction::Complete()
{
auto ret = WaitForSingleObjectEx(this->event_, 0, true);
if (ret == WAIT_OBJECT_0)
DWORD read;
if (this->latch_)
{
DispatchCb();
return true;
}
if (GetOverlappedResult(this->handle_->handle, &this->overlap_, &read, false))
{
auto hold = AuExchange(this->pin_, {});
hold->DispatchCb(read);
return true;
}
return false;
}
@ -313,11 +318,15 @@ namespace Aurora::IO::FS
bool NtAsyncFileTransaction::Wait(AuUInt32 timeout)
{
if (this->latch_)
{
return true;
}
auto ret = WaitForSingleObjectEx(this->event_, timeout ? timeout : INFINITE, true);
if (ret == WAIT_OBJECT_0)
{
DispatchCb();
return true;
return Complete();
}
return false;
}
@ -354,37 +363,20 @@ namespace Aurora::IO::FS
return {};
}
try
fileHandle = AuMakeShared<FileHandle>();
if (!fileHandle->Init(path, openMode, directIO, lock))
{
fileHandle = AuMakeShared<FileHandle>();
if (!fileHandle->Init(path, openMode, directIO, lock))
{
return {};
}
}
catch (...)
{
SysPushErrorCatch("Couldn't initialize FileHandle");
return {};
}
try
stream = _new NtAsyncFileStream();
if (!stream)
{
stream = _new NtAsyncFileStream();
if (!stream)
{
return {};
}
stream->Init(fileHandle);
}
catch (...)
{
if (stream) delete stream;
SysPushErrorCatch("Couldn't initialize NtAsyncFileStream");
return {};
}
stream->Init(fileHandle);
return stream;
}

View File

@ -53,7 +53,7 @@ namespace Aurora::IPC
this->pid = getpid();
#else
auto temp = AuRng::ReadString(AuArraySize(this->path), AuRng::ERngStringCharacters::eAlphaNumericCharacters);
AuMemcpy(this->path, temp.data(), data.size());
AuMemcpy(this->path, temp.data(), temp.size());
#endif
}
@ -81,6 +81,8 @@ namespace Aurora::IPC
if (in.size() > 4 + 16)
{
char *endPtr;
auto word = strtoll(in.c_str() + 4 + 16, &endPtr, 10);
if (errno == ERANGE)
{
@ -96,6 +98,11 @@ namespace Aurora::IPC
return true;
}
else
{
return false;
}
#endif
#if defined(AURORA_IS_POSIX_DERIVED)

View File

@ -88,11 +88,10 @@ namespace Aurora::Locale::Encoding
return base;
}
#if defined(AURORA_IS_POSIX_DERIVED)
AuStreamReadWrittenPair_t IConvWork(iconv_t handle, const void *in, AuUInt length, void *out, AuUInt32 outLen)
{
#if defined(AURORA_IS_POSIX_DERIVED)
auto originalLength = length;
size_t canReadLength = length;
@ -144,13 +143,10 @@ namespace Aurora::Locale::Encoding
return {a, b};
#else
return {};
#endif
}
#endif
AuStreamReadWrittenPair_t IConvCPToUTF8(ECodePage page, const void *in, AuUInt length, void *utf8, AuUInt32 utf8Max)
{
#if defined(AURORA_IS_POSIX_DERIVED)

View File

@ -19,7 +19,7 @@ namespace Aurora::Loop
bool Win32Dummy::WaitOn(AuUInt32 timeout)
{
// TODO: Close
static HANDLE kAlwaysOffMutex = CreateEventW(nullptr, true, nullptr);
static HANDLE kAlwaysOffMutex = CreateEventW(nullptr, true, false, nullptr);
return MsgWaitForMultipleObjects(0, &kAlwaysOffMutex, false, timeout ? timeout : INFINITE, QS_ALLEVENTS) == WAIT_OBJECT_0 + 1;
}

View File

@ -517,7 +517,7 @@ namespace Aurora::Loop
{
try
{
shouldRemove &= handler->OnFinished(source.source);
shouldRemove &= handler->OnFinished(source.source, 0);
}
catch (...)
{
@ -938,7 +938,7 @@ namespace Aurora::Loop
{
try
{
shouldRemove &= handler->OnFinished(source.source);
shouldRemove &= handler->OnFinished(source.source, 0);
}
catch (...)
{

View File

@ -20,7 +20,15 @@ namespace Aurora::Loop
if (handles.size() == 1)
{
one = 0;
return WaitForSingleObjectEx(reinterpret_cast<HANDLE>(handles.at(0)), timeout, true) == WAIT_OBJECT_0;
DWORD ret;
do
{
ret = WaitForSingleObjectEx(reinterpret_cast<HANDLE>(handles.at(0)), timeout, true);
}
while (ret == WAIT_IO_COMPLETION);
return ret == WAIT_OBJECT_0;
}
else
{
@ -48,7 +56,15 @@ namespace Aurora::Loop
bool WaitSingleGeneric::WaitForOne(AuUInt32 timeout, AuUInt handle)
{
return WaitForSingleObjectEx(reinterpret_cast<HANDLE>(handle), timeout, true) == WAIT_OBJECT_0;
DWORD ret;
do
{
ret = WaitForSingleObjectEx(reinterpret_cast<HANDLE>(handle), timeout, true);
}
while (ret == WAIT_IO_COMPLETION);
return ret == WAIT_OBJECT_0;
}
void WaitSingleGeneric::OnPresleep()