Skip to content

Commit

Permalink
Complete Windows port
Browse files Browse the repository at this point in the history
  • Loading branch information
Evian-Zhang committed Jul 26, 2024
1 parent ab8ccf2 commit 94c1652
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
21 changes: 17 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Rust
name: Rust CI

on:
push:
Expand All @@ -18,13 +18,25 @@ jobs:
os: [
ubuntu-latest,
macos-latest,
windows-latest
]
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
- os: macos-latest
target: aarch64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: windows-latest
target: i686-pc-windows-msvc
steps:
- uses: actions/checkout@v4
- name: Build all features
run: cargo build --verbose --all-features
run: cargo build --verbose --all-features --target ${{ matrix.target }}
- name: Run tests
run: cargo test --verbose
run: cargo test --verbose --target ${{ matrix.target }} -- --test-threads=1

cross:
runs-on: ubuntu-latest
Expand All @@ -33,6 +45,7 @@ jobs:
matrix:
target: [
i686-unknown-linux-gnu,
aarch64-unknown-linux-gnu,
]
steps:
- name: checkout
Expand All @@ -42,7 +55,7 @@ jobs:
- name: Build all features
run: cross build --verbose --all-features --target ${{ matrix.target }}
- name: Run tests
run: cross test --verbose --target ${{ matrix.target }}
run: cross test --verbose --target ${{ matrix.target }} -- --test-threads=1

rustfmt:
name: Rustfmt
Expand Down
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,26 @@ struct JumpEntry {

impl JumpEntry {
/// Update fields to be absolute address
#[cfg(not(all(target_os = "windows", target_arch = "x86_64")))]
fn make_relative_address_absolute(&mut self) {
self.code = (core::ptr::addr_of!(self.code) as usize).wrapping_add(self.code);
self.target = (core::ptr::addr_of!(self.target) as usize).wrapping_add(self.target);
self.key = (core::ptr::addr_of!(self.key) as usize).wrapping_add(self.key);
}

// For Win64, the relative address is truncated into 32bit.
// See https://github.com/llvm/llvm-project/blob/862d837e483437b33f5588f89e62085de3a806b9/llvm/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp#L48-L51
/// Update fields to be absolute address
#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
fn make_relative_address_absolute(&mut self) {
let code = (self.code as i32) as i64 as usize;
self.code = (core::ptr::addr_of!(self.code) as usize).wrapping_add(code);
let target = (self.target as i32) as i64 as usize;
self.target = (core::ptr::addr_of!(self.target) as usize).wrapping_add(target);
let key = (self.key as i32) as i64 as usize;
self.key = (core::ptr::addr_of!(self.key) as usize).wrapping_add(key);
}

/// Absolute address of the JMP/NOP instruction to be modified
fn code_addr(&self) -> usize {
self.code
Expand Down
2 changes: 2 additions & 0 deletions tests/basic.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! This test is designed to be run in single thread. Always pass `--test-threads=1`!
#![feature(asm_goto)]
#![feature(asm_const)]

Expand Down

0 comments on commit 94c1652

Please sign in to comment.