I have already submitted this question on StackOverflow but I figured that this may be a more appropriate location.

I'm building a custom kernel for Mac OS (Mountain Lion, Darwin 2050.22.13). I can build the kernel just fine and I can add stuff to it but I'm missing something.

To keep things short, here is a sample of what I'm trying to do.

Let's say that I want to add a function [my_func(void*)] to say, bsd/kern/kern_fork.c I can add an include file and stick it into osfmk/bsd and change the Makefile so that the new .h file is now copied to BUILD/obj/RELEASE_X86_64/EXPORT_HDRS/

I also added the function name to config/BSDKernel.exports. I can see the function with its symbol in /mach_kernel so it would appear to be fine.

Now, here's the tricky part. It's not tricky per se but I can't figure it out. What I want to do is to be able to make a call to my function from a kext that I am also writing. Basically it would be some sort of private API for me.

My kext compiles fine but when I run kextload/kextutil it complains that it can't find the my_func symbol.

(kernel) kxld[com.blah.foo.kext]: The following symbols are unresolved by this kext (kernel) kxld[com.blah.foo.kext]: _my_func

kextlibs returns: For all architectures: com.apple.kpi.libkern = 12.3

for x86_64: 1 symbol not found in any library kext

So the question is how do I do to make my function(s) visible to my kext(s)? Thanks!

Update: I agree that this was the wrong spot to post the question but I must say that I didn't know any better. Anyway, just in case people here would be interested in my finding, here's the answer to the question (I got some help from another member of SE):

Took some effort but it seems to be good now.

The OSBundleLibraries now looks like this:


The GCC command looks like this:

cc -m64 -Xlinker -kext -static -c foo.c -o Contents/MacOS/foo -fno-builtin -nostdlib -lkmod -r -mlong-branch -I/System/Library/Frameworks/Kernel.Framework/Headers -Wall

In config/BSDKernel.exports: _my_func

In osfmk/bsd, I have bdsfoo.h [which has an extern int my_func(void) ]

To build the kernel:


Once mach_kernel is copied to /

cp BUILD/obj/RELEASE_X86_64/BSDKernel.symbolset /System/Library/Extensions/System.kext/PlugIns/BSDKernel.kext/BSDKernel

This was the missing link, thanks again to pmjordan

reboot. Build my kext and kextload, success!

  • Questions like this are definitively better suited for StackOverflow than AD – nohillside Jul 18 '13 at 4:48
  • Fair enough. I wasn't sure about it so I figured that I'd post it here. My bad. – E.T Jul 18 '13 at 6:33

You must log in to answer this question.

Browse other questions tagged .