Skip to content

Commit 999b393

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
fix windows build
1 parent 7f1c209 commit 999b393

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

lib/dsc-lib-pal/src/windows.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Licensed under the MIT License.
33

44
//#[link(name = "ext-ms-win-cng-rng-l1-1-0")]
5-
extern "C" {
6-
fn ProcessPrng(data: *mut u8, len: usize) -> u32;
5+
unsafe extern "C" {
6+
unsafe fn ProcessPrng(data: *mut u8, len: usize) -> u32;
77
}
88

99
/// # Safety
@@ -14,5 +14,7 @@ extern "C" {
1414
///
1515
/// Will panic if the api returns 0
1616
pub unsafe fn getrandom(data: *mut u8, len: usize) {
17+
unsafe {
1718
assert!((ProcessPrng(data, len) != 0), "ProcessPrng failed");
19+
}
1820
}

resources/dism_dsc/src/optional_feature/dism.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const DISMAPI_E_UNKNOWN_FEATURE: i32 = 0x800F080Cu32 as i32;
1616
const LOAD_LIBRARY_SEARCH_SYSTEM32: u32 = 0x0000_0800;
1717

1818
#[link(name = "kernel32")]
19-
extern "system" {
19+
unsafe extern "system" {
2020
fn LoadLibraryExW(
2121
lpLibFileName: *const u16,
2222
hFile: *mut c_void,
@@ -77,7 +77,7 @@ type DismShutdownFn = unsafe extern "system" fn() -> i32;
7777
type DismDeleteFn = unsafe extern "system" fn(*const c_void) -> i32;
7878

7979
// Kernel32 functions for dynamic loading
80-
extern "system" {
80+
unsafe extern "system" {
8181
fn GetProcAddress(h_module: *mut c_void, lp_proc_name: *const u8) -> *mut c_void;
8282
fn FreeLibrary(h_lib_module: *mut c_void) -> i32;
8383
}
@@ -93,18 +93,22 @@ unsafe fn from_wide_ptr(ptr: *const u16) -> String {
9393
if ptr.is_null() {
9494
return String::new();
9595
}
96-
let len = (0..65536).take_while(|&i| *ptr.add(i) != 0).count();
97-
let slice = std::slice::from_raw_parts(ptr, len);
98-
String::from_utf16_lossy(slice)
96+
unsafe {
97+
let len = (0..65536).take_while(|&i| *ptr.add(i) != 0).count();
98+
let slice = std::slice::from_raw_parts(ptr, len);
99+
String::from_utf16_lossy(slice)
100+
}
99101
}
100102

101103
unsafe fn load_fn<T>(lib: *mut c_void, name: &[u8]) -> Result<T, String> {
102-
let ptr = GetProcAddress(lib, name.as_ptr());
103-
if ptr.is_null() {
104-
let fn_name = std::str::from_utf8(&name[..name.len() - 1]).unwrap_or("?");
105-
return Err(t!("dism.functionNotFound", name = fn_name).to_string());
104+
unsafe {
105+
let ptr = GetProcAddress(lib, name.as_ptr());
106+
if ptr.is_null() {
107+
let fn_name = std::str::from_utf8(&name[..name.len() - 1]).unwrap_or("?");
108+
return Err(t!("dism.functionNotFound", name = fn_name).to_string());
109+
}
110+
Ok(std::mem::transmute_copy(&ptr))
106111
}
107-
Ok(std::mem::transmute_copy(&ptr))
108112
}
109113

110114
struct DismApi {

0 commit comments

Comments
 (0)