mac的内核_Mac编程

mac的内核_Mac编程MAC内核编程指南-综述等


Jetbrains全系列IDE稳定放心使用

综述
为什么想起写这个类似于读书笔记的翻译呢,主要是MAC内核开发的资料基本都是en文的,中文的几乎没有(反正我没找到,你要有麻烦给一个,不甚感谢),而读en的资料对初学者来说又比较费时间,所以时间够的话我会把觉得重要的东西记下来,以飨读者。
一、Why You Should Avoid Programming in the Kernel
  一个内核bug可能导致整个系统Crash,所以应尽可能避免内核编程,而选择在用户空间编码。
二、The Early Boot Process
  和普通PC的BIOS类似,苹果机使用Boot ROM来引导和加载系统,大体流程如下:
Boot ROM
When the power to a Macintosh computer is turned on, the BootROM firmware is activated. BootROM (which is part of the computer’s hardware) has two primary responsibilities: it initializes system hardware and it selects an operating system to run. BootROM has two components to help it carry out these functions:
    •    POST (Power-On Self Test) initializes some hardware interfaces and verifies that sufficient memory is available and in a good state.
    •    EFI does basic hardware initialization and selects which operating system to use.
If multiple installations of Mac OS X are available, BootROM chooses the one that was last selected by the Startup Disk System Preference. The user can override this choice by holding down the Option key while the computer boots, which causes EFI to display a screen for choosing the boot volume.

The Boot Loader
Once BootROM is finished and a Mac OS X partition has been selected, control passes to the boot.efi boot loader. The principal job of this boot loader is to load the kernel environment. As it does this, the boot loader draws the “booting” image on the screen.
If full-disk encryption is enabled, the boot loader is responsible for drawing the login UI and prompting for the user’s password, which needed to access the encrypted disk to boot from it. (This UI is drawn by loginwindow otherwise.)
In the simplest case, the boot loader can be found in the /System/Library/CoreServices directory on the root partition, in a file named boot.efi .
Note:  Booting from a UFS volume is deprecated as of Mac OS X v10.5.
In order to speed up boot time, the boot loader uses several caches. The contents and location of these caches varies between versions of Mac OS X, but knowing some details about the caching may be helpful when debugging kernel extensions.
After you install or modify a kernel extension, touch the /System/Library/Extensions directory; the system rebuilds the caches automatically.
Important:  You should not depend on the implementation details of the kernel caches in your software.
In Mac OS X v10.7, the boot loader looks for the unified prelinked kernel. This cache contains all kernel extensions that may be needed to boot a Mac with any hardware configuration, with the extensions already linked against the kernel. It is located at /System/Library/Caches/com.apple.kext.caches/Startup/kernelcache .
In Mac OS X v10.6 and earlier, the boot loader first looks for the prelinked kernel (also called the kernel cache). This cache contains exactly the set of kernel extensions that were needed during the previous system startup, already linked against the kernel. If the prelinked kernel is missing or unusable (for example, because a hardware configuration has changed), the booter looks for the mkext cache, which contains all kernel extensions that may be needed to boot the system. Using the mkext cache is much slower because the linker must be run. On Mac OS X v10.5 and v10.6, these caches are located in /System/Library/Caches/com.apple.kext.caches/Startup/ ; on previous versions of Mac OS X, it was located at /System/Library/Caches/com.apple.kernelcaches/ .
Finally, if the caches cannot be used, the boot loader searches /System/Library/Extensions for drivers and other kernel extensions whose OSBundleRequired property is set to a value appropriate to the type of boot (for example, local or network boot). This process is very slow, because the Info.plist file of every kernel extension must be parsed, and then the linker must be run.
For more information on how drivers are loaded, see I/O Kit Fundamentals , the manual page for kextcache , and Kernel Extension Programming Topics .

Rooting
Once the kernel and all drivers necessary for booting are loaded, the boot loader starts the kernel’s initialization procedure. At this point, enough drivers are loaded for the kernel to find the root device.
The kernel initializes the Mach and BSD data structures and then initializes the I/O Kit . The I/O Kit links the loaded drivers into the kernel, using the device tree to determine which drivers to link. Once the kernel finds the root device, it roots(*) BSD off of it.
Note:  As a terminology aside, the term “boot” was historically reserved for loading a bootstrap loader and kernel off of a disk or partition. In more recent years, the usage has evolved to allow a second meaning: the entire process from initial bootstrap until the OS is generally usable by an end user. In this case, the term is used according to the former meaning.
As used here, the term “root” refers to mounting a partition as the root, or top-level, filesystem. Thus, while the OS boots off of the root partition, the kernel roots the OS off of the partition before executing startup scripts from it.
Boot≠Root is a technology that allows the system to boot from a partition other than the root partition. This is used to boot systems where the root partition is encrypted using full-disk encryption, or where the root partition is located on a device which requires additional drivers (such as a RAID array). Boot≠Root uses a helper partition to store the files needed to boot, such as the kernel cache. For more information on how to set up the property in a filter-scheme driver, see “Developing a Filter Scheme” in Mass Storage Device Driver Programming Guide .
三、参考资料
Information on the Web
Apple maintains several websites where developers can go for general and technical information on Mac OS X.
    •    Apple Developer Connection: Developer Documentation (http://developer.apple.com/documentation/ ). Features the same documentation that is installed on Mac OS X, except that often the documentation is more up-to-date. Also includes legacy documentation.
    •    Apple Developer Connection: Mac OS X (http://developer.apple.com/devcenter/macosx/ ). Offers SDKs, release notes, product notes and news, and other resources and information related to Mac OS X.
    •    AppleCare Tech Info Library (http://www.apple.com/support/ ). Contains technical articles, tutorials, FAQs, technical notes, and other information.
Next

原书地址:http://developer.apple.com/library/mac/#documentation/Darwin/Conceptual/KernelProgramming/About/About.htm

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/184550.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • ODT入门_odt是什么

    ODT入门_odt是什么操作关键:推平一段区间cf896c题意:操作分四种,区间加上一个数、区间赋值、求区间第k小、求区间幂次和将序列中连续的相同的元素整合、用一个三元组(L,R,val)来表示set维护定义内部类:structnode{intl,r;//区间的左端点、右端点mutableLLv;//数值node(intL,intR=-1,LLV=…

    2022年9月9日
  • js页面刷新或关闭时弹框消失_js刷新页面如何保留页面内容

    js页面刷新或关闭时弹框消失_js刷新页面如何保留页面内容onbeforeunload事件属性  定义:在即将离开当前页面(刷新或关闭)时执行JavaScript,例如:<script>window.onbeforeunload=function(e){e.returnValue=(“确定离开当前页面吗?”);}</script>  用法:onbeforeunload事件在…

    2022年10月28日
  • scratch文字朗读没有声音怎么办_pocketfiles怎样解密

    scratch文字朗读没有声音怎么办_pocketfiles怎样解密问题说明今天在使用pocketsphinx_continuous识别中文wav文件是,报如下错误:&gt;pocketsphinx_continuous-hmmzh_broadcastnews_ptm256_8000-lmzh_broadcastnews_64000_utf8.DMP-dictzh_broadcastnews_utf8.dic-infilemyfile…

    2022年10月10日
  • mysql慢查询日志默认在哪里_MySQL 慢查询日志[通俗易懂]

    mysql慢查询日志默认在哪里_MySQL 慢查询日志[通俗易懂]慢查询日志概念MySQL的慢查询日志是MySQL提供的一种日志记录,它用来记录在MySQL中查询响应时间超过阈值的语句,具体指响应时间超过long_query_time值的SQL,会被记录到慢查询日志。long_query_time的默认值是10s,意思是查询响应时间超过10s的SQL语句。默认情况下,MySQL是不开启慢查询日志的,需要我们手动设置这个参数值,当然,如果…

    2022年10月14日
  • chmod 755 与chmod +x的区别

    chmod 755 与chmod +x的区别在写linuxshell脚本时,经常使用chmod755example.sh或chmod+xexample.sh来将文本文件转变为可执行文件。那么这个指令就行对文件做了什么事情?这两个指令之间又有什么区别呢?chmod是“changemode”的意思,用于改变Linux文件代表不同用户对此文件权限的一串flag。组成如下:chmod755的含义是将此文件的permissionflags改为111(7)101(5)101(5)也就是。因此我们也可以说chmod755的作用

    2022年7月16日
  • CreateFileMapping用法

    CreateFileMapping的MSDN翻译和使用心得 测试创建和打开文件映射的时候老是得到”句柄无效”的错误,仔细看了MSDN以后才发觉是函数认识不透,这里把相关的解释翻译出来HANDLECreateFileMapping( HANDLEhFile,                      //物理文件句柄 LPSECURITY_ATTRIBUTESl

    2022年4月6日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号