The variable __native_startup_lock should be volatile. But currently its
type is "volatile void *", which means that the dereferenced pointer value
is volatile, not the variable itself. Currently the compiler is throwing a
warning when the variable is used by InterlockedCompareExchangePointer() or
InterlockedExchangePointer() call. But all current usage do explicit cast
to (volatile PVOID *) which hides all warnings.
Existing type:
volatile PVOID * = void * volatile *
Before this change:
typeof(&__native_startup_lock) = void volatile **
After this change:
typeof(&__native_startup_lock) = void * volatile *
---
mingw-w64-crt/crt/crtdll.c | 10 +++++-----
mingw-w64-crt/crt/crtexe.c | 6 +++---
mingw-w64-crt/crt/natstart.c | 2 +-
mingw-w64-crt/include/internal.h | 2 +-
4 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/mingw-w64-crt/crt/crtdll.c b/mingw-w64-crt/crt/crtdll.c
index 90da38e604f7..a8b95ec50d59 100644
--- a/mingw-w64-crt/crt/crtdll.c
+++ b/mingw-w64-crt/crt/crtdll.c
@@ -79,8 +79,8 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason,
LPVOID lpreserved)
void *fiberid = ((PNT_TIB)NtCurrentTeb ())->StackBase;
int nested = FALSE;
- while ((lock_free = InterlockedCompareExchangePointer ((volatile PVOID
*) &__native_startup_lock,
- fiberid, 0)) != 0)
+ while ((lock_free = InterlockedCompareExchangePointer
(&__native_startup_lock,
+ fiberid, NULL)) !=
0)
{
if (lock_free == fiberid)
{
@@ -107,7 +107,7 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD
dwReason, LPVOID lpreserved)
}
if (! nested)
{
- (void) InterlockedExchangePointer ((volatile PVOID *)
&__native_startup_lock, 0);
+ (void) InterlockedExchangePointer (&__native_startup_lock, NULL);
}
if (__dyn_tls_init_callback != NULL)
{
@@ -118,7 +118,7 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD
dwReason, LPVOID lpreserved)
else if (dwReason == DLL_PROCESS_DETACH)
{
void *lock_free = NULL;
- while ((lock_free = InterlockedCompareExchangePointer ((volatile PVOID
*) &__native_startup_lock,(PVOID) 1, 0)) != 0)
+ while ((lock_free = InterlockedCompareExchangePointer
(&__native_startup_lock, (PVOID) 1, NULL)) != 0)
{
Sleep(1000);
}
@@ -130,7 +130,7 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD
dwReason, LPVOID lpreserved)
{
_execute_onexit_table(&atexit_table);
__native_startup_state = __uninitialized;
- (void) InterlockedExchangePointer ((volatile PVOID *)
&__native_startup_lock, 0);
+ (void) InterlockedExchangePointer (&__native_startup_lock, NULL);
}
}
return TRUE;
diff --git a/mingw-w64-crt/crt/crtexe.c b/mingw-w64-crt/crt/crtexe.c
index 328cc305b9b8..7cef6d7312d5 100644
--- a/mingw-w64-crt/crt/crtexe.c
+++ b/mingw-w64-crt/crt/crtexe.c
@@ -212,8 +212,8 @@ __tmainCRTStartup (void)
void *lock_free = NULL;
void *fiberid = ((PNT_TIB)NtCurrentTeb())->StackBase;
int nested = FALSE;
- while((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *)
&__native_startup_lock,
- fiberid, 0)) != 0)
+ while((lock_free = InterlockedCompareExchangePointer
(&__native_startup_lock,
+ fiberid, NULL)) != 0)
{
if (lock_free == fiberid)
{
@@ -242,7 +242,7 @@ __tmainCRTStartup (void)
}
_ASSERTE(__native_startup_state == __initialized);
if (! nested)
- (VOID)InterlockedExchangePointer ((volatile PVOID *)
&__native_startup_lock, 0);
+ (VOID)InterlockedExchangePointer (&__native_startup_lock, NULL);
if (__dyn_tls_init_callback != NULL)
__dyn_tls_init_callback (NULL, DLL_THREAD_ATTACH, NULL);
diff --git a/mingw-w64-crt/crt/natstart.c b/mingw-w64-crt/crt/natstart.c
index 06def19d51a9..0afbaa801a9a 100644
--- a/mingw-w64-crt/crt/natstart.c
+++ b/mingw-w64-crt/crt/natstart.c
@@ -11,4 +11,4 @@ _PGLOBAL
volatile unsigned int __native_dllmain_reason = UINT_MAX;
volatile unsigned int __native_vcclrit_reason = UINT_MAX;
volatile __enative_startup_state __native_startup_state;
-volatile void *__native_startup_lock;
+void *volatile __native_startup_lock;
diff --git a/mingw-w64-crt/include/internal.h b/mingw-w64-crt/include/internal.h
index 752c5dc9662c..b3f1186e1d83 100644
--- a/mingw-w64-crt/include/internal.h
+++ b/mingw-w64-crt/include/internal.h
@@ -130,7 +130,7 @@ extern "C" {
} __enative_startup_state;
extern volatile __enative_startup_state __native_startup_state;
- extern volatile void *__native_startup_lock;
+ extern void *volatile __native_startup_lock;
extern volatile unsigned int __native_dllmain_reason;
extern volatile unsigned int __native_vcclrit_reason;
--
2.20.1
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public