[*] 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;
@ -578,6 +604,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()
{ {
@ -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,
@ -1208,7 +1252,7 @@ namespace Aurora
void Win32DropSchedulerResolution(); void Win32DropSchedulerResolution();
void Win32Terminate(); void Win32Terminate();
AUKN_SYM /* I'm going to be kind */ AUKN_SYM /* I'm going to be kind */
HANDLE Win32Open(LPCWSTR lpFileName, HANDLE Win32Open(LPCWSTR lpFileName,
DWORD dwDesiredAccess = GENERIC_READ | GENERIC_WRITE, DWORD dwDesiredAccess = GENERIC_READ | GENERIC_WRITE,
@ -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,14 +471,12 @@ 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)
{ {
STORAGE_DEVICE_NUMBER sdn {}; STORAGE_DEVICE_NUMBER sdn {};
@ -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,18 +62,23 @@ 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)
AuBitsToHigher(uLength), AuBitsToHigher(uLength),
AuBitsToLower(uLength), AuBitsToLower(uLength),
#else #else
0, 0,
uLength, uLength,
#endif #endif
path.c_str()); path.c_str());
if ((file == INVALID_HANDLE_VALUE) || if ((file == INVALID_HANDLE_VALUE) ||
(!file)) (!file))
@ -81,11 +86,11 @@ 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,
uLength); uLength);
if (!map) if (!map)
{ {
SysPushErrorIO(); SysPushErrorIO();
@ -124,9 +129,9 @@ 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());
if ((file == INVALID_HANDLE_VALUE) || if ((file == INVALID_HANDLE_VALUE) ||
(!file)) (!file))
@ -134,11 +139,11 @@ 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,
uLength); uLength);
if (!map) if (!map)
{ {
SysPushErrorIO(); SysPushErrorIO();

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,13 +238,13 @@ 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);
if (hPipe == INVALID_HANDLE_VALUE) if (hPipe == INVALID_HANDLE_VALUE)
{ {

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,15 +99,56 @@ 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))
{ {
SysPushErrorIO("No Lock"); #if 0
return {}; if (GetLastError() == ERROR_IO_PENDING)
{
::WaitForSingleObject(hEventHandle, 0);
DWORD idc {};
if (!::GetOverlappedResult(hHandle,
&overlapped,
&idc,
true))
{
SysPushErrorIO("No Lock");
AuWin32CloseHandle(hEventHandle);
return {};
}
}
else
#endif
{
SysPushErrorIO("No Lock");
AuWin32CloseHandle(hEventHandle);
return {};
}
}
else
{
AuWin32CloseHandle(hEventHandle);
} }
} }
@ -130,17 +172,22 @@ namespace Aurora::Process
return {}; return {};
}; };
hFileMap = ::CreateFileMappingA((HANDLE)pIOHandle->GetOSHandle(), if (!pCreateFileMappingA)
nullptr, {
pageAttributes, return {};
#if defined(AURORA_IS_64BIT) }
AuBitsToHigher(uLength),
AuBitsToLower(uLength), hFileMap = pCreateFileMappingA((HANDLE)pIOHandle->GetOSHandle(),
#else nullptr,
0, pageAttributes,
uLength, #if defined(AURORA_IS_64BIT)
#endif AuBitsToHigher(uLength + uOffset),
nullptr); AuBitsToLower(uLength + uOffset),
#else
0,
uLength,
#endif
nullptr);
if ((hFileMap == INVALID_HANDLE_VALUE) || if ((hFileMap == INVALID_HANDLE_VALUE) ||
(!hFileMap)) (!hFileMap))
{ {
@ -148,11 +195,11 @@ namespace Aurora::Process
return {}; return {};
} }
auto map = ::MapViewOfFile(hFileMap, auto map = pMapViewOfFile(hFileMap,
desiredAccess, desiredAccess,
AuBitsToHigher(uOffset), AuBitsToHigher(uOffset),
AuBitsToLower(uOffset), AuBitsToLower(uOffset),
uLength); uLength);
if (!map) if (!map)
{ {
SysPushErrorIO("Couldn't create map of section"); SysPushErrorIO("Couldn't create map of section");
@ -232,9 +279,9 @@ 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) ||
(!hFileMap)) (!hFileMap))
{ {
@ -242,11 +289,11 @@ namespace Aurora::Process
return {}; return {};
} }
auto map = ::MapViewOfFile(hFileMap, auto map = pMapViewOfFile(hFileMap,
desiredAccess, desiredAccess,
AuBitsToHigher(uOffset), AuBitsToHigher(uOffset),
AuBitsToLower(uOffset), AuBitsToLower(uOffset),
uLength); uLength);
if (!map) if (!map)
{ {
SysPushErrorIO("Couldn't create map of IPC section (handle: {})", handleString); SysPushErrorIO("Couldn't create map of IPC section (handle: {})", handleString);
@ -312,17 +359,22 @@ namespace Aurora::Process
uPageFlags = PAGE_EXECUTE_READ; uPageFlags = PAGE_EXECUTE_READ;
} }
hFileMap = ::CreateFileMappingA(INVALID_HANDLE_VALUE, if (!pCreateFileMappingA)
nullptr, {
uPageFlags, return {};
#if defined(AURORA_IS_64BIT) }
AuBitsToHigher(uLength),
AuBitsToLower(uLength), hFileMap = pCreateFileMappingA(INVALID_HANDLE_VALUE,
#else nullptr,
0, uPageFlags,
uLength, #if defined(AURORA_IS_64BIT)
#endif AuBitsToHigher(uLength),
nullptr); AuBitsToLower(uLength),
#else
0,
uLength,
#endif
nullptr);
if ((hFileMap == INVALID_HANDLE_VALUE) || if ((hFileMap == INVALID_HANDLE_VALUE) ||
(!hFileMap)) (!hFileMap))
{ {
@ -346,11 +398,11 @@ 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,
uLength); uLength);
if (!map) if (!map)
{ {
SysPushErrorIO("Couldn't create allocation of section"); SysPushErrorIO("Couldn't create allocation of section");

View File

@ -249,17 +249,22 @@ namespace Aurora::Process
return {}; return {};
} }
hFileMap = ::CreateFileMappingA(INVALID_HANDLE_VALUE, if (!pCreateFileMappingA)
nullptr, {
uPageFlags, return {};
#if defined(AURORA_IS_64BIT) }
AuBitsToHigher(uLength),
AuBitsToLower(uLength), hFileMap = pCreateFileMappingA(INVALID_HANDLE_VALUE,
#else nullptr,
0, uPageFlags,
uLength, #if defined(AURORA_IS_64BIT)
#endif AuBitsToHigher(uLength),
nullptr); AuBitsToLower(uLength),
#else
0,
uLength,
#endif
nullptr);
if ((hFileMap == INVALID_HANDLE_VALUE) || if ((hFileMap == INVALID_HANDLE_VALUE) ||
(!hFileMap)) (!hFileMap))
{ {
@ -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,15 +376,56 @@ 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))
{ {
SysPushErrorIO("No Lock"); #if 0
return {}; if (GetLastError() == ERROR_IO_PENDING)
{
::WaitForSingleObject(hEventHandle, 0);
DWORD idc {};
if (!::GetOverlappedResult(hHandle,
&overlapped,
&idc,
true))
{
SysPushErrorIO("No Lock");
AuWin32CloseHandle(hEventHandle);
return {};
}
}
else
#endif
{
SysPushErrorIO("No Lock");
AuWin32CloseHandle(hEventHandle);
return {};
}
}
else
{
AuWin32CloseHandle(hEventHandle);
} }
} }
@ -401,18 +448,23 @@ namespace Aurora::Process
SysPushErrorGeneric(); SysPushErrorGeneric();
return {}; return {};
}; };
if (!pCreateFileMappingA)
{
return {};
}
hFileMap = ::CreateFileMappingA((HANDLE)pIOHandle->GetOSHandle(), 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,
#endif #endif
nullptr); nullptr);
if ((hFileMap == INVALID_HANDLE_VALUE) || if ((hFileMap == INVALID_HANDLE_VALUE) ||
(!hFileMap)) (!hFileMap))
{ {
@ -515,9 +567,9 @@ 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) ||
(!hFileMap)) (!hFileMap))
{ {

View File

@ -67,11 +67,11 @@ namespace Aurora::Process
} }
auto pRet = ::mmap(this->pBaseAddress + uFoundOffset, auto pRet = ::mmap(this->pBaseAddress + uFoundOffset,
uLength, uLength,
prot, prot,
share | MAP_FIXED, share | MAP_FIXED,
fd, fd,
offset); offset);
if (!pRet) if (!pRet)
{ {
@ -98,18 +98,18 @@ namespace Aurora::Process
} }
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapFileByObject(const AuSPtr<IO::IIOHandle> &pIOHandle, AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapFileByObject(const AuSPtr<IO::IIOHandle> &pIOHandle,
AuUInt64 uOffset, AuUInt64 uOffset,
AuUInt uLength, AuUInt uLength,
AuFS::EFileOpenMode mode, AuFS::EFileOpenMode mode,
AuFS::EFileAdvisoryLockLevel processLockLevel) AuFS::EFileAdvisoryLockLevel processLockLevel)
{ {
return this->MapFileByObjectEx(-1, pIOHandle, uOffset, uLength, mode, processLockLevel); return this->MapFileByObjectEx(-1, pIOHandle, uOffset, uLength, mode, processLockLevel);
} }
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapIPCMemory(const AuString &handleString, AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapIPCMemory(const AuString &handleString,
AuUInt64 uOffset, AuUInt64 uOffset,
AuUInt uLength, AuUInt uLength,
AuFS::EFileOpenMode mode) AuFS::EFileOpenMode mode)
{ {
return this->MapIPCMemoryEx(-1, handleString, uOffset, uLength, mode); return this->MapIPCMemoryEx(-1, handleString, uOffset, uLength, mode);
} }
@ -258,9 +258,9 @@ namespace Aurora::Process
} }
auto pNewObject = AuMakeShared<ProcessSectionFileMapView>(AuUInt(map), auto pNewObject = AuMakeShared<ProcessSectionFileMapView>(AuUInt(map),
uLength, uLength,
false, false,
fd); fd);
if (!pNewObject) if (!pNewObject)
{ {
SysPushErrorMem(); SysPushErrorMem();
@ -273,10 +273,10 @@ namespace Aurora::Process
} }
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapIPCMemoryEx(AuUInt viewOffset, AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapIPCMemoryEx(AuUInt viewOffset,
const AuString &handleString, const AuString &handleString,
AuUInt64 uOffset, AuUInt64 uOffset,
AuUInt uLength, AuUInt uLength,
Aurora::IO::FS::EFileOpenMode mode) Aurora::IO::FS::EFileOpenMode mode)
{ {
AuIPC::IPCHandle handle; AuIPC::IPCHandle handle;
@ -351,9 +351,9 @@ namespace Aurora::Process
} }
auto pNewObject = AuMakeShared<ProcessSectionFileMapView>(AuUInt(map), auto pNewObject = AuMakeShared<ProcessSectionFileMapView>(AuUInt(map),
uLength, uLength,
false, false,
fd); fd);
if (!pNewObject) if (!pNewObject)
{ {
SysPushErrorMem(); SysPushErrorMem();

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,21 +76,21 @@ 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
nSize, // Out buffer size nSize, // Out buffer size
nSize, // In buffer size nSize, // In buffer size
120 * 1000, // Timeout in ms 120 * 1000, // Timeout in ms
lpPipeAttributes lpPipeAttributes
); );
if (!ReadPipeHandle) if (!ReadPipeHandle)
@ -98,14 +98,13 @@ CreatePipeEx(
return FALSE; return FALSE;
} }
WritePipeHandle = CreateFileA( WritePipeHandle = Aurora::Win32Open2(sPipeNameBuffer,
PipeNameBuffer, GENERIC_WRITE,
GENERIC_WRITE, 0, // No sharing
0, // No sharing lpPipeAttributes,
lpPipeAttributes, OPEN_EXISTING,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | dwWriteMode,
FILE_ATTRIBUTE_NORMAL | dwWriteMode, NULL // Template file
NULL // Template file
); );
if (INVALID_HANDLE_VALUE == WritePipeHandle) if (INVALID_HANDLE_VALUE == WritePipeHandle)

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 {};