Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin working towards Rust 2024 compatibility #289

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def contains_unsafe(change) -> bool:
return False

with open(f'{repo_path}/{change.a_path}') as fd:
return 'unsafe ' in fd.read()
content = fd.read()
return 'unsafe ' in content or 'unsafe(' in content

# Look for modified / added files
repo = Repo(repo_path)
Expand Down
14 changes: 11 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,17 @@ pbjson-build = { git = "https://github.com/jstarks/pbjson", branch = "aliases" }

[workspace.lints.rust]
# Lint groups need a priority lower than individual lints so they get applied first.
future_incompatible = { level = "deny", priority = -1 }
nonstandard_style = { level = "deny", priority = -1 }
rust_2018_idioms = { level = "deny", priority = -1 }
future_incompatible = { level = "deny", priority = -2 }
nonstandard_style = { level = "deny", priority = -2 }
rust_2018_idioms = { level = "deny", priority = -2 }

rust-2024-compatibility = { level = "warn", priority = -1 }
# TODO: Fix all of the below, https://github.com/microsoft/openvmm/issues/288
edition_2024_expr_fragment_specifier = "allow"
impl_trait_overcaptures = "allow"
deprecated-safe-2024 = "allow"
# Needed for linkme compatibility for now, https://github.com/dtolnay/linkme/issues/101
smalis-msft marked this conversation as resolved.
Show resolved Hide resolved
unsafe-attr-outside-unsafe = "allow"

unused_qualifications = "warn"

Expand Down
4 changes: 2 additions & 2 deletions openhcl/build_info/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ impl BuildInfo {

// UNSAFETY: link_section and export_name are considered unsafe.
#[allow(unsafe_code)]
#[link_section = ".build_info"]
#[export_name = "BUILD_INFO"]
#[unsafe(link_section = ".build_info")]
#[unsafe(export_name = "BUILD_INFO")]
static BUILD_INFO: BuildInfo = BuildInfo::new();

pub fn get() -> &'static BuildInfo {
Expand Down
4 changes: 2 additions & 2 deletions openhcl/minimal_rt/src/arch/aarch64/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/// Hand rolled implementation of memcpy.
#[cfg(minimal_rt)]
#[no_mangle]
#[unsafe(no_mangle)]
unsafe extern "C" fn memcpy(mut dest: *mut u8, src: *const u8, len: usize) -> *mut u8 {
// SAFETY: the caller guarantees the pointers and length are correct.
unsafe {
Expand All @@ -31,7 +31,7 @@ unsafe extern "C" fn memcpy(mut dest: *mut u8, src: *const u8, len: usize) -> *m

/// Hand rolled implementation of memset.
#[cfg(minimal_rt)]
#[no_mangle]
#[unsafe(no_mangle)]
unsafe extern "C" fn memset(mut ptr: *mut u8, val: i32, len: usize) -> *mut u8 {
// SAFETY: the caller guarantees the pointer and length are correct.
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion openhcl/minimal_rt/src/arch/x86_64/hypercall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//!
//! The hypercall ABI for x64 is well documented in the TLFS.

extern "C" {
unsafe extern "C" {
/// The hypercall page. The actual hypercall page must be mapped on top of
/// this page before it is used.
pub static mut HYPERCALL_PAGE: [u8; 4096];
Expand Down
4 changes: 2 additions & 2 deletions openhcl/minimal_rt/src/arch/x86_64/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/// Hand rolled implementation of memset.
#[cfg(minimal_rt)]
#[no_mangle]
#[unsafe(no_mangle)]
unsafe extern "C" fn memset(mut ptr: *mut u8, val: i32, len: usize) -> *mut u8 {
// SAFETY: The caller guarantees that the pointer and length are correct.
unsafe {
Expand All @@ -22,7 +22,7 @@ unsafe extern "C" fn memset(mut ptr: *mut u8, val: i32, len: usize) -> *mut u8 {

/// Hand rolled implementation of memcpy.
#[cfg(minimal_rt)]
#[no_mangle]
#[unsafe(no_mangle)]
unsafe extern "C" fn memcpy(mut dest: *mut u8, src: *const u8, len: usize) -> *mut u8 {
// SAFETY: The caller guarantees that the pointers and length are correct.
unsafe {
Expand Down
6 changes: 3 additions & 3 deletions openhcl/minimal_rt/src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ mod instead_of_builtins {
}
}

extern "C" {
unsafe extern "C" {
fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8;
}

/// Implementation cribbed from compiler_builtins.
#[no_mangle]
#[unsafe(no_mangle)]
unsafe extern "C" fn memmove(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
let delta = (dest as usize).wrapping_sub(src as usize);
if delta >= n {
Expand All @@ -47,7 +47,7 @@ mod instead_of_builtins {
/// This implementation is cribbed from compiler_builtins. It would be nice to
/// use those implementation for all the above functions, but those require
/// nightly as these are not yet stabilized.
#[no_mangle]
#[unsafe(no_mangle)]
unsafe extern "C" fn bcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 {
// SAFETY: The caller guarantees that the pointers and length are correct.
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion openhcl/openhcl_boot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ struct Fdt {
/// where the shim is loaded. Return a ShimParams structure based on the raw
/// offset based RawShimParams.
fn shim_parameters(shim_params_raw_offset: isize) -> ShimParams {
extern "C" {
unsafe extern "C" {
static __ehdr_start: u8;
}

Expand Down
2 changes: 1 addition & 1 deletion openhcl/sidecar/src/arch/x86_64/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use x86defs::IdtEntry64;
use x86defs::Pte;
use zerocopy::FromZeroes;

extern "C" {
unsafe extern "C" {
static IMAGE_PDE: Pte;
fn irq_entry();
fn exc_gpf();
Expand Down
2 changes: 1 addition & 1 deletion openhcl/sidecar/src/arch/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod addr_space {

const PAGE_SIZE: u64 = 0x1000;

extern "C" {
unsafe extern "C" {
static __ehdr_start: u8;
}

Expand Down
4 changes: 2 additions & 2 deletions support/openssl_crypto_only/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use core::ffi::c_int;
use core::ffi::c_void;

extern "C" {
unsafe extern "C" {
#[doc(hidden)]
pub fn OPENSSL_init_crypto(opts: u64, settings: *const c_void) -> c_int;
}
Expand All @@ -33,7 +33,7 @@ macro_rules! openssl_crypto_only {
/// # Safety
///
/// The caller must call as documented for `OPENSSL_init_ssl`.
#[no_mangle]
#[unsafe(no_mangle)]
unsafe extern "C" fn OPENSSL_init_ssl(
opts: u64,
settings: *const ::core::ffi::c_void,
Expand Down
4 changes: 2 additions & 2 deletions support/openssl_kdf/src/sys/evp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub enum KDF {}

pub enum KDF_CTX {}

extern "C" {
unsafe extern "C" {
pub fn EVP_MD_get0_name(md: *const EVP_MD) -> *const c_char;
}

Expand All @@ -31,7 +31,7 @@ pub const OSSL_PARAM_OCTET_STRING: c_uchar = 5;
pub const OSSL_PARAM_UTF8_PTR: c_uchar = 6;
pub const OSSL_PARAM_OCTET_PTR: c_uchar = 7;

extern "C" {
unsafe extern "C" {
pub fn EVP_KDF_fetch(
libctx: *mut OSSL_LIB_CTX,
algorithm: *const c_char,
Expand Down
2 changes: 1 addition & 1 deletion support/openssl_kdf/src/sys/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use libc::time_t;
use openssl_sys::BIGNUM;
use std::ffi::CStr;

extern "C" {
unsafe extern "C" {
pub fn OSSL_PARAM_get_int(p: *const OSSL_PARAM, val: *mut c_int) -> c_int;
pub fn OSSL_PARAM_get_uint(p: *const OSSL_PARAM, val: *mut c_uint) -> c_int;
pub fn OSSL_PARAM_get_long(p: *const OSSL_PARAM, val: *mut c_long) -> c_int;
Expand Down
2 changes: 1 addition & 1 deletion support/pal/src/windows/alpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mod ntlpcapi {
pub const OB_ALL_OBJECT_TYPE_CODES: u32 = 0x00000ffd;

// This is defined incorrectly in ntapi 0.3.6.
extern "C" {
unsafe extern "C" {
pub fn AlpcInitializeMessageAttribute(
AttributeFlags: u32,
Buffer: PALPC_MESSAGE_ATTRIBUTES,
Expand Down
2 changes: 1 addition & 1 deletion support/pal/src/windows/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl SecurityDescriptor {
}

#[link(name = "api-ms-win-security-base-private-l1-1-1")]
extern "C" {
unsafe extern "C" {
fn CreateAppContainerToken(
token: HANDLE,
caps: LPSECURITY_CAPABILITIES,
Expand Down
2 changes: 1 addition & 1 deletion support/sparse_mmap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn initialize_try_copy() {
}
}

extern "C" {
unsafe extern "C" {
#[cfg(unix)]
fn install_signal_handlers() -> i32;

Expand Down
18 changes: 9 additions & 9 deletions support/win_prng_support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ macro_rules! use_win10_prng_apis {
$($crate::use_win10_prng_apis!(@x $lib);)*
};
(@x advapi32) => {
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "system" fn SystemFunction036(data: *mut u8, len: u32) -> u8 {
// SAFETY: passing through guarantees.
unsafe { $crate::private::SystemFunction036(data, len) }
}

/// If a call to SystemFunction036 is marked as a dllimport, then it may be an indirect call
/// through __imp_SystemFunction036 instead.
#[no_mangle]
#[unsafe(no_mangle)]
pub static __imp_SystemFunction036: unsafe extern "system" fn(*mut u8, u32) -> u8 =
SystemFunction036;
};
(@x bcrypt) => {
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "system" fn BCryptOpenAlgorithmProvider(
handle: *mut ::core::ffi::c_void,
psz_alg_id: *mut u16,
Expand All @@ -56,7 +56,7 @@ macro_rules! use_win10_prng_apis {
}
}

#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "system" fn BCryptCloseAlgorithmProvider(
handle: *mut ::core::ffi::c_void,
flags: u32,
Expand All @@ -65,7 +65,7 @@ macro_rules! use_win10_prng_apis {
unsafe { $crate::private::BCryptCloseAlgorithmProvider(handle, flags) }
}

#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "system" fn BCryptGenRandom(
algorithm: usize,
data: *mut u8,
Expand All @@ -78,23 +78,23 @@ macro_rules! use_win10_prng_apis {

/// If a call to BCryptGenRandom is marked as a dllimport, then it may be an indirect call
/// through __imp_BCryptGenRandom instead.
#[no_mangle]
#[unsafe(no_mangle)]
pub static __imp_BCryptGenRandom: unsafe extern "system" fn(
usize,
*mut u8,
u32,
u32,
) -> u32 = BCryptGenRandom;

#[no_mangle]
#[unsafe(no_mangle)]
pub static __imp_BCryptOpenAlgorithmProvider: unsafe extern "system" fn(
*mut ::core::ffi::c_void,
*mut u16,
*mut u16,
u32,
) -> u32 = BCryptOpenAlgorithmProvider;

#[no_mangle]
#[unsafe(no_mangle)]
pub static __imp_BCryptCloseAlgorithmProvider: unsafe extern "system" fn(
*mut ::core::ffi::c_void,
u32,
Expand All @@ -115,7 +115,7 @@ pub mod private {
const BCRYPT_MAGIC_ALGORITHM_HANDLE: usize = 0x1234abcd;

#[link(name = "ext-ms-win-cng-rng-l1-1-0")]
extern "C" {
unsafe extern "C" {
/// The lowest-level PRNG API in Windows.
fn ProcessPrng(data: *mut u8, len: usize) -> u32;
}
Expand Down
Loading