From 07633821ed63360d4d7464998c29f4f588930a03 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 9 Mar 2024 18:42:26 +0000 Subject: [PATCH] Add bcryptprimitives.dll shim for wine --- .github/workflows/main.yml | 30 +++++++++++++++++++----------- patches/bcryptprimitives.rs | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 patches/bcryptprimitives.rs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5f0f3e6549c..526871d0c05 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -44,10 +44,9 @@ jobs: env: TARGET_TRIPLE: x86_64-apple-darwin # cross-compile from Linux to Windows using mingw - # FIXME The wine version in Ubuntu 22.04 is missing ProcessPrng - #- os: ubuntu-latest - # env: - # TARGET_TRIPLE: x86_64-pc-windows-gnu + - os: ubuntu-latest + env: + TARGET_TRIPLE: x86_64-pc-windows-gnu - os: ubuntu-latest env: TARGET_TRIPLE: aarch64-unknown-linux-gnu @@ -81,11 +80,11 @@ jobs: if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' run: rustup set default-host x86_64-pc-windows-gnu - #- name: Install MinGW toolchain and wine - # if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' - # run: | - # sudo apt-get update - # sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable + - name: Install MinGW toolchain and wine + if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' + run: | + sudo apt-get update + sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable - name: Install AArch64 toolchain and qemu if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'aarch64-unknown-linux-gnu' @@ -108,6 +107,15 @@ jobs: - name: Prepare dependencies run: ./y.sh prepare + # The Wine version shipped with Ubuntu 22.04 doesn't implement bcryptprimitives.dll + - name: Build bcryptprimitives.dll shim for Wine + if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' + run: | + rustup target add x86_64-pc-windows-gnu + mkdir wine_shims + rustc patches/bcryptprimitives.rs -Copt-level=3 -Clto=fat --out-dir wine_shims --target x86_64-pc-windows-gnu + echo "WINEPATH=$(pwd)/wine_shims" >> $GITHUB_ENV + - name: Build run: ./y.sh build --sysroot none @@ -234,11 +242,11 @@ jobs: if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' run: rustup set default-host x86_64-pc-windows-gnu - - name: Install MinGW toolchain and wine + - name: Install MinGW toolchain if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' run: | sudo apt-get update - sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable + sudo apt-get install -y gcc-mingw-w64-x86-64 - name: Prepare dependencies run: ./y.sh prepare diff --git a/patches/bcryptprimitives.rs b/patches/bcryptprimitives.rs new file mode 100644 index 00000000000..4d186485aac --- /dev/null +++ b/patches/bcryptprimitives.rs @@ -0,0 +1,22 @@ +// Shim for bcryptprimitives.dll. The Wine version shipped with Ubuntu 22.04 +// doesn't support it yet. Authored by @ChrisDenton + +#![crate_type = "cdylib"] +#![allow(nonstandard_style)] + +#[no_mangle] +pub unsafe extern "system" fn ProcessPrng(mut pbData: *mut u8, mut cbData: usize) -> i32 { + while cbData > 0 { + let size = core::cmp::min(cbData, u32::MAX as usize); + RtlGenRandom(pbData, size as u32); + cbData -= size; + pbData = pbData.add(size); + } + 1 +} + +#[link(name = "advapi32")] +extern "system" { + #[link_name = "SystemFunction036"] + pub fn RtlGenRandom(RandomBuffer: *mut u8, RandomBufferLength: u32) -> u8; +}