Martin Storsjo : ntdll: Implement NtFlushInstructionCache using __clear_cache where available.
Alexandre Julliard
julliard at winehq.org
Mon Jan 22 15:34:55 CST 2018
Module: wine
Branch: master
Commit: 4415653f842ae145178703a643cc1f62ee70b648
URL: https://source.winehq.org/git/wine.git/?a=commit;h=4415653f842ae145178703a643cc1f62ee70b648
Author: Martin Storsjo <martin at martin.st>
Date: Mon Jan 22 00:05:09 2018 +0200
ntdll: Implement NtFlushInstructionCache using __clear_cache where available.
The configure check needs to be done with a more elaborate test than
just AC_CHECK_FUNC, since it's a built-in function in clang and errors
out if invoked with no parameters.
Signed-off-by: Martin Storsjo <martin at martin.st>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
configure | 33 +++++++++++++++++++++++++++++++++
configure.ac | 8 ++++++++
dlls/ntdll/process.c | 24 ++++++++++++++----------
include/config.h.in | 4 ++++
4 files changed, 59 insertions(+), 10 deletions(-)
diff --git a/configure b/configure
index f62b9e3..bcba635 100755
--- a/configure
+++ b/configure
@@ -17759,6 +17759,39 @@ $as_echo "#define HAVE___BUILTIN_POPCOUNT 1" >>confdefs.h
fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __clear_cache" >&5
+$as_echo_n "checking for __clear_cache... " >&6; }
+if ${ac_cv_have___clear_cache+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+__clear_cache((void*)0, (void*)0); return 0;
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_have___clear_cache="yes"
+else
+ ac_cv_have___clear_cache="no"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have___clear_cache" >&5
+$as_echo "$ac_cv_have___clear_cache" >&6; }
+if test "$ac_cv_have___clear_cache" = "yes"
+then
+
+$as_echo "#define HAVE___CLEAR_CACHE 1" >>confdefs.h
+
+fi
+
case $host_cpu in
*i[3456789]86*) { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we need to define __i386__" >&5
diff --git a/configure.ac b/configure.ac
index 9aa3228..db666b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2706,6 +2706,14 @@ then
AC_DEFINE(HAVE___BUILTIN_POPCOUNT, 1, [Define to 1 if you have the `__builtin_popcount' built-in function.])
fi
+AC_CACHE_CHECK([for __clear_cache], ac_cv_have___clear_cache,
+ AC_LINK_IFELSE([AC_LANG_PROGRAM(,[[__clear_cache((void*)0, (void*)0); return 0;]])],
+ [ac_cv_have___clear_cache="yes"], [ac_cv_have___clear_cache="no"]))
+if test "$ac_cv_have___clear_cache" = "yes"
+then
+ AC_DEFINE(HAVE___CLEAR_CACHE, 1, [Define to 1 if you have the `__clear_cache' (potentially built-in) function.])
+fi
+
dnl *** check for the need to define platform-specific symbols
case $host_cpu in
diff --git a/dlls/ntdll/process.c b/dlls/ntdll/process.c
index f615ce2..40034b4 100644
--- a/dlls/ntdll/process.c
+++ b/dlls/ntdll/process.c
@@ -653,20 +653,24 @@ NTSTATUS WINAPI NtSetInformationProcess(
* NtFlushInstructionCache [NTDLL.@]
* ZwFlushInstructionCache [NTDLL.@]
*/
-NTSTATUS WINAPI NtFlushInstructionCache(
- IN HANDLE ProcessHandle,
- IN LPCVOID BaseAddress,
- IN SIZE_T Size)
+NTSTATUS WINAPI NtFlushInstructionCache( HANDLE handle, const void *addr, SIZE_T size )
{
- static int once;
- if (!once++)
- {
#if defined(__x86_64__) || defined(__i386__)
- TRACE("%p %p %ld - no-op on x86 and x86_64\n", ProcessHandle, BaseAddress, Size );
+ /* no-op */
+#elif defined(HAVE___CLEAR_CACHE)
+ if (handle == GetCurrentProcess())
+ {
+ __clear_cache( (char *)addr, (char *)addr + size );
+ }
+ else
+ {
+ static int once;
+ if (!once++) FIXME( "%p %p %ld other process not supported\n", handle, addr, size );
+ }
#else
- FIXME("%p %p %ld\n", ProcessHandle, BaseAddress, Size );
+ static int once;
+ if (!once++) FIXME( "%p %p %ld\n", handle, addr, size );
#endif
- }
return STATUS_SUCCESS;
}
diff --git a/include/config.h.in b/include/config.h.in
index 9224837..4db349c 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -1407,6 +1407,10 @@
/* Define to 1 if you have the `__builtin_popcount' built-in function. */
#undef HAVE___BUILTIN_POPCOUNT
+/* Define to 1 if you have the `__clear_cache' (potentially built-in)
+ function. */
+#undef HAVE___CLEAR_CACHE
+
/* Define to 1 if you have the `__res_getservers' function. */
#undef HAVE___RES_GETSERVERS
More information about the wine-cvs
mailing list