Skip to content

Commit

Permalink
rust: task: use safe macro
Browse files Browse the repository at this point in the history
  • Loading branch information
antonio-hickey committed Jan 2, 2024
1 parent 8f7e376 commit d9406b3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion rust/kernel/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Task {
/// Returns the given task's pid in the current pid namespace.
pub fn pid_in_current_ns(&self) -> Pid {
// SAFETY: Calling `task_active_pid_ns` with the current task is always safe.
let namespace = unsafe { bindings::task_active_pid_ns(bindings::get_current()) };
let namespace = unsafe { bindings::task_active_pid_ns(current!()) };
// SAFETY: We know that `self.0.get()` is valid by the type invariant.
unsafe { bindings::task_tgid_nr_ns(self.0.get(), namespace) }
}
Expand All @@ -176,6 +176,15 @@ impl Task {
// running.
unsafe { bindings::wake_up_process(self.0.get()) };
}

/// Returns a raw pointer to the underlying C task struct.
///
/// # Safety
///
/// Callers must ensure that the pointer is not used after `Task` is invalidated.
pub unsafe fn as_raw(&self) -> *const bindings::task_struct {
self.0.get()
}
}

impl Kuid {
Expand Down

0 comments on commit d9406b3

Please sign in to comment.