* Replace SetErrorMode with SetThreadErrorMode.
Replaces all possible locations.
Removed SetErrorMode from PAL.
#SetEvent
#SetFilePointer
#SetLastError
-#SetErrorMode
#SetThreadDescription
#Sleep
#SleepEx
typedef Wrapper<HKEY,DoNothing,RegKeyRelease> RegKeyHolder;
#endif // HOST_WINDOWS
-class ErrorModeHolder
+class ErrorModeHolder final
{
- UINT m_oldMode;
+#ifdef HOST_WINDOWS
+ BOOL m_revert;
+ DWORD m_oldMode;
public:
- ErrorModeHolder(UINT newMode){m_oldMode=SetErrorMode(newMode);};
- ~ErrorModeHolder(){SetErrorMode(m_oldMode);};
- UINT OldMode() {return m_oldMode;};
+ ErrorModeHolder()
+ : m_revert{ FALSE }
+ {
+ DWORD newMode = SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS;
+ m_revert = ::SetThreadErrorMode(newMode, &m_oldMode);
+ }
+ ~ErrorModeHolder() noexcept
+ {
+ if (m_revert != FALSE)
+ (void)::SetThreadErrorMode(m_oldMode, NULL);
+ }
+#endif // HOST_WINDOWS
};
#ifdef HOST_WINDOWS
VOID
PALAPI
PAL_SetCreateDumpCallback(
- IN PCREATEDUMP_CALLBACK callback);
+ IN PCREATEDUMP_CALLBACK callback);
PALIMPORT
BOOL
PALIMPORT VOID PALAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection);
PALIMPORT VOID PALAPI DeleteCriticalSection(IN OUT LPCRITICAL_SECTION lpCriticalSection);
-#define SEM_FAILCRITICALERRORS 0x0001
-#define SEM_NOOPENFILEERRORBOX 0x8000
-
-PALIMPORT
-UINT
-PALAPI
-SetErrorMode(
- IN UINT uMode);
-
#define PAGE_NOACCESS 0x01
#define PAGE_READONLY 0x02
#define PAGE_READWRITE 0x04
/*++
Function:
- SetErrorMode
-
-The SetErrorMode function controls whether the system will handle the
-specified types of serious errors, or whether the process will handle
-them.
-
-Parameters
-
-uMode
- [in] Specifies the process error mode. This parameter can be one or more of the following values.
-
- Value Action
- 0 Use the system default, which is to display all error dialog boxes.
- SEM_FAILCRITICALERRORS The system does not display the critical-error-handler message box. Instead,
- the system sends the error to the calling process.
- SEM_NOOPENFILEERRORBOX The system does not display a message box when it fails to find a file. Instead,
- the error is returned to the calling process.
-
-Return Values
-
-The return value is the previous state of the error-mode bit flags.
-
---*/
-UINT
-PALAPI
-SetErrorMode(
- IN UINT uMode)
-{
- PERF_ENTRY(SetErrorMode);
- ENTRY("SetErrorMode (uMode=%#x)\n", uMode);
-
- LOGEXIT("SetErrorMode returns UINT 0\n");
- PERF_EXIT(SetErrorMode);
- return 0;
-}
-
-
-/*++
-Function:
GetLastError
GetLastError
threading/ResetEvent/test3/test3.cpp
threading/ResetEvent/test4/test4.cpp
threading/ResumeThread/test1/test1.cpp
- threading/SetErrorMode/test1/test1.cpp
threading/SetEvent/test1/test1.cpp
threading/SetEvent/test2/test2.cpp
threading/SetEvent/test3/test3.cpp
threading/ResetEvent/test3/paltest_resetevent_test3
threading/ResetEvent/test4/paltest_resetevent_test4
threading/ResumeThread/test1/paltest_resumethread_test1
-threading/SetErrorMode/test1/paltest_seterrormode_test1
threading/SetEvent/test1/paltest_setevent_test1
threading/SetEvent/test2/paltest_setevent_test2
threading/SetEvent/test3/paltest_setevent_test3
threading/ResetEvent/test3/paltest_resetevent_test3
threading/ResetEvent/test4/paltest_resetevent_test4
threading/ResumeThread/test1/paltest_resumethread_test1
-threading/SetErrorMode/test1/paltest_seterrormode_test1
threading/SetEvent/test1/paltest_setevent_test1
threading/SetEvent/test2/paltest_setevent_test2
threading/SetEvent/test3/paltest_setevent_test3
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*=====================================================================
-**
-** Source: test1.c (SetErrorMode)
-**
-** Purpose: Tests the PAL implementation of the SetErrorMode function.
-** This test will set the error mode and then read the error
-** set with GetLastError().
-**
-**
-**===================================================================*/
-
-#include <palsuite.h>
-
-PALTEST(threading_SetErrorMode_test1_paltest_seterrormode_test1, "threading/SetErrorMode/test1/paltest_seterrormode_test1")
-{
- DWORD dErrorReturn;
- UINT dErrorModes[] = {SEM_NOOPENFILEERRORBOX, SEM_FAILCRITICALERRORS, 0};
- int i;
-
- /*
- * Initialize the Pal
- */
- if ((PAL_Initialize(argc,argv)) != 0)
- {
- return (FAIL);
- }
-
- /*
- * Loop through the supported Error Modes and verify
- * that GetLastError() returns the correct Error Mode
- */
- for (i=0; i < (sizeof(dErrorModes) / sizeof(UINT)); i++)
- {
- SetLastError(dErrorModes[i]);
- if ((dErrorReturn = GetLastError()) != dErrorModes[i])
- {
- Fail("ERROR: SetLastError was set to 0x%4.4x but,"
- " GetLastError returned 0x%4.4x\n",
- dErrorModes[i],
- dErrorReturn);
- }
- }
-
- PAL_Terminate();
- return (PASS);
-}
// AddRef which we take inside the lock at the bottom of this method.
CrstHolder holder(&m_ISymUnmanagedReaderCrst);
- UINT lastErrorMode = 0;
-
// If we haven't created a reader yet, do so now
if (m_pISymUnmanagedReader == NULL)
{
// Note: we change the error mode here so we don't get any popups as the PDB symbol reader attempts to search the
// hard disk for files.
- lastErrorMode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);
+ ErrorModeHolder errorMode{};
SafeComHolder<ISymUnmanagedReader> pReader;
hr = pBinder->GetReaderForFile(pUnk, path, NULL, &pReader);
}
- SetErrorMode(lastErrorMode);
-
if (SUCCEEDED(hr))
{
m_pISymUnmanagedReader = pReader.Extract();
if (m_hFile!=INVALID_HANDLE_VALUE)
return S_OK;
- ErrorModeHolder mode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);
+ ErrorModeHolder mode{};
m_hFile=WszCreateFile((LPCWSTR)GetPathToLoad(),
GENERIC_READ
#if TARGET_WINDOWS
PVOID loadedImage;
#if TARGET_UNIX
{
- ErrorModeHolder mode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);
HANDLE fileHandle = WszCreateFile(
fullPath,
GENERIC_READ,
STATIC_CONTRACT_FAULT;
HMODULE hMod;
- UINT last = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);
+ ErrorModeHolder errorMode{};
{
INDEBUG(PEDecoder::ForceRelocForDLL(lpLibFileName));
hMod = WszLoadLibrary(lpLibFileName);
*pLastError = GetLastError();
}
- SetErrorMode(last);
return hMod;
}
STATIC_CONTRACT_FAULT;
HMODULE hMod;
- UINT last = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);
+ ErrorModeHolder errorMode{};
{
INDEBUG(PEDecoder::ForceRelocForDLL(lpLibFileName));
hMod = WszLoadLibraryEx(lpLibFileName, hFile, dwFlags);
*pLastError = GetLastError();
}
- SetErrorMode(last);
return hMod;
}