From 1266ebb2227e5fff5aece90a7dcae081766df693 Mon Sep 17 00:00:00 2001 From: Xu Jun <693788454@qq.com> Date: Thu, 13 Aug 2020 16:40:19 +0800 Subject: [PATCH] fix coding style for windows build patch (#350) --- build-scripts/runtime_lib.cmake | 4 ++-- core/iwasm/common/arch/invokeNative_ia32.asm | 2 +- .../platform/windows/platform_internal.h | 14 ++++++----- core/shared/platform/windows/win_memmap.c | 23 +++++++++++-------- core/shared/platform/windows/win_thread.c | 18 ++++++++------- core/shared/platform/windows/win_time.c | 2 +- core/shared/utils/uncommon/bh_read_file.c | 4 ++-- wamr-compiler/build_llvm.py | 6 ++--- 8 files changed, 40 insertions(+), 33 deletions(-) diff --git a/build-scripts/runtime_lib.cmake b/build-scripts/runtime_lib.cmake index eb5a90a15..a87a2ff63 100644 --- a/build-scripts/runtime_lib.cmake +++ b/build-scripts/runtime_lib.cmake @@ -83,8 +83,8 @@ endif () ####################### Common sources ####################### if (NOT MSVC) -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections \ - -Wall -Wno-unused-parameter -Wno-pedantic") + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections \ + -Wall -Wno-unused-parameter -Wno-pedantic") endif () # include the build config template file diff --git a/core/iwasm/common/arch/invokeNative_ia32.asm b/core/iwasm/common/arch/invokeNative_ia32.asm index 8bd28722c..c52c8d6ed 100644 --- a/core/iwasm/common/arch/invokeNative_ia32.asm +++ b/core/iwasm/common/arch/invokeNative_ia32.asm @@ -6,7 +6,7 @@ .386 .model flat .code -_invokeNative PROC +_invokeNative PROC push ebp mov ebp,esp mov ecx, [ebp+16] ; ecx = argc */ diff --git a/core/shared/platform/windows/platform_internal.h b/core/shared/platform/windows/platform_internal.h index 8803e8029..65a933ac3 100644 --- a/core/shared/platform/windows/platform_internal.h +++ b/core/shared/platform/windows/platform_internal.h @@ -45,17 +45,19 @@ typedef void *korp_sem; typedef void *korp_thread; typedef struct { - korp_sem s; - unsigned int waiting_count; + korp_sem s; + unsigned int waiting_count; } korp_cond; #define os_printf printf #define os_vprintf vprintf -static inline size_t getpagesize() { - SYSTEM_INFO S; - GetNativeSystemInfo(&S); - return S.dwPageSize; +static inline size_t +getpagesize() +{ + SYSTEM_INFO S; + GetNativeSystemInfo(&S); + return S.dwPageSize; } #ifdef __cplusplus diff --git a/core/shared/platform/windows/win_memmap.c b/core/shared/platform/windows/win_memmap.c index e5d478b16..6bcf6b3e0 100644 --- a/core/shared/platform/windows/win_memmap.c +++ b/core/shared/platform/windows/win_memmap.c @@ -4,6 +4,7 @@ */ #include "platform_api_vmcore.h" + void * os_mmap(void *hint, size_t size, int prot, int flags) { DWORD AllocType = MEM_RESERVE | MEM_COMMIT; @@ -17,14 +18,14 @@ void * os_mmap(void *hint, size_t size, int prot, int flags) if (request_size < size) /* integer overflow */ return NULL; - + if (prot & MMAP_PROT_EXEC) { if (prot & MMAP_PROT_WRITE) flProtect = PAGE_EXECUTE_READWRITE; - else + else flProtect = PAGE_EXECUTE_READ; - } - else if (prot & MMAP_PROT_WRITE) + } + else if (prot & MMAP_PROT_WRITE) flProtect = PAGE_READWRITE; else if (prot & MMAP_PROT_READ) flProtect = PAGE_READONLY; @@ -40,12 +41,12 @@ os_munmap(void *addr, size_t size) { size_t page_size = getpagesize(); size_t request_size = (size + page_size - 1) & ~(page_size - 1); + if (addr) { - if (VirtualFree(addr, 0, MEM_RELEASE) == 0) { if (VirtualFree(addr, size, MEM_DECOMMIT) == 0) { os_printf("os_munmap error addr:%p, size:0x%lx, errno:%d\n", - addr, request_size, errno); + addr, request_size, errno); } } } @@ -56,16 +57,17 @@ os_mprotect(void *addr, size_t size, int prot) { DWORD AllocType = MEM_RESERVE | MEM_COMMIT; DWORD flProtect = PAGE_NOACCESS; + if (!addr) return 0; - + if (prot & MMAP_PROT_EXEC) { if (prot & MMAP_PROT_WRITE) flProtect = PAGE_EXECUTE_READWRITE; - else + else flProtect = PAGE_EXECUTE_READ; - } - else if (prot & MMAP_PROT_WRITE) + } + else if (prot & MMAP_PROT_WRITE) flProtect = PAGE_READWRITE; else if (prot & MMAP_PROT_READ) flProtect = PAGE_READONLY; @@ -76,4 +78,5 @@ os_mprotect(void *addr, size_t size, int prot) void os_dcache_flush(void) { + } diff --git a/core/shared/platform/windows/win_thread.c b/core/shared/platform/windows/win_thread.c index d4b9e64a8..896137ef7 100644 --- a/core/shared/platform/windows/win_thread.c +++ b/core/shared/platform/windows/win_thread.c @@ -97,22 +97,24 @@ int os_cond_wait(korp_cond *cond, korp_mutex *mutex) int gettimeofday(struct timeval * tp, struct timezone * tzp) { - // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's - // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC) - // until 00:00:00 January 1, 1970 + /* Note: some broken versions only have 8 trailing zero's, + the correct epoch has 9 trailing zero's + This magic number is the number of 100 nanosecond intervals + since January 1, 1601 (UTC) until 00:00:00 January 1, 1970 */ static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL); SYSTEMTIME system_time; FILETIME file_time; uint64_t time; - GetSystemTime( &system_time ); - SystemTimeToFileTime( &system_time, &file_time ); - time = ((uint64_t)file_time.dwLowDateTime ) ; + GetSystemTime(&system_time); + SystemTimeToFileTime(&system_time, &file_time); + time = ((uint64_t)file_time.dwLowDateTime); time += ((uint64_t)file_time.dwHighDateTime) << 32; - tp->tv_sec = (long) ((time - EPOCH) / 10000000L); - tp->tv_usec = (long) (system_time.wMilliseconds * 1000); + tp->tv_sec = (long)((time - EPOCH) / 10000000L); + tp->tv_usec = (long)(system_time.wMilliseconds * 1000); + return 0; } diff --git a/core/shared/platform/windows/win_time.c b/core/shared/platform/windows/win_time.c index 3028a2efb..a48e4191d 100644 --- a/core/shared/platform/windows/win_time.c +++ b/core/shared/platform/windows/win_time.c @@ -11,6 +11,6 @@ os_time_get_boot_microsecond() struct timespec ts; timespec_get(&ts, TIME_UTC); - return ((uint64) ts.tv_sec) * 1000 * 1000 + ((uint64)ts.tv_nsec) / 1000; + return ((uint64)ts.tv_sec) * 1000 * 1000 + ((uint64)ts.tv_nsec) / 1000; } diff --git a/core/shared/utils/uncommon/bh_read_file.c b/core/shared/utils/uncommon/bh_read_file.c index 08165c535..e13b388d6 100644 --- a/core/shared/utils/uncommon/bh_read_file.c +++ b/core/shared/utils/uncommon/bh_read_file.c @@ -24,13 +24,13 @@ bh_read_file_to_buffer(const char *filename, uint32 *ret_size) if (_sopen_s(&file, filename, _O_RDONLY| _O_BINARY, _SH_DENYNO, 0)) { printf("Read file to buffer failed: open file %s failed.\n", - filename); + filename); return NULL; } if (fstat(file, &stat_buf) != 0) { printf("Read file to buffer failed: fstat file %s failed.\n", - filename); + filename); _close(file); return NULL; } diff --git a/wamr-compiler/build_llvm.py b/wamr-compiler/build_llvm.py index ba965a350..d9912af2f 100644 --- a/wamr-compiler/build_llvm.py +++ b/wamr-compiler/build_llvm.py @@ -59,7 +59,7 @@ def main(): Path(build_dir_name).mkdir(exist_ok = True) build_dir = Path(build_dir_name) os.chdir(build_dir) - + if ( not Path(llvm_file).exists()): core_number = os.cpu_count() print("Build llvm with", core_number, " cores") @@ -81,10 +81,10 @@ def main(): -DLLVM_APPEND_VC_REV:BOOL=OFF' print(cmd) for line in os.popen(cmd): - print(line) + print(line) else: print("llvm has already been Cmaked") - + if(current_os == "linux"): for line in os.popen("make -j {}".format(core_number)): print(line)