[*] Minor tweaks + more not-so-lazy loads in case of uwp

This commit is contained in:
Reece Wilson 2024-04-09 23:39:00 +01:00
parent 7f0dc81ec3
commit a087595009
12 changed files with 524 additions and 192 deletions

View File

@ -40,6 +40,23 @@ namespace Aurora
FARPROC UWPProcAddress(HMODULE hModule, FARPROC UWPProcAddress(HMODULE hModule,
LPCSTR lpProcName); LPCSTR lpProcName);
HANDLE __stdcall UWPCreateFileMappingA(HANDLE hFile,
LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCSTR lpName);
HANDLE __stdcall UWPOpenFileMappingA(DWORD dwDesiredAccess,
BOOL bInheritHandle,
LPCSTR lpName);
LPVOID __stdcall UWPMapViewOfFile(HANDLE hFileMappingObject,
DWORD dwDesiredAccess,
DWORD dwFileOffsetHigh,
DWORD dwFileOffsetLow,
SIZE_T dwNumberOfBytesToMap);
#endif #endif
#if !defined(AURORA_DLL_BLACKLIST) #if !defined(AURORA_DLL_BLACKLIST)
@ -250,11 +267,14 @@ namespace Aurora
ADD_GET_PROC(Nt, NtWaitForMultipleObjects) ADD_GET_PROC(Nt, NtWaitForMultipleObjects)
ADD_GET_PROC_BI(Kernel32, KernelBase, VirtualAlloc2) ADD_GET_PROC_BI(Kernel32, KernelBase, VirtualAlloc2)
ADD_GET_PROC_BI(Kernel32, KernelBase, MapViewOfFile)
ADD_GET_PROC_BI(Kernel32, KernelBase, MapViewOfFile3) ADD_GET_PROC_BI(Kernel32, KernelBase, MapViewOfFile3)
ADD_GET_PROC_BI(Kernel32, KernelBase, UnmapViewOfFile2) ADD_GET_PROC_BI(Kernel32, KernelBase, UnmapViewOfFile2)
ADD_GET_PROC_BI(Kernel32, KernelBase, CreateFileW) ADD_GET_PROC_BI(Kernel32, KernelBase, CreateFileW)
ADD_GET_PROC_BI(Kernel32, KernelBase, CreateFile2W) ADD_GET_PROC_BI(Kernel32, KernelBase, CreateFile2W)
ADD_GET_PROC_BI(Kernel32, KernelBase, GetTempPathW) ADD_GET_PROC_BI(Kernel32, KernelBase, GetTempPathW)
ADD_GET_PROC_BI(Kernel32, KernelBase, CreateFileMappingA)
ADD_GET_PROC_BI(Kernel32, KernelBase, OpenFileMappingA)
ADD_GET_PROC(Kernel32, GetSystemCpuSetInformation) ADD_GET_PROC(Kernel32, GetSystemCpuSetInformation)
ADD_GET_PROC(Kernel32, GetLogicalProcessorInformation) ADD_GET_PROC(Kernel32, GetLogicalProcessorInformation)
@ -423,6 +443,12 @@ namespace Aurora
pGetProcAddress = UWPProcAddress; pGetProcAddress = UWPProcAddress;
pCreateFile2W = CreateFile2FromAppW; pCreateFile2W = CreateFile2FromAppW;
pCreateFileMappingFromApp = CreateFileMappingFromApp;
pOpenFileMappingFromApp = OpenFileMappingFromApp;
pMapViewOfFileFromApp = MapViewOfFileFromApp;
pCreateFileMappingA = UWPCreateFileMappingA;
pOpenFileMappingA = UWPOpenFileMappingA;
pMapViewOfFile = UWPMapViewOfFile;
pWaitOnAddress = WaitOnAddress; pWaitOnAddress = WaitOnAddress;
pWakeByAddressSingle = WakeByAddressSingle; pWakeByAddressSingle = WakeByAddressSingle;
@ -579,6 +605,63 @@ namespace Aurora
} }
} }
HANDLE UWPCreateFileMappingA(HANDLE hFile,
LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCSTR lpName)
{
auto uSize = AuUInt64(AuUInt64(dwMaximumSizeHigh) << 32ull) |
AuUInt64(dwMaximumSizeLow);
if (!uSize && SysHandleIsNonZero(AuUInt(hFile)))
{
uSize = SysGetFileLength(AuUInt(hFile));
}
if (!pCreateFileMappingFromApp)
{
return NULL;
}
return pCreateFileMappingFromApp(hFile,
lpFileMappingAttributes,
flProtect,
uSize,
lpName ? AuLocale::ConvertFromUTF8(lpName).c_str() : nullptr);
}
HANDLE UWPOpenFileMappingA(DWORD dwDesiredAccess,
BOOL bInheritHandle,
LPCSTR lpName)
{
if (!pOpenFileMappingFromApp)
{
return NULL;
}
return pOpenFileMappingFromApp(dwDesiredAccess,
bInheritHandle,
lpName ? AuLocale::ConvertFromUTF8(lpName).c_str() : nullptr);
}
LPVOID UWPMapViewOfFile(HANDLE hFileMappingObject,
DWORD dwDesiredAccess,
DWORD dwFileOffsetHigh,
DWORD dwFileOffsetLow,
SIZE_T dwNumberOfBytesToMap)
{
if (!pMapViewOfFileFromApp)
{
return NULL;
}
return pMapViewOfFileFromApp(hFileMappingObject,
dwDesiredAccess,
AuUInt64(AuUInt64(dwFileOffsetHigh) << 32ull) | AuUInt64(dwFileOffsetLow),
dwNumberOfBytesToMap);
}
void Win32Terminate() void Win32Terminate()
{ {
if (gUseFastFail) if (gUseFastFail)
@ -691,6 +774,96 @@ namespace Aurora
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
HANDLE Win32Open2(LPCWSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlags,
DWORD dwAttributes)
{
bool bSpecialFlags = (dwFlags & 0x4ffff7);
bool bSpecialAttrs = (dwAttributes & 0xFFB00008);
if (!pCreateFile2W)
{
if (bSpecialFlags)
{
SysPushErrorFeatureMissing("Do not use Windows8+ attributes/flags under Win32Open");
return INVALID_HANDLE_VALUE;
}
if (bSpecialAttrs)
{
SysPushErrorFeatureMissing("Do not use Windows8+ attributes/flags under Win32Open");
return INVALID_HANDLE_VALUE;
}
}
if (!dwAttributes)
{
dwAttributes = FILE_ATTRIBUTE_NORMAL;
}
if (pCreateFileW &&
!bSpecialFlags &&
!bSpecialAttrs)
{
return pCreateFileW(lpFileName,
dwDesiredAccess,
dwShareMode,
lpSecurityAttributes,
dwCreationDisposition,
dwFlags | dwAttributes,
NULL);
}
if (pCreateFile2W)
{
_CREATEFILE2_EXTENDED_PARAMETERS params {};
bool bRead {};
HANDLE hHandle {};
params.dwSize = sizeof(_CREATEFILE2_EXTENDED_PARAMETERS);
params.dwFileFlags = dwFlags;
params.dwFileAttributes = dwAttributes;
params.lpSecurityAttributes = lpSecurityAttributes;
if ((bRead = (::wcscmp(lpFileName, L"CONIN$") == 0)) ||
(::wcscmp(lpFileName, L"CONOUT$") == 0) ||
(::wcscmp(lpFileName, L"CONERR$") == 0))
{
if (!bRead)
{
dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
}
else
{
dwDesiredAccess = GENERIC_READ;
}
if ((hHandle = pCreateFile2W(lpFileName,
dwDesiredAccess,
dwShareMode,
dwCreationDisposition,
&params)) != INVALID_HANDLE_VALUE)
{
return hHandle;
}
lpFileName = L"CON";
}
return pCreateFile2W(lpFileName,
dwDesiredAccess,
dwShareMode,
dwCreationDisposition,
&params);
}
return INVALID_HANDLE_VALUE;
}
#if !defined(AURORA_PLATFORM_WIN32) #if !defined(AURORA_PLATFORM_WIN32)
HMODULE UWPLibraryW(LPCWSTR lpLibFileName) HMODULE UWPLibraryW(LPCWSTR lpLibFileName)
{ {

View File

@ -234,6 +234,50 @@ namespace Aurora
HANDLE hTemplateFile HANDLE hTemplateFile
); );
inline HANDLE(__stdcall *pCreateFileMappingA)(
HANDLE hFile,
LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCSTR lpName
);
inline HANDLE(__stdcall *pCreateFileMappingFromApp)(
HANDLE hFile,
PSECURITY_ATTRIBUTES SecurityAttributes,
ULONG PageProtection,
ULONG64 MaximumSize,
PCWSTR Name
);
inline HANDLE(__stdcall *pOpenFileMappingA)(
ULONG DesiredAccess,
BOOL InheritHandle,
LPCSTR Name
);
inline HANDLE(__stdcall *pOpenFileMappingFromApp)(
ULONG DesiredAccess,
BOOL InheritHandle,
PCWSTR Name
);
inline LPVOID(__stdcall *pMapViewOfFile)(
HANDLE hFileMappingObject,
DWORD dwDesiredAccess,
DWORD dwFileOffsetHigh,
DWORD dwFileOffsetLow,
SIZE_T dwNumberOfBytesToMap
);
inline LPVOID(__stdcall *pMapViewOfFileFromApp)(
HANDLE hFileMappingObject,
ULONG DesiredAccess,
ULONG64 FileOffset,
SIZE_T dwNumberOfBytesToMap
);
inline NTSTATUS(__stdcall *pNtNotifyChangeDirectoryFile)( inline NTSTATUS(__stdcall *pNtNotifyChangeDirectoryFile)(
HANDLE FileHandle, HANDLE FileHandle,
HANDLE Event, HANDLE Event,
@ -1219,6 +1263,16 @@ namespace Aurora
DWORD dwAttributes = 0 DWORD dwAttributes = 0
); );
AUKN_SYM /* I'm going to be kind */
HANDLE Win32Open2(LPCWSTR lpFileName,
DWORD dwDesiredAccess = GENERIC_READ | GENERIC_WRITE,
DWORD dwShareMode = FILE_SHARE_READ,
LPSECURITY_ATTRIBUTES lpSecurityAttributes = NULL,
DWORD dwCreationDisposition = 0,
DWORD dwFlags = 0,
DWORD dwAttributes = 0
);
inline HMODULE(__stdcall *pLoadLibraryW)( inline HMODULE(__stdcall *pLoadLibraryW)(
LPCWSTR lpLibFileName LPCWSTR lpLibFileName
); );

View File

@ -115,13 +115,12 @@ namespace Aurora::IO::FS
return utf8Root; return utf8Root;
} }
auto hFile = ::CreateFileW(widePath.c_str(), auto hFile = Win32Open(widePath.c_str(),
0, 0,
FILE_SHARE_WRITE | FILE_SHARE_READ, FILE_SHARE_WRITE | FILE_SHARE_READ,
nullptr, false,
OPEN_EXISTING, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS);
nullptr);
if (hFile == INVALID_HANDLE_VALUE) if (hFile == INVALID_HANDLE_VALUE)
{ {
@ -188,13 +187,11 @@ namespace Aurora::IO::FS
return kImScaredAndDisorientated; return kImScaredAndDisorientated;
} }
auto hDevice = ::CreateFileW(widePath.c_str(), auto hDevice = Win32Open(widePath.c_str(),
0, 0,
0, 0,
nullptr, false,
OPEN_EXISTING, OPEN_EXISTING);
0,
nullptr);
if (hDevice == INVALID_HANDLE_VALUE) if (hDevice == INVALID_HANDLE_VALUE)
{ {
@ -348,13 +345,11 @@ namespace Aurora::IO::FS
return 0; return 0;
} }
auto hDevice = ::CreateFileW(widePath.c_str(), auto hDevice = Win32Open(widePath.c_str(),
0, 0,
0, 0,
nullptr, false,
OPEN_EXISTING, OPEN_EXISTING);
0,
nullptr);
if (hDevice == INVALID_HANDLE_VALUE) if (hDevice == INVALID_HANDLE_VALUE)
{ {
@ -476,13 +471,11 @@ namespace Aurora::IO::FS
continue; continue;
} }
hDevice = ::CreateFileW(pInterfaceDetailData->DevicePath, hDevice = Win32Open(pInterfaceDetailData->DevicePath,
0, 0,
0x00000007, 0x00000007,
nullptr, false,
OPEN_EXISTING, OPEN_EXISTING);
0,
nullptr);
if (hDevice != INVALID_HANDLE_VALUE) if (hDevice != INVALID_HANDLE_VALUE)
{ {
@ -707,13 +700,11 @@ namespace Aurora::IO::FS
strVolumePath[i - 1] = '\x00'; strVolumePath[i - 1] = '\x00';
} }
auto hVolume = ::CreateFileW(strVolumePath.c_str(), auto hVolume = Win32Open(strVolumePath.c_str(),
0, 0,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, false,
OPEN_EXISTING, OPEN_EXISTING);
0,
0);
if (hVolume == INVALID_HANDLE_VALUE) if (hVolume == INVALID_HANDLE_VALUE)
{ {

View File

@ -62,8 +62,13 @@ namespace Aurora::IO::IPC
handle.PushId(EIPCHandleType::eIPCMemory, token); handle.PushId(EIPCHandleType::eIPCMemory, token);
if (!pCreateFileMappingA)
{
return {};
}
auto path = token.ToNTPath(); auto path = token.ToNTPath();
auto file = CreateFileMappingA(INVALID_HANDLE_VALUE, auto file = pCreateFileMappingA(INVALID_HANDLE_VALUE,
nullptr, nullptr,
PAGE_READWRITE, PAGE_READWRITE,
#if defined(AURORA_IS_64BIT) #if defined(AURORA_IS_64BIT)
@ -81,7 +86,7 @@ namespace Aurora::IO::IPC
return {}; return {};
} }
auto map = ::MapViewOfFile(file, auto map = pMapViewOfFile(file,
FILE_MAP_ALL_ACCESS, FILE_MAP_ALL_ACCESS,
0, 0,
0, 0,
@ -124,7 +129,7 @@ namespace Aurora::IO::IPC
auto uLength = token->token.word; auto uLength = token->token.word;
auto path = token->token.ToNTPath(); auto path = token->token.ToNTPath();
auto file = ::OpenFileMappingA(FILE_MAP_ALL_ACCESS, auto file = pOpenFileMappingA(FILE_MAP_ALL_ACCESS,
FALSE, FALSE,
path.c_str()); path.c_str());
@ -134,7 +139,7 @@ namespace Aurora::IO::IPC
return {}; return {};
} }
auto map = ::MapViewOfFile(file, auto map = pMapViewOfFile(file,
FILE_MAP_ALL_ACCESS, FILE_MAP_ALL_ACCESS,
0, 0,
0, 0,

View File

@ -459,13 +459,12 @@ namespace Aurora::IO::IPC
#else #else
auto name = "\\\\.\\pipe\\LOCAL\\" + token->token.ToNTPath(); auto name = "\\\\.\\pipe\\LOCAL\\" + token->token.ToNTPath();
#endif #endif
pipe = CreateFileA(name.c_str(), pipe = Win32Open(AuLocale::ConvertFromUTF8(name).c_str(),
GENERIC_WRITE | GENERIC_READ, GENERIC_WRITE | GENERIC_READ,
0, 0,
NULL, false,
OPEN_ALWAYS, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED);
NULL);
if ((!pipe) || if ((!pipe) ||
(pipe == INVALID_HANDLE_VALUE)) (pipe == INVALID_HANDLE_VALUE))

View File

@ -238,10 +238,10 @@ namespace Aurora::IO::NT
DWORD dwWritten {}; DWORD dwWritten {};
auto name = GetIPCServerNameOfPid(handle.pid); auto name = GetIPCServerNameOfPid(handle.pid);
hPipe = CreateFileA(name.c_str(), hPipe = Win32Open(AuLocale::ConvertFromUTF8(name).c_str(),
GENERIC_WRITE | GENERIC_READ, GENERIC_WRITE | GENERIC_READ,
0, 0,
NULL, false,
OPEN_ALWAYS, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL,
NULL); NULL);

View File

@ -28,6 +28,8 @@ namespace Aurora::Locale
AUKN_SYM AuString ConvertFromWChar(const wchar_t *in) AUKN_SYM AuString ConvertFromWChar(const wchar_t *in)
{ {
AU_DEBUG_MEMCRUNCH;
try try
{ {
return ConvertFromWChar(in, wcslen(in)); return ConvertFromWChar(in, wcslen(in));
@ -41,6 +43,8 @@ namespace Aurora::Locale
AUKN_SYM AuString ConvertFromWChar(const wchar_t *in, AuMach length) AUKN_SYM AuString ConvertFromWChar(const wchar_t *in, AuMach length)
{ {
AU_DEBUG_MEMCRUNCH;
try try
{ {
#if defined(AU_HAS_MSFT_NATIONALLANGSUPPORT) #if defined(AU_HAS_MSFT_NATIONALLANGSUPPORT)
@ -72,6 +76,8 @@ namespace Aurora::Locale
AUKN_SYM std::wstring ConvertFromUTF8(const AuString &in) AUKN_SYM std::wstring ConvertFromUTF8(const AuString &in)
{ {
AU_DEBUG_MEMCRUNCH;
try try
{ {
#if defined(AU_HAS_MSFT_NATIONALLANGSUPPORT) #if defined(AU_HAS_MSFT_NATIONALLANGSUPPORT)

View File

@ -86,6 +86,7 @@ namespace Aurora::Process
if (processLockLevel != AuFS::EFileAdvisoryLockLevel::eNoSafety) if (processLockLevel != AuFS::EFileAdvisoryLockLevel::eNoSafety)
{ {
DWORD dwFlags {}; DWORD dwFlags {};
HANDLE hEventHandle { INVALID_HANDLE_VALUE };
OVERLAPPED overlapped {}; OVERLAPPED overlapped {};
if (processLockLevel == AuFS::EFileAdvisoryLockLevel::eBlockReadWrite) if (processLockLevel == AuFS::EFileAdvisoryLockLevel::eBlockReadWrite)
@ -98,17 +99,58 @@ namespace Aurora::Process
overlapped.Offset = AuBitsToLower(uOffset); overlapped.Offset = AuBitsToLower(uOffset);
overlapped.OffsetHigh = AuBitsToHigher(uOffset); overlapped.OffsetHigh = AuBitsToHigher(uOffset);
if (!::LockFileEx((HANDLE)pIOHandle->GetOSHandle(), #if 0
bool bIsAsync = pIOHandle->IsAsync();
if (bIsAsync)
{
hEventHandle = ::CreateEventA(nullptr, false, false, nullptr);
if (!hEventHandle)
{
SysPushErrorGeneric();
return {};
}
overlapped.hEvent = hEventHandle;
}
#endif
auto hHandle = (HANDLE)pIOHandle->GetOSHandle();
if (!::LockFileEx(hHandle,
dwFlags, dwFlags,
0, 0,
AuBitsToLower(uLength), AuBitsToLower(uLength),
AuBitsToHigher(uLength), AuBitsToHigher(uLength),
&overlapped)) &overlapped))
{
#if 0
if (GetLastError() == ERROR_IO_PENDING)
{
::WaitForSingleObject(hEventHandle, 0);
DWORD idc {};
if (!::GetOverlappedResult(hHandle,
&overlapped,
&idc,
true))
{ {
SysPushErrorIO("No Lock"); SysPushErrorIO("No Lock");
AuWin32CloseHandle(hEventHandle);
return {}; return {};
} }
} }
else
#endif
{
SysPushErrorIO("No Lock");
AuWin32CloseHandle(hEventHandle);
return {};
}
}
else
{
AuWin32CloseHandle(hEventHandle);
}
}
switch (mode) switch (mode)
{ {
@ -130,12 +172,17 @@ namespace Aurora::Process
return {}; return {};
}; };
hFileMap = ::CreateFileMappingA((HANDLE)pIOHandle->GetOSHandle(), if (!pCreateFileMappingA)
{
return {};
}
hFileMap = pCreateFileMappingA((HANDLE)pIOHandle->GetOSHandle(),
nullptr, nullptr,
pageAttributes, pageAttributes,
#if defined(AURORA_IS_64BIT) #if defined(AURORA_IS_64BIT)
AuBitsToHigher(uLength), AuBitsToHigher(uLength + uOffset),
AuBitsToLower(uLength), AuBitsToLower(uLength + uOffset),
#else #else
0, 0,
uLength, uLength,
@ -148,7 +195,7 @@ namespace Aurora::Process
return {}; return {};
} }
auto map = ::MapViewOfFile(hFileMap, auto map = pMapViewOfFile(hFileMap,
desiredAccess, desiredAccess,
AuBitsToHigher(uOffset), AuBitsToHigher(uOffset),
AuBitsToLower(uOffset), AuBitsToLower(uOffset),
@ -232,7 +279,7 @@ namespace Aurora::Process
return {}; return {};
}; };
hFileMap = ::OpenFileMappingA(desiredAccess, hFileMap = pOpenFileMappingA(desiredAccess,
FALSE, FALSE,
path.c_str()); path.c_str());
if ((hFileMap == INVALID_HANDLE_VALUE) || if ((hFileMap == INVALID_HANDLE_VALUE) ||
@ -242,7 +289,7 @@ namespace Aurora::Process
return {}; return {};
} }
auto map = ::MapViewOfFile(hFileMap, auto map = pMapViewOfFile(hFileMap,
desiredAccess, desiredAccess,
AuBitsToHigher(uOffset), AuBitsToHigher(uOffset),
AuBitsToLower(uOffset), AuBitsToLower(uOffset),
@ -312,7 +359,12 @@ namespace Aurora::Process
uPageFlags = PAGE_EXECUTE_READ; uPageFlags = PAGE_EXECUTE_READ;
} }
hFileMap = ::CreateFileMappingA(INVALID_HANDLE_VALUE, if (!pCreateFileMappingA)
{
return {};
}
hFileMap = pCreateFileMappingA(INVALID_HANDLE_VALUE,
nullptr, nullptr,
uPageFlags, uPageFlags,
#if defined(AURORA_IS_64BIT) #if defined(AURORA_IS_64BIT)
@ -346,7 +398,7 @@ namespace Aurora::Process
sectionPermission |= SECTION_MAP_EXECUTE; sectionPermission |= SECTION_MAP_EXECUTE;
} }
auto map = ::MapViewOfFile(hFileMap, auto map = pMapViewOfFile(hFileMap,
sectionPermission, sectionPermission,
0, 0,
0, 0,

View File

@ -249,7 +249,12 @@ namespace Aurora::Process
return {}; return {};
} }
hFileMap = ::CreateFileMappingA(INVALID_HANDLE_VALUE, if (!pCreateFileMappingA)
{
return {};
}
hFileMap = pCreateFileMappingA(INVALID_HANDLE_VALUE,
nullptr, nullptr,
uPageFlags, uPageFlags,
#if defined(AURORA_IS_64BIT) #if defined(AURORA_IS_64BIT)
@ -358,6 +363,7 @@ namespace Aurora::Process
if (processLockLevel != AuFS::EFileAdvisoryLockLevel::eNoSafety) if (processLockLevel != AuFS::EFileAdvisoryLockLevel::eNoSafety)
{ {
DWORD dwFlags {}; DWORD dwFlags {};
HANDLE hEventHandle { INVALID_HANDLE_VALUE };
OVERLAPPED overlapped {}; OVERLAPPED overlapped {};
if (processLockLevel == AuFS::EFileAdvisoryLockLevel::eBlockReadWrite) if (processLockLevel == AuFS::EFileAdvisoryLockLevel::eBlockReadWrite)
@ -370,17 +376,58 @@ namespace Aurora::Process
overlapped.Offset = AuBitsToLower(uOffset); overlapped.Offset = AuBitsToLower(uOffset);
overlapped.OffsetHigh = AuBitsToHigher(uOffset); overlapped.OffsetHigh = AuBitsToHigher(uOffset);
if (!::LockFileEx((HANDLE)pIOHandle->GetOSHandle(), #if 0
bool bIsAsync = pIOHandle->IsAsync();
if (bIsAsync)
{
hEventHandle = ::CreateEventA(nullptr, false, false, nullptr);
if (!hEventHandle)
{
SysPushErrorGeneric();
return {};
}
overlapped.hEvent = hEventHandle;
}
#endif
auto hHandle = (HANDLE)pIOHandle->GetOSHandle();
if (!::LockFileEx(hHandle,
dwFlags, dwFlags,
0, 0,
AuBitsToLower(uLength), AuBitsToLower(uLength),
AuBitsToHigher(uLength), AuBitsToHigher(uLength),
&overlapped)) &overlapped))
{
#if 0
if (GetLastError() == ERROR_IO_PENDING)
{
::WaitForSingleObject(hEventHandle, 0);
DWORD idc {};
if (!::GetOverlappedResult(hHandle,
&overlapped,
&idc,
true))
{ {
SysPushErrorIO("No Lock"); SysPushErrorIO("No Lock");
AuWin32CloseHandle(hEventHandle);
return {}; return {};
} }
} }
else
#endif
{
SysPushErrorIO("No Lock");
AuWin32CloseHandle(hEventHandle);
return {};
}
}
else
{
AuWin32CloseHandle(hEventHandle);
}
}
switch (mode) switch (mode)
{ {
@ -402,12 +449,17 @@ namespace Aurora::Process
return {}; return {};
}; };
hFileMap = ::CreateFileMappingA((HANDLE)pIOHandle->GetOSHandle(), if (!pCreateFileMappingA)
{
return {};
}
hFileMap = pCreateFileMappingA((HANDLE)pIOHandle->GetOSHandle(),
nullptr, nullptr,
pageAttributes, pageAttributes,
#if defined(AURORA_IS_64BIT) #if defined(AURORA_IS_64BIT)
AuBitsToHigher(uLength), AuBitsToHigher(uLength + uOffset),
AuBitsToLower(uLength), AuBitsToLower(uLength + uOffset),
#else #else
0, 0,
uLength, uLength,
@ -515,7 +567,7 @@ namespace Aurora::Process
return {}; return {};
} }
hFileMap = ::OpenFileMappingA(desiredAccess, hFileMap = pOpenFileMappingA(desiredAccess,
FALSE, FALSE,
path.c_str()); path.c_str());
if ((hFileMap == INVALID_HANDLE_VALUE) || if ((hFileMap == INVALID_HANDLE_VALUE) ||

View File

@ -40,7 +40,7 @@ CreatePipeEx(
{ {
HANDLE ReadPipeHandle, WritePipeHandle; HANDLE ReadPipeHandle, WritePipeHandle;
DWORD dwError; DWORD dwError;
char PipeNameBuffer[MAX_PATH]; wchar_t sPipeNameBuffer[MAX_PATH];
// //
// Only one valid OpenMode flag - FILE_FLAG_OVERLAPPED // Only one valid OpenMode flag - FILE_FLAG_OVERLAPPED
@ -76,14 +76,14 @@ CreatePipeEx(
nSize = 16 * AuHwInfo::GetPageSize(); nSize = 16 * AuHwInfo::GetPageSize();
} }
sprintf(PipeNameBuffer, swprintf(sPipeNameBuffer,
"\\\\.\\Pipe\\AuroraProcessCStandardStream.%08x.%08x", L"\\\\.\\Pipe\\AuroraProcessCStandardStream.%08x.%08x",
GetCurrentProcessId(), GetCurrentProcessId(),
AuAtomicAdd(&gPipeSerialNumber, 1u) AuAtomicAdd(&gPipeSerialNumber, 1u)
); );
ReadPipeHandle = CreateNamedPipeA( ReadPipeHandle = CreateNamedPipeW(
PipeNameBuffer, sPipeNameBuffer,
PIPE_ACCESS_INBOUND | dwReadMode, PIPE_ACCESS_INBOUND | dwReadMode,
PIPE_TYPE_BYTE | PIPE_WAIT, PIPE_TYPE_BYTE | PIPE_WAIT,
1, // Number of pipes 1, // Number of pipes
@ -98,8 +98,7 @@ CreatePipeEx(
return FALSE; return FALSE;
} }
WritePipeHandle = CreateFileA( WritePipeHandle = Aurora::Win32Open2(sPipeNameBuffer,
PipeNameBuffer,
GENERIC_WRITE, GENERIC_WRITE,
0, // No sharing 0, // No sharing
lpPipeAttributes, lpPipeAttributes,

View File

@ -236,6 +236,7 @@
// benchmarking: https://github.com/microsoft/STL/issues/2085 // benchmarking: https://github.com/microsoft/STL/issues/2085
#define GIB__GetSteadyTimeNS #define GIB__GetSteadyTimeNS
// moved: _GetSteadyTimeNS
// ~3.0741 seconds // ~3.0741 seconds
@ -326,7 +327,7 @@ namespace Aurora::Time
AUKN_SYM AuUInt64 SteadyClock() AUKN_SYM AuUInt64 SteadyClock()
{ {
#if defined(AURORA_IS_MODERNNT_DERIVED) || defined(AURORA_IS_XNU_DERIVED) #if defined(GIB__GetSteadyTimeNS)
return _NTLikeQueryCounter(); return _NTLikeQueryCounter();
#else #else
return SteadyClockNS() / (1000000000ull / SteadyClockFrequency()); return SteadyClockNS() / (1000000000ull / SteadyClockFrequency());
@ -335,7 +336,7 @@ namespace Aurora::Time
AUKN_SYM AuUInt64 SteadyClockMS() AUKN_SYM AuUInt64 SteadyClockMS()
{ {
#if defined(AURORA_IS_MODERNNT_DERIVED) || defined(AURORA_IS_XNU_DERIVED) #if defined(GIB__GetSteadyTimeNS)
return AuNSToMS<AuUInt64>(_GetSteadyTimeNS()); return AuNSToMS<AuUInt64>(_GetSteadyTimeNS());
#elif defined(AURORA_IS_POSIX_DERIVED) #elif defined(AURORA_IS_POSIX_DERIVED)
::timespec spec {}; ::timespec spec {};
@ -354,7 +355,7 @@ namespace Aurora::Time
AUKN_SYM AuUInt64 SteadyClockNS() AUKN_SYM AuUInt64 SteadyClockNS()
{ {
#if defined(AURORA_IS_MODERNNT_DERIVED) || defined(AURORA_IS_XNU_DERIVED) #if defined(GIB__GetSteadyTimeNS)
return _GetSteadyTimeNS(); return _GetSteadyTimeNS();
#elif defined(AURORA_IS_POSIX_DERIVED) #elif defined(AURORA_IS_POSIX_DERIVED)
::timespec spec {}; ::timespec spec {};
@ -379,7 +380,7 @@ namespace Aurora::Time
return gFrequency; return gFrequency;
} }
#if defined(AURORA_IS_MODERNNT_DERIVED) || defined(AURORA_IS_XNU_DERIVED) #if defined(GIB__GetSteadyTimeNS)
return gFrequency = _NTLikeQueryFrequency(); return gFrequency = _NTLikeQueryFrequency();
#elif defined(AURORA_IS_POSIX_DERIVED) #elif defined(AURORA_IS_POSIX_DERIVED)
::timespec spec {}; ::timespec spec {};