From 9833ee17e09abdc132899a5d4c161979f5f0f54e Mon Sep 17 00:00:00 2001 From: Timothy Roberts <39689890+timrobertsdev@users.noreply.github.com> Date: Wed, 7 Sep 2022 01:44:17 -0400 Subject: [PATCH 1/3] Change `Event` to be FFI-safe using `NonNull` --- src/data_types/mod.rs | 2 +- src/proto/media/disk.rs | 2 +- uefi-test-runner/src/proto/media/known_disk.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/data_types/mod.rs b/src/data_types/mod.rs index f369f25fd..e4058725c 100644 --- a/src/data_types/mod.rs +++ b/src/data_types/mod.rs @@ -39,7 +39,7 @@ impl Handle { /// Handle to an event structure #[repr(transparent)] -pub struct Event(*mut c_void); +pub struct Event(NonNull); impl Event { /// Clone this `Event` diff --git a/src/proto/media/disk.rs b/src/proto/media/disk.rs index 9cf7926a7..56e54b6ef 100644 --- a/src/proto/media/disk.rs +++ b/src/proto/media/disk.rs @@ -74,7 +74,7 @@ impl DiskIo { #[repr(C)] pub struct DiskIo2Token { /// Event to be signalled when an asynchronous disk I/O operation completes. - pub event: Event, + pub event: Option, /// Transaction status code. pub transaction_status: Status, } diff --git a/uefi-test-runner/src/proto/media/known_disk.rs b/uefi-test-runner/src/proto/media/known_disk.rs index 717859811..e0f5bf315 100644 --- a/uefi-test-runner/src/proto/media/known_disk.rs +++ b/uefi-test-runner/src/proto/media/known_disk.rs @@ -214,7 +214,7 @@ fn test_raw_disk_io2(handle: Handle, bt: &BootServices) { // Initialise the task context let mut task = DiskIoTask { token: DiskIo2Token { - event: event.unsafe_clone(), + event: Some(event.unsafe_clone()), transaction_status: uefi::Status::NOT_READY, }, buffer: [0; 512], From 44db75e3e31cf0fbefe721d134a0c9beed038938 Mon Sep 17 00:00:00 2001 From: Timothy Roberts <39689890+timrobertsdev@users.noreply.github.com> Date: Wed, 12 Oct 2022 23:25:31 -0400 Subject: [PATCH 2/3] Add `Event` change to changelog. Improve `Event` docstring. --- CHANGELOG.md | 1 + src/data_types/mod.rs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5636458e0..596f9f465 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ `Address` always take a 64-bit value, regardless of target platform. - The conversion methods on `DevicePathToText` and `DevicePathFromText` now return a `uefi::Result` instead of an `Option`. +- `Event` is now a newtype around `NonNull` instead of `*mut c_void`. ## uefi-macros - [Unreleased] diff --git a/src/data_types/mod.rs b/src/data_types/mod.rs index 7ce404748..4505aee3c 100644 --- a/src/data_types/mod.rs +++ b/src/data_types/mod.rs @@ -37,7 +37,9 @@ impl Handle { } } -/// Handle to an event structure +/// Handle to an event structure, guaranteed to be non-null. +/// +/// If you need to have a nullable event, use `Option`. #[repr(transparent)] pub struct Event(NonNull); From 19ecdb356d66a01913809f3f166ec3bf4878a080 Mon Sep 17 00:00:00 2001 From: Timothy Roberts <39689890+timrobertsdev@users.noreply.github.com> Date: Mon, 17 Oct 2022 16:05:02 -0400 Subject: [PATCH 3/3] Cargo fmt for whitespace --- src/data_types/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data_types/mod.rs b/src/data_types/mod.rs index 4505aee3c..987d7e95b 100644 --- a/src/data_types/mod.rs +++ b/src/data_types/mod.rs @@ -38,7 +38,7 @@ impl Handle { } /// Handle to an event structure, guaranteed to be non-null. -/// +/// /// If you need to have a nullable event, use `Option`. #[repr(transparent)] pub struct Event(NonNull);