Skip to content

Commit

Permalink
rust: rros: fix warnings
Browse files Browse the repository at this point in the history
Modify code to eliminate compilation warnings.
  • Loading branch information
JiajunDu committed Dec 17, 2023
1 parent 320c464 commit 1c1c52f
Show file tree
Hide file tree
Showing 73 changed files with 660 additions and 451 deletions.
2 changes: 1 addition & 1 deletion drivers/android/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ impl IoctlHandler for Process {
}

impl FileOpener<Ref<Context>> for Process {
fn open(ctx: &Ref<Context>, fileref: &File) -> Result<Self::Wrapper> {
fn open(ctx: &Ref<Context>, _fileref: &File) -> Result<Self::Wrapper> {
Self::new(ctx.clone())
}
}
Expand Down
8 changes: 5 additions & 3 deletions kernel/rros/arch/arm64/syscall.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use kernel::bindings;
use kernel::prelude::*;
use kernel::ptrace::{IrqStage, PtRegs};
use kernel::{
bindings,
prelude::*,
ptrace::PtRegs,
};

/// Returns the first register value from the given out-of-bounds pointer.
#[macro_export]
Expand Down
39 changes: 20 additions & 19 deletions kernel/rros/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,35 @@

#![allow(warnings, unused)]
#![feature(stmt_expr_attributes)]
use crate::factory;
use crate::list::*;
use crate::sched::{rros_cpu_rq, this_rros_rq, RQ_TDEFER, RQ_TIMER, RQ_TPROXY};
use crate::thread::T_ROOT;
use crate::tick;
use crate::timeout::RROS_INFINITE;
use crate::{
factory::CloneData, factory::RrosElement, factory::RrosFactory, factory::RustFile, lock::*,
factory::{CloneData, RrosElement, RrosFactory, RustFile, RROS_CLONE_PUBLIC},
factory,
lock::*,
tick::*, timer::*, RROS_OOB_CPUS,
list::*,
sched::{rros_cpu_rq, this_rros_rq, RQ_TDEFER, RQ_TIMER, RQ_TPROXY},
thread::T_ROOT,
tick,
timeout::RROS_INFINITE,
};
use alloc::rc::Rc;
use core::borrow::{Borrow, BorrowMut};
use core::cell::RefCell;
use core::cell::UnsafeCell;
use core::clone::Clone;
use core::ops::Deref;
use core::ops::DerefMut;
use core::{mem::align_of, mem::size_of, todo};
use factory::RROS_CLONE_PUBLIC;
use kernel::device::DeviceType;
use kernel::file::File;
use kernel::io_buffer::IoBufferWriter;
use core::{
borrow::{Borrow, BorrowMut},
cell::{RefCell, UnsafeCell},
clone::Clone,
ops::{DerefMut, Deref},
mem::{align_of, size_of},
todo,
};
use kernel::{
bindings, c_types, cpumask, double_linked_list::*, file_operations::{FileOperations, FileOpener}, ktime::*,
percpu, prelude::*, premmpt, spinlock_init, str::CStr, sync::Lock, sync::SpinLock, sysfs,
timekeeping,
clockchips,
uidgid::{KgidT, KuidT},
file::File,
io_buffer::IoBufferWriter,
device::DeviceType,
};

static mut CLOCKLIST_LOCK: SpinLock<i32> = unsafe { SpinLock::new(1) };
Expand Down Expand Up @@ -662,7 +663,7 @@ impl clockchips::CoreTick for RrosCoreTick {
// pr_debug!("in rros_core_tick");
let this_rq = this_rros_rq();
// if (RROS_WARN_ON_ONCE(CORE, !is_rros_cpu(rros_rq_cpu(this_rq))))
// pr_debug!("in rros_core_tick");
// pr_info!("in rros_core_tick");
unsafe {
do_clock_tick(&mut RROS_MONO_CLOCK, rros_this_cpu_timers(&RROS_MONO_CLOCK));

Expand Down
2 changes: 1 addition & 1 deletion kernel/rros/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use kernel::{
mm::{remap_pfn_range, PAGE_SHARED},
prelude::*,
str::CStr,
sync::{Mutex, SpinLock},
sync::SpinLock,
};

pub const CONFIG_RROS_NR_CONTROL: usize = 0;
Expand Down
43 changes: 17 additions & 26 deletions kernel/rros/factory.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
use core::{cell::RefCell, clone::Clone, convert::TryInto, default::Default, result::Result::Ok, ptr};
use core::{cell::RefCell, clone::Clone, convert::TryInto, default::Default, result::Result::Ok, ptr, mem::size_of};

use crate::{clock, control, file::RrosFileBinding, proxy, thread, xbuf};

use alloc::rc::Rc;
use kernel::file::fd_install;
use kernel::uidgid::{KgidT, KuidT};

use kernel::{
bindings,
bitmap::{self, bitmap_zalloc},
c_str, c_types, chrdev, class, device,
file::{self, File},
file::{self, File, fd_install},
file_operations::FileOperations,
fs::{self, Filename},
irq_work, rbtree, spinlock_init, kernelh,
prelude::*,
str::CStr,
sync::{Guard, Lock, SpinLock},
sync::{Lock, SpinLock},
sysfs,
task::Task,
types::{self, hash_init},
types,
uidgid, workqueue, ThisModule,
file_operations::{FileOpener, IoctlCommand},
uidgid::{KgidT, KuidT},
device::DeviceType,
io_buffer::IoBufferWriter,
};
use kernel::{device::DeviceType, io_buffer::IoBufferWriter};


extern "C" {
#[allow(improper_ctypes)]
fn rust_helper_dev_name(dev: *mut bindings::device) -> *const c_types::c_char;
fn rust_helper_put_user(val: u32, ptr: *mut u32) -> c_types::c_int;
}

Expand Down Expand Up @@ -294,17 +294,13 @@ impl device::Devnode for FactoryTypeDevnode {
if let Some(e) = element {
let inside = unsafe { (*(e.factory.locked_data().get())).inside.as_ref().unwrap() };
if let Some(uid) = uid {
unsafe {
if let Some(e_uid) = inside.kuid.as_ref() {
*uid = *e_uid;
}
if let Some(e_uid) = inside.kuid.as_ref() {
*uid = *e_uid;
}
}
if let Some(gid) = gid {
unsafe {
if let Some(e_gid) = inside.kgid.as_ref() {
*gid = *e_gid;
}
if let Some(e_gid) = inside.kgid.as_ref() {
*gid = *e_gid;
}
}
}
Expand Down Expand Up @@ -1171,11 +1167,9 @@ pub fn rros_early_init_factories(
CStr::from_bytes_with_nul("rros\0".as_bytes())?.as_char_ptr(),
)?)?;
// TODO: 创建一个结构体,实现rros_devnode
unsafe {
Arc::get_mut(&mut rros_class)
.unwrap()
.set_devnode::<RrosDevnode>();
}
Arc::get_mut(&mut rros_class)
.unwrap()
.set_devnode::<RrosDevnode>();
// unsafe {
// (*rros_class.ptr).devnode = Option::Some(rros_devnode);
// }
Expand Down Expand Up @@ -1344,9 +1338,6 @@ fn rros_index_factory_element() {}
// rros_index_element(&e->factory->index, e);
// }

use core::mem::size_of;
use kernel::user_ptr::UserSlicePtr;

extern "C" {
pub fn rust_helper_copy_from_user(
to: *mut c_types::c_void,
Expand Down
5 changes: 1 addition & 4 deletions kernel/rros/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ use crate::{

use kernel::{
bindings,
c_str,
c_types,
double_linked_list::*,
file::{File, FilesStruct},
file::FilesStruct,
init_static_sync,
prelude::*,
rbtree,
Expand Down
3 changes: 0 additions & 3 deletions kernel/rros/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use crate::{
timeout::{RrosTmode, RROS_INFINITE},
wait::{RrosWaitQueue, RROS_WAIT_PRIO},
};
use alloc::boxed::Box;
use kernel::prelude::*;
use core::{cell::Cell, ptr::NonNull};
use kernel::bindings;

pub struct RrosFlag {
pub wait: RrosWaitQueue,
Expand Down
14 changes: 7 additions & 7 deletions kernel/rros/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ fn set_rros_state(state: RrosRunStates) {
fn init_core() -> Result<Pin<Box<chrdev::Registration<{ factory::NR_FACTORIES }>>>> {
let res =
irqstage::enable_oob_stage(CStr::from_bytes_with_nul("rros\0".as_bytes())?.as_char_ptr());
pr_debug!("hello");
pr_info!("hello");
match res {
Ok(_o) => (),
Err(_e) => {
pr_warn!("rros cannot be enabled");
return Err(kernel::Error::EINVAL);
}
}
pr_debug!("hella");
pr_info!("hella");
let res = rros_init_memory();
match res {
Ok(_o) => (),
Expand All @@ -202,7 +202,7 @@ fn init_core() -> Result<Pin<Box<chrdev::Registration<{ factory::NR_FACTORIES }>
return Err(_e);
}
}
pr_debug!("haly");
pr_info!("haly");

let res = rros_clock_init();
match res {
Expand Down Expand Up @@ -359,7 +359,7 @@ impl KernelModule for Rros {
)
};
match res {
Ok(_o) => (pr_debug!("load parameters {}\n", str::from_utf8(oobcpus_arg.read())?)),
Ok(_o) => (pr_info!("load parameters {}\n", str::from_utf8(oobcpus_arg.read())?)),
Err(_e) => {
pr_warn!("wrong oobcpus_arg");
unsafe {
Expand Down Expand Up @@ -395,7 +395,7 @@ impl KernelModule for Rros {
test_mem();
match res {
Ok(_o) => {
pr_debug!("Success boot the rros.");
pr_info!("Success boot the rros.");
fac_reg = _o;
}
Err(_e) => {
Expand All @@ -422,11 +422,11 @@ impl KernelModule for Rros {

#[no_mangle]
unsafe extern "C" fn helloworld() {
pr_debug!("hello world! from C to rust");
pr_info!("hello world! from C to rust");
}

impl Drop for Rros {
fn drop(&mut self) {
pr_debug!("Bye world from rros!\n");
pr_info!("Bye world from rros!\n");
}
}
2 changes: 1 addition & 1 deletion kernel/rros/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn init_system_heap(heap: Arc<SpinLock<RrosHeap>>, sysheap_size_arg: u32) -> Res

let res = rros_init_heap(heap, memptr as *mut u8, size);
match res {
Ok(_o) => pr_debug!("Rros core system memory success init!\n"),
Ok(_o) => pr_info!("Rros core system memory success init!\n"),
Err(_e) => {
vmalloc::c_vfree(memptr);
return Err(_e);
Expand Down
8 changes: 3 additions & 5 deletions kernel/rros/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ use crate::{
factory::{RrosElement, RrosFactory},
fifo::RROS_FIFO_MAX_PRIO,
list, sched,
Box,
wait::RrosWaitQueue,
};

use kernel::{
c_types, prelude::*, spinlock_init, str::CStr, sync::SpinLock, user_ptr, Error, device::DeviceType,
file::File,
file_operations::FileOperations,
io_buffer::IoBufferWriter,
};

use kernel::file::File;
use kernel::file_operations::FileOperations;
use kernel::io_buffer::IoBufferWriter;

#[allow(dead_code)]
pub struct RrosMonitorItem1 {
pub mutex: SpinLock<i32>,
Expand Down
64 changes: 40 additions & 24 deletions kernel/rros/net/device.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
use core::clone::Clone;
use core::ffi::c_void;
use core::mem::size_of;
use core::ptr::NonNull;

use kernel::linked_list::{GetLinks, Links, List};
use kernel::prelude::*;
use kernel::sync::Lock;
use kernel::{bindings, init_static_sync, sync::SpinLock};
use kernel::{c_str, spinlock_init, vmalloc, Result};
use kernel::notifier::NotifierBlock;
use kernel::net::Namespace;
use alloc::sync::Arc;

use crate::crossing::RrosCrossing;
use crate::flags::RrosFlag;
use crate::net::input::rros_net_do_rx;
use crate::net::skb::rros_net_dev_build_pool;
use crate::thread::KthreadRunner;
// use crate::uapi::rros::socket::RrosNetdevActivation;
use crate::wait::RrosWaitQueue;

use super::skb::RrosSkbQueue;
use super::socket::RrosNetdevActivation;
use core::{
clone::Clone,
ffi::c_void,
mem::size_of,
ptr::NonNull,
};

use kernel::{
bindings,
net::Namespace,
init_static_sync, c_str, spinlock_init, Result,
sync::{
SpinLock,
Lock,
},
vmalloc,
prelude::*,
linked_list::{
GetLinks,
Links,
List,
},
notifier::NotifierBlock,
};

use crate::{
flags::RrosFlag,
net::{
input::rros_net_do_rx,
skb::rros_net_dev_build_pool,
},
thread::KthreadRunner,
wait::RrosWaitQueue,
crossing::RrosCrossing,
};
use super::{
skb::RrosSkbQueue,
socket::RrosNetdevActivation,
};

const IFF_OOB_PORT: usize = 1 << 1;
const IFF_OOB_CAPABLE: usize = 1 << 0;
Expand Down Expand Up @@ -207,6 +222,7 @@ impl NetDevice {

pub fn get_net(&self) -> *const Namespace {
extern "C" {
#[allow(improper_ctypes)]
fn rust_helper_dev_net(dev: *const bindings::net_device) -> *const Namespace;
}
unsafe { rust_helper_dev_net(self.0.as_ptr() as *const bindings::net_device) }
Expand Down
Loading

0 comments on commit 1c1c52f

Please sign in to comment.