如何获取 kext 中的 OS X 版本号?
我有一个 kext 需要知道它运行的 OS X 版本。 CocoaDev 有一篇文章 描述了如何使用 Gestalt() 获取 OS X 版本信息,但代码需要Cocoa。
我可以从 kext 调用 Gestalt() 吗?
如果是这样,我应该使用什么#include 来定义它?
如果没有,还有其他解决方案吗?
背景:
我想在从 10.4 到 10.7 的所有版本的 OS X 上使用相同的 kext。
但是: kext 调用 cdevsw_add
,在 Lion 中以非向后兼容的方式进行了更改。随着(显然)对调用它的某些内核程序的更改,这些更改意味着 - 根据例程之前的注释 - 在 10.7 上应该使用与 OS X 10.0 上不同的第一个参数来调用 cdevsw_add
10.6。 (Lion 上为 -12,早期版本为 -1。)
如果 kext 可以确定它们正在运行的 OS X 版本,那就很容易了。 (如果没有,这将是一件痛苦的事情 - 也许是一个可怕的混乱,比如构建两个不同版本的 kext 并让 kext 加载代码选择加载哪个版本。)
I have a kext that needs to know what version of OS X it is running on. CocoaDev has an article which describes how to get the OS X version info using Gestalt(), but the code requires Cocoa.
Can I call Gestalt() from a kext?
If so, what #include do I use to define it?
If not, are there any other solutions?
Background:
I'd like to use the same kexts in on all versions of OS X from 10.4 through 10.7.
BUT: The kexts call cdevsw_add
, which was changed in Lion in a non-backward-compatible way. Along with (apparently) changes to some kernel programs that call it, the changes mean — per the comment before the routine — that cdevsw_add
should be called with a different first argument on 10.7 than on OS X 10.0 through 10.6. (-12 on Lion, -1 on earlier versions.)
If the kexts can determine which version of OS X they are running on, it's easy. (If not, it will be a pain to do — maybe a horrible kludge like building two different versions of the kexts and having the kext-loading code pick which one to load.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Kernel.framework提供。声明了一些外部变量,如 version_major、version_minor 等。据我所知,这些变量是从 libkern.kpi 导出的。
希望有帮助。
Kernel.framework provides <libkern/version.h>. There are declared some extern variables like version_major, version_minor etc. AFAIK those are exported from the libkern.kpi.
Hope it helps.
您可以使用
sysctl
获取内核版本(向下滚动到方法3)。据称,当您开发内核模块时它会起作用。这是该方法的示例,以防网站出现故障。
当然,您需要弄清楚 Snow Leopard 和 Lion 的内核版本,但这应该不是很困难。 (我可以证明当前 Lion 版本的内核版本是
11.0.0
。)You can use
sysctl
to get the kernel version (scroll down to method 3). It allegedly works when you develop kernel modules.Here's an example of the method, in case the site ever goes down.
Of course, you'll need to figure out the kernel versions of Snow Leopard and Lion, but that shouldn't be very hard. (I can testify that the kernel version of the current Lion release is
11.0.0
.)