Debian Codegraph @

tapset/linux/task.stp

raw
1 // task information tapset
2 // Copyright (C) 2006 Intel Corporation.
3 // Copyright (C) 2010-2017 Red Hat Inc.
4 //
5 // This file is part of systemtap, and is free software. You can
6 // redistribute it and/or modify it under the terms of the GNU General
7 // Public License (GPL); either version 2, or (at your option) any
8 // later version.
9
10 %{
11 #include <linux/version.h>
12 #include <linux/file.h>
13 #include <linux/fdtable.h>
14 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0)
15 #include <linux/sched/rt.h>
16 #endif
17 #ifndef STAPCONF_TASK_UID
18 #include <linux/cred.h>
19 #endif
20 #include <linux/fs_struct.h>
21 #include <linux/mm.h>
22 %}
23
24 /**
25 * sfunction task_current - The current task_struct of the current task
26 *
27 * Description: This function returns the task_struct representing the current process.
28 * This address can be passed to the various task_*() functions to extract
29 * more task-specific data.
30 */
31 function task_current:long () {
32 return & @task(%{ /* pure */ (unsigned long)current %})
33 }
34
35 @__private30 function _task_rlimit_cur:long (task:long, nd_limit:long)
36 {
37 if (nd_limit < 0 || nd_limit >= @const("RLIM_NLIMITS")) {
38 return -1;
39 }
40 sig = @task(task)->signal;
41 return @cast(sig, "signal_struct", "kernel")->rlim[nd_limit]->rlim_cur;
42 }
43
44 /* sfunction task_rlimit - The current resource limit of the task
45 *
46 * @task: task_struct pointer
47 * @lim_str: String representing limit.
48 *
49 * Description: Little bit slower way how ger resource limits of
50 * process.
51 * There is need translate string into number for each call.
52 */
53 function task_rlimit:long (task:long, lim_str:string)
54 {
55 lim = rlimit_from_str(lim_str);
56 if (lim == -1) { return -1; }
57 return _task_rlimit_cur(task, lim);
58 }
59
60 /* Fast and "safe" way how to do it. */
61
62 function task_rlimit_cpu:long (task:long)
63 {
64 return _task_rlimit_cur(task, @const("RLIMIT_CPU") );
65 }
66
67 function task_rlimit_fsize:long (task:long)
68 {
69 return _task_rlimit_cur(task, @const("RLIMIT_FSIZE"));
70 }
71
72 function task_rlimit_data:long (task:long)
73 {
74 return _task_rlimit_cur(task, @const("RLIMIT_DATA"));
75 }
76
77 function task_rlimit_stack:long (task:long)
78 {
79 return _task_rlimit_cur(task, @const("RLIMIT_STACK"));
80 }
81
82 function task_rlimit_core:long (task:long)
83 {
84 return _task_rlimit_cur(task, @const("RLIMIT_CORE"));
85 }
86
87 function task_rlimit_rss:long (task:long)
88 {
89 return _task_rlimit_cur(task, @const("RLIMIT_RSS"));
90 }
91
92 function task_rlimit_nproc:long (task:long)
93 {
94 return _task_rlimit_cur(task, @const("RLIMIT_NPROC"));
95 }
96
97 function task_rlimit_nofile:long(task:long)
98 {
99 return _task_rlimit_cur(task, @const("RLIMIT_NOFILE"));
100 }
101
102 function task_rlimit_memlock:long(task:long)
103 {
104 return _task_rlimit_cur(task, @const("RLIMIT_MEMLOCK"));
105 }
106
107 function task_rlimit_as:long(task:long)
108 {
109 return _task_rlimit_cur(task, @const("RLIMIT_AS"));
110 }
111
112 function task_rlimit_locks:long(task:long)
113 {
114 return _task_rlimit_cur(task, @const("RLIMIT_LOCKS"));
115 }
116
117 function task_rlimit_sigpending:long(task:long)
118 {
119 %( kernel_v >= "2.6.8" %?
120 return _task_rlimit_cur(task, @const("RLIMIT_SIGPENDING"));
121 %:
122 return -1
123 %)
124 }
125
126 function task_rlimit_msgqueue:long(task:long)
127 {
128 %( kernel_v >= "2.6.8" %?
129 return _task_rlimit_cur(task, @const("RLIMIT_MSGQUEUE"));
130 %:
131 return -1
132 %)
133 }
134
135 function task_rlimit_nice:long(task:long)
136 {
137 %( kernel_v >= "2.6.12" %?
138 return _task_rlimit_cur(task, @const("RLIMIT_NICE"));
139 %:
140 return -1
141 %)
142 }
143
144 function task_rlimit_rtprio:long(task:long)
145 {
146 %( kernel_v >= "2.6.12" %?
147 return _task_rlimit_cur(task, @const("RLIMIT_RTPRIO"));
148 %:
149 return -1
150 %)
151 }
152
153 function task_rlimit_rttime:long(task:long)
154 {
155 %( kernel_v >= "2.6.25" %?
156 return _task_rlimit_cur(task, @const("RLIMIT_RTTIME"));
157 %:
158 return -1
159 %)
160 }
161
162 /**
163 * sfunction task_parent - The task_struct of the parent task
164 *
165 * @task: task_struct pointer
166 *
167 * Description: This function returns the parent task_struct of
168 * the given task. This address can be passed to the various
169 * task_*() functions to extract more task-specific data.
170 */
171 function task_parent:long(task:long)
172 {
173 return @choose_defined(@task(task)->real_parent, @task(task)->parent)
174 }
175
176 /**
177 * sfunction task_state - The state of the task
178 *
179 * @task: task_struct pointer
180 *
181 * Description: Return the state of the given task, one of:
182 * TASK_RUNNING (0), TASK_INTERRUPTIBLE (1), TASK_UNINTERRUPTIBLE (2),
183 * TASK_STOPPED (4), TASK_TRACED (8), EXIT_ZOMBIE (16), or EXIT_DEAD (32).
184 */
185 function task_state:long (task:long)
186 {
187 return @choose_defined(@task(task)->state,@task(task)->__state)
188 }
189
190 /**
191 * sfunction task_execname - The name of the task
192 *
193 * @task: task_struct pointer
194 *
195 * Description: Return the name of the given task.
196 */
197 function task_execname:string (task:long)
198 {
199 return kernel_string(@task(task)->comm)
200 }
201
202 /**
203 * sfunction task_pid - The process identifier of the task
204 *
205 * @task: task_struct pointer
206 *
207 * Description: This fucntion returns the process id of the given task.
208 */
209 function task_pid:long (task:long)
210 {
211 return @task(task)->tgid
212 }
213
214 /**
215 * sfunction task_ns_pid - The process identifier of the task
216 *
217 * @task: task_struct pointer
218 *
219 * Description: This fucntion returns the process id of the given task based on
220 * the specified pid namespace..
221 */
222 function task_ns_pid:long (task:long) %{ /* pure */ /* guru */
223 struct task_struct *t = (struct task_struct *)(uintptr_t)STAP_ARG_task;
224 int64_t rc;
225
226 /* Before using the task_struct pointer, make sure it is valid to
227 * read. */
228 (void)kderef_buffer(NULL, t, sizeof(struct task_struct));
229
230 rc = from_target_pid_ns(t, PID);
231 if (rc < 0)
232 STAP_ERROR ("cannot resolve id in namespace");
233 else
234 STAP_RETURN (rc);
235 CATCH_DEREF_FAULT();
236 %}
237
238 /**
239 * sfunction pid2task - The task_struct of the given process identifier
240 *
241 * @pid: process identifier
242 *
243 * Description: Return the task struct of the given process id.
244 */
245 function pid2task:long (pid:long) {
246 return & @task(%{ /* pure */ ({
247 struct task_struct *t = NULL;
248 pid_t t_pid = (pid_t)(long)STAP_ARG_pid;
249 struct pid *p_pid = find_get_pid(t_pid);
250 rcu_read_lock();
251 t = pid_task(p_pid, PIDTYPE_PID);
252 put_pid(p_pid);
253 rcu_read_unlock();
254 (unsigned long)t;
255 }) %})
256 }
257
258 /**
259 * sfunction pid2execname - The name of the given process identifier
260 *
261 * @pid: process identifier
262 *
263 * Description: Return the name of the given process id.
264 */
265 function pid2execname:string (pid:long) {
266 tsk = pid2task(pid)
267 if (tsk)
268 return task_execname(tsk)
269 return ""
270 }
271
272 /**
273 * sfunction task_tid - The thread identifier of the task
274 *
275 * @task: task_struct pointer
276 *
277 * Description: This function returns the thread id of the given task.
278 */
279 function task_tid:long (task:long)
280 {
281 return @task(task)->pid
282 }
283
284 /**
285 * sfunction task_ns_tid - The thread identifier of the task as seen in a namespace
286 *
287 * @task: task_struct pointer
288 *
289 * Description: This function returns the thread id of the given task as seen
290 * in the pid namespace.
291 */
292 function task_ns_tid:long (task:long)%{ /* pure */ /* guru */
293 struct task_struct *t = (struct task_struct *)(uintptr_t)STAP_ARG_task;
294 int64_t rc;
295
296 /* Before using the task_struct pointer, make sure it is valid to
297 * read. */
298 (void)kderef_buffer(NULL, t, sizeof(struct task_struct));
299
300 rc = from_target_pid_ns(t, TID);
301 if (rc < 0)
302 STAP_ERROR ("cannot resolve id in namespace");
303 else
304 STAP_RETURN (rc);
305 CATCH_DEREF_FAULT();
306 %}
307
308 /**
309 * sfunction task_gid - The group identifier of the task
310 *
311 * @task: task_struct pointer
312 *
313 * Description: This function returns the group id of the given task.
314 */
315 function task_gid:long (task:long) %{ /* pure */
316 struct task_struct *t = (struct task_struct *)(uintptr_t)STAP_ARG_task;
317 #ifdef STAPCONF_TASK_UID
318 STAP_RETVALUE = kread(&(t->gid));
319 #else
320 #ifdef STAPCONF_FROM_KUID_MUNGED
321 struct user_namespace *user_ns;
322 #endif
323
324 /* We can't easily kread the task_struct's rcu-protected
325 * credential fields. So, let's just make sure the entire
326 * task_struct is valid to read. */
327 (void)kderef_buffer(NULL, t, sizeof(struct task_struct));
328
329 /* If task_gid() isn't defined, make our own. */
330 #if !defined(task_gid) && defined(task_cred_xxx)
331 #define task_gid(task) (task_cred_xxx((task), gid))
332 #endif
333
334 #ifdef STAPCONF_FROM_KUID_MUNGED
335 /* We also need to validate the namespace structure. */
336 user_ns = task_cred_xxx(t, user_ns);
337 (void)kderef_buffer(NULL, user_ns, sizeof(struct user_namespace));
338 STAP_RETVALUE = from_kgid_munged(user_ns, task_gid(t));
339 #else
340 STAP_RETVALUE = task_gid (t);
341 #endif
342 #endif
343 CATCH_DEREF_FAULT();
344 %}
345
346 /**
347 * sfunction task_ns_gid - The group identifier of the task as seen in a namespace
348 *
349 * @task: task_struct pointer
350 *
351 * Description: This function returns the group id of the given task as seen in
352 * in the given user namespace.
353 */
354 function task_ns_gid:long (task:long) %{ /* pure */ /* guru */
355 struct task_struct *t = (struct task_struct *)(uintptr_t)STAP_ARG_task;
356 int64_t rc;
357
358 /* Before using the task_struct pointer, make sure it is valid to
359 * read. */
360 (void)kderef_buffer(NULL, t, sizeof(struct task_struct));
361
362 rc = from_target_user_ns(t, GID);
363 if (rc < 0)
364 STAP_ERROR ("cannot resolve id in namespace");
365 else
366 STAP_RETURN (rc);
367 CATCH_DEREF_FAULT();
368 %}
369
370 /**
371 * sfunction task_egid - The effective group identifier of the task
372 *
373 * @task: task_struct pointer
374 *
375 * Description: This function returns the effective group id of the given task.
376 */
377 function task_egid:long (task:long) %{ /* pure */
378 struct task_struct *t = (struct task_struct *)(uintptr_t)STAP_ARG_task;
379 #ifdef STAPCONF_TASK_UID
380 STAP_RETVALUE = kread(&(t->egid));
381 #else
382 #ifdef STAPCONF_FROM_KUID_MUNGED
383 struct user_namespace *user_ns;
384 #endif
385
386 /* We can't easily kread the task_struct's rcu-protected
387 * credential fields. So, let's just make sure the entire
388 * task_struct is valid to read. */
389 (void)kderef_buffer(NULL, t, sizeof(struct task_struct));
390
391 /* If task_egid() isn't defined, make our own. */
392 #if !defined(task_egid) && defined(task_cred_xxx)
393 #define task_egid(task) (task_cred_xxx((task), egid))
394 #endif
395
396 #ifdef STAPCONF_FROM_KUID_MUNGED
397 /* We also need to validate the namespace structure. */
398 user_ns = task_cred_xxx(t, user_ns);
399 (void)kderef_buffer(NULL, user_ns, sizeof(struct user_namespace));
400 STAP_RETVALUE = from_kgid_munged(user_ns, task_egid(t));
401 #else
402 STAP_RETVALUE = task_egid (t);
403 #endif
404 #endif
405 CATCH_DEREF_FAULT();
406 %}
407
408 /**
409 * sfunction task_ns_egid - The effective group identifier of the task
410 *
411 * @task: task_struct pointer
412 *
413 * Description: This function returns the effective group id of the given task.
414 */
415 function task_ns_egid:long (task:long) %{ /* pure */ /* guru */
416 struct task_struct *t = (struct task_struct *)(uintptr_t)STAP_ARG_task;
417 int64_t rc;
418
419 /* Before using the task_struct pointer, make sure it is valid to
420 * read. */
421 (void)kderef_buffer(NULL, t, sizeof(struct task_struct));
422
423 rc = from_target_user_ns(current, EGID);
424 if (rc < 0)
425 STAP_ERROR ("cannot resolve id in namespace");
426 else
427 STAP_RETURN (rc);
428 CATCH_DEREF_FAULT();
429 %}
430
431 /**
432 * sfunction task_uid - The user identifier of the task
433 *
434 * @task: task_struct pointer
435 *
436 * Description: This function returns the user id of the given task.
437 */
438 function task_uid:long (task:long) %{ /* pure */
439 struct task_struct *t = (struct task_struct *)(uintptr_t)STAP_ARG_task;
440 #ifdef STAPCONF_TASK_UID
441 STAP_RETVALUE = kread(&(t->uid));
442 #else
443 #ifdef STAPCONF_FROM_KUID_MUNGED
444 struct user_namespace *user_ns;
445 #endif
446
447 /* We can't easily kread the task_struct's rcu-protected
448 * credential fields. So, let's just make sure the entire
449 * task_struct is valid to read. */
450 (void)kderef_buffer(NULL, t, sizeof(struct task_struct));
451
452 #ifdef STAPCONF_FROM_KUID_MUNGED
453 /* We also need to validate the namespace structure. */
454 user_ns = task_cred_xxx(t, user_ns);
455 (void)kderef_buffer(NULL, user_ns, sizeof(struct user_namespace));
456 STAP_RETVALUE = from_kuid_munged(user_ns, task_uid(t));
457 #else
458 STAP_RETVALUE = task_uid (t);
459 #endif
460 #endif
461 CATCH_DEREF_FAULT();
462 %}
463
464 /**
465 * sfunction task_ns_uid - The user identifier of the task
466 *
467 * @task: task_struct pointer
468 *
469 * Description: This function returns the user id of the given task.
470 */
471 function task_ns_uid:long (task:long) %{ /* pure */ /* guru */
472 struct task_struct *t = (struct task_struct *)(uintptr_t)STAP_ARG_task;
473 int64_t rc;
474
475 /* Before using the task_struct pointer, make sure it is valid to
476 * read. */
477 (void)kderef_buffer(NULL, t, sizeof(struct task_struct));
478
479 rc = from_target_user_ns(current, UID);
480 if (rc < 0)
481 STAP_ERROR ("cannot resolve id in namespace");
482 else
483 STAP_RETURN (rc);
484 CATCH_DEREF_FAULT();
485 %}
486
487 /**
488 * sfunction task_euid - The effective user identifier of the task
489 *
490 * @task: task_struct pointer
491 *
492 * Description: This function returns the effective user id of the given task.
493 */
494 function task_euid:long (task:long) %{ /* pure */
495 struct task_struct *t = (struct task_struct *)(uintptr_t)STAP_ARG_task;
496 #ifdef STAPCONF_TASK_UID
497 STAP_RETVALUE = kread(&(t->euid));
498 #else
499 #ifdef STAPCONF_FROM_KUID_MUNGED
500 struct user_namespace *user_ns;
501 #endif
502
503 /* We can't easily kread the task_struct's rcu-protected
504 * credential fields. So, let's just make sure the entire
505 * task_struct is valid to read. */
506 (void)kderef_buffer(NULL, t, sizeof(struct task_struct));
507
508 #ifdef STAPCONF_FROM_KUID_MUNGED
509 /* We also need to validate the namespace structure. */
510 user_ns = task_cred_xxx(t, user_ns);
511 (void)kderef_buffer(NULL, user_ns, sizeof(struct user_namespace));
512 STAP_RETVALUE = from_kuid_munged(user_ns, task_euid(t));
513 #else
514 STAP_RETVALUE = task_euid (t);
515 #endif
516 #endif
517 CATCH_DEREF_FAULT();
518 %}
519
520 /**
521 * sfunction task_ns_euid - The effective user identifier of the task
522 *
523 * @task: task_struct pointer
524 *
525 * Description: This function returns the effective user id of the given task.
526 */
527 function task_ns_euid:long (task:long) %{ /* pure */ /* guru */
528 struct task_struct *t = (struct task_struct *)(uintptr_t)STAP_ARG_task;
529 int64_t rc;
530
531 /* Before using the task_struct pointer, make sure it is valid to
532 * read. */
533 (void)kderef_buffer(NULL, t, sizeof(struct task_struct));
534
535 rc = from_target_user_ns(current, EUID);
536 if (rc < 0)
537 STAP_ERROR ("cannot resolve id in namespace");
538 else
539 STAP_RETURN (rc);
540 CATCH_DEREF_FAULT();
541 %}
542
543
544 /**
545 * sfunction task_prio - The priority value of the task
546 *
547 * @task: task_struct pointer
548 *
549 * Description: This function returns the priority value of the given task.
550 */
551 function task_prio:long (task:long) %{ /* pure */
552 struct task_struct *t = (struct task_struct *)(uintptr_t)STAP_ARG_task;
553 STAP_RETVALUE = kread(&(t->prio)) - MAX_RT_PRIO;
554 CATCH_DEREF_FAULT();
555 %}
556
557
558 /**
559 * sfunction task_nice - The nice value of the task
560 *
561 * @task: task_struct pointer
562 *
563 * Description: This function returns the nice value of the given task.
564 */
565 function task_nice:long (task:long) %{ /* pure */
566 struct task_struct *t = (struct task_struct *)(uintptr_t)STAP_ARG_task;
567 STAP_RETVALUE = kread(&(t->static_prio)) - MAX_RT_PRIO - 20;
568 CATCH_DEREF_FAULT();
569 %}
570
571 /**
572 * sfunction task_cpu - The scheduled cpu of the task
573 *
574 * @task: task_struct pointer
575 *
576 * Description: This function returns the scheduled cpu for the given task.
577 */
578 function task_cpu:long (task:long)
579 {
580 if (@defined(@task(task)->cpu))
581 return @task(task)->cpu
582 else
583 {
584 ti = @choose_defined(@task(task)->stack, @task(task)->thread_info);
585 return @cast(ti, "thread_info", "kernel<linux/sched.h>")->cpu
586 }
587 }
588
589 /**
590 * sfunction task_open_file_handles - The number of open files of the task
591 *
592 * @task: task_struct pointer
593 *
594 * Description: This function returns the number of open file handlers for the given task.
595 */
596 function task_open_file_handles:long (task:long)
597 %{ /* pure */
598 int locked = 0;
599 unsigned int count=0, fd, max;
600 struct task_struct *t;
601 struct files_struct *fs;
602 struct fdtable *f;
603 t = (struct task_struct *)(uintptr_t)STAP_ARG_task;
604 fs = kread(&(t->files));
605 f = kread(&(fs->fdt));
606 rcu_read_lock();
607 locked = 1;
608 max = kread(&(f->max_fds));
609 for (fd = 0; fd < max; fd++) {
610 if ( kread(&(f->fd[fd])) != NULL)
611 count ++;
612 }
613 STAP_RETVALUE = count;
614 CATCH_DEREF_FAULT();
615 if (locked)
616 rcu_read_unlock();
617 %}
618
619 /**
620 * sfunction task_max_file_handles - The max number of open files for the task
621 *
622 * @task: task_struct pointer
623 *
624 * Description: This function returns the maximum number of file handlers for the given task.
625 */
626 function task_max_file_handles:long (task:long)
627 %{ /* pure */
628 int locked = 0;
629 struct task_struct *t;
630 struct files_struct *fs;
631 struct fdtable *f;
632 t = (struct task_struct *)(uintptr_t)STAP_ARG_task;
633 fs = kread (&(t->files));
634 f = kread(&(fs->fdt));
635 rcu_read_lock();
636 locked = 1;
637 STAP_RETVALUE = kread(&(f->max_fds));
638 CATCH_DEREF_FAULT();
639 if (locked)
640 rcu_read_unlock();
641 %}
642
643 /**
644 * sfunction task_fd_lookup - get the file struct for a task's fd
645 *
646 * @task: task_struct pointer.
647 * @fd: file descriptor number.
648 *
649 * Description: Returns the file struct pointer for a task's file
650 * descriptor.
651 */
652 function task_fd_lookup:long(task:long, fd:long)
653 %{ /* pure */
654 struct task_struct *t = (struct task_struct *)(uintptr_t)STAP_ARG_task;
655 struct files_struct *files = NULL;
656 unsigned int fd = (unsigned int)(unsigned long)STAP_ARG_fd;
657 struct file *file = NULL;
658
659 /* Before using the task_struct pointer, make sure it is valid
660 * to read.
661 *
662 * Note that originally we called
663 * get_task_struct()/put_task_struct() here. However, just
664 * because the task_struct memory is valid to read, doesn't
665 * mean it is valid to *write* to this memory, which
666 * get_task_struct() does. So, we won't bother with
667 * get_task_struct()/put_task_struct(). */
668 (void)kderef_buffer(NULL, t, sizeof(struct task_struct));
669
670 // We should be calling get_files_struct() here, but it isn't
671 // exported. This means that we can't lock the
672 // files_struct.
673 files = t->files;
674 if (files) {
675 /* Before using the files_struct pointer, make sure it is
676 * valid to read. */
677 (void)kderef_buffer(NULL, files, sizeof(struct files_struct));
678
679 spin_lock(&files->file_lock);
680 #ifdef STAPCONF_FILES_LOOKUP_FD_RAW
681 file = files_lookup_fd_raw(files, fd);
682 #else
683 file = fcheck_files(files, fd);
684 #endif
685 spin_unlock(&files->file_lock);
686 }
687
688 if (file) {
689 // Note that we're returning a pointer which isn't
690 // locked or has had its usage count increased. There
691 // is nothing keeping this pointer valid until we use
692 // it. So, before using it, it must be validated by
693 // callers.
694 STAP_RETURN((unsigned long)file);
695 }
696 else {
697 STAP_ERROR ("cannot find file in task");
698 }
699
700 CATCH_DEREF_FAULT();
701 %}
702
703 /**
704 * sfunction task_cwd_path - get the path struct pointer for a task's current working directory
705 *
706 * @task: task_struct pointer.
707 */
708 function task_cwd_path:long(task:long)
709 %{ /* pure */
710 struct task_struct *task
711 = (struct task_struct *)(uintptr_t)STAP_ARG_task;
712 int put_task_struct_needed = 0;
713
714 // Before using the task_struct pointer, make sure it is valid
715 // to read.
716 (void)kderef_buffer(NULL, task, sizeof(struct task_struct));
717
718 // OK, we now know it is valid to read. But, is it really a
719 // task struct?
720 if (!_stp_task_struct_valid(task)) {
721 STAP_ERROR ("invalid task struct pointer");
722 }
723
724 get_task_struct(task);
725 put_task_struct_needed = 1;
726
727 // The kernel calls get_fs_pwd() here, which is an inlined
728 // function in include/linux/fs_struct.h. This function
729 // doesn't return a path pointer, but assumes the caller has
730 // allocated storage for the struct path. Instead, we're going
731 // to return a pointer to task->fs->pwd.
732 if (task->fs) {
733 // Sigh. On kernels before 2.6.25, the task->fs->pwd
734 // structure exists, but isn't a 'path'
735 // structure. Instead it is a 'dentry' structure. The
736 // 'pwd' and 'pwdmnt' (which is a 'vfsmount'
737 // structure) variables would both be needed to get a
738 // pathname. However, this function can't return 2
739 // items or really declare a static 'path' structure
740 // to put the 2 pointers in.
741 //
742 // So, on those RHEL5-era kernels, we'll just return
743 // NULL here.
744 #ifdef STAPCONF_DPATH_PATH
745 // Before using the task->fs pointer, let's be
746 // paranoid and make sure it is valid to read.
747 (void)kderef_buffer(NULL, task->fs, sizeof(struct fs_struct));
748 if (put_task_struct_needed)
749 put_task_struct(task);
750 STAP_RETURN((unsigned long)&task->fs->pwd);
751 #endif
752 }
753 CATCH_DEREF_FAULT();
754 if (put_task_struct_needed)
755 put_task_struct(task);
756 %}
757
758 /**
759 * sfunction current_exe_file - get the file struct pointer for the current task's executable file
760 *
761 * Description: This function returns the file struct pointer for the
762 * current task's executable file. Note that the file struct pointer
763 * isn't locked on return. The return value of this function can be
764 * passed to fullpath_struct_file() to get the path from the file
765 * struct.
766 */
767 function current_exe_file:long()
768 %{ /* pure */
769 struct file *exe_file = NULL;
770
771 if (current == NULL) {
772 STAP_ERROR ("No current task");
773 }
774
775 // Since we're stopped inside current, it isn't going away. So
776 // don't bother incrementing the task's usage count by calling
777 // get_task_struct()/put_task_struct(). We also don't need to
778 // bother to try to lock current->mm.
779 if (current->mm) {
780 exe_file = stap_find_exe_file(current->mm);
781 if (exe_file) {
782 STAP_RETVALUE = (unsigned long)exe_file;
783 fput(exe_file);
784 }
785 }
786 %}
787
788 %(systemtap_v <= "3.2" %?
789 /**
790 * sfunction task_exe_file - get the file struct pointer for a task's executable file
791 *
792 * @task: task_struct pointer.
793 */
794 function task_exe_file:long(task:long)
795 {
796 if (task == task_current()) {
797 return current_exe_file()
798 }
799 error("Only the exe file for the current task can be returned")
800 }
801 %)