diff --git a/include/unicorn/platform.h b/include/unicorn/platform.h index 4b9233d1..220bf56e 100644 --- a/include/unicorn/platform.h +++ b/include/unicorn/platform.h @@ -169,20 +169,24 @@ static int gettimeofday(struct timeval* t, void* timezone) // unistd.h compatibility #if defined(_MSC_VER) -// horrible kludge requiring winsock to get microsecond sleep resolution. -// if this is removed then all winsock references can also be removed. -static int usleep(uint32_t t) +static int usleep(uint32_t usec) { - int ret, err_code; - long value = t; // time in microseconds - struct timeval tv; - FD_SET dummy_set; - FD_ZERO(&dummy_set); - tv.tv_sec = value / 1000000; - tv.tv_usec = value % 1000000; - ret = select(0, &dummy_set, NULL, NULL, &tv); - err_code = WSAGetLastError(); - return ret==0 ? 0 : -1; + HANDLE timer; + LARGE_INTEGER due; + + timer = CreateWaitableTimer(NULL, TRUE, NULL); + if (!timer) + return -1; + + due.QuadPart = (-((int64_t) usec)) * 10LL; + if (!SetWaitableTimer(timer, &due, 0, NULL, NULL, 0)) { + CloseHandle(timer); + return -1; + } + WaitForSingleObject(timer, INFINITE); + CloseHandle(timer); + + return 0; } #else diff --git a/msvc/unicorn/unicorn/unicorn.vcxproj b/msvc/unicorn/unicorn/unicorn.vcxproj index cb042e05..441e695a 100644 --- a/msvc/unicorn/unicorn/unicorn.vcxproj +++ b/msvc/unicorn/unicorn/unicorn.vcxproj @@ -1,4 +1,4 @@ - + @@ -99,7 +99,7 @@ Windows true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);ws2_32.lib;aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib $(SolutionDir)$(Platform)\$(Configuration)\ @@ -117,7 +117,7 @@ Windows true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);ws2_32.lib;aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib $(SolutionDir)$(Platform)\$(Configuration)\ @@ -140,7 +140,7 @@ true true true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);ws2_32.lib;aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib $(SolutionDir)$(Platform)\$(Configuration)\ @@ -175,7 +175,7 @@ copy $(SolutionDir)..\include\unicorn\*.h $(SolutionDir)distro\include\unicorn\ true true true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);ws2_32.lib;aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib $(SolutionDir)$(Platform)\$(Configuration)\ diff --git a/msvc/unicorn/unicorn_static/unicorn_static.vcxproj b/msvc/unicorn/unicorn_static/unicorn_static.vcxproj index b1c08164..55776960 100644 --- a/msvc/unicorn/unicorn_static/unicorn_static.vcxproj +++ b/msvc/unicorn/unicorn_static/unicorn_static.vcxproj @@ -1,4 +1,4 @@ - + @@ -250,7 +250,7 @@ $(SolutionDir)$(Platform)\$(Configuration)\ - ws2_32.lib;aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib + aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib ..\prebuild_script.bat @@ -274,7 +274,7 @@ $(SolutionDir)$(Platform)\$(Configuration)\ - ws2_32.lib;aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib + aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib ..\prebuild_script.bat @@ -303,7 +303,7 @@ $(SolutionDir)$(Platform)\$(Configuration)\ - ws2_32.lib;aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib + aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib ..\prebuild_script.bat @@ -343,7 +343,7 @@ copy $(SolutionDir)..\include\unicorn\*.h $(SolutionDir)distro\include\unicorn\ $(SolutionDir)$(Platform)\$(Configuration)\ - ws2_32.lib;aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib + aarch64-softmmu.lib;arm-softmmu.lib;m68k-softmmu.lib;mips-softmmu.lib;mips64-softmmu.lib;mipsel-softmmu.lib;mips64el-softmmu.lib;sparc-softmmu.lib;sparc64-softmmu.lib;x86_64-softmmu.lib ..\prebuild_script.bat diff --git a/qemu/include/qemu/atomic.h b/qemu/include/qemu/atomic.h index f9fbd7ca..79c10efe 100644 --- a/qemu/include/qemu/atomic.h +++ b/qemu/include/qemu/atomic.h @@ -19,8 +19,9 @@ /* Compiler barrier */ #ifdef _MSC_VER -// TODO: fix me!!! -#define barrier() //{ __asm volatile("" ::: "memory"); (void)0; } +void _ReadWriteBarrier(void); +#pragma intrinsic(_ReadWriteBarrier) +#define barrier() do { _ReadWriteBarrier(); } while (0) #else #define barrier() ({ asm volatile("" ::: "memory"); (void)0; }) #endif diff --git a/uc.c b/uc.c index 8cbfafc2..6a6ad445 100644 --- a/uc.c +++ b/uc.c @@ -268,14 +268,6 @@ uc_err uc_open(uc_arch arch, uc_mode mode, uc_engine **result) if (uc->reg_reset) uc->reg_reset(uc); - // init winsock sockets so we can use select() for usleep() implementation -#ifdef _MSC_VER - { - WSADATA wsa_data; - WSAStartup(0x202, &wsa_data); - } -#endif - return UC_ERR_OK; } else { return UC_ERR_ARCH; @@ -354,13 +346,6 @@ uc_err uc_close(uc_engine *uc) // finally, free uc itself. memset(uc, 0, sizeof(*uc)); free(uc); - - // free winsock sockets - used so we can use select() for usleep() implementation -#ifdef _MSC_VER - { - WSACleanup(); - } -#endif return UC_ERR_OK; }