2

I'm working on Kext which should have access to struct proc->p_pid field. The problem is the structure is defined in XNU sources only, so I faced incomplete definition of type 'struct proc' error during compilation.

From my point of view, to include XNU headers into my own project is a bad smelling solution, but what is the alternative way? Is it to copy and to paste the structure into my own code?

1 Answers1

5

You're supposed to use proc_pid(proc_t) for this. The structure is meant to be opaque as, if it gets changed between kernel revisions, your code could be accessing the incorrect offset.

I would only include the definitions for structures if I'm doing something nefarious, otherwise I'd go looking for a functional interface.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • Unfortunately I can't use `proc_pid()` as I already have pointer to proc inside `mac_rex_policy_gettask` handler (it's TrustedBSD framework), also I do not need current PID, I need provided PID. – Alexander Stavonin Jul 07 '13 at 18:33
  • 1
    `proc_pid` takes a `proc_t` as the parameter i.e. you can use the pointer that you already have - apologies if the answer was a little bit ambiguous. I'll add the proc_t parameter to function text name. (`typedef struct proc * proc_t` in kernel_types.h) – Anya Shenanigans Jul 07 '13 at 18:44