Skip to content

Commit 0763382

Browse files
committed
Add bcryptprimitives.dll shim for wine
1 parent e18201d commit 0763382

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

.github/workflows/main.yml

+19-11
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ jobs:
4444
env:
4545
TARGET_TRIPLE: x86_64-apple-darwin
4646
# cross-compile from Linux to Windows using mingw
47-
# FIXME The wine version in Ubuntu 22.04 is missing ProcessPrng
48-
#- os: ubuntu-latest
49-
# env:
50-
# TARGET_TRIPLE: x86_64-pc-windows-gnu
47+
- os: ubuntu-latest
48+
env:
49+
TARGET_TRIPLE: x86_64-pc-windows-gnu
5150
- os: ubuntu-latest
5251
env:
5352
TARGET_TRIPLE: aarch64-unknown-linux-gnu
@@ -81,11 +80,11 @@ jobs:
8180
if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
8281
run: rustup set default-host x86_64-pc-windows-gnu
8382

84-
#- name: Install MinGW toolchain and wine
85-
# if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
86-
# run: |
87-
# sudo apt-get update
88-
# sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
83+
- name: Install MinGW toolchain and wine
84+
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
85+
run: |
86+
sudo apt-get update
87+
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
8988
9089
- name: Install AArch64 toolchain and qemu
9190
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'aarch64-unknown-linux-gnu'
@@ -108,6 +107,15 @@ jobs:
108107
- name: Prepare dependencies
109108
run: ./y.sh prepare
110109

110+
# The Wine version shipped with Ubuntu 22.04 doesn't implement bcryptprimitives.dll
111+
- name: Build bcryptprimitives.dll shim for Wine
112+
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
113+
run: |
114+
rustup target add x86_64-pc-windows-gnu
115+
mkdir wine_shims
116+
rustc patches/bcryptprimitives.rs -Copt-level=3 -Clto=fat --out-dir wine_shims --target x86_64-pc-windows-gnu
117+
echo "WINEPATH=$(pwd)/wine_shims" >> $GITHUB_ENV
118+
111119
- name: Build
112120
run: ./y.sh build --sysroot none
113121

@@ -234,11 +242,11 @@ jobs:
234242
if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
235243
run: rustup set default-host x86_64-pc-windows-gnu
236244

237-
- name: Install MinGW toolchain and wine
245+
- name: Install MinGW toolchain
238246
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
239247
run: |
240248
sudo apt-get update
241-
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
249+
sudo apt-get install -y gcc-mingw-w64-x86-64
242250
243251
- name: Prepare dependencies
244252
run: ./y.sh prepare

patches/bcryptprimitives.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Shim for bcryptprimitives.dll. The Wine version shipped with Ubuntu 22.04
2+
// doesn't support it yet. Authored by @ChrisDenton
3+
4+
#![crate_type = "cdylib"]
5+
#![allow(nonstandard_style)]
6+
7+
#[no_mangle]
8+
pub unsafe extern "system" fn ProcessPrng(mut pbData: *mut u8, mut cbData: usize) -> i32 {
9+
while cbData > 0 {
10+
let size = core::cmp::min(cbData, u32::MAX as usize);
11+
RtlGenRandom(pbData, size as u32);
12+
cbData -= size;
13+
pbData = pbData.add(size);
14+
}
15+
1
16+
}
17+
18+
#[link(name = "advapi32")]
19+
extern "system" {
20+
#[link_name = "SystemFunction036"]
21+
pub fn RtlGenRandom(RandomBuffer: *mut u8, RandomBufferLength: u32) -> u8;
22+
}

0 commit comments

Comments
 (0)