sysctl errors with 64-bit kernel
sysctl errors with 64-bit kernel
- Subject: sysctl errors with 64-bit kernel
- From: Thomás Inskip <email@hidden>
- Date: Wed, 15 Jul 2009 12:50:17 -0400
Hello.
I have have a project that relies on the Darwin kernel's trace
facility. It was originally built against the 792.18.15 kernel
sources, and has worked until now. Well, it still works, as long as
the kernel is running in 32-bit mode. The following code is failing
in the second sysctl (KERN_KDTHRMAP) call:
int mib[6], err;
size_t needed;
kbufinfo_t bufInfo;
kd_threadmap *threadMap = NULL;
// get number of threads
needed = sizeof (kbufinfo_t);
mib[0] = CTL_KERN;
mib[1] = KERN_KDEBUG;
mib[2] = KERN_KDGETBUF;
mib[3] = 0;
mib[4] = 0;
mib[5] = 0;
if ((err = sysctl(mib, 3, &bufInfo, &needed, 0, 0)) < 0) {
fprintf(stderr, "KERN_KDGETBUF sysctl error %d\n", err);
return;
}
// get thread info
needed = bufInfo.nkdthreads * sizeof(kd_threadmap);
threadMap = (kd_threadmap *)malloc(needed);
if (threadMap == NULL) {
fprintf(stderr, "thread map malloc error\n");
return;
}
mib[0] = CTL_KERN;
mib[1] = KERN_KDEBUG;
mib[2] = KERN_KDTHRMAP;
mib[3] = 0;
mib[4] = 0;
mib[5] = 0;
if ((err = sysctl(mib, 3, threadMap, &needed, NULL, 0)) < 0)
{
fprintf(stderr, "KERN_KDTHRMAP sysctl error %d\n", err);
return;
}
The error reported is EINVAL (invalid argument). This only fails when
the kernel is running in 64 bit mode. The value in bufInfo.nkdthreads
from the first sysctl call appears sane (around 400).
I next tried rebuilding the project as a 64-bit binary, and using the
latest available (afaik) kernel sources (1228.12.14), and that didn't
resolve the problem. As a last thing to try I built fs_usage
(system_cmds-433.8), which also uses kernel trace, and it fails in the
same fashion, even though the one supplied by Apple in the latest SL
build works. This leaves me thinking that either (1) I am missing
some build option, or more likely (2) I need a new set of kernel
sources, which afaik are not yet available for public consumption.
Anyone run into a similar situation, or know what the problem might
be? Any help with this would be greatly appreciated.
Thanks,
Thomás.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden