kxld not able to resolve symbol vm_kernel_unslide_or_perm_external

Hi,

I am using function vm_kernel_unslide_or_perm_external declared in "vm/vm_kern.h" in my kernel extension.

It is in exported KPI list at /System/Library/Frameworks/Kernel.framework//Resources/SupportedKPIs-all-archs.txt

exported by dependency com.apple.kpi.mach

I have added com.apple.kpi.mach in my Kext's dependency list.

I am able use other symbols from com.apple.kpi.mach e.g. current_thread


While loading my kext I get following error

$ sudo kextutil -tcnv test.kext
Defaulting to kernel file '/System/Library/Kernels/kernel'
kxld[com.test.test]: The following symbols are unresolved for this kext:
kxld[com.test.test]: vm_kernel_addrperm_external(unsigned long, unsigned long*)
Link failed (error code 5).
Check library declarations for your kext with kextlibs(8).


Running kextlibs shows following error


$ sudo kextlibs test.kext
For all architectures:
    com.apple.kpi.bsd = 16.7
    com.apple.kpi.iokit = 16.7
    com.apple.kpi.libkern = 16.7
    com.apple.kpi.mach = 16.7
For x86_64:
    1 symbol not found in any library kext.



It the function vm_kernel_unslide_or_perm_external not a supported KPI anymore?


I am testing on macOS 10.12.6.

Accepted Reply

kxld[com.test.test]: vm_kernel_addrperm_external(unsigned long, unsigned long*)

This is a vital clue. Note how the error message includes the type information. This shouldn’t be the case for a plain C API like this one. I believe that the prototype in the headers is missing the

extern "C"
, and thus the function name gets mangled, and thus don’t find the plain C export.

In my experience you can work around problems like this by adding your own prototype with the correct

extern "C"
.

Once you’ve confirmed this please do file a bug about the headers. They are supposed to be annotated properly by default. I’d also appreciate you posting your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

kxld[com.test.test]: vm_kernel_addrperm_external(unsigned long, unsigned long*)

This is a vital clue. Note how the error message includes the type information. This shouldn’t be the case for a plain C API like this one. I believe that the prototype in the headers is missing the

extern "C"
, and thus the function name gets mangled, and thus don’t find the plain C export.

In my experience you can work around problems like this by adding your own prototype with the correct

extern "C"
.

Once you’ve confirmed this please do file a bug about the headers. They are supposed to be annotated properly by default. I’d also appreciate you posting your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks eskimo.

Adding an extern "C" declaration resolved the issue. I did not realize this looking at the full symbol, thanks for pointing it out.


Created a bug #39275593 for the same.