Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions stl/src/filesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,11 @@ extern "C" _CRTIMP2_PURE wchar_t* __CLRCALL_PURE_OR_CDECL _Read_dir(
}

static unsigned int _Filesys_code_page() { // determine appropriate code page
#if defined(_ONECORE)
return CP_ACP;
#else // ^^^ defined(_ONECORE) / !defined(_ONECORE) vvv
if (AreFileApisANSI()) {
return CP_ACP;
} else {
return CP_OEMCP;
}
#endif // ^^^ !defined(_ONECORE) ^^^
}

extern "C" _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _To_wide(const char* _Bsrc, wchar_t* _Wdest) noexcept {
Expand Down Expand Up @@ -198,21 +194,12 @@ extern "C" _CRTIMP2_PURE void* __CLRCALL_PURE_OR_CDECL _Open_dir(
extern "C" _CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL _Current_get(wchar_t (&_Dest)[_MAX_FILESYS_NAME]) noexcept {
// get current working directory
_Strcpy(_Dest, L"");
#ifdef _CRT_APP
return false; // no support
#else // ^^^ defined(_CRT_APP) / !defined(_CRT_APP) vvv
return _wgetcwd(_Dest, _MAX_FILESYS_NAME) != nullptr;
#endif // ^^^ !defined(_CRT_APP) ^^^
}

extern "C" _CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL _Current_set(const wchar_t* _Dirname) noexcept {
// set current working directory
#ifdef _CRT_APP
(void) _Dirname;
return false; // no support
#else // ^^^ defined(_CRT_APP) / !defined(_CRT_APP) vvv
return _wchdir(_Dirname) == 0;
#endif // ^^^ !defined(_CRT_APP) ^^^
}

extern "C" _CRTIMP2_PURE wchar_t* __CLRCALL_PURE_OR_CDECL _Symlink_get(
Expand Down Expand Up @@ -405,24 +392,12 @@ extern "C" _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Equivalent(

extern "C" _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Link(const wchar_t* _Fname1, const wchar_t* _Fname2) noexcept {
// link _Fname2 to _Fname1
#ifdef _CRT_APP
(void) _Fname1;
(void) _Fname2;
return errno = EDOM; // hardlinks not supported
#else // ^^^ defined(_CRT_APP) / !defined(_CRT_APP) vvv
return CreateHardLinkW(_Fname2, _Fname1, nullptr) ? 0 : GetLastError();
#endif // ^^^ !defined(_CRT_APP) ^^^
}

extern "C" _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Symlink(const wchar_t* _Fname1, const wchar_t* _Fname2) noexcept {
// link _Fname2 to _Fname1
#ifdef _CRT_APP
(void) _Fname1;
(void) _Fname2;
return errno = EDOM; // symlinks not supported
#else // ^^^ defined(_CRT_APP) / !defined(_CRT_APP) vvv
return CreateSymbolicLinkW(_Fname2, _Fname1, 0) ? 0 : GetLastError();
#endif // ^^^ !defined(_CRT_APP) ^^^
}

extern "C" _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Rename(const wchar_t* _Fname1, const wchar_t* _Fname2) noexcept {
Expand Down
30 changes: 2 additions & 28 deletions stl/src/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@
static_assert(__std_code_page::_Utf8 == __std_code_page{CP_UTF8});

namespace {

#ifdef _CRT_APP
BOOLEAN __stdcall _Not_supported_CreateSymbolicLinkW(const wchar_t*, const wchar_t*, DWORD) {
SetLastError(ERROR_NOT_SUPPORTED);
return 0;
}
#define __vcrt_CreateSymbolicLinkW _Not_supported_CreateSymbolicLinkW
#else // ^^^ defined(_CRT_APP) / !defined(_CRT_APP) vvv
#define __vcrt_CreateSymbolicLinkW CreateSymbolicLinkW
#endif // ^^^ !defined(_CRT_APP) ^^^

HANDLE __stdcall __vcp_CreateFile(const wchar_t* const _File_name, const unsigned long _Desired_access,
const unsigned long _Share, SECURITY_ATTRIBUTES* const _Security_attributes,
const unsigned long _Creation_disposition, const unsigned long _Flags_and_attributes,
Expand Down Expand Up @@ -70,14 +59,14 @@ namespace {

[[nodiscard]] __std_win_error __stdcall _Create_symlink(
const wchar_t* const _Symlink_file_name, const wchar_t* const _Target_file_name, const DWORD _Flags) noexcept {
if (__vcrt_CreateSymbolicLinkW(
if (CreateSymbolicLinkW(
_Symlink_file_name, _Target_file_name, _Flags | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)) {
return __std_win_error::_Success;
}

DWORD _Last_error = GetLastError();
if (_Last_error == ERROR_INVALID_PARAMETER) {
if (__vcrt_CreateSymbolicLinkW(_Symlink_file_name, _Target_file_name, _Flags)) {
if (CreateSymbolicLinkW(_Symlink_file_name, _Target_file_name, _Flags)) {
return __std_win_error::_Success;
}

Expand Down Expand Up @@ -234,11 +223,9 @@ void __stdcall __std_fs_directory_iterator_close(_In_ const __std_fs_dir_handle
return __std_code_page{CP_UTF8};
}

#if !defined(_ONECORE)
if (!AreFileApisANSI()) {
return __std_code_page{CP_OEMCP};
}
#endif // !defined(_ONECORE)

return __std_code_page{CP_ACP};
}
Expand Down Expand Up @@ -455,17 +442,11 @@ struct __std_fs_file_id { // typedef struct _FILE_ID_INFO {

[[nodiscard]] __std_win_error __stdcall __std_fs_create_hard_link(
_In_z_ const wchar_t* const _File_name, _In_z_ const wchar_t* const _Existing_file_name) noexcept {
#if defined(_CRT_APP)
(void) _File_name;
(void) _Existing_file_name;
return __std_win_error::_Not_supported;
#else // ^^^ defined(_CRT_APP) / !defined(_CRT_APP) vvv
if (CreateHardLinkW(_File_name, _Existing_file_name, nullptr)) {
return __std_win_error::_Success;
}

return __std_win_error{GetLastError()};
#endif // defined(_CRT_APP)
}

[[nodiscard]] __std_win_error __stdcall __std_fs_create_symbolic_link(
Expand Down Expand Up @@ -789,7 +770,6 @@ struct __std_fs_file_id { // typedef struct _FILE_ID_INFO {
namespace {
_Success_(return > 0 && return < nBufferLength) DWORD WINAPI _Stl_GetTempPath2W(
_In_ DWORD nBufferLength, _Out_writes_to_opt_(nBufferLength, return +1) LPWSTR lpBuffer) noexcept {
#if !defined(_ONECORE)
// See GH-3011: This is intentionally not attempting to cache the function pointer.
// TRANSITION, ABI: This should use __crtGetTempPath2W after this code is moved into the STL's DLL.

Expand All @@ -800,7 +780,6 @@ namespace {
if (_Pf) {
return _Pf(nBufferLength, lpBuffer);
}
#endif // ^^^ !defined(_ONECORE) ^^^

// ...otherwise use GetTempPathW.
return GetTempPathW(nBufferLength, lpBuffer);
Expand Down Expand Up @@ -1000,10 +979,6 @@ namespace {
// TRANSITION, ABI: __std_fs_create_directory_template() is preserved for binary compatibility
[[nodiscard]] __std_fs_create_directory_result __stdcall __std_fs_create_directory_template(
_In_z_ const wchar_t* const _Template_directory, _In_z_ const wchar_t* const _New_directory) noexcept {
#if defined(_CRT_APP)
(void) _Template_directory;
return __std_fs_create_directory(_New_directory);
#else // ^^^ defined(_CRT_APP) / !defined(_CRT_APP) vvv
if (CreateDirectoryExW(_Template_directory, _New_directory, nullptr)) {
return {true, __std_win_error::_Success};
}
Expand All @@ -1014,7 +989,6 @@ namespace {
}

return {false, _Last_error};
#endif // defined(_CRT_APP)
}

[[nodiscard]] _Success_(return._Error == __std_win_error::_Success) __std_ulong_and_error
Expand Down
8 changes: 0 additions & 8 deletions stl/src/taskscheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,12 @@ namespace Concurrency {
// the DLL in which the callback is located.

HMODULE _Call_get_module_handle_ex(DWORD _Flags, LPCWSTR _Addr) {
#if defined(_CRT_APP)
// We can't call GetModuleHandleExW from an app context, so treat
// that as a failure to call.
(void) _Flags;
(void) _Addr;
return nullptr;
#else // ^^^ defined(_CRT_APP) / !defined(_CRT_APP) vvv
HMODULE _Result;
if (!GetModuleHandleExW(_Flags, _Addr, &_Result)) {
return nullptr;
}

return _Result;
#endif // defined(_CRT_APP)
}

enum class _STL_host_status { _Exe, _Dll, _Unknown };
Expand Down
21 changes: 0 additions & 21 deletions stl/src/winapisupp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <Windows.h>

#if !defined(_ONECORE)
namespace {

// Use this macro for defining the following function pointers
Expand All @@ -24,7 +23,6 @@ namespace {
#define IFDYNAMICGETCACHEDFUNCTION(fn_name) if (const auto pf##fn_name = __KERNEL32Function_##fn_name)

} // unnamed namespace
#endif // ^^^ !defined(_ONECORE) ^^^

#if !defined(_CRT_WINDOWS) && !defined(UNDOCKED_WINDOWS_UCRT)

Expand Down Expand Up @@ -130,15 +128,7 @@ extern "C" _CRTIMP2 DWORD __cdecl __crtGetCurrentProcessorNumber() noexcept {
// TRANSITION, ABI: preserved for binary compatibility
extern "C" _CRTIMP2 BOOLEAN __cdecl __crtCreateSymbolicLinkW(
_In_ LPCWSTR const lpSymlinkFileName, _In_ LPCWSTR const lpTargetFileName, _In_ DWORD const dwFlags) noexcept {
#ifdef _CRT_APP
(void) lpSymlinkFileName;
(void) lpTargetFileName;
(void) dwFlags;
SetLastError(ERROR_NOT_SUPPORTED);
return 0;
#else // ^^^ defined(_CRT_APP) / !defined(_CRT_APP) vvv
return CreateSymbolicLinkW(lpSymlinkFileName, lpTargetFileName, dwFlags);
#endif // ^^^ !defined(_CRT_APP) ^^^
}

// TRANSITION, ABI: preserved for binary compatibility
Expand All @@ -164,25 +154,16 @@ extern "C" _CRTIMP2 void __cdecl __crtGetSystemTimePreciseAsFileTime(_Out_ LPFIL

extern "C" _Success_(return > 0 && return < BufferLength) DWORD __stdcall __crtGetTempPath2W(
_In_ DWORD BufferLength, _Out_writes_to_opt_(BufferLength, return +1) LPWSTR Buffer) noexcept {
#if !defined(_ONECORE)
// use GetTempPath2W if it is available (only on Windows 11+)...
IFDYNAMICGETCACHEDFUNCTION(GetTempPath2W) {
return pfGetTempPath2W(BufferLength, Buffer);
}
#endif // ^^^ !defined(_ONECORE) ^^^

// ...otherwise use GetTempPathW.
return GetTempPathW(BufferLength, Buffer);
}

// Helper to load all necessary Win32 API function pointers

#if defined(_ONECORE)

// All APIs are statically available, and we can't call GetModuleHandleW().

#else // ^^^ defined(_ONECORE) / !defined(_ONECORE) vvv

static int __cdecl initialize_pointers() noexcept {
HINSTANCE hKernel32 = GetModuleHandleW(L"kernel32.dll");
_Analysis_assume_(hKernel32);
Expand All @@ -195,5 +176,3 @@ static int __cdecl initialize_pointers() noexcept {
}

_CRTALLOC(".CRT$XIC") static _PIFV pinit = initialize_pointers;

#endif // ^^^ !defined(_ONECORE) ^^^