From ba34ef9bd7cba3caab2512be587286659223c6d3 Mon Sep 17 00:00:00 2001 From: Yiwei Yang <40686366+victoryang00@users.noreply.github.com> Date: Tue, 27 Feb 2024 19:17:53 -0800 Subject: [PATCH] push windows --- .github/workflows/build-windows.yml | 2 +- CMakeLists.txt | 6 +- artifact/bench_windows.py | 284 ++++++++++++++-------------- artifact/result/windows.csv | 111 +++++++++++ artifact/result/windows.pdf | Bin 0 -> 1205 bytes src/wamr_mvvm.cpp | 42 ++++ 6 files changed, 303 insertions(+), 142 deletions(-) create mode 100644 artifact/result/windows.csv create mode 100644 artifact/result/windows.pdf diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 436eca7..69e9c3b 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -36,7 +36,7 @@ jobs: cd vcpkg git checkout a56d892ac792797d779eae79d3423e0131422628 ./bootstrap-vcpkg.bat - ./vcpkg install fmt:x64-windows cxxopts:x64-windows spdlog:x64-windows + ./vcpkg install fmt:x64-windows cxxopts:x64-windows spdlog:x64-windows detours:x64-windows echo "C:/tools/msys64/usr/bin/" >> "$GITHUB_PATH" C:/tools/msys64/usr/bin/pacman.exe --noconfirm -S gcc diff --git a/CMakeLists.txt b/CMakeLists.txt index 56c8201..428a2c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,11 @@ else () set(CMAKE_MSVC_RUNTIME_LIBRARY "") set(CMAKE_GENERATOR_PLATFORM "") set(CMAKE_CXX_FLAGS "/MD") - set(WIN_EXTRA_LIBS uvwasi_a uv_a ws2_32) + find_library(DETOURS_LIBRARY detours REQUIRED) + find_path(DETOURS_INCLUDE_DIRS "detours/detours.h") + find_library(DETOURS_LIBRARY detours REQUIRED) + set(WIN_EXTRA_LIBS uvwasi_a msvcrt.lib libcmt.lib ${DETOURS_LIBRARY} uv_a ws2_32) + include_directories(${DETOURS_INCLUDE_DIRS}) if(MVVM_BUILD_TEST) set(BLAS_LIBRARIES "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/lib/x64/cublas.lib" "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/lib/x64/cudart.lib") set(BLAS_INCLUDE_DIRS "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/include/") diff --git a/artifact/bench_windows.py b/artifact/bench_windows.py index 74d92fa..6a58409 100644 --- a/artifact/bench_windows.py +++ b/artifact/bench_windows.py @@ -1,21 +1,13 @@ import csv import common_util -from multiprocessing import Pool - +import numpy as np +import matplotlib.pyplot as plt +from collections import defaultdict cmd = [ "linpack", "llama", "rgbd_tum", - "bfs", - "bc", - "bfs", - "cc", - "cc_sv", - "pr", - "pr_spmv", - "sssp", - "tc", "bt", "cg", "ep", @@ -24,21 +16,11 @@ "mg", "sp", "redis", - "hdastar", ] folder = [ "linpack", "llama", "ORB_SLAM2", - "gapbs", - "gapbs", - "gapbs", - "gapbs", - "gapbs", - "gapbs", - "gapbs", - "gapbs", - "gapbs", "nas", "nas", "nas", @@ -47,21 +29,11 @@ "nas", "nas", "redis", - "hdastar", ] arg = [ [], ["stories110M.bin", "-z", "tokenizer.bin", "-t", "0.0"], ["./ORBvoc.txt,", "./TUM3.yaml", "./", "./associations/fr1_xyz.txt"], - ["-f", "./road.sg", "-n300"], - ["-g20", "-vn300"], - ["-g20", "-vn300"], - ["-f", "./road.sg", "-n300"], - ["-g20", "-vn300"], - ["-g20", "-vn300"], - ["-g20", "-vn300"], - ["-g20", "-vn300"], - ["-g20", "-n300"], [], [], [], @@ -70,127 +42,56 @@ [], [], [], - ["maze-6404.txt", "8"], ] envs = [ "a=b", - "OMP_NUM_THREADS=4", - "a=b", - "OMP_NUM_THREADS=4", - "OMP_NUM_THREADS=4", - "OMP_NUM_THREADS=4", - "OMP_NUM_THREADS=4", - "OMP_NUM_THREADS=4", - "OMP_NUM_THREADS=4", - "OMP_NUM_THREADS=4", - "OMP_NUM_THREADS=4", - "OMP_NUM_THREADS=4", - "OMP_NUM_THREADS=4", - "OMP_NUM_THREADS=4", - "OMP_NUM_THREADS=4", - "OMP_NUM_THREADS=4", - "OMP_NUM_THREADS=4", - "OMP_NUM_THREADS=4", - "OMP_NUM_THREADS=4", + "OMP_NUM_THREADS=1", "a=b", + "OMP_NUM_THREADS=1", + "OMP_NUM_THREADS=1", + "OMP_NUM_THREADS=1", + "OMP_NUM_THREADS=1", + "OMP_NUM_THREADS=1", + "OMP_NUM_THREADS=1", + "OMP_NUM_THREADS=1", "a=b", ] -pool = Pool(processes=1) - def run_mvvm(): results = [] results1 = [] for _ in range(common_util.trial): for i in range(len(cmd)): - for j in range(len(common_util.aot_variant)): - for env in common_util.list_of_arg: - aot = cmd[i] + common_util.aot_variant[j] - results1.append( - pool.apply_async(common_util.run, (aot, arg[i], env)) - ) + aot = cmd[i] + ".aot" + results1.append(common_util.run(aot, arg[i], envs[i])) # print the results - results1 = [x.get() for x in results1] + for exec, output in results1: lines = output.split("\n") for line in lines: if line.__contains__("Execution time:"): exec_time = line.split(" ")[-2] print(exec, exec_time) - results.append((exec , exec_time)) # discover 4 aot_variant + results.append((exec, exec_time)) # discover 4 aot_variant return results - -def run_hcontainer(): +def run_wamr(): results = [] results1 = [] - for _ in range(common_util.trial): - for env in common_util.envs: - for i in range(len(cmd)): - aot = cmd[i] - results1.append( - pool.apply_async( - common_util.run_hcontainer, - (aot, "linpack", arg[i], env), - ) - ) - # print the results - results1 = [x.get() for x in results1] - for exec, output in results1: - print(exec, output) - lines = output.split("\n") - for line in lines: - if line.__contains__("user"): - exec_time = float(line.split(" ")[0].replace("user", "")) - results.append((exec, exec_time)) - return results - -def run_qemu_x86_64(): - results= [] - results1 = [] for _ in range(common_util.trial): for i in range(len(cmd)): - aot = cmd[i] - results1.append( - pool.apply_async( - common_util.run_qemu_x86_64, - (aot, "linpack", arg[i], envs[i]), - ) - ) + aot = cmd[i] + "-pure.aot" + results1.append(common_util.run(aot, arg[i], envs[i])) # print the results - results1 = [x.get() for x in results1] - for exec, output in results1: - print(exec, output) - lines = output.split("\n") - for line in lines: - if line.__contains__("user"): - exec_time = float(line.split(" ")[0].replace("user", "")) - results.append((exec, exec_time)) - return results - -def run_qemu_aarch64(): - results = [] - results1 = [] - for _ in range(common_util.trial): - for i in range(len(cmd)): - aot = cmd[i] - results1.append( - pool.apply_async( - common_util.run_qemu_aarch64, - (aot, "linpack", arg[i], envs[i]), - ) - ) - results1 = [x.get() for x in results1] for exec, output in results1: - print(exec, output) lines = output.split("\n") for line in lines: - if line.__contains__("user"): - exec_time = float(line.split(" ")[0].replace("user", "")) - results.append((exec, exec_time)) - + if line.__contains__("Execution time:"): + exec_time = line.split(" ")[-2] + print(exec, exec_time) + results.append((exec, exec_time)) # discover 4 aot_variant return results @@ -201,30 +102,35 @@ def run_native(): for i in range(len(cmd)): aot = cmd[i] results1.append( - pool.apply_async( - common_util.run_native, - (aot, "linpack", arg[i], envs[i]), - ) + common_util.run_native(aot, folder[i], arg[i], envs[i]), ) - results1 = [x.get() for x in results1] for exec, output in results1: print(exec, output) lines = output.split("\n") for line in lines: - if line.__contains__("user"): - exec_time = float(line.split(" ")[0].replace("user", "")) - results.append((exec, exec_time)) + if line.__contains__("elapsed"): + # Split the time string into minutes, seconds, and milliseconds + minutes, seconds = line.split(" ")[2].replace("elapsed", "").split(":") + seconds, milliseconds = seconds.split(".") + + # Convert each part to seconds (note that milliseconds are converted and added as a fraction of a second) + total_seconds = ( + int(minutes) * 60 + int(seconds) + int(milliseconds) / 1000 + ) + + print(total_seconds) + exec_time = total_seconds + results.append((exec, exec_time)) return results + def write_to_csv(filename): # 'data' is a list of tuples, e.g., [(checkpoint_result_0, checkpoint_result_1, restore_result_2), ...] with open(filename, "a+", newline="") as csvfile: writer = csv.writer(csvfile) # Optionally write headers - writer.writerow( - ["name", "mvvm", "hcontainer", "qemu_x86_64", "qemu_aach64", "native"] - ) + writer.writerow(["name", "mvvm", "wamr", "native"]) # Write the data for idx, row in enumerate(mvvm_results): @@ -232,20 +138,118 @@ def write_to_csv(filename): [ row[0], row[1], - hcontainer_results[idx][1], - qemu_x86_64_results[idx][1], - qemu_aarch64_results[idx][1], + wamr_results[idx][1], native_results[idx][1], ] ) +def read_from_csv(filename): + with open(filename, "r") as csvfile: + reader = csv.reader(csvfile) + next(reader) + results = [] + for row in reader: + results.append((row[0], float(row[1]), float(row[2]), float(row[3]))) + return results + + +# print the results +def plot(result, file_name="windows.pdf"): + workloads = defaultdict(list) + for workload, mvvm, wamr, native in result: + workloads[ + workload.replace("OMP_NUM_THREADS=", "") + .replace("-g15", "") + .replace("-n300", "") + .replace(" -f ", "") + .replace("-vn300", "") + .replace("maze-6404.txt", "") + .replace("stories110M.bin", "") + .replace("-z tokenizer.bin -t 0.0", "") + .replace("ORBvoc.txt", "") + .replace("TUM3.yaml", "") + .replace("./associations/fr1_xyz.txt", "") + .replace("./", "") + .strip() + ].append((mvvm, wamr, native)) + + # Calculate the medians and standard deviations for each workload + statistics = {} + for workload, times in workloads.items(): + mvvms, wamr,native = zip(*times) + statistics[workload] = { + "mvvm_median": np.median(mvvms), + "wamr_median": np.median(wamr), + "native_median": np.median(native), + "mvvm_std": np.std(mvvms), + "wamr_std": np.std(wamr), + "native_std": np.std(native), + } + font = {"size": 14} + + # using rc function + plt.rc("font", **font) + # Plotting + fig, ax = plt.subplots(figsize=(15, 7)) + # Define the bar width and positions + bar_width = 0.7 / 3 + index = np.arange(len(statistics)) + + # Plot the bars for each workload + # for i, (workload, stats) in enumerate(statistics.items()): + # ax.bar(index[i], stats['mvvm_median'], bar_width, yerr=stats['mvvm_std'], capsize=5, label=f'mvvm') + # ax.bar(index[i] + bar_width, stats['wamr_median'], bar_width, yerr=stats['wamr_std'], capsize=5, label=f'wamr') + for i, (workload, stats) in enumerate(statistics.items()): + ax.bar( + index[i], + stats["mvvm_median"], + bar_width, + yerr=stats["mvvm_std"], + capsize=5, + color="blue", + label="MVVM" if i == 0 else "", + ) + ax.bar( + index[i] + bar_width, + stats["wamr_median"], + bar_width, + yerr=stats["wamr_std"], + capsize=5, + color="red", + label="WAMR" if i == 0 else "", + ) + ax.bar( + index[i] + 2 * bar_width, + stats["native_median"], + bar_width, + yerr=stats["native_std"], + capsize=5, + color="green", + label="Native" if i == 0 else "", + ) + # Labeling and formatting + ax.set_ylabel("Time(s)") + ax.set_xticks(index + bar_width / 2) + ticklabel = (x.replace("a=b", "") for x in list(statistics.keys())) + ax.set_xticklabels(ticklabel, fontsize=10) + ax.legend() + + # Show the plot + plt.tight_layout() + plt.show() + plt.savefig(file_name) + # %% + + if __name__ == "__main__": mvvm_results = run_mvvm() + wamr_results = run_wamr() native_results = run_native() - qemu_x86_64_results = run_qemu_x86_64() # print the results - qemu_aarch64_results = run_qemu_aarch64() - hcontainer_results = run_hcontainer() - - write_to_csv("llama_result.csv") + print(mvvm_results) + print(wamr_results) + print(native_results) + write_to_csv("windows.csv") + # results = read_from_csv("windows.csv") + # plot(results) diff --git a/artifact/result/windows.csv b/artifact/result/windows.csv new file mode 100644 index 0000000..0434222 --- /dev/null +++ b/artifact/result/windows.csv @@ -0,0 +1,111 @@ +name,mvvm,wamr,native +a=b linpack.aot,65.257584,23.685475,29.01 +OMP_NUM_THREADS=1 llama.aot stories110M.bin -z tokenizer.bin -t 0.0,48.162543,23.685475,13.02 +"a=b rgbd_tum.aot ./ORBvoc.txt, ./TUM3.yaml ./ ./associations/fr1_xyz.txt",872.773619,23.685475,0.008 +OMP_NUM_THREADS=1 bt.aot,872.773619,23.685475,31.071 +OMP_NUM_THREADS=1 cg.aot,22.757516,23.685475,12.033 +OMP_NUM_THREADS=1 ep.aot,0.000539,23.685475,0.004 +OMP_NUM_THREADS=1 ft.aot,31.111255,23.685475,31.005 +OMP_NUM_THREADS=1 lu.aot,0.024766,23.685475,0.004 +OMP_NUM_THREADS=1 mg.aot,20.22196,23.685475,10.052 +OMP_NUM_THREADS=1 sp.aot,20.22196,23.685475,0.06 +a=b redis.aot,20.22196,23.685475,0.004 +a=b linpack.aot,21.222971,23.071749,29.094 +OMP_NUM_THREADS=1 llama.aot stories110M.bin -z tokenizer.bin -t 0.0,21.222971,23.071749,13.023 +"a=b rgbd_tum.aot ./ORBvoc.txt, ./TUM3.yaml ./ ./associations/fr1_xyz.txt",825.783301,23.071749,0.004 +OMP_NUM_THREADS=1 bt.aot,825.783301,23.071749,31.049 +OMP_NUM_THREADS=1 cg.aot,23.273768,23.071749,12.012 +OMP_NUM_THREADS=1 ep.aot,0.000604,23.071749,0.002 +OMP_NUM_THREADS=1 ft.aot,34.869603,23.071749,29.077 +OMP_NUM_THREADS=1 lu.aot,0.027421,23.071749,0.003 +OMP_NUM_THREADS=1 mg.aot,21.568194,23.071749,10.008 +OMP_NUM_THREADS=1 sp.aot,21.568194,23.071749,0.059 +a=b redis.aot,21.568194,23.071749,0.002 +a=b linpack.aot,24.285947,22.907635,29.091 +OMP_NUM_THREADS=1 llama.aot stories110M.bin -z tokenizer.bin -t 0.0,24.285947,22.907635,13.009 +"a=b rgbd_tum.aot ./ORBvoc.txt, ./TUM3.yaml ./ ./associations/fr1_xyz.txt",861.7128,22.907635,0.004 +OMP_NUM_THREADS=1 bt.aot,861.7128,22.907635,31.005 +OMP_NUM_THREADS=1 cg.aot,24.943927,22.907635,11.097 +OMP_NUM_THREADS=1 ep.aot,0.000552,22.907635,0.002 +OMP_NUM_THREADS=1 ft.aot,35.43775,22.907635,30.044 +OMP_NUM_THREADS=1 lu.aot,0.024445,22.907635,0.003 +OMP_NUM_THREADS=1 mg.aot,21.484104,22.907635,10.008 +OMP_NUM_THREADS=1 sp.aot,21.484104,22.907635,0.057 +a=b redis.aot,21.484104,22.907635,0.002 +a=b linpack.aot,21.571797,23.432488,28.08 +OMP_NUM_THREADS=1 llama.aot stories110M.bin -z tokenizer.bin -t 0.0,21.571797,23.432488,13.009 +"a=b rgbd_tum.aot ./ORBvoc.txt, ./TUM3.yaml ./ ./associations/fr1_xyz.txt",852.130692,23.432488,0.004 +OMP_NUM_THREADS=1 bt.aot,852.130692,23.432488,31.013 +OMP_NUM_THREADS=1 cg.aot,24.996387,23.432488,12.023 +OMP_NUM_THREADS=1 ep.aot,0.00054,23.432488,0.002 +OMP_NUM_THREADS=1 ft.aot,34.067451,23.432488,29.015 +OMP_NUM_THREADS=1 lu.aot,0.029147,23.432488,0.003 +OMP_NUM_THREADS=1 mg.aot,21.092533,23.432488,10.02 +OMP_NUM_THREADS=1 sp.aot,21.092533,23.432488,0.058 +a=b redis.aot,21.092533,23.432488,0.002 +a=b linpack.aot,21.317692,22.04948,29.099 +OMP_NUM_THREADS=1 llama.aot stories110M.bin -z tokenizer.bin -t 0.0,21.317692,22.04948,13.014 +"a=b rgbd_tum.aot ./ORBvoc.txt, ./TUM3.yaml ./ ./associations/fr1_xyz.txt",855.494118,22.04948,0.004 +OMP_NUM_THREADS=1 bt.aot,855.494118,22.04948,32.011 +OMP_NUM_THREADS=1 cg.aot,24.755341,22.04948,11.085 +OMP_NUM_THREADS=1 ep.aot,0.000491,22.04948,0.002 +OMP_NUM_THREADS=1 ft.aot,33.525148,22.04948,29.02 +OMP_NUM_THREADS=1 lu.aot,0.023048,22.04948,0.003 +OMP_NUM_THREADS=1 mg.aot,20.931011,22.04948,9.081 +OMP_NUM_THREADS=1 sp.aot,20.931011,22.04948,0.061 +a=b redis.aot,20.931011,22.04948,0.002 +a=b linpack.aot,21.744898,22.17191,30.086 +OMP_NUM_THREADS=1 llama.aot stories110M.bin -z tokenizer.bin -t 0.0,21.744898,22.17191,13.074 +"a=b rgbd_tum.aot ./ORBvoc.txt, ./TUM3.yaml ./ ./associations/fr1_xyz.txt",842.886785,22.17191,0.004 +OMP_NUM_THREADS=1 bt.aot,842.886785,22.17191,30.073 +OMP_NUM_THREADS=1 cg.aot,24.598304,22.17191,12.029 +OMP_NUM_THREADS=1 ep.aot,0.000423,22.17191,0.002 +OMP_NUM_THREADS=1 ft.aot,33.236581,22.17191,29.073 +OMP_NUM_THREADS=1 lu.aot,0.025789,22.17191,0.003 +OMP_NUM_THREADS=1 mg.aot,21.231102,22.17191,10.051 +OMP_NUM_THREADS=1 sp.aot,21.231102,22.17191,0.059 +a=b redis.aot,21.231102,22.17191,0.002 +a=b linpack.aot,21.170858,21.879022,30.022 +OMP_NUM_THREADS=1 llama.aot stories110M.bin -z tokenizer.bin -t 0.0,21.170858,21.879022,13.035 +"a=b rgbd_tum.aot ./ORBvoc.txt, ./TUM3.yaml ./ ./associations/fr1_xyz.txt",841.635191,21.879022,0.004 +OMP_NUM_THREADS=1 bt.aot,841.635191,21.879022,31.097 +OMP_NUM_THREADS=1 cg.aot,24.747761,21.879022,12.036 +OMP_NUM_THREADS=1 ep.aot,0.000422,21.879022,0.002 +OMP_NUM_THREADS=1 ft.aot,33.843813,21.879022,29.097 +OMP_NUM_THREADS=1 lu.aot,0.02354,21.879022,0.003 +OMP_NUM_THREADS=1 mg.aot,21.320099,21.879022,10.008 +OMP_NUM_THREADS=1 sp.aot,21.320099,21.879022,0.057 +a=b redis.aot,21.320099,21.879022,0.002 +a=b linpack.aot,22.022136,21.401152,28.093 +OMP_NUM_THREADS=1 llama.aot stories110M.bin -z tokenizer.bin -t 0.0,22.022136,21.401152,13.033 +"a=b rgbd_tum.aot ./ORBvoc.txt, ./TUM3.yaml ./ ./associations/fr1_xyz.txt",849.786345,21.401152,0.004 +OMP_NUM_THREADS=1 bt.aot,849.786345,21.401152,30.032 +OMP_NUM_THREADS=1 cg.aot,24.168857,21.401152,11.067 +OMP_NUM_THREADS=1 ep.aot,0.000439,21.401152,0.002 +OMP_NUM_THREADS=1 ft.aot,34.130708,21.401152,27.094 +OMP_NUM_THREADS=1 lu.aot,0.026111,21.401152,0.003 +OMP_NUM_THREADS=1 mg.aot,22.90108,21.401152,9.086 +OMP_NUM_THREADS=1 sp.aot,22.90108,21.401152,0.056 +a=b redis.aot,22.90108,21.401152,0.002 +a=b linpack.aot,23.213674,21.673556,28.047 +OMP_NUM_THREADS=1 llama.aot stories110M.bin -z tokenizer.bin -t 0.0,23.213674,21.673556,12.089 +"a=b rgbd_tum.aot ./ORBvoc.txt, ./TUM3.yaml ./ ./associations/fr1_xyz.txt",857.563863,21.673556,0.004 +OMP_NUM_THREADS=1 bt.aot,857.563863,21.673556,29.03 +OMP_NUM_THREADS=1 cg.aot,25.684547,21.673556,11.056 +OMP_NUM_THREADS=1 ep.aot,0.000533,21.673556,0.002 +OMP_NUM_THREADS=1 ft.aot,36.856358,21.673556,27.056 +OMP_NUM_THREADS=1 lu.aot,0.025263,21.673556,0.003 +OMP_NUM_THREADS=1 mg.aot,21.693797,21.673556,10.053 +OMP_NUM_THREADS=1 sp.aot,21.693797,21.673556,0.06 +a=b redis.aot,21.693797,21.673556,0.002 +a=b linpack.aot,23.564979,23.490303,29.065 +OMP_NUM_THREADS=1 llama.aot stories110M.bin -z tokenizer.bin -t 0.0,23.564979,23.490303,13.028 +"a=b rgbd_tum.aot ./ORBvoc.txt, ./TUM3.yaml ./ ./associations/fr1_xyz.txt",865.143924,23.490303,0.004 +OMP_NUM_THREADS=1 bt.aot,865.143924,23.490303,30.027 +OMP_NUM_THREADS=1 cg.aot,25.359335,23.490303,12.018 +OMP_NUM_THREADS=1 ep.aot,0.000653,23.490303,0.002 +OMP_NUM_THREADS=1 ft.aot,35.618984,23.490303,27.087 +OMP_NUM_THREADS=1 lu.aot,0.029986,23.490303,0.003 +OMP_NUM_THREADS=1 mg.aot,22.961563,23.490303,10.016 +OMP_NUM_THREADS=1 sp.aot,22.961563,23.490303,0.06 +a=b redis.aot,22.961563,23.490303,0.002 diff --git a/artifact/result/windows.pdf b/artifact/result/windows.pdf new file mode 100644 index 0000000000000000000000000000000000000000..28e7d038b3641fa871a8f66258daad6aabc81b9d GIT binary patch literal 1205 zcmZWpzi-n(6pk28VL{m+L)2DkbLXFNt5QLerV6w)N*Iu;4vu|ET@qh(xwe4`HY7G? zkl0}=5)y1|h)957?SP74=1<_A?FK7857vG6?%wyl@7vWWIz-GTj`@ zt+wldy+rYjvc;#u7+lfD|^;e>MF#U_V1g z&ljM0EB1mRyM#Vzu@OHKKGvi7WBwf$gx&@pV@8Uf<K5vx=#e2cj&Xb<);FlAjz|G&Y?uNBfQ21T4*Oj8!wwvqWw)#^!GV;+ z(JCQ>=~9`C-l9gDf(J)FnvvZ#47$+q{0FF5dICnq$A>(ssm5KXts2y@s9{ue*Kl-W znO5d0onOq58w=LeDCm|(rvn_@Hf`v_6w^^DH6WT|j)}cAgV_ekJd0WRy|#lQ&&Ijf z*fW?zu|H=p>g02nCVD;-XVZL~LGw8*H_y*m$iLil{R +#include +#endif bool WAMRInstance::get_int3_addr() { if (!is_aot) @@ -107,10 +111,34 @@ bool WAMRInstance::get_int3_addr() { } return true; } +#if defined(_WIN32) +extern "C" int raise(int sig); + +// Pointer to the original 'raise' function +static int (WINAPI *TrueRaise)(int sig) = raise; + +// Our replacement function +inline int WINAPI MyRaise(int sig) { + return 0; +} +#endif bool WAMRInstance::replace_int3_with_nop() { if (!is_aot) return true; +#if defined(_WIN32) + DetourRestoreAfterWith(); + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach(&(PVOID&)TrueRaise, MyRaise); + + if (DetourTransactionCommit() == NO_ERROR) { + SPDLOG_DEBUG("Successfully detoured raise.\n"); + } else { + SPDLOG_DEBUG("Failed to detour raise.\n"); + return false; + } +#else auto module = get_module(); auto code = static_cast(module->code); auto code_size = module->code_size; @@ -156,6 +184,7 @@ bool WAMRInstance::replace_int3_with_nop() { } #if defined(__APPLE__) pthread_jit_write_protect_np(1); +#endif #endif return true; } @@ -197,6 +226,18 @@ bool WAMRInstance::replace_mfence_with_nop() { } bool WAMRInstance::replace_nop_with_int3() { +#if defined(_WIN32) + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + // Detach the detour, restoring the original function + DetourDetach(&(PVOID&)TrueRaise, MyRaise); + if (DetourTransactionCommit() == NO_ERROR) { + SPDLOG_DEBUG("Successfully detoured raise.\n"); + } else { + SPDLOG_DEBUG("Failed to detour raise.\n"); + return false; + } +#else if (!is_aot) return true; auto module = get_module(); @@ -226,4 +267,5 @@ bool WAMRInstance::replace_nop_with_int3() { os_mprotect(mmap_addr, total_size, map_prot); } return true; +#endif }