Lines Matching +full:current +full:-

1 // SPDX-License-Identifier: GPL-2.0
35 macro_rules! current { macro
39 // leave current task context:
41 // * To return to userspace, the caller must leave the current scope.
47 unsafe { &*$crate::task::Task::current() }
62 /// The following is an example of getting the PID of the current thread with zero additional cost
66 /// let pid = current!().pid();
69 /// Getting the PID of the current process, also zero additional cost:
72 /// let pid = current!().group_leader().pid();
75 /// Getting the current task and storing it in some struct. The reference count is automatically
87 /// fn new() -> Self {
89 /// creator: ARef::from(&**current!()),
98 // SAFETY: By design, the only way to access a `Task` is via the `current` function or via an
109 /// Represents the [`Task`] in the `current` global.
111 /// This type exists to provide more efficient operations that are only valid on the current task.
112 /// For example, to retrieve the pid-namespace of a task, you must use rcu protection unless it is
113 /// the current task.
126 /// Other operations temporarily create a new sub-context:
142 fn deref(&self) -> &Task { in deref()
157 /// Returns a raw pointer to the current task.
161 pub fn current_raw() -> *mut bindings::task_struct { in current_raw()
162 // SAFETY: Getting the current pointer is always safe. in current_raw()
168 /// The recommended way to get the current task/thread is to use the
169 /// [`current`] macro because it is safe.
177 pub unsafe fn current() -> impl Deref<Target = CurrentTask> { in current() method
185 fn deref(&self) -> &Self::Target { in current()
187 // the `TaskRef`, which the caller of `Task::current()` has promised will not in current()
188 // outlive the task/thread for which `self.task` is the `current` pointer. Thus, it in current()
202 pub fn as_ptr(&self) -> *mut bindings::task_struct { in as_ptr()
207 pub fn pid(&self) -> Pid { in pid()
215 pub fn uid(&self) -> Kuid { in uid()
222 pub fn euid(&self) -> Kuid { in euid()
229 pub fn signal_pending(&self) -> bool { in signal_pending()
236 pub fn get_pid_ns(&self) -> Option<ARef<PidNamespace>> { in get_pid_ns()
252 pub fn tgid_nr_ns(&self, pidns: Option<&PidNamespace>) -> Pid { in tgid_nr_ns()
274 /// Access the address space of the current task.
278 pub fn mm(&self) -> Option<&MmWithUser> { in mm()
279 // SAFETY: The `mm` field of `current` is not modified from other threads, so reading it is in mm()
287 // SAFETY: If `current->mm` is non-null, then it references a valid mm with a non-zero in mm()
289 // `CurrentTask`, so it cannot escape the scope in which the current pointer was obtained. in mm()
299 // In either case, it's not possible to read `current->mm` and keep using it after the in mm()
304 /// Access the pid namespace of the current task.
311 pub fn active_pid_ns(&self) -> Option<&PidNamespace> { in active_pid_ns()
313 // on the current task. in active_pid_ns()
324 // From system call context retrieving the `PidNamespace` for the current task is always in active_pid_ns()
326 // `PidNamespace` after `release_task()` for current will return `NULL` but no codepath in active_pid_ns()
329 // SAFETY: If `current`'s pid ns is non-null, then it references a valid pid ns. in active_pid_ns()
331 // escape the scope in which the current pointer was obtained, e.g. it cannot live past a in active_pid_ns()
336 /// Returns the group leader of the current task.
337 pub fn group_leader(&self) -> &Task { in group_leader()
339 // is the current task, which is guaranteed running. in group_leader()
342 // SAFETY: `current->group_leader` stays valid for at least the duration in which `current` in group_leader()
344 // only be used while `current` is still valid, thus still running. in group_leader()
366 fn eq(&self, other: &Self) -> bool { in eq()
374 /// Get the current euid.
376 pub fn current_euid() -> Kuid { in current_euid()
383 pub fn from_raw(kuid: bindings::kuid_t) -> Self { in from_raw()
389 pub fn into_raw(self) -> bindings::kuid_t { in into_raw()
395 /// Uses the namespace of the current task.
397 pub fn into_uid_in_current_ns(self) -> bindings::uid_t { in into_uid_in_current_ns()
405 fn eq(&self, other: &Kuid) -> bool { in eq()
420 /// [`might_sleep()`]: https://docs.kernel.org/driver-api/basics.html#c.might_sleep
429 // SAFETY: `file.as_ptr()` is valid for reading and guaranteed to be nul-terminated. in might_sleep()