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

rbtree.rs - add support for searching neighbors #1

Closed
wants to merge 10 commits into from
2 changes: 2 additions & 0 deletions arch/um/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
-Din6addr_loopback=kernel_in6addr_loopback \
-Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr

KBUILD_RUSTFLAGS += -Crelocation-model=pie

KBUILD_AFLAGS += $(ARCH_INCLUDE)

USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \
Expand Down
6 changes: 6 additions & 0 deletions arch/x86/Makefile.um
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# SPDX-License-Identifier: GPL-2.0
core-y += arch/x86/crypto/

#
# Disable SSE and other FP/SIMD instructions to match normal x86
#
KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
KBUILD_RUSTFLAGS += -Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2

ifeq ($(CONFIG_X86_32),y)
START := 0x8048000

Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio_pl061_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl amba::Driver for PL061Device {
)?;

// SAFETY: General part of the data is pinned when `data` is.
let gen_inner = unsafe { data.as_mut().map_unchecked_mut(|d| &mut (**d).inner) };
let gen_inner = unsafe { data.as_mut().map_unchecked_mut(|d| &mut d.inner) };
kernel::rawspinlock_init!(gen_inner, "PL061Data::inner");

let data = Arc::<DeviceData>::from(data);
Expand Down
12 changes: 6 additions & 6 deletions rust/kernel/amba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use crate::{
bindings, device, driver, error::from_kernel_result, io_mem::Resource, power, str::CStr,
to_result, types::PointerWrapper, Result, ThisModule,
to_result, types::ForeignOwnable, Result, ThisModule,
};

/// A registration of an amba driver.
Expand Down Expand Up @@ -43,7 +43,7 @@ unsafe impl const driver::RawDeviceId for DeviceId {
/// An amba driver.
pub trait Driver {
/// Data stored on device by driver.
type Data: PointerWrapper + Send + Sync + driver::DeviceRemoval = ();
type Data: ForeignOwnable + Send + Sync + driver::DeviceRemoval = ();

/// The type that implements the power-management operations.
///
Expand Down Expand Up @@ -88,7 +88,7 @@ impl<T: Driver> driver::DriverOps for Adapter<T> {
amba.id_table = t.as_ref();
}
if cfg!(CONFIG_PM) {
// SAFETY: `probe_callback` sets the driver data after calling `T::Data::into_pointer`,
// SAFETY: `probe_callback` sets the driver data after calling `T::Data::into_foreign`,
// and we guarantee that `T::Data` is the same as `T::PowerOps::Data` by a constraint
// in the type declaration.
amba.drv.pm = unsafe { power::OpsTable::<T::PowerOps>::build() };
Expand Down Expand Up @@ -131,7 +131,7 @@ unsafe extern "C" fn probe_callback<T: Driver>(
unsafe { (&*ptr).as_ref() }
};
let data = T::probe(&mut dev, info)?;
let ptr = T::Data::into_pointer(data);
let ptr = T::Data::into_foreign(data);
// SAFETY: `adev` is valid for write by the contract with the C code.
unsafe { bindings::amba_set_drvdata(adev, ptr as _) };
Ok(0)
Expand All @@ -143,8 +143,8 @@ unsafe extern "C" fn remove_callback<T: Driver>(adev: *mut bindings::amba_device
let ptr = unsafe { bindings::amba_get_drvdata(adev) };
// SAFETY: The value returned by `amba_get_drvdata` was stored by a previous call to
// `amba_set_drvdata` in `probe_callback` above; the value comes from a call to
// `T::Data::into_pointer`.
let data = unsafe { T::Data::from_pointer(ptr) };
// `T::Data::into_foreign`.
let data = unsafe { T::Data::from_foreign(ptr) };
T::remove(&data);
<T::Data as driver::DeviceRemoval>::device_remove(&data);
}
Expand Down
44 changes: 22 additions & 22 deletions rust/kernel/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
iov_iter::IovIter,
mm,
sync::CondVar,
types::PointerWrapper,
types::ForeignOwnable,
user_ptr::{UserSlicePtr, UserSlicePtrReader, UserSlicePtrWriter},
ARef, AlwaysRefCounted,
};
Expand Down Expand Up @@ -309,7 +309,7 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
let fileref = unsafe { File::from_ptr(file) };
// SAFETY: `arg` was previously returned by `A::convert` and must
// be a valid non-null pointer.
let ptr = T::open(unsafe { &*arg }, fileref)?.into_pointer();
let ptr = T::open(unsafe { &*arg }, fileref)?.into_foreign();
// SAFETY: The C contract guarantees that `private_data` is available
// for implementers of the file operations (no other C code accesses
// it), so we know that there are no concurrent threads/CPUs accessing
Expand All @@ -329,7 +329,7 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
let mut data =
unsafe { UserSlicePtr::new(buf as *mut core::ffi::c_void, len).writer() };
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
// `T::Data::into_pointer`. `T::Data::from_pointer` is only called by the
// `T::Data::into_foreign`. `T::Data::from_foreign` is only called by the
// `release` callback, which the C API guarantees that will be called only when all
// references to `file` have been released, so we know it can't be called while this
// function is running.
Expand All @@ -356,7 +356,7 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
let file = unsafe { (*iocb).ki_filp };
let offset = unsafe { (*iocb).ki_pos };
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
// `T::Data::into_pointer`. `T::Data::from_pointer` is only called by the
// `T::Data::into_foreign`. `T::Data::from_foreign` is only called by the
// `release` callback, which the C API guarantees that will be called only when all
// references to `file` have been released, so we know it can't be called while this
// function is running.
Expand All @@ -382,7 +382,7 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
let mut data =
unsafe { UserSlicePtr::new(buf as *mut core::ffi::c_void, len).reader() };
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
// `T::Data::into_pointer`. `T::Data::from_pointer` is only called by the
// `T::Data::into_foreign`. `T::Data::from_foreign` is only called by the
// `release` callback, which the C API guarantees that will be called only when all
// references to `file` have been released, so we know it can't be called while this
// function is running.
Expand All @@ -409,7 +409,7 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
let file = unsafe { (*iocb).ki_filp };
let offset = unsafe { (*iocb).ki_pos };
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
// `T::Data::into_pointer`. `T::Data::from_pointer` is only called by the
// `T::Data::into_foreign`. `T::Data::from_foreign` is only called by the
// `release` callback, which the C API guarantees that will be called only when all
// references to `file` have been released, so we know it can't be called while this
// function is running.
Expand All @@ -430,7 +430,7 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
file: *mut bindings::file,
) -> core::ffi::c_int {
let ptr = mem::replace(unsafe { &mut (*file).private_data }, ptr::null_mut());
T::release(unsafe { T::Data::from_pointer(ptr as _) }, unsafe {
T::release(unsafe { T::Data::from_foreign(ptr as _) }, unsafe {
File::from_ptr(file)
});
0
Expand All @@ -449,7 +449,7 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
_ => return Err(EINVAL),
};
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
// `T::Data::into_pointer`. `T::Data::from_pointer` is only called by the
// `T::Data::into_foreign`. `T::Data::from_foreign` is only called by the
// `release` callback, which the C API guarantees that will be called only when all
// references to `file` have been released, so we know it can't be called while this
// function is running.
Expand All @@ -466,7 +466,7 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
) -> core::ffi::c_long {
from_kernel_result! {
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
// `T::Data::into_pointer`. `T::Data::from_pointer` is only called by the
// `T::Data::into_foreign`. `T::Data::from_foreign` is only called by the
// `release` callback, which the C API guarantees that will be called only when all
// references to `file` have been released, so we know it can't be called while this
// function is running.
Expand All @@ -484,7 +484,7 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
) -> core::ffi::c_long {
from_kernel_result! {
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
// `T::Data::into_pointer`. `T::Data::from_pointer` is only called by the
// `T::Data::into_foreign`. `T::Data::from_foreign` is only called by the
// `release` callback, which the C API guarantees that will be called only when all
// references to `file` have been released, so we know it can't be called while this
// function is running.
Expand All @@ -501,7 +501,7 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
) -> core::ffi::c_int {
from_kernel_result! {
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
// `T::Data::into_pointer`. `T::Data::from_pointer` is only called by the
// `T::Data::into_foreign`. `T::Data::from_foreign` is only called by the
// `release` callback, which the C API guarantees that will be called only when all
// references to `file` have been released, so we know it can't be called while this
// function is running.
Expand Down Expand Up @@ -529,7 +529,7 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
let end = end.try_into()?;
let datasync = datasync != 0;
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
// `T::Data::into_pointer`. `T::Data::from_pointer` is only called by the
// `T::Data::into_foreign`. `T::Data::from_foreign` is only called by the
// `release` callback, which the C API guarantees that will be called only when all
// references to `file` have been released, so we know it can't be called while this
// function is running.
Expand All @@ -544,7 +544,7 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
wait: *mut bindings::poll_table_struct,
) -> bindings::__poll_t {
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
// `T::Data::into_pointer`. `T::Data::from_pointer` is only called by the `release`
// `T::Data::into_foreign`. `T::Data::from_foreign` is only called by the `release`
// callback, which the C API guarantees that will be called only when all references to
// `file` have been released, so we know it can't be called while this function is running.
let f = unsafe { T::Data::borrow((*file).private_data) };
Expand Down Expand Up @@ -775,7 +775,7 @@ pub trait OpenAdapter<T: Sync> {
pub trait Operations {
/// The type of the context data returned by [`Operations::open`] and made available to
/// other methods.
type Data: PointerWrapper + Send + Sync = ();
type Data: ForeignOwnable + Send + Sync = ();

/// The type of the context data passed to [`Operations::open`].
type OpenData: Sync = ();
Expand All @@ -797,7 +797,7 @@ pub trait Operations {
///
/// Corresponds to the `read` and `read_iter` function pointers in `struct file_operations`.
fn read(
_data: <Self::Data as PointerWrapper>::Borrowed<'_>,
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_writer: &mut impl IoBufferWriter,
_offset: u64,
Expand All @@ -809,7 +809,7 @@ pub trait Operations {
///
/// Corresponds to the `write` and `write_iter` function pointers in `struct file_operations`.
fn write(
_data: <Self::Data as PointerWrapper>::Borrowed<'_>,
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_reader: &mut impl IoBufferReader,
_offset: u64,
Expand All @@ -821,7 +821,7 @@ pub trait Operations {
///
/// Corresponds to the `llseek` function pointer in `struct file_operations`.
fn seek(
_data: <Self::Data as PointerWrapper>::Borrowed<'_>,
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_offset: SeekFrom,
) -> Result<u64> {
Expand All @@ -832,7 +832,7 @@ pub trait Operations {
///
/// Corresponds to the `unlocked_ioctl` function pointer in `struct file_operations`.
fn ioctl(
_data: <Self::Data as PointerWrapper>::Borrowed<'_>,
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_cmd: &mut IoctlCommand,
) -> Result<i32> {
Expand All @@ -843,7 +843,7 @@ pub trait Operations {
///
/// Corresponds to the `compat_ioctl` function pointer in `struct file_operations`.
fn compat_ioctl(
_data: <Self::Data as PointerWrapper>::Borrowed<'_>,
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_cmd: &mut IoctlCommand,
) -> Result<i32> {
Expand All @@ -854,7 +854,7 @@ pub trait Operations {
///
/// Corresponds to the `fsync` function pointer in `struct file_operations`.
fn fsync(
_data: <Self::Data as PointerWrapper>::Borrowed<'_>,
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_start: u64,
_end: u64,
Expand All @@ -867,7 +867,7 @@ pub trait Operations {
///
/// Corresponds to the `mmap` function pointer in `struct file_operations`.
fn mmap(
_data: <Self::Data as PointerWrapper>::Borrowed<'_>,
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_vma: &mut mm::virt::Area,
) -> Result {
Expand All @@ -879,7 +879,7 @@ pub trait Operations {
///
/// Corresponds to the `poll` function pointer in `struct file_operations`.
fn poll(
_data: <Self::Data as PointerWrapper>::Borrowed<'_>,
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_table: &PollTable,
) -> Result<u32> {
Expand Down
Loading