@@ -124,11 +124,16 @@ impl Task {
124
124
}
125
125
}
126
126
127
+ /// Returns a raw pointer to the underlying C task struct.
128
+ pub fn as_raw ( & self ) -> * mut bindings:: task_struct {
129
+ self . 0 . get ( )
130
+ }
131
+
127
132
/// Returns the group leader of the given task.
128
133
pub fn group_leader ( & self ) -> & Task {
129
- // SAFETY: By the type invariant, we know that `self.0 ` is a valid task. Valid tasks always
134
+ // SAFETY: By the type invariant, we know that `self.as_raw() ` is a valid task. Valid tasks always
130
135
// have a valid group_leader.
131
- let ptr = unsafe { * ptr:: addr_of!( ( * self . 0 . get ( ) ) . group_leader) } ;
136
+ let ptr = unsafe { * ptr:: addr_of!( ( * self . as_raw ( ) ) . group_leader) } ;
132
137
133
138
// SAFETY: The lifetime of the returned task reference is tied to the lifetime of `self`,
134
139
// and given that a task has a reference to its group leader, we know it must be valid for
@@ -138,43 +143,43 @@ impl Task {
138
143
139
144
/// Returns the PID of the given task.
140
145
pub fn pid ( & self ) -> Pid {
141
- // SAFETY: By the type invariant, we know that `self.0 ` is a valid task. Valid tasks always
146
+ // SAFETY: By the type invariant, we know that `self.as_raw() ` is a valid task. Valid tasks always
142
147
// have a valid pid.
143
- unsafe { * ptr:: addr_of!( ( * self . 0 . get ( ) ) . pid) }
148
+ unsafe { * ptr:: addr_of!( ( * self . as_raw ( ) ) . pid) }
144
149
}
145
150
146
151
/// Returns the UID of the given task.
147
152
pub fn uid ( & self ) -> Kuid {
148
- // SAFETY: By the type invariant, we know that `self.0 ` is valid.
149
- Kuid :: from_raw ( unsafe { bindings:: task_uid ( self . 0 . get ( ) ) } )
153
+ // SAFETY: By the type invariant, we know that `self.as_raw() ` is valid.
154
+ Kuid :: from_raw ( unsafe { bindings:: task_uid ( self . as_raw ( ) ) } )
150
155
}
151
156
152
157
/// Returns the effective UID of the given task.
153
158
pub fn euid ( & self ) -> Kuid {
154
- // SAFETY: By the type invariant, we know that `self.0 ` is valid.
155
- Kuid :: from_raw ( unsafe { bindings:: task_euid ( self . 0 . get ( ) ) } )
159
+ // SAFETY: By the type invariant, we know that `self.as_raw() ` is valid.
160
+ Kuid :: from_raw ( unsafe { bindings:: task_euid ( self . as_raw ( ) ) } )
156
161
}
157
162
158
163
/// Determines whether the given task has pending signals.
159
164
pub fn signal_pending ( & self ) -> bool {
160
- // SAFETY: By the type invariant, we know that `self.0 ` is valid.
161
- unsafe { bindings:: signal_pending ( self . 0 . get ( ) ) != 0 }
165
+ // SAFETY: By the type invariant, we know that `self.as_raw() ` is valid.
166
+ unsafe { bindings:: signal_pending ( self . as_raw ( ) ) != 0 }
162
167
}
163
168
164
169
/// Returns the given task's pid in the current pid namespace.
165
170
pub fn pid_in_current_ns ( & self ) -> Pid {
166
171
// SAFETY: Calling `task_active_pid_ns` with the current task is always safe.
167
172
let namespace = unsafe { bindings:: task_active_pid_ns ( bindings:: get_current ( ) ) } ;
168
- // SAFETY: We know that `self.0.get ()` is valid by the type invariant.
169
- unsafe { bindings:: task_tgid_nr_ns ( self . 0 . get ( ) , namespace) }
173
+ // SAFETY: We know that `self.raw ()` is valid by the type invariant.
174
+ unsafe { bindings:: task_tgid_nr_ns ( self . as_raw ( ) , namespace) }
170
175
}
171
176
172
177
/// Wakes up the task.
173
178
pub fn wake_up ( & self ) {
174
- // SAFETY: By the type invariant, we know that `self.0.get ()` is non-null and valid.
179
+ // SAFETY: By the type invariant, we know that `self.raw ()` is non-null and valid.
175
180
// And `wake_up_process` is safe to be called for any valid task, even if the task is
176
181
// running.
177
- unsafe { bindings:: wake_up_process ( self . 0 . get ( ) ) } ;
182
+ unsafe { bindings:: wake_up_process ( self . as_raw ( ) ) } ;
178
183
}
179
184
}
180
185
0 commit comments