Re: KEXT resolving problem
Re: KEXT resolving problem
- Subject: Re: KEXT resolving problem
- From: Anton Altaparmakov <email@hidden>
- Date: Wed, 17 Jun 2009 14:54:37 +0100
Hi,
What makes you think that you can call the functions "host_info()" and
"host_self()" from a kernel extension?
The reason this is not working is because those functions cannot be
called by kexts as they are not exported by the kernel.
Whenever you are wondering whether a function is exported (and thus
can be called form a kext) you need to look at the kernel source code
in directory config (i.e. "xnu/config/") and grep in there for the
function. So for example to check if host_self is exported you would
do:
grep host_self /path/to/kernel/sources/xnu/config/*
This returns nothing thus the function is not exported. If you grep
for an exported function, e.g. OSFree:
grep OSFree /path/to/kernel/sources/xnu/config/*
You get a result back like this one:
Libkern.exports:_OSFree
Thus you need to include the com.apple.kpi.libkern OS bundle library
in the Info.plist of your kext to get access to the OSFree() function.
Best regards,
Anton
On 17 Jun 2009, at 14:28, Andrea Di Pasquale wrote:
Hi guys!
I'm writing my first KEXT. When i launch it, i've this problem:
Manson:tmp spikey$ sudo kextload -vt host_info.kext
kextload: resolving dependencies for kernel extensions with
validation and authentication failures
kextload: extension host_info.kext appears to be loadable
kextload: loading extension host_info.kext
kextload: sending 1 personality to the kernel
kld(): Undefined symbols:
_host_info
_host_self
kextload: kld_load_from_memory() failed for module /private/tmp/
host_info.kext/Contents/MacOS/host_info
kextload: a link/load error occured for kernel extension
host_info.kext
link/load failed for extension host_info.kext
(run kextload with -t for diagnostic output)
The code is:
#include <sys/systm.h>
#include <mach/mach_types.h>
#include <mach/mach_host.h>
#include <mach/host_info.h>
#include <kern/kern_types.h>
#include <kern/host.h>
kern_return_t
host_info_start(kmod_info_t *ki, void *d)
{
host_basic_info_t info;
mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
kern_return_t ret;
printf("KEXT has loaded!\n");
ret = host_info(host_self(), HOST_BASIC_INFO, (host_info_t) info,
&count);
if (ret == KERN_FAILURE)
printf("KEXT host_info() error!\n");
printf("CPU Stat:\n");
printf("=========\n");
printf("- Max CPUs: %d\n", info->max_cpus);
printf("- Avaible CPUs: %d\n", info->avail_cpus);
printf("- Max Physical CPUs\n", info->physical_cpu_max);
printf("- Physical CPUs: %d\n", info->physical_cpu);
printf("- Max Logical CPUs: %d\n", info->logical_cpu_max);
printf("- Logical CPUs: %d\n", info->logical_cpu);
return (ret);
}
kern_return_t
host_info_stop(kmod_info_t *ki, void *d)
{
printf("KEXT will be unloaded\n");
return (KERN_SUCCESS);
}
Can you help me, please?
Best regards,
-- Andrea
_______________________________________________
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
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer, http://www.linux-ntfs.org/
_______________________________________________
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