Skip to content

Commit

Permalink
rust: task: use safe current! macro
Browse files Browse the repository at this point in the history
Refactor the `Task::pid_in_current_ns()` to use the safe abstraction
`current!()` instead of the unsafe `bindings::get_current()` binding.

Signed-off-by: Antonio Hickey <antoniohickey99@gmail.com>
  • Loading branch information
antonio-hickey committed Jan 4, 2024
1 parent f3bc6f9 commit b54bde5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rust/kernel/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ impl Task {

/// Returns the given task's pid in the current pid namespace.
pub fn pid_in_current_ns(&self) -> Pid {
let current = current!();
// 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.as_raw()) };
// SAFETY: We know that `self.raw()` is valid by the type invariant.
unsafe { bindings::task_tgid_nr_ns(self.as_raw(), namespace) }
}
Expand Down

0 comments on commit b54bde5

Please sign in to comment.