proc_t or sysctl from a KEXT

Questions and Answers about all things *OS (macOS, iOS, tvOS, watchOS)

proc_t or sysctl from a KEXT

Postby Emmanuel » Wed Jul 24, 2013 5:26 am

I need to do some processing where I would get either a proc_t or just a pid.
If I go the pid route, I would do a sysctl() of sorts.

Unfortunately, I can't do either. proc_t is undefined and sysctl() isn't either. sysctlbyname() can be called but kinfo_proc isn't defined.
I'm assuming that sysctl() is there to be used in user mode but is there any way I can use proc_t?
I tried to use the XNU/osfmk/bsd include dir but then it won't compile because of redefinitions and other errors.
It's a little disconcerting and I'm still trying to wrap my head around what I can and cannot do.

Any suggestion?
Emmanuel
 
Posts: 7
Joined: Thu Jul 18, 2013 4:41 pm

Re: proc_t or sysctl from a KEXT

Postby morpheus » Thu Jul 25, 2013 12:01 pm

Hello Emmanuel,

proc_t is an opaque structure. It is a struct proc * in kernel_types.h, but struct proc itself is left opaque (actually defined in bsd/sys/proc_internal.h, q.v. page 504 in book), as you are not supposed to rely on its members; rather - you are meant to use accessors (e.g. proc_pid, or basically anything in the publicly visible proc.h). That aside, you can define it yourself, if you really need to (i.e. kernel hacking), by extracting from proc_internal.

J
morpheus
Site Admin
 
Posts: 532
Joined: Thu Apr 11, 2013 6:24 pm

Re: proc_t or sysctl from a KEXT

Postby Emmanuel » Mon Jul 29, 2013 8:18 pm

Cool! That helped a lot.
I ended up using those and for now that's all that I need.
I don't need much info for the time being. I was trying to get info from the internal structure but it doesn't has much advantage over the few functions in proc.h
Emmanuel
 
Posts: 7
Joined: Thu Jul 18, 2013 4:41 pm


Return to Questions and Answers

Who is online

Users browsing this forum: No registered users and 1 guest