URGENT/11 白皮书笔记——远程危害VxWorks的关键漏洞6.9.3及以上

Introduction

Armis 研究人员在 VxWorks 中发现了 11 个零日漏洞,VxWorks 是最流行的实时操作系统 (RTOS),被超过 20 亿台设备使用,包括工业、医疗和企业设备等关键任务设备。把这些漏洞称为 URGENT/11,这些漏洞位于 IPnet、TCP/IP 堆栈中,影响了过去13年的版本,并且是已发现的影响操作系统的漏洞的罕见示例。在其 32 年的历史中,MITRE 仅仅列出了 13 个影响 VxWorks 的 CVE,其中没有一个漏洞像 URGENT/11 那样严重影响核心网络堆栈。
近年来,在广泛使用的 TCP/IP 堆栈实现中的漏洞变得十分罕见,尤其是那些可以在目标设备上执行远程代码的漏洞。这种类型的漏洞是攻击者的圣杯,因为他们不依赖于构建在易受攻击的堆栈之上的特定应用程序,而是只需要攻击者对目标设备具有网络访问权限,这使得它们本质上可以被用来远程利用。当在 TCP 实现中发现这类漏洞的时候,它们甚至可以被用来绕过防火墙或者 NAT 解决方案,因为它们隐藏在看起来无辜的 TCP 流量中。
发现的11个漏洞中包括6个可能导致远程代码执行的严重漏洞:

  1. IPv4 数据包中 IP 选项解析过程中的堆栈溢出(CVE-2019-12256)
  2. TCP 紧急指针 = 0 导致整数下溢(CVE-2019-12255)
  3. 由格式错误的 TCP AO 选项造成的TCP 紧急指针状态混乱(CVE-2019-12260)
  4. 在连接到远程主机期间 TCP 紧急指针状态混乱(CVE-2019-12261)
  5. 由竞争条件引起的 TCP 紧急指针状态混乱(CVE-2019-12263)
  6. ipdhcpc 中的DHCP Offer /ACK 解析中的堆溢出(CVE-2019-12257)

以及还有5个可能导致拒绝服务、逻辑错误或者信息泄露的漏洞

  1. 通过格式错误的 TCP 选项进行 TCP 连接 DOS(CVE-2019-12258)
  2. 处理未经请求的反向 ARP 回复(逻辑缺陷)(CVE-2019-12262)
  3. ipdhcpc DHCP 客户端分配 IPv4 的逻辑缺陷(CVE-2019-12264)
  4. 在 IGMP 解析中通过NULL引用来进行DOS(CVE-2019-12259)
  5. 通过 IGMPv3 特定成员报告泄露 IGMP 信息(CVE-2019-12265)

本文档将详细介绍各种深奥的且被人有些遗忘的 TCP/IP 机制,这些机制已经被发现包含有网络堆栈实现过程中的漏洞,以及这些漏洞本身。白皮书还将展示这些漏洞产生的严重后果,漏洞将影响很多设备。
有关 URGENT/11 的更多信息,请访问 https://armis.com/urgent11

Armis Labs 是 Armis 的研究团队,专注于混合和拆分构成我们周围物联网设备的原子——无论是智能个人助理、外观良好的打印机、SCADA 控制器还是医院床边等生命支持设备例如一个病人监护仪。
之前的研究包括:

  • 通过蓝牙堆栈中的 RCE 漏洞针对设备的攻击向量
  • 德州仪器 BLE 芯片中的两个芯片级漏洞,嵌入在企业级接入点中。

为什么要研究 RTOS 网络堆栈?
就原始数据而言,据我们所知,运行在 RTOS 上的嵌入式微控制器和 CPU 的数量远远大于运行在成熟操作系统上的 CPU 或设备的数量。在当今世界,这些嵌入式产品和组件越来越多地连接到 LAN,甚至直接连接到 Internet。此外,构成我们基础架构的关键设备可能至少具有使用着 RTOS 的某些组件。因此,在流行着的 RTOS 中的严重漏洞的影响是巨大的而且迄今为止还没有得到人们很好的理解。
最重要的是,这些 RTOS 的代码库通常是封闭源代码的,并且在大多数情况下,对它们的安全研究很少。

执行摘要
URGENT/11 是一组 11 个被发现影响 IPnet、VxWorks 的 TCP/IP 堆栈的漏洞。其中六个漏洞被归类为严重漏洞并可以启用远程代码执行 (RCE)的漏洞。其余漏洞被归类为拒绝服务、信息泄漏或逻辑缺陷等漏洞。由于每个漏洞影响网络堆栈的不同部分,所以它们会影响一组不同的 VxWorks 版本。作为一个整体,URGENT/11 影响 VxWorks 的 6.5 及更高版本,每个版本都至少有一个 RCE 漏洞影响。过去 13 年中有很多受影响的版本,这种情况在网络领域是罕见的,是 VxWorks 在研究界相对默默无闻的结果。这个时间跨度或许会更长,根据 Wind River 的说法,当 2006 年从 Interpeak 收购 IPnet 时,其中的三个漏洞已经存在。
URGENT/11 支持三种攻击场景,具体取决于设备在网络上的位置和攻击者的位置。
第一种攻击场景影响驻留在网络边界的任何受影响的 VxWorks 设备,并这些设备直接暴露于互联网,例如防火墙、调制解调器、路由器。攻击者可以直接从 Internet 攻击此类设备,破坏它们并随后破坏它们所保护的网络。
第二种攻击场景会影响驻留在边界后方、内部网络内的任何受影响的 VxWorks 设备,这些设备通过防火墙或 NAT 解决方案连接到 Internet。URGENT/11 可以允许攻击者接管这些设备,通过拦截它们创建的到 Internet 的 TCP 连接,和操纵防火墙或 NAT 解决方案发回的数据包中的 TCP 报头的某些字段。这是由于漏洞在TCP报头的解析和处理中处于唯一的低级位置。
在最后一种情况下,由于先前的攻击而已经位于网络中的攻击者可以发送特制的广播 IP 数据包,该数据包将立即攻击本地 LAN 中所有易受攻击的 VxWorks 设备。这是由于在解析和处理 IP 标头时发现的一个非常独特的漏洞,甚至在广播过程中也会触发该漏洞。该漏洞也是一个可以导致远程接管的 RCE 漏洞。

基础工作准备
过去的研究
TCP/IP 堆栈的各个层中的实现漏洞在过去相对常见。不出所料,1990 年的软件和操作系统在其网络堆栈中存在各种 DoS 和 RCE 错误。当时,连接互联网的 PC 才刚刚开始流行,因此即使是微不足道的错误按照今天的标准来说也是可以预料的。然而,多年来,网络堆栈受到了合理的审查与考验,如今此类漏洞已经极为罕见。
在这项研究中,我们研究了 TCP/IP 协议栈的一种更现代、最新的实现。有趣的是,我们在现代 RTOS 中发现的错误与古老的与之相近的错误遭受着相同的陷阱。
例如,1997 年开始广为人知并随后被广泛利用的 WinNuke 漏洞是 Windows 95 和 NT 中的远程 DoS 漏洞。只需将单个 TCP 带外段(设置了 URG 标志)发送到 Windows 机器,即可触发该漏洞,从而导致 BSOD错误。
这与本文中介绍的 CVE-2019-12255(TCP 紧急指针 = 0 导致整数下溢)非常相似。然而,在我们的情况下,该漏洞被归类为 RCE(内存损坏)。
另一个古老的 TCP/IP 实现错误的例子是 Ping Of Death,这是一种 DoS 攻击,当时影响了许多不同的操作系统——包括 Windows、Linux、Mac 和 Unix。这个简单攻击是通过发送带有64KB数据(IP 分段数据包中可能的最大有效负载)的有效负载的 ICMP 回显请求(ping)生效的。早在 1997 年,这就是远程使各种操作系统崩溃所需要的一切。
令人惊讶的是,远程触发 TCP/IP 错误的现代示例仍然可以在最广泛使用的操作系统中找到,尽管这种情况十分罕见。例如,CVE-2019-0547 就是一个 Windows 10 DHCP 客户端中的 RCE型漏洞。这个错误可以由格式错误的 DHCP 选项触发,这很像本文档中介绍的 CVE-2019-12257 (ipdhcpc 内的 DHCP Offer/ACK 解析过程中的堆溢出)。
另一个例子是 Apple 的从 2018 年开始影响所有 Apple 设备和操作系统的堆溢出错误,即 CVE-2018-4407。这是 ICMP 错误数据包构造过程中的一个错误,该错误数据包是为了响应具有特殊手动定制 IP 选项的格式错误的 IPv4 数据包而发送的。这也与我们的 CVE-2019-12256(IPv4 数据包 IP 选项解析中的堆栈溢出)非常相似,在我们的例子中是一个 RCE 漏洞。
最近对 AWS FreeRTOS 上(Amazon 为物联网设备的 RTOS) TCP/IP 实现的研究也导致了许多 RCE 错误(CVE-2018-16522 到 CVE-2018-16528)的发现。

研究 VxWorks
VxWorks 不是开源产品。最初创作 VxWorks 的公司 Wind River 仍在对其进行更新和销售。当他们的客户购买许可证以将 VxWorks RTOS 嵌入到他们的产品中时,他们通常会收到 Wind River Workbench IDE。此 IDE 附带 VxWorks 源代码和各种硬件板级支持包 (BSP)。
过去,我们可以直接从他们的网站上获取在 VMWare 上可使用的工作 BSP 映像文件,如本文所述。如今,在联系他们的销售团队后,仍然可以获得类似的评估产品,但是这种方法对安全研究人员可能没有用。虽然合法地获取用于研究目的的源代码很困难,但二进制分析在这种对 VxWorks 研究的情况下是有效的。有大量运行着最新版本的 VxWorks 的现实产品可供购买,并且它们的固件通常可以免费在线下载。由于 workbench 自然生成二进制文件的性质,这些固件通常附带有包含完整调试符号的 ELF 文件,这就使得它们易于使用现代工具进行反编译,从而获得高质量的结果。

识别 TCP/IP 协议具体实现过程中的弱点
过去在许多不同的操作系统和软件实现中存在的 TCP/IP 漏洞具有共同的弱点。协议规定中的某些地方存在着过多的实现错误。在某些情况下,完全独立的实现中会出现完全相同的错误。在处理发现 VxWorks TCP/IP 堆栈中的安全问题任务时,我们将以下弱点图作为指导。我们发现的大多数错误都不是什么小事,与90年代的错误不同。但是,它们都与 TCP/IP 的以下部分有些相关:

  • IPv4 选项的解析和处理
    • 这些选项的结构可能会变得相当复杂。
    • 许多 IP 选项被认为是高度深奥的,在实践中很少使用,但仍然会由各种堆栈进行解析。
  • TCP 选项的解析和处理
    • 与 IP 选项类似,一些 TCP 选项在现代 Internet 上不再有意义,但大多数仍然会在各种 TCP 堆栈中实现。
    • 例如,MD5 签名选项和相当于其现代的继任者 TCP 身份验证选项 (TCP-AO) 在如今 TLS 为王的世界中几乎没有立足之地。 因此,它们几乎从未被使用过(或测试过)。
  • ICMP 错误数据包
    • 处理 IPv4 数据包时的各种错误情况,以及更高层的 TCP、UDP 和 ICMP 协议,都可能导致 ICMP 错误数据包的发送。
    • 这些错误数据包的结构非常重要,因为它们有时会包含原始坏了的数据包的副本(有时或许已被修改)。此外,某些 IP 选项也会影响它们的处理。
  • TCP 紧急/带外数据 TCP Urgent / out-of-band data
    • 根据 RFC,TCP 支持使用每个 TCP 报文段中存在的 URG 标志和紧急指针字段来发送和接收带外数据。
    • 然而,这个的准确行为定义的很糟糕,可想而知,它的实现也很糟糕(稍后将会详细介绍)。
  • IP 数据报分片
    • IPv4(和v6)支持 IP 层的数据报分段。一个64KB的数据包可以根据底层 MTU 进行分片。
    • 在实践中,这个功能很少被使用,因此分段的 IP 数据报与 IP 层之上的各种协议的组合可以产生很有趣的边缘情况。

发现的六个关键的 RCE 漏洞
如上所述,发现的六个漏洞具有严重的危害性,因为它们是可以造成导致远程代码执行后果的内存损坏型的漏洞。这六个漏洞是在 VxWorks 的TCP/IP 协议栈(IPnet)的三个相互独立的子系统中发现的。

  1. IP 层的一个 RCE 漏洞(CVE-2019-12256)
  2. TCP 层的四个 RCE 漏洞(CVE-2019-12255、CVE-2019-12260、CVE-2019-12261、CVE-2019-12263)
  3. IPnet 的内置 DHCP 客户端 ipdhcpc 中的一个 RCE 漏洞 (CVE-2019-12257)

以下部分将提供与发现这些漏洞的机制有关的一些背景知识,并详细说明漏洞本身。

漏洞:解析 IPv4 数据报的 IP 选项时的堆栈溢出
TL;DR
当向易受攻击的 VxWorks 设备发送一个包含多个源记录路由 (SRR) 选项的格式错误 IP 数据包时,会生成一个 ICMP 错误响应数据包作为响应。SSR 选项将会被复制到响应数据包的 IP 选项中,而没有进行适当的长度验证,这会导致攻击者可以控制堆栈溢出。

背景知识 - ICMP 错误数据包、IP 选项和松散源路由

ICMP error packets
ICMP 错误数据报是作为对在处理 IP 数据报期间出现的错误情况的响应而发送的。它们通常寻址到数据包的源 IP 地址。虽然大多数 ICMP 错误表明网络问题,例如路由循环或无法路由到目标 IP,但有些错误是由于传入数据包(坏的)本身的问题而出现的。例如,参数问题错误是作为有 IP 选项格式错误的 IP 数据包的响应而发送的。
许多这些返回的错误数据包中还将包含触发错误的传入的坏的数据包的副本。这个副本将会包含原始 IP 报头、TCP或UDP报头以及来自数据包有效负载中的一些附加字节。

ICMP 错误数据包的结构
在这里插入图片描述
由于在处理格式错误的数据时可能会出现某些边缘情况,一些 TCP/IP 实现无法将这些报头正确地重新组织到 ICMP 错误数据包中。
此类问题的一个示例是2018 年的 Apple 的 XNU 内核堆溢出错误 (CVE-2018-4407)。函数 icmp_error ( bsd/netinet/ip_icmp.c:313 )中存在整数下溢错误。如果坏数据包的 IP 报头+TCP 报头的长度超过84字节,就会触发该错误。回想一下,IP 和 TCP 报头都有一个选项字段,因此它们每个都可以最大长达 60(20+40) 个字节。
一个具有有效的 40 字节长的 TCP 选项字段和无效的 40 字节长的 IP 选项字段的TCP 数据包将会导致一个 ICMP 错误,并触发整数下溢漏洞。这反过来会导致通配符堆溢出。作者对此漏洞进行了分析。
将各种各样的 IP 选项与为响应格式错误的数据包而发送的 ICMP 错误数据包结合使用可能会导致可能会产生错误的边缘情况。但是 IP 选项本身的实际功能是什么?

IP 选项和松散源路由
每个 IPv4 数据包都有一个非强制选项字段,最长可达 40 个字节。这个字段中每个单独的选项都显示为一个 TLV 字段(类型、长度、值),并且所有选项加在一起必须在 40 个字节内。如果在解析这些选项的过程中遇到错误,将会发送一个 ICMP 参数问题数据报。
一些更广为人知的选择有:

  1. **Time Stamp(时间戳)😗*请求转发数据包的每个路由器将其当前时间戳附加到时间戳选项字段中。整个选项的大小由发送人设置。
  2. **Record Route(记录路径) 😗*请求每个路由器将其 IP 地址附加到选项中,从而有效地记录数据包所经过的路由。
  3. **Loose Source Route (LSRR)(松散源路由 )😗*指示路由器通过给定的 IP 列表路由数据包,并将使用过的路由记录在该选项中。只要数据包还在通过列表中的每个 IP 路由,就可以采用更长的路由。
  4. **Strict Source Route (SSRR) (严格源路由)😗*与上面相同,但必须采取给定的路由路径。
  5. **Traceroute (跟踪路由)😗*请求每个路由器都向源 IP 发送一个 ICMP 跟踪路由数据包。
  6. **Router Alert (路由器警报)😗*警告路由器数据包在到达目的地的途中可能需要途中的路由器进行更广泛的处理。

众所周知,上述臭名昭著的 LSRR 和 SSRR 选项会给任何支持它们的路由器带来安全问题,因为它们使得攻击者能够滥用数据包的默认路由路径并在包含它们(LSRR/SSRR)的数据包上强制执行恶意路由。由于这个问题,默认情况下它们几乎被所有路由器所阻止。然而,在大多数 TCP/IP 实现过程中,这些相当复杂的选项在它们被阻止之前仍会先被解析,因此,它们会带来额外的攻击面。

每个 LSRR\SSRR 选项都具有以下结构:
在这里插入图片描述
该选项包含一个 IP 地址列表,数据包应通过这些地址路由(严格或松散)。Pointer(指针)是选项中的偏移量,指向数据包应该通过的下一个 IP 地址,并且它由数据包经过的每个路由器递增。
根据 RFC1122 ,一旦数据包到达其目的地,需要记录下来选项中的 IP 列表并将其向上传递给运输层或 ICMP 消息处理。记录下来的路由将会被反转并用于形成回复数据报的返回源路由,或用于把 ICMP 错误消息发送回发送者的源路由。
该逻辑可以通过以下复制逻辑进行:

  • 所有 IP 地址都以相反的顺序复制,直到(但不包括)Pointer 指向的地址之前的地址。
  • 数据包的源 IP 地址被添加到列表的末尾,而不是未包含的地址。

支持源路由选项的路由器和支持接收包含这些选项的数据包的主机的逻辑都很复杂。因此,此类选项的解析过程也存在潜在的错误。

Wireshark 中的 捕获到的 LSRR 选项示例:
在这里插入图片描述
如 RFC1122 中所述,对一个设备表现为源路由主机的支持在实践中从未获得实现。然而在 VxWorks 中,这种支持由于某种原因而存在,这为以下漏洞引入了攻击面。

漏洞(CVE-2019-12256)
在VxWorks 的 IPnet 堆栈中,IPv4协议在模块ipnet2/src/ipnet_ip4.c 中实现。函数 ipnet_ip4_input 是传入的 IPv4 数据报的函数入口点。这个函数首先会执行数据报报头的基本验证,然后会调用函数 ipnet_dst_cache_get。这将会根据数据包的源地址和目标地址查找处理程序回调。例如,如果目标地址与本地地址相匹配,则会调用 ipnet_ip4_local_rx 处理程序。否则,数据包可能会被转发(路由),或者触发目标不可达条件。
某些错误条件,例如目标不可达将触发一个通过调用函数 ipnet_icmp4_send发送的 ICMP 错误数据包。当由于 IP 选项格式发生错误时,也会调用此函数,并且将会发送一个 ICMP 参数问题包。这可以在解析 IP 选项的多个过程中发生:在函数 ipnet_ip4_multiple_srr_opt_check 中,它用来验证选项字段中仅存在 LSRR 或 SSRR 选项两者中的一个;或者是发生在任意选项解析函数- ipnet_ip4_opt__rx* 中。在函数 ipnet_icmp4_send 内部,构造了一个错误数据包,并且复制了传入数据包(格式错误的包)中的某些选项字段的值到里面。这是由函数 ipnet_icmp4_copyopts 完成的,
上述流程如下图所示:
在这里插入图片描述
如上所示,在解析传入的 IPv4 数据包时,各种代码流可能导致 ICMP 消息发送作为对错误数据包(如格式错误)的响应。函数 ipnet_icmp4_send 将用于发送响应 ICMP 数据包,它会尝试调用函数 ipnet_icmp4_copyopts 将某些 IP 选项从传入数据包中复制到传出数据包中。在至少两个代码流中,传出的 ICMP 数据包将在传入的数据包被完全解析之前发送,无论传入的 IP 选项被完全验证为合法,或者即使它们已经验证失败。这个设计缺陷可能导致此过程中的 ipnet_icmp4_send 上下文中的堆栈溢出。
此漏洞自 VxWorks 版本 6.9.3 起就存在。
两个不同的流可以导致这个漏洞发生:

  1. 一个发送到目标机的 MAC 地址的数据包,但是目标 IP 地址并不是目标机的单播地址,且无法到达,这将导致调用函数 ipnet_ip4_dst_unreachable
  2. 一个普通的使用其 MAC 和 IP 地址定向到目标机子的单播数据包。 这将发生在 ipnet_ip4_multiple_srr_opt_check 函数中。

第一个流发生在函数 ipnet_ip4_input 中,发生在根据函数 ipnet_dst_cache_new 的返回值判断知道传入数据包的目标 IP 不可达时,函数 ipnet_dst_cache_new 的返回值是来表明下一步应如何路由数据包的。
来自函数 ipnet_ip4_input 的反编译片段:
在这里插入图片描述
函数 ipnet_ip4_dst_unreachable 将会调用函数 ipnet_icmp4_send 并将原始的数据包附加到 icmp_param 结构体中。在函数 ipnet_icmp4_send 中,传入的错误的数据包中的 IP 选项将会被一个结构体所引用,然后再传递给函数 ipnet_icmp4_copyopts
如下图所示:
在这里插入图片描述在这里插入图片描述
默认情况下,options_to_copy结构会指导函数 options_to_copy将 SSRR 和 LSRR 选项从失败的数据包复制到输出数据包。当失败的数据包没有被验证包含有效的 IP 选项时(如上述流程所述),函数 ipnet_icmp4_copyopts 将会被强制从失败的数据包复制多个 SSRR 或 LSRR 选项到函数 ipnet_icmp4_send 堆栈上分配的 opts 结构上。此外,这些复制的选项可能包含不应该被允许的非法结构。
例如,当发送一个在 IP 选项字段中包含以下字节的 IP 数据包时,将会发生堆栈溢出:
在这里插入图片描述
在这个例子中,在此示例中,IP 选项字段中包含两个 LSRR 选项。这些 LSRR 选项不包含任何路由条目(每个选项长度仅为3字节),并且 SRR-Pointer 字段指向超过选项末尾的位置。如前所述,接收 SRR 选项的主机需要获取所有记录的路由条目,反转它们的顺序,并使用它们来创建一个新的 SRR 选项,该选项将被添加到任何返回的数据包中。
可以在函数 ipnet_icmp4_copyopts 中查看此功能:
在这里插入图片描述
在这里插入图片描述
函数 ipnet_icmp4_copyopts中的代码将使用这些 SRR-Pointer 字段作为SSR 选项中的最终路由条目的偏移量,并将所有到它的路由条目复制到传出数据包选项 opts,opts 是在函数 ipnet_icmp4_send 的堆栈上分配的。输入缓冲区中的每个 LSRR 选项都是 3 字节长,但它会生成一个 43 字节的复制输出选项(3 字节的头部,36 字节的路由条目,4 字节的当前路由的新路由条目)。由于没有验证(在这种情况下)失败的数据包是否包含多个 SSRR\LSRR 选项,所以发送多个这种类型的选项将导致 opts 溢出,opts 是一个分配在堆栈上的 40 字节数组。

如上所述,此漏洞也可以由另一个流触发,当包含上述选项的数据包直接发送到目标设备时,不会导致目标不可达的情况。这是因为当选项在各种 ipnet_opt__r x* 函数解析过程中或者是在函数 ipnet_ip4_multiple_srr_opt_check 解析过程中发生错误的时候,一个 ICMP 错误消息将会作为回应而发送(通过函数 ipnet_ip4_opt_icmp_param_prob )。发生这种情况时,没有被这些验证函数解析的剩余选项仍可能包含非法值,例如上面介绍的多个 SRR 选项,这将导致上述堆栈溢出。由于溢出将包含来自输入数据包中的由攻击者控制的数据,因此此漏洞可能导致在两个流中的远程代码执行。
幸运的是,由于该漏洞依赖于发送带有无效 IP 选项的数据包,因此无法通过 Internet 进行利用。Internet 上遇到这种数据包的第一个路由器将丢弃它。 因此,该漏洞只能被 LAN 上的攻击者所利用。
由于此漏洞是在解析 IP 报头本身的过程中,因此也可以通过在广播数据包中发送带有无效 IP 选项的特制 IP 数据包来触发。这可以允许攻击者同时攻击多个易受攻击的设备。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
PART I: CORE TECHNOLOGIES 1 Overview ...................................................................................................... 3 1.1 Introduction ...................................................................................................................... 3 1.2 Kernel Architecture ......................................................................................................... 3 1.3 Related Documentation Resources .............................................................................. 4 1.4 VxWorks Configuration and Build .............................................................................. 5 2 VxWorks Configuration ............................................................................. 7 2.1 Introduction ...................................................................................................................... 7 2.2 About VxWorks Configuration ................................................................................... 7 2.2.1 Default Configuration and Images ................................................................. 8 2.2.2 Configuration With VxWorks Image Projects ............................................... 8 2.2.3 Configuration With VxWorks Source Build Projects ................................... 8 2.2.4 Configuration and Customization .................................................................. 8 2.2.5 Configuration Tools: Workbench and vxprj .................................................. 9 2.3 VxWorks Image Projects: VIPs .................................................................................... 9 2.3.1 VxWorks Components ...................................................................................... 10 Component Names .......................................................................................... 10 Basic VxWorks Components ............................................................................ 11 2.3.2 Device Driver Selection ................................................................................... 13 2.3.3 Component Bundles and Configuration Profiles ........................................ 14 2.3.4 VxWorks Component Reference .................................................................... 14 2.4 VxWorks Source Build Projects: VSBs ....................................................................... 14 2.4.1 Basic Operating System VSB Options ........................................................... 16 BSP-Specific Optimizations ............................................................................. 16 VxWorks Kernel Programmer's Guide, 6.9 iv Inconsistent Cache Mode Support .................................................................. 17 System Viewer Instrumentation Support ...................................................... 17 Real-Time Process Support .............................................................................. 17 Object Management Support ........................................................................... 17 Error Detection and Reporting Policy Hooks ............................................... 18 Task Switch Hook Support .............................................................................. 18 Task Create Hook Support ............................................................................... 18 CPU Power Management Support ................................................................. 19 Advanced Options ............................................................................................ 19 VxWorks BSP Validation Test Suite Support ................................................. 19 Symmetric Multiprocessor (SMP) Support ................................................... 19 SMP Determinism ............................................................................................. 19 MIPC Support .................................................................................................... 20 WRLOAD Support ............................................................................................ 20 Task-Specific Current Working Directory ...................................................... 20 Device Name Length ........................................................................................ 20 NFS V3 Server Optimization ........................................................................... 20 DOSFS Name Length Compatible .................................................................. 21 2.4.2 VSB Profiles ........................................................................................................ 21 2.4.3 Using VSB Projects to Create VxWorks Systems: Basic Steps .................... 21 2.4.4 Developing Kernel Applications for VSB Systems ..................................... 21 2.5 VxWorks Without Networking ..................................................................................... 22 2.6 Small-Footprint VxWorks Configuration ................................................................... 22 2.6.1 About Small-Footprint VxWorks .................................................................... 22 Kernel Facilities ................................................................................................. 22 Unsupported Facilities ..................................................................................... 23 BSPs ..................................................................................................................... 23 2.6.2 Configuring Small Footprint VxWorks .......................................................... 23 Small-Footprint VSB Profile and Options ...................................................... 24 VSB Options Specific to the Small-Footprint Profile .................................... 24 Small-Footprint VIP Profile and Components .............................................. 25 Optional Components for a Small Footprint VIP Project ............................ 25 2.6.3 Configuration and Build Steps for Small-Footprint VxWorks ................... 25 2.6.4 Writing Applications for Small-Footprint VxWorks .................................... 26 2.6.5 Example Application ........................................................................................ 26 2.6.6 Debugging Small-Footprint VxWorks ............................................................ 28 2.7 VxWorks Image Types ................................................................................................... 28 2.7.1 Default VxWorks Images ................................................................................ 29 2.7.2 VxWorks Images for Development and Production Systems ..................... 29 2.7.3 Boot Parameter Configuration for Standalone VxWorks Images .............. 30 2.8 Image Size Considerations ............................................................................................ 30 2.8.1 Boot Loader and Downloadable Image ......................................................... 30 2.8.2 Self-Booting Image ............................................................................................ 31 Contents v 3 Boot Loader ................................................................................................. 33 3.1 Introduction ...................................................................................................................... 33 3.2 Using a Default Boot Loader ......................................................................................... 34 3.3 Boot Loader Image Types ............................................................................................... 35 3.4 Boot Loader Shell ............................................................................................................ 35 3.4.1 Boot Loader Shell Commands ......................................................................... 36 3.5 Boot Parameters ............................................................................................................... 39 3.5.1 Displaying Current Boot Parameters ............................................................. 40 3.5.2 Description of Boot Parameters ...................................................................... 41 3.5.3 Changing Boot Parameters Interactively ....................................................... 44 3.6 Rebooting VxWorks ........................................................................................................ 45 3.7 Configuring and Building Boot Loaders .................................................................... 46 3.7.1 Boot Loader Profiles .......................................................................................... 46 3.7.2 Boot Loader Components ................................................................................ 47 3.7.3 Configuring Boot Parameters Statically ......................................................... 47 3.7.4 Enabling Networking for Non-Boot Interfaces ............................................. 48 3.7.5 Selecting a Boot Device ..................................................................................... 48 3.7.6 Reconfiguring Boot Loader Memory Layout for 32-Bit VxWorks ............. 50 Redefining the Boot Loader Link Address for Custom Boot Loaders ....... 50 Reconfiguring Memory Layout for a Persistent Memory Region ............. 51 3.7.7 Reconfiguring Boot Loader Memory Layout for 64-Bit VxWorks ............. 53 3.7.8 Building Boot Loaders ...................................................................................... 53 3.8 Installing Boot Loaders .................................................................................................. 53 3.9 Booting From a Network ............................................................................................... 53 3.10 Booting From a Target File System ............................................................................. 55 3.11 Booting From the Host File System Using TSFS ..................................................... 55 4 Kernel Applications .................................................................................... 57 4.1 Introduction ...................................................................................................................... 57 4.2 About Kernel Applications ........................................................................................... 58 4.3 Comparing Kernel Applications with RTP Applications ....................................... 59 4.4 C and C++ Libraries ........................................................................................................ 60 VxWorks Kernel Programmer's Guide, 6.9 vi 4.5 Kernel Application Structure ........................................................................................ 60 4.6 VxWorks Header Files .................................................................................................... 61 4.6.1 VxWorks Header File: vxWorks.h ................................................................... 61 4.6.2 Other VxWorks Header Files ........................................................................... 62 4.6.3 ANSI Header Files ............................................................................................ 62 4.6.4 ANSI C++ Header Files .................................................................................... 62 4.6.5 The -I Compiler Flag ......................................................................................... 62 4.6.6 VxWorks Nested Header Files ........................................................................ 62 4.6.7 VxWorks Private Header Files ........................................................................ 63 4.7 Custom Header Files ....................................................................................................... 63 4.8 Static Instantiation of Kernel Objects ......................................................................... 64 4.8.1 About Static Instantiation of Kernel Objects ................................................. 64 Kernel Objects That can be Instantiated Statically ....................................... 65 Static Instantiation and Code Size .................................................................. 65 Advantages of Static Instantiation .................................................................. 65 Applications and Static Instantiation ............................................................. 66 4.8.2 Scope Of Static Declarations ............................................................................ 66 4.8.3 Caveat With Regard to Macro Use .................................................................. 66 4.8.4 Static Instantiation of Tasks ............................................................................. 66 4.8.5 Static Instantiation Of Semaphores ................................................................ 67 4.8.6 Static Instantiation of Message Queues ......................................................... 68 4.8.7 Static Instantiation of Watchdog Timers ........................................................ 68 4.9 Boot-Time Hook Routine Facility ............................................................................... 69 Boot-Time Hook Routine Stubs and Components ....................................... 69 Using Boot-Time Hook Routine Stubs ........................................................... 70 4.10 Kernel Applications and Kernel Component Requirements ................................. 71 4.11 Building Kernel Application Modules ....................................................................... 71 4.12 Downloading Kernel Application Object Modules to a Target ............................. 72 4.13 Linking Kernel Application Object Modules with VxWorks ................................ 72 4.14 Configuring VxWorks to Run Applications Automatically ................................... 72 5 C++ Development ....................................................................................... 75 5.1 Introduction ...................................................................................................................... 75 5.2 Configuring VxWorks for C++ ..................................................................................... 76 5.3 C++ Header Files ............................................................................................................. 76 Contents vii 5.4 Spawning Tasks That Use C++ ..................................................................................... 76 5.5 Calls Between C and C++ Code .................................................................................... 77 5.6 C++ Compiler Caveats .................................................................................................... 77 5.7 Using C++ in Signal Handlers and ISRs ................................................................... 78 5.8 Downloadable Kernel Modules in C++ ..................................................................... 78 5.9 C++ Compiler Differences ............................................................................................ 78 5.9.1 Template Instantiation ...................................................................................... 78 5.9.2 Run-Time Type Information ............................................................................ 80 5.10 Namespaces ...................................................................................................................... 80 5.11 C++ Exception Handling ................................................................................................ 81 5.12 Standard Template Library (STL) ................................................................................ 81 5.13 C++ Demo Example ........................................................................................................ 81 6 Multitasking ................................................................................................. 83 6.1 Introduction ...................................................................................................................... 83 6.2 About Tasks and Multitasking ..................................................................................... 84 6.2.1 Task States and Transitions .............................................................................. 85 Tasks States and State Symbols ....................................................................... 85 Illustration of Basic Task State Transitions .................................................... 86 6.3 VxWorks System Tasks .................................................................................................. 87 Basic VxWorks Tasks ......................................................................................... 88 Tasks for Optional Components ..................................................................... 91 6.4 Task Scheduling .............................................................................................................. 93 6.4.1 Task Priorities .................................................................................................... 93 6.4.2 VxWorks Traditional Scheduler ...................................................................... 93 Priority-Based Preemptive Scheduling .......................................................... 94 Scheduling and the Ready Queue ................................................................. 94 Round-Robin Scheduling ................................................................................. 95 6.5 Task Creation and Management ................................................................................... 97 6.5.1 Task Creation and Activation .......................................................................... 97 Static instantiation of Tasks ............................................................................. 98 6.5.2 Task Names and IDs ......................................................................................... 98 Task Naming Rules ........................................................................................... 99 Task Name and ID Routines ............................................................................ 99 VxWorks Kernel Programmer's Guide, 6.9 viii 6.5.3 Inter-Process Communication With Public Tasks ......................................... 99 6.5.4 Task Creation Options ...................................................................................... 100 6.5.5 Task Stack ........................................................................................................... 102 Task Stack Protection ........................................................................................ 102 6.5.6 Task Information ............................................................................................... 103 6.5.7 Task Deletion and Deletion Safety .................................................................. 104 6.5.8 Task Execution Control ..................................................................................... 105 6.5.9 Task Scheduling Control .................................................................................. 106 6.5.10 Tasking Extensions: Using Hook Routines .................................................... 107 6.6 Task Error Status: errno .................................................................................................. 108 6.6.1 Layered Definitions of errno ........................................................................... 109 6.6.2 A Separate errno Value for Each Task ............................................................ 109 6.6.3 Error Return Convention ................................................................................. 109 6.6.4 Assignment of Error Status Values ................................................................. 110 6.7 Task Exception Handling ............................................................................................... 110 6.8 Shared Code and Reentrancy ........................................................................................ 111 6.8.1 Dynamic Stack Variables .................................................................................. 112 6.8.2 Guarded Global and Static Variables ............................................................. 112 6.8.3 Task-Specific Variables .................................................................................... 113 Thread-Local Variables: __thread Storage Class ........................................... 113 taskVarLib and Task Variables ........................................................................ 114 6.8.4 Multiple Tasks with the Same Main Routine ................................................ 114 7 Intertask and Interprocess Communication ............................................. 117 7.1 Introduction ...................................................................................................................... 117 7.2 About Intertask and Interprocess Communication .................................................. 118 7.3 Shared Data Structures ................................................................................................... 119 7.4 Interrupt Locks ............................................................................................................... 120 7.5 Task Locks ........................................................................................................................ 121 7.6 Semaphores ...................................................................................................................... 122 7.6.1 Inter-Process Communication With Public Semaphores ............................. 123 7.6.2 Semaphore Creation and Use .......................................................................... 123 Options for Scalable and Inline Semaphore Routines ................................ 125 Static Instantiation of Semaphores ................................................................. 125 Scalable and Inline Semaphore Take and Give Routines ........................... 126 Contents ix 7.6.3 Binary Semaphores ........................................................................................... 126 Mutual Exclusion .............................................................................................. 127 Synchronization ................................................................................................. 128 7.6.4 Mutual-Exclusion Semaphores ....................................................................... 129 Priority Inversion and Priority Inheritance ................................................... 129 Deletion Safety ................................................................................................... 132 Recursive Resource Access .............................................................................. 133 7.6.5 Counting Semaphores ...................................................................................... 134 7.6.6 Read/Write Semaphores ................................................................................. 134 Specification of Read or Write Mode .............................................................. 135 Precedence for Write Access Operations ....................................................... 136 Read/Write Semaphores and System Performance ..................................... 136 7.6.7 Special Semaphore Options ............................................................................. 136 Semaphore Timeout .......................................................................................... 136 Semaphores and Queueing .............................................................................. 137 Semaphores and VxWorks Events .................................................................. 137 7.7 Message Queues .............................................................................................................. 137 7.7.1 Inter-Process Communication With Public Message Queues ..................... 138 7.7.2 Message Creation and Use ............................................................................... 138 Static Instantiation of Message Queues ......................................................... 139 Message Queue Timeout .................................................................................. 139 Message Queue Urgent Messages .................................................................. 140 Message Queues and Queuing Options ........................................................ 140 7.7.3 Displaying Message Queue Attributes .......................................................... 141 7.7.4 Servers and Clients with Message Queues .................................................... 141 7.7.5 Message Queues and VxWorks Events .......................................................... 142 7.8 Pipes ................................................................................................................................... 142 7.8.1 Creating Pipes ................................................................................................... 142 7.8.2 Writing to Pipes from ISRs ............................................................................... 142 7.8.3 I/O Control Functions ...................................................................................... 143 7.9 VxWorks Events ............................................................................................................... 143 7.9.1 Configuring VxWorks for Events .................................................................... 144 7.9.2 About Event Flags and the Task Events Register ......................................... 144 7.9.3 Receiving Events ............................................................................................... 145 7.9.4 Sending Events .................................................................................................. 146 7.9.5 Inter-Process Communication With Events .................................................. 148 7.9.6 Events Routines ................................................................................................. 148 7.9.7 Code Example ................................................................................................... 149 7.9.8 Show Routines and Events .............................................................................. 149 VxWorks Kernel Programmer's Guide, 6.9 x 7.10 Inter-Process Communication With Public Objects ................................................. 149 Creating and Naming Public and Private Objects ....................................... 150 Example of Inter-process Communication With a Public Semaphore ...... 150 7.11 About VxWorks API Timeout Parameters .................................................................. 152 7.12 About Object Ownership and Resource Reclamation ............................................. 152 8 Signals, ISRs, and Watchdog Timers ........................................................ 155 8.1 Introduction ...................................................................................................................... 155 8.2 Signals .............................................................................................................................. 156 8.2.1 Configuring VxWorks for Signals .................................................................. 157 8.2.2 Basic Signal Routines ........................................................................................ 158 8.2.3 Queued Signal Routines .................................................................................. 159 8.2.4 Signal Events ...................................................................................................... 162 8.2.5 Signal Handlers ................................................................................................. 163 8.3 Interrupt Service Routines: ISRs ................................................................................. 166 8.3.1 Configuring VxWorks for ISRs ........................................................................ 166 Configuring the Interrupt Stack ...................................................................... 166 Adding Show Routine Support ....................................................................... 167 8.3.2 Writing ISRs ....................................................................................................... 167 Restrictions on ISRs ........................................................................................... 167 Facilities Available for ISRs .............................................................................. 169 Reserving High Interrupt Levels .................................................................... 170 8.3.3 System Clock ISR Modification ....................................................................... 171 8.3.4 Connecting ISRs to Interrupts ......................................................................... 171 8.3.5 Getting Information About ISRs ..................................................................... 172 8.3.6 Debugging ISRs ................................................................................................. 173 8.4 Watchdog Timers ............................................................................................................. 174 Static Instantiation of Watchdog Timers ........................................................ 175 8.4.1 Inter-Process Communication With Public Watchdog Timers ................... 176 9 POSIX Facilities .......................................................................................... 177 9.1 Introduction ...................................................................................................................... 178 9.2 Configuring VxWorks with POSIX Facilities ............................................................ 179 9.2.1 VxWorks Components for POSIX Facilities .................................................. 179 9.3 General POSIX Support ................................................................................................. 180 9.4 POSIX Header Files ........................................................................................................ 181 Contents xi 9.5 POSIX Namespace .......................................................................................................... 183 9.6 POSIX Clocks and Timers ............................................................................................. 183 9.7 POSIX Asynchronous I/O .............................................................................................. 186 9.8 POSIX Advisory File Locking ....................................................................................... 186 9.9 POSIX Page-Locking Interface ..................................................................................... 186 9.10 POSIX Threads ................................................................................................................ 187 9.10.1 POSIX Thread Attributes ................................................................................. 188 9.10.2 VxWorks-Specific Pthread Attributes ............................................................ 188 9.10.3 Specifying Attributes when Creating Pthreads ........................................... 189 9.10.4 POSIX Thread Creation and Management .................................................... 190 9.10.5 POSIX Thread Attribute Access ...................................................................... 190 9.10.6 POSIX Thread Private Data ............................................................................. 191 9.10.7 POSIX Thread Cancellation ............................................................................. 192 9.11 POSIX Thread Mutexes and Condition Variables .................................................... 193 9.11.1 Thread Mutexes ................................................................................................. 193 Protocol Mutex Attribute ................................................................................ 194 Priority Ceiling Mutex Attribute .................................................................... 195 9.11.2 Condition Variables .......................................................................................... 195 9.12 POSIX and VxWorks Scheduling ................................................................................. 196 9.12.1 Differences in POSIX and VxWorks Scheduling ........................................... 197 9.12.2 POSIX and VxWorks Priority Numbering ..................................................... 198 9.12.3 Default Scheduling Policy ................................................................................ 198 9.12.4 VxWorks Traditional Scheduler ...................................................................... 198 9.12.5 POSIX Threads Scheduler ................................................................................ 199 9.12.6 POSIX Scheduling Routines ............................................................................ 203 9.12.7 Getting Scheduling Parameters: Priority Limits and Time Slice ................ 204 9.13 POSIX Semaphores ......................................................................................................... 204 9.13.1 Comparison of POSIX and VxWorks Semaphores ....................................... 205 9.13.2 Using Unnamed Semaphores .......................................................................... 206 9.13.3 Using Named Semaphores .............................................................................. 208 9.14 POSIX Message Queues ................................................................................................. 211 9.14.1 Comparison of POSIX and VxWorks Message Queues ............................... 212 9.14.2 POSIX Message Queue Attributes .................................................................. 213 9.14.3 Displaying Message Queue Attributes .......................................................... 214 VxWorks Kernel Programmer's Guide, 6.9 xii 9.14.4 Communicating Through a Message Queue ................................................ 215 9.14.5 Notification of Message Arrival ..................................................................... 218 9.15 POSIX Signals .................................................................................................................. 222 9.16 POSIX Memory Management ....................................................................................... 222 10 Memory Management ................................................................................. 223 10.1 Introduction ...................................................................................................................... 223 10.2 32-Bit VxWorks Memory Layout ................................................................................. 224 10.2.1 Displaying Information About Memory Layout .......................................... 224 10.2.2 System Memory Map Without RTP Support ................................................ 224 10.2.3 System Memory Map with RTP Support ....................................................... 226 10.2.4 System RAM Autosizing .................................................................................. 228 10.2.5 Reserved Memory: User-Reserved Memory and Persistent Memory ...... 228 10.3 64-Bit VxWorks Memory Layout ................................................................................. 229 10.3.1 Displaying Information About Memory Layout .......................................... 230 10.3.2 Virtual Memory Regions .................................................................................. 230 Kernel System Virtual Memory Region ......................................................... 231 Kernel Virtual Memory Pool Region .............................................................. 232 Kernel Reserved Memory Region ................................................................... 232 Shared User Virtual Memory Region ............................................................. 232 RTP Private Virtual Memory Region .............................................................. 232 10.3.3 Global RAM Pool .............................................................................................. 233 10.3.4 Kernel Memory Map ........................................................................................ 233 Kernel System Memory .................................................................................... 235 Kernel Common Heap ...................................................................................... 235 DMA32 Heap ..................................................................................................... 235 User-Reserved Memory ................................................................................... 235 Persistent Memory ............................................................................................ 235 10.3.5 Reserved Memory Configuration: User-Reserved Memory and Persistent Memory .............................................................................................................. 236 10.3.6 System RAM Autosizing .................................................................................. 236 10.4 About VxWorks Memory Allocation Facilities ......................................................... 236 10.5 32-Bit VxWorks Heap and Memory Partition Management .................................. 237 10.5.1 Configuring the Kernel Heap and the Memory Partition Manager .......... 238 10.5.2 Basic Heap and Memory Partition Manager ................................................. 238 10.5.3 Full Heap and Memory Partition Manager ................................................... 238 10.6 64-Bit VxWorks Heap and Memory Partition Management .................................. 239 10.6.1 Kernel Common Heap ...................................................................................... 239 Contents xiii 10.6.2 Kernel Proximity Heap ..................................................................................... 240 10.6.3 DMA32 Heap ..................................................................................................... 240 10.7 SMP-Optimized Memory Allocation .......................................................................... 241 10.7.1 Configuration ..................................................................................................... 241 10.7.2 Usage scenarios ................................................................................................. 241 10.8 Memory Pools .................................................................................................................. 242 10.9 POSIX Memory Management ....................................................................................... 242 10.9.1 POSIX Memory Management APIs ................................................................ 243 10.9.2 POSIX Memory Mapping ................................................................................ 244 10.9.3 POSIX Memory Protection ............................................................................... 244 10.9.4 POSIX Memory Locking .................................................................................. 244 10.10 Memory Mapping Facilities .......................................................................................... 245 10.10.1 POSIX Memory-Mapped Files ........................................................................ 247 10.10.2 POSIX Shared Memory Objects ...................................................................... 247 10.10.3 Anonymous Memory Mapping ...................................................................... 247 10.10.4 Device Memory Objects ................................................................................... 248 10.10.5 Shared Data Regions ......................................................................................... 249 10.11 Virtual Memory Management ..................................................................................... 249 10.11.1 Configuring Virtual Memory Management .................................................. 250 10.11.2 Managing Virtual Memory Programmatically ............................................. 251 Modifying Page States ...................................................................................... 252 Making Memory Non-Writable ...................................................................... 253 Invalidating Memory Pages ............................................................................ 255 Locking TLB Entries .......................................................................................... 255 Page Size Optimization .................................................................................... 255 Setting Page States in ISRs ............................................................................... 256 10.11.3 Troubleshooting ................................................................................................. 256 10.12 Additional Memory Protection Features ................................................................... 257 10.12.1 Configuring VxWorks for Additional Memory Protection ......................... 257 10.12.2 Stack Overrun and Underrun Detection ........................................................ 258 10.12.3 Non-Executable Task Stack .............................................................................. 258 10.12.4 Text Segment Write Protection ........................................................................ 258 10.12.5 Exception Vector Table Write Protection ........................................................ 259 10.13 Memory Error Detection ................................................................................................ 259 10.13.1 Heap and Partition Memory Instrumentation .............................................. 259 10.13.2 Compiler Instrumentation: 32-Bit VxWorks .................................................. 264 VxWorks Kernel Programmer's Guide, 6.9 xiv 11 I/O System ................................................................................................... 269 11.1 Introduction ...................................................................................................................... 269 11.2 About the VxWorks I/O System ................................................................................... 270 Differences Between VxWorks and Host System I/O ................................. 270 11.3 Configuring VxWorks With I/O Facilities .................................................................. 271 11.4 I/O Devices, Named Files, and File Systems ............................................................ 272 11.5 Remote File System Access From VxWorks ............................................................... 273 NFS File System Access from VxWorks ......................................................... 273 Non-NFS Network File System Access from VxWorks WIth FTP or RSH 273 11.6 Basic I/O ............................................................................................................................ 275 11.6.1 File Descriptors .................................................................................................. 275 File Descriptor Table ......................................................................................... 276 11.6.2 Standard Input, Standard Output, and Standard Error .............................. 276 11.6.3 Standard I/O Redirection ................................................................................ 276 Issues with Standard I/O Redirection ........................................................... 277 11.6.4 Open and Close ................................................................................................. 278 11.6.5 Create and Remove ........................................................................................... 280 11.6.6 Read and Write .................................................................................................. 281 11.6.7 File Truncation ................................................................................................... 281 11.6.8 I/O Control ........................................................................................................ 282 11.6.9 Pending on Multiple File Descriptors with select( ) ..................................... 282 11.6.10 POSIX File System Routines ............................................................................ 284 11.7 Standard I/O ..................................................................................................................... 285 11.7.1 Configuring VxWorks With Standard I/O .................................................... 285 11.7.2 About printf( ), sprintf( ), and scanf( ) ............................................................ 286 11.7.3 About Standard I/O and Buffering ................................................................ 286 11.7.4 About Standard Input, Standard Output, and Standard Error .................. 287 11.8 Other Formatted I/O ....................................................................................................... 287 11.8.1 Output in Serial I/O Polled Mode: kprintf( ) ................................................ 287 Writing to User-Defined Storage Media With kprintf( ) and kputs( ) ....... 288 11.8.2 Additional Formatted I/O Routines ............................................................. 289 11.8.3 Message Logging ............................................................................................... 289 11.9 Asynchronous Input/Output ......................................................................................... 289 11.9.1 The POSIX AIO Routines ................................................................................. 290 Contents xv 11.9.2 AIO Control Block ............................................................................................. 291 11.9.3 Using AIO ........................................................................................................... 292 AIO with Periodic Checks for Completion ................................................... 292 Alternatives for Testing AIO Completion ..................................................... 294 12 Devices ........................................................................................................ 297 12.1 Introduction ...................................................................................................................... 297 12.2 About Devices in VxWorks ........................................................................................... 298 12.3 Serial I/O Devices: Terminal and Pseudo-Terminal Devices .................................. 299 tty Options .......................................................................................................... 299 12.3.1 Raw Mode and Line Mode .............................................................................. 300 12.3.2 tty Special Characters ....................................................................................... 300 12.3.3 I/O Control Functions ...................................................................................... 301 12.4 Pipe Devices ..................................................................................................................... 302 12.5 Pseudo I/O Device ........................................................................................................... 302 12.5.1 I/O Control Functions ...................................................................................... 303 12.6 Null Devices .................................................................................................................... 303 12.7 Block Devices ................................................................................................................... 303 12.7.1 XBD RAM Disk .................................................................................................. 305 12.7.2 SCSI Drivers ....................................................................................................... 306 Configuring SCSI Drivers ................................................................................ 306 Structure of the SCSI Subsystem ..................................................................... 307 Booting and Initialization ................................................................................ 308 Device-Specific Configuration Options ......................................................... 308 SCSI Configuration Examples ......................................................................... 310 Troubleshooting ................................................................................................. 312 12.8 Extended Block Device Facility: XBD ......................................................................... 313 12.8.1 XBD Disk Partition Manager ........................................................................... 313 12.8.2 XBD Block Device Wrapper ............................................................................. 314 12.8.3 XBD TRFS Component ..................................................................................... 314 12.9 PCMCIA ............................................................................................................................ 315 12.10 Peripheral Component Interconnect: PCI .................................................................. 315 12.11 Network File System (NFS) Devices ........................................................................... 315 12.11.1 I/O Control Functions for NFS Clients .......................................................... 316 12.12 Non-NFS Network Devices ........................................................................................... 317 VxWorks Kernel Programmer's Guide, 6.9 xvi 12.12.1 Creating Network Devices ............................................................................... 318 12.12.2 I/O Control Functions ...................................................................................... 318 12.13 Sockets ............................................................................................................................... 318 12.14 Internal I/O System Structure ....................................................................................... 319 12.14.1 Drivers ................................................................................................................ 321 The Driver Table and Installing Drivers ........................................................ 322 Example of Installing a Driver ........................................................................ 322 12.14.2 Devices ................................................................................................................ 323 The Device List and Adding Devices ............................................................. 323 Example of Adding Devices ............................................................................ 324 Deleting Devices ................................................................................................ 324 12.14.3 File Descriptors .................................................................................................. 327 File Descriptor Table ......................................................................................... 327 Example of Opening a File ............................................................................... 327 Example of Reading Data from the File ......................................................... 330 Example of Closing a File ................................................................................. 331 Implementing select( ) ...................................................................................... 331 Cache Coherency ............................................................................................... 334 13 Local File Systems ..................................................................................... 339 13.1 Introduction ...................................................................................................................... 339 13.2 File System Monitor ...................................................................................................... 341 Device Insertion Events .................................................................................... 342 XBD Name Mapping Facility .......................................................................... 343 13.3 Virtual Root File System: VRFS ................................................................................... 343 13.4 Highly Reliable File System: HRFS ............................................................................ 345 13.4.1 Configuring VxWorks for HRFS ..................................................................... 345 13.4.2 Configuring HRFS ............................................................................................ 346 13.4.3 Creating an HRFS File System ....................................................................... 347 Overview of HRFS File System Creation ....................................................... 347 HRFS File System Creation Steps ................................................................... 347 13.4.4 HRFS, ATA, and RAM Disk Examples .......................................................... 348 13.4.5 Optimizing HRFS Performance ...................................................................... 353 13.4.6 Transactional Operations and Commit Policies ......................................... 353 Automatic Commit Policy ............................................................................... 353 High-Speed Commit Policy ............................................................................. 354 Mandatory Commits ......................................................................................... 354 Rollbacks ............................................................................................................. 354 Programmatically Initiating Commits ........................................................... 354 13.4.7 File Access Time Stamps .................................................................................. 355 Contents xvii 13.4.8 Maximum Number of Files and Directories ................................................. 355 13.4.9 Working with Directories ................................................................................. 355 Creating Subdirectories .................................................................................... 355 Removing Subdirectories ................................................................................. 356 Reading Directory Entries ................................................................................ 356 13.4.10 Working with Files ............................................................................................ 356 File I/O Routines ............................................................................................... 356 File Linking and Unlinking ............................................................................. 356 File Permissions ................................................................................................. 357 13.4.11 I/O Control Functions Supported by HRFS ................................................. 357 13.4.12 Crash Recovery and Volume Consistency ..................................................... 358 Crash Recovery .................................................................................................. 358 Consistency Checking ...................................................................................... 358 13.4.13 File Management and Full Devices ................................................................ 358 13.5 MS-DOS-Compatible File System: dosFs .................................................................. 359 13.5.1 Configuring VxWorks for dosFs ..................................................................... 360 13.5.2 Configuring dosFs ............................................................................................ 361 13.5.3 Creating a dosFs File System ........................................................................... 362 Overview of dosFs File System Creation ....................................................... 362 dosFs File System Creation Steps ................................................................... 363 13.5.4 dosFs, ATA Disk, and RAM Disk Examples ................................................. 365 13.5.5 Optimizing dosFs Performance ...................................................................... 369 13.5.6 Working with Volumes and Disks .................................................................. 370 Accessing Volume Configuration Information ............................................. 370 Synchronizing Volumes .................................................................................... 370 13.5.7 Working with Directories ................................................................................. 370 Creating Subdirectories .................................................................................... 370 Removing Subdirectories ................................................................................. 371 Reading Directory Entries ................................................................................ 371 13.5.8 Working with Files ............................................................................................ 371 File I/O Routines ............................................................................................... 371 File Attributes .................................................................................................... 371 13.5.9 Disk Space Allocation Options ........................................................................ 373 Choosing an Allocation Method ..................................................................... 374 Using Cluster Group Allocation ..................................................................... 374 Using Absolutely Contiguous Allocation ...................................................... 374 13.5.10 Crash Recovery and Volume Consistency ..................................................... 376 13.5.11 I/O Control Functions Supported by dosFsLib ............................................ 376 13.5.12 Booting from a Local dosFs File System Using SCSI ................................... 378 13.6 Transaction-Based Reliable File System Support for dosFs: TRFS ....................... 380 VxWorks Kernel Programmer's Guide, 6.9 xviii 13.6.1 Configuring VxWorks With TRFS ................................................................... 380 13.6.2 Automatic Instantiation of TRFS .................................................................... 380 13.6.3 Formatting a Device for TRFS ......................................................................... 381 13.6.4 Using TRFS in Applications ............................................................................ 382 TRFS Code Examples ....................................................................................... 382 13.7 Raw File System: rawFs ................................................................................................. 383 13.7.1 Configuring VxWorks for rawFs ..................................................................... 383 13.7.2 Creating a rawFs File System .......................................................................... 383 13.7.3 Mounting rawFs Volumes ................................................................................ 384 13.7.4 rawFs File I/O ................................................................................................... 385 13.7.5 I/O Control Functions Supported by rawFsLib ........................................... 385 13.8 CD-ROM File System: cdromFs ................................................................................... 386 13.8.1 Configuring VxWorks for cdromFs ................................................................ 387 13.8.2 Creating and Using cdromFs ........................................................................... 387 13.8.3 I/O Control Functions Supported by cdromFsLib ...................................... 389 13.8.4 Version Numbers ............................................................................................... 390 13.9 Read-Only Memory File System: ROMFS ................................................................. 390 13.9.1 Configuring VxWorks with ROMFS ............................................................... 391 13.9.2 Adding a ROMFS Directory and File Content to VxWorks ........................ 391 13.9.3 Accessing Files in ROMFS ............................................................................... 392 13.9.4 Using ROMFS to Start Applications Automatically .................................... 392 13.10 Target Server File System: TSFS ................................................................................... 392 Socket Support ................................................................................................... 393 Error Handling .................................................................................................. 394 Configuring VxWorks for TSFS Use ............................................................... 394 Security Considerations ................................................................................... 394 Using the TSFS to Boot a Target ...................................................................... 395 14 Flash File System Support: TrueFFS ........................................................ 397 14.1 Introduction ...................................................................................................................... 397 14.2 Overview of Implementation Steps ............................................................................ 398 14.3 Creating a VxWorks System with TrueFFS ................................................................ 400 14.3.1 Selecting an MTD .............................................................................................. 400 14.3.2 Identifying the Socket Driver .......................................................................... 400 14.3.3 Configuring VxWorks with TrueFFS and File System ................................. 401 Including the Core TrueFFS Component ....................................................... 401 Including the MTD Component ...................................................................... 402 Contents xix Including the Translation Layer Component ................................................ 402 Including the Socket Driver ............................................................................. 403 Including the XBD Wrapper Component ...................................................... 403 Including File System Components ............................................................... 403 Including Utility Components ........................................................................ 403 14.3.4 Building the System .......................................................................................... 404 14.3.5 Formatting the Flash ......................................................................................... 404 Formatting With sysTffsFormat( ) .................................................................. 404 Formatting With tffsDevFormat( ) .................................................................. 405 14.3.6 Reserving a Region in Flash for a Boot Image .............................................. 406 Reserving a Fallow Region .............................................................................. 407 Writing the Boot Image to Flash ...................................................................... 408 14.3.7 Mounting the Drive .......................................................................................... 409 14.3.8 Creating a File System ...................................................................................... 409 14.3.9 Testing the Drive ............................................................................................... 410 14.4 Using TrueFFS Shell Commands ................................................................................. 410 14.5 Using TrueFFS With HRFS ............................................................................................

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pekingkenny

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值