summaryrefslogtreecommitdiffstats
path: root/vendor/rustix-0.36.5/src/utils.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /vendor/rustix-0.36.5/src/utils.rs
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix-0.36.5/src/utils.rs')
-rw-r--r--vendor/rustix-0.36.5/src/utils.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/rustix-0.36.5/src/utils.rs b/vendor/rustix-0.36.5/src/utils.rs
new file mode 100644
index 000000000..dcbadb260
--- /dev/null
+++ b/vendor/rustix-0.36.5/src/utils.rs
@@ -0,0 +1,29 @@
+/// Convert a `&T` into a `*const T` without using an `as`.
+#[inline]
+#[allow(dead_code)]
+pub(crate) const fn as_ptr<T>(t: &T) -> *const T {
+ t
+}
+
+/// Convert a `&mut T` into a `*mut T` without using an `as`.
+#[inline]
+#[allow(dead_code)]
+pub(crate) fn as_mut_ptr<T>(t: &mut T) -> *mut T {
+ t
+}
+
+/// Convert a `*mut c_void` to a `*mut T`, checking that it is not null,
+/// misaligned, or pointing to a region of memory that wraps around the address
+/// space.
+#[allow(dead_code)]
+pub(crate) fn check_raw_pointer<T>(value: *mut core::ffi::c_void) -> Option<core::ptr::NonNull<T>> {
+ if (value as usize)
+ .checked_add(core::mem::size_of::<T>())
+ .is_none()
+ || (value as usize) % core::mem::align_of::<T>() != 0
+ {
+ return None;
+ }
+
+ core::ptr::NonNull::new(value.cast())
+}