core_v5.3与core_v5.2区别

时间: 2023-05-02 09:07:28 浏览: 45
core_v5.3和core_v5.2是两种不同版本的核心技术,主要用于网站或应用程序的开发。它们的最大区别在于在5.3版本中实现了对.NET Core 3.1的支持,而5.2版本只支持到.NET Core 2.2。 因此,core_v5.3相对于core_v5.2具有更强大的功能和性能,并且能够使用新的.NET Core 3.1版本,这意味着开发人员可以使用更先进的编程技术和功能提高应用程序的性能和安全性。 此外,core_v5.3还具有更好的稳定性和可靠性,可以更好地处理重要数据和处理高访问量的网站。它还引入了更多的API,使它更具有可扩展性,并且更容易与其他系统集成。 总之,core_v5.3是一种更现代、更强大、更稳定的版本,具有更好的性能、功能和安全性,它是一个更值得采用的技术选择。
相关问题

WWW/FTP服务器基本配置实验步骤与结果 2000字

一、实验目的 1. 学习Linux操作系统的基本命令和网络基础知识; 2. 掌握Web服务器和FTP服务器的安装配置和使用方法; 3. 了解Web服务器和FTP服务器的工作原理和相关协议。 二、实验环境 1. 操作系统:CentOS 7.0; 2. 软件环境:Apache HTTP Server、vsftpd; 3. 硬件环境:Intel Core i5 CPU、4GB内存、500GB硬盘。 三、实验步骤与结果 1. 安装Apache HTTP Server 1.1 首先,我们需要更新系统软件包: ``` yum -y update ``` 1.2 安装Apache HTTP Server: ``` yum -y install httpd ``` 1.3 启动Apache HTTP Server: ``` systemctl start httpd.service ``` 1.4 设置Apache HTTP Server开机自启动: ``` systemctl enable httpd.service ``` 1.5 验证Apache HTTP Server是否安装成功,打开浏览器输入服务器IP地址或主机名: ``` http://<IP地址或主机名> ``` 如果出现Apache HTTP Server默认页面,则说明安装成功。 2. 配置Apache HTTP Server 2.1 修改Apache HTTP Server默认网站根目录: 默认情况下,Apache HTTP Server的网站根目录是/var/www/html。我们可以将其修改为其他目录,以方便管理网站文件。 编辑Apache HTTP Server主配置文件: ``` vi /etc/httpd/conf/httpd.conf ``` 找到以下行: ``` DocumentRoot "/var/www/html" <Directory "/var/www/html"> ``` 将/var/www/html改为其他目录,例如/home/www: ``` DocumentRoot "/home/www" <Directory "/home/www"> ``` 保存文件并退出。 2.2 修改Apache HTTP Server默认页面 Apache HTTP Server默认页面位于/var/www/html/index.html。我们可以将其修改为其他页面。 创建新的默认页面: ``` vi /home/www/index.html ``` 输入以下内容: ``` <!DOCTYPE html> <html> <head> <title>My Website</title> </head> <body> <h1>Welcome to my website!</h1> <p>This is my first web page.</p> </body> </html> ``` 保存文件并退出。 重新启动Apache HTTP Server: ``` systemctl restart httpd.service ``` 打开浏览器输入服务器IP地址或主机名,应该能看到新的默认页面。 3. 安装vsftpd 3.1 安装vsftpd: ``` yum -y install vsftpd ``` 3.2 启动vsftpd: ``` systemctl start vsftpd.service ``` 3.3 设置vsftpd开机自启动: ``` systemctl enable vsftpd.service ``` 4. 配置vsftpd 4.1 修改vsftpd配置文件: ``` vi /etc/vsftpd/vsftpd.conf ``` 找到以下行,去掉注释并修改: ``` anonymous_enable=YES ``` 改为: ``` anonymous_enable=NO ``` 这样就禁用了匿名用户登录。 4.2 创建FTP用户 创建FTP用户并设置密码: ``` useradd -d /home/ftpuser -m ftpuser passwd ftpuser ``` 4.3 设置FTP用户的主目录 编辑vsftpd配置文件: ``` vi /etc/vsftpd/vsftpd.conf ``` 找到以下行,去掉注释并修改: ``` #chroot_local_user=YES ``` 改为: ``` chroot_local_user=YES ``` 这样就限制了FTP用户只能访问自己的主目录。 4.4 重启vsftpd: ``` systemctl restart vsftpd.service ``` 5. 测试FTP服务器 5.1 使用FTP客户端连接FTP服务器: ``` ftp <IP地址或主机名> ``` 5.2 输入FTP用户名和密码登录FTP服务器。 5.3 查看FTP用户的主目录: ``` pwd ``` 应该显示为/home/ftpuser。 5.4 在FTP用户的主目录下创建一个文件: ``` touch test.txt ``` 5.5 使用FTP客户端下载该文件: ``` get test.txt ``` 文件应该下载成功。 四、实验总结 通过本次实验,我学习了Linux操作系统的基本命令和网络基础知识,掌握了Web服务器和FTP服务器的安装配置和使用方法,了解了Web服务器和FTP服务器的工作原理和相关协议。这些知识对我今后的工作和学习都有很大的帮助。

帮我写一套ROG全家桶配置

### 回答1: 好的,以下是一套ROG全家桶配置: 1. 主机板:ROG MAXIMUS XIII HERO Z590 ATX 这是一款高性能的主板,采用了LGA1200插槽,支持第11代英特尔Core处理器,具有出色的超频性能和稳定性。此外,该主板还支持PCIe 4.0,内置WiFi 6E和Bluetooth 5.2。 2. 处理器:英特尔酷睿i9-11900K 这是一款高性能的处理器,具有8个核心和16个线程,主频为3.5GHz,最大睿频可达5.3GHz。它还支持Intel Turbo Boost Max Technology 3.0和Intel Thermal Velocity Boost技术,可提供更快的单线程和多线程性能。 3. 显卡:ROG STRIX GeForce RTX 3080 OC 10GB 这是一款高性能的显卡,具有10GB GDDR6X内存和三个风扇,可提供流畅的游戏体验。此外,该显卡还支持Ray Tracing技术和DLSS技术,可以提供更高的图形质量和更高的帧率。 4. 内存:ROG MAXIMUS XIII HERO Z590 ATX 为了充分发挥主板的性能,我们建议选择16GB或更高容量的DDR4内存,并采用ROG品牌的内存模块,以确保最佳的兼容性和稳定性。 5. 存储:ROG Strix Arion M.2 NVMe SSD 这是一款高速的SSD存储设备,具有读写速度高达1,000MB/s和1,000MB/s。此外,该设备还支持AES 256位硬件加密和TRIM命令,可提供更好的数据保护和稳定性。 6. 机箱:ROG Strix Helios GX601 RGB 这是一款高端的机箱,具有大尺寸的侧透玻璃面板和RGB灯效。此外,该机箱还具有高度可定制化的内部空间和散热系统,可确保硬件的最佳工作温度和稳定性。 7. 电源:ROG Thor 1200W Platinum 这是一款高品质的电源,具有1200瓦的额定功率和80 Plus Platinum认证。此外,该电源还支持Aura Sync RGB灯效和ROG制造标志,可增强整个系统的协调性和风格。 总体来说,以上是一套ROG全家桶配置,它具有出色的性能、稳定性和可定制性,非常适合高端游戏和工作应用。当然,具体的配置应该根据个人需要和预算来定制 ### 回答2: 当然,以下是一套ROG全家桶的配置建议: 1. 主机:ROG Strix GL12CX-XB9810(Intel Core i9-9900K, NVIDIA GeForce RTX 2080 Ti, 64GB DDR4 RAM, 1TB SSD + 2TB HDD) 这款主机配备了顶级的Intel Core i9-9900K处理器和NVIDIA GeForce RTX 2080 Ti显卡,提供强大的性能和图形处理能力。64GB DDR4内存和大容量的储存空间(1TB SSD + 2TB HDD)可以满足你的存储需求。 2. 显示器:ROG Swift PG27UQ(27英寸,4K UHD,144Hz刷新率) ROG Swift PG27UQ是一款高性能的27英寸显示器,支持4K UHD分辨率和144Hz刷新率,提供了极致的视觉体验。此外,它还具备G-Sync技术,可以消除游戏过程中的画面撕裂和卡顿。 3. 键盘:ROG Strix Flare(机械键盘,RGB背光,Cherry MX轴) ROG Strix Flare是一款高品质的机械键盘,采用Cherry MX轴,提供出色的键盘反馈和耐久性。它还具有可定制的RGB背光,可以根据你的喜好进行个性化设置。 4. 鼠标:ROG Gladius II(光学游戏鼠标,12000 DPI) ROG Gladius II是一款专为游戏而设计的光学鼠标,采用12000 DPI传感器,提供精确的跟踪能力。它还具有可定制的RGB照明和可拆卸的侧握设计。 5. 耳机:ROG Strix Fusion 700(7.1环绕声耳机,RGB照明,蓝牙连接) ROG Strix Fusion 700是一款高品质的游戏耳机,采用7.1环绕声技术,提供沉浸式的音频体验。它还具有可定制的RGB照明和蓝牙连接功能。 以上是一套ROG全家桶的配置建议,可以提供出色的游戏体验和工作效率。当然,你可以根据个人的喜好和需求进行选择和调整。

相关推荐

pdf
PART I: VXBUS FUNDAMENTALS 1 Getting Started with Device Driver Development .................................... 3 1.1 About Device Drivers ..................................................................................................... 3 1.2 About this Documentation ............................................................................................ 4 1.2.1 Intended Audience ........................................................................................... 4 1.2.2 Navigating this Manual .................................................................................. 4 Experienced VxWorks Device Driver Developers ........................................ 4 Novice VxWorks Device Driver Developers ................................................. 5 1.2.3 Documentation Conventions .......................................................................... 5 1.3 Additional Documentation Resources ....................................................................... 6 2 VxBus and VxBus Device Drivers ............................................................. 7 2.1 Introduction ...................................................................................................................... 7 2.2 About VxBus ................................................................................................................... 7 2.3 VxBus Device Drivers ................................................................................................... 8 2.4 Design Goals ................................................................................................................... 11 2.4.1 Performance ....................................................................................................... 11 2.4.2 Maintenance and Readability .......................................................................... 11 2.4.3 Ease of Configuration ....................................................................................... 12 2.4.4 Performance Testing ......................................................................................... 12 2.4.5 Code Size ............................................................................................................ 12 3 Device Driver Fundamentals ..................................................................... 13 3.1 Introduction ...................................................................................................................... 13 3.2 Driver Classes ................................................................................................................. 14 VxBus Device Driver Developer's Guide, 6.9 iv 3.2.1 General Classes .................................................................................................. 14 Serial Drivers .................................................................................................... 14 Storage Drivers ................................................................................................. 14 Network Interface Drivers .............................................................................. 15 Non-Volatile RAM Drivers ............................................................................. 15 Timer Drivers .................................................................................................... 16 DMA Controller Drivers ................................................................................. 16 Bus Controller Drivers ..................................................................................... 16 USB Drivers ....................................................................................................... 17 Interrupt Controller Drivers ........................................................................... 17 Multifunction Drivers ...................................................................................... 17 Remote Processing Element Drivers ............................................................. 18 Console Drivers ................................................................................................ 18 Resource Drivers .............................................................................................. 19 3.2.2 Other Classes .................................................................................................... 19 3.3 Driver Organization ....................................................................................................... 19 3.3.1 File Location ...................................................................................................... 20 Wind River Drivers ........................................................................................... 20 Third-Party Drivers .......................................................................................... 20 3.3.2 Sample Driver Files: wrsample ....................................................................... 21 3.3.3 Required Files ................................................................................................... 21 Driver Source File ............................................................................................. 22 Component Description File ........................................................................... 24 Driver Configuration Stub Files ..................................................................... 29 README File .................................................................................................... 31 Device Driver Makefiles .................................................................................. 31 3.4 VxBus Driver Methods .................................................................................................. 33 3.4.1 Representing Driver Methods in the Documentation ................................ 33 3.4.2 Parts of a Driver Method ................................................................................. 33 3.4.3 Calling Driver Methods ................................................................................... 34 3.4.4 Advertising Driver Methods .......................................................................... 35 3.4.5 Driver Method Limitations ............................................................................. 36 3.5 Driver Run-time Life Cycle .......................................................................................... 36 3.5.1 Driver Initialization Sequence ........................................................................ 36 Making Assumptions About Initialization Order ....................................... 37 Early in the Boot Process ................................................................................. 37 sysHwInit( ), PLB, and Hardware Discovery ............................................... 37 Driver Registration ........................................................................................... 38 Driver Initialization Phase 1 ........................................................................... 38 Kernel Startup ................................................................................................... 39 Driver Initialization Phase 2 ........................................................................... 39 Driver Initialization Phase 3 ........................................................................... 39 3.5.2 Invoking a Driver Method .............................................................................. 39 3.5.3 Run-time Operation ......................................................................................... 39 Contents v Unloading a Driver .......................................................................................... 40 Removing a Device from the System ............................................................ 40 Dissociating a Device from a Driver .............................................................. 40 3.5.4 Handling a System Shutdown Notification ................................................. 41 3.5.5 Handling Late Driver Registration ................................................................ 41 3.5.6 Driver Registration Order Considerations ................................................... 42 3.5.7 Driver-to-Device Matching and Hardware Availability ............................. 42 PLB ..................................................................................................................... 43 Other Bus Types ................................................................................................ 43 3.6 Services Available to Drivers ....................................................................................... 44 3.6.1 Configuration .................................................................................................... 44 Determining Driver Configuration Information ......................................... 45 Responding to Changes in Device Parameters ............................................ 47 3.6.2 Memory Allocation .......................................................................................... 47 Allocating Memory During System Startup ................................................ 48 Allocating Memory During Normal System Operation ............................. 49 Intermixing Memory Allocation Methods within a Single Driver ........... 49 3.6.3 Non-Volatile RAM Support ............................................................................. 49 3.6.4 Hardware Access .............................................................................................. 50 Finding the Address of the Hardware Registers ......................................... 50 Reading and Writing to the Hardware Registers ........................................ 51 Special Requirements for Hardware Register Access ................................. 53 VxBus Version Considerations ........................................................................ 53 3.6.5 Interrupt Handling ........................................................................................... 54 Overview of Interrupt Handling .................................................................... 54 Interrupt Indexes .............................................................................................. 54 Dynamic Interrupt Handling .......................................................................... 55 Minimizing Work Performed Within an ISR ................................................ 56 3.6.6 Synchronization ................................................................................................ 57 Task-Level Synchronization ............................................................................ 57 Interrupt-Level Synchronization .................................................................... 58 3.6.7 Direct Memory Access (DMA) ....................................................................... 59 vxbDmaBufLib .................................................................................................. 60 DMA Considerations ........................................................................................ 60 Allocating External DMA Engines ................................................................ 63 3.6.8 Atomic Operators ............................................................................................. 65 3.7 BSP Configuration ......................................................................................................... 66 3.7.1 Requirements for PLB Devices ....................................................................... 67 3.7.2 Configuring Device Parameters in the BSP .................................................. 68 3.8 SMP Considerations ...................................................................................................... 69 3.8.1 Lack of Implicit Locking ................................................................................. 69 VxBus Device Driver Developer's Guide, 6.9 vi 3.8.2 True Task-to-Task Contention ......................................................................... 70 3.8.3 Interrupt Routing ............................................................................................. 70 3.8.4 Deferring Interrupt Processing ...................................................................... 71 3.9 Device Memory Mapping in 64-Bit Devices .............................................................. 72 3.10 Physical-to-Virtual Address Translations in 64-Bit VxWorks ................................. 73 3.10.1 64-bit Changes to the Memory Management Model ................................... 73 3.10.2 Porting Drivers That Rely on Physical-to-Virtual Address Translations .. 74 Transfer Using Descriptors .............................................................................. 74 Strategies When Order is Unpredictable ....................................................... 75 4 Development Strategies ............................................................................. 77 4.1 Introduction ...................................................................................................................... 77 4.2 Writing New VxBus Drivers ........................................................................................ 77 4.2.1 Creating the VxBus Infrastructure ................................................................. 78 Writing Driver Source Files ............................................................................. 78 Writing Header Files (Optional) .................................................................... 78 Writing the Component Description File (CDF) .......................................... 78 Writing the Configuration Stub Files ............................................................ 79 Verifying the Infrastructure ............................................................................ 80 4.2.2 Modifying the BSP (Optional) ........................................................................ 80 4.2.3 Adding Debug Code ........................................................................................ 81 4.2.4 Adding the VxBus Driver Methods ............................................................... 81 4.2.5 Removing Global Variables ............................................................................ 82 4.3 VxBus Show Routines ................................................................................................... 83 4.3.1 Available Show Routines ................................................................................ 83 vxBusShow( ) ..................................................................................................... 83 vxbDevStructShow( ) ........................................................................................ 85 vxbDevPathShow( ) .......................................................................................... 86 4.3.2 PCI Show Routines .......................................................................................... 86 pciDevShow( ) ................................................................................................... 87 vxbPciDeviceShow( ) ........................................................................................ 87 vxbPciHeaderShow( ) ....................................................................................... 88 vxbPciFindDeviceShow( ) ................................................................................ 89 vxbPciFindClassShow( ) ................................................................................... 89 vxbPciConfigTopoShow( ) ............................................................................... 90 4.3.3 Using Show Routines from Software ............................................................ 91 4.3.4 Configuring Show Routines into VxWorks .................................................. 93 4.4 Debugging ....................................................................................................................... 94 4.4.1 Configuring Show Routines ........................................................................... 94 Contents vii 4.4.2 Deferring Driver Registration ........................................................................ 95 4.4.3 Including Debug Code .................................................................................... 95 4.4.4 Confirming Register Access ............................................................................ 96 4.4.5 Increasing the Size of HWMEM_POOL ........................................................ 96 4.4.6 Confirming Device and Driver Name Matches ........................................... 96 5 Driver Release Procedure .......................................................................... 99 5.1 Introduction ..................................................................................................................... 99 5.2 Driver Source Location .................................................................................................. 100 5.3 Driver-Specific Directories ............................................................................................ 101 5.4 Driver Installation and the README File ................................................................ 102 5.5 Driver Packaging ............................................................................................................ 103 5.6 Driver Release Procedure ............................................................................................. 104 PART II: DEVICE DRIVER PORTING 6 Class-Specific Driver Development .......................................................... 107 6.1 About VxBus Driver Classes ........................................................................................ 107 6.2 Before You Begin ............................................................................................................. 107 6.3 About the Class-Specific Driver Documentation ..................................................... 108 7 Bus Controller Drivers ................................................................................ 109 7.1 Introduction ..................................................................................................................... 109 7.2 Overview .......................................................................................................................... 109 7.3 VxBus Driver Methods .................................................................................................. 111 7.3.1 {busCtlrDevCfgRead}( ) ................................................................................... 111 7.3.2 {busCtlrCfgRead}( ) ........................................................................................... 112 7.3.3 {busCtlrDevCfgWrite}( ) ................................................................................... 113 7.3.4 {busCtlrCfgWrite}( ) .......................................................................................... 113 7.3.5 {busCtlrDevCtlr}( ) ............................................................................................ 114 7.3.6 {busCtlrAccessOverride}( ) .............................................................................. 115 Override for (*busCfgRead)( ) ......................................................................... 115 Override for (*busCfgWrite)( ) ........................................................................ 116 Override for (*vxbDevControl)( ) ................................................................... 116 VxBus Device Driver Developer's Guide, 6.9 viii 7.3.7 {busCtlrCfgInfo}( ) ............................................................................................. 116 7.3.8 {busCtlrBaseAddrCvt}( ) .................................................................................. 117 7.3.9 {vxbDevRegMap}( ) ........................................................................................... 117 Specifying a Predefined Transaction Type ..................................................... 119 Providing a New Transaction Type ............................................................... 120 7.3.10 {vxbIntDynaVecProgram}( ) ............................................................................. 122 7.4 Header Files ..................................................................................................................... 122 7.5 BSP Configuration .......................................................................................................... 123 7.5.1 PCI Configuration ............................................................................................ 124 7.5.2 PCI Autoconfiguration .................................................................................... 124 7.6 Available Utility Routines ............................................................................................ 125 7.6.1 PCI Configuration ............................................................................................ 125 7.6.2 PCI Autoconfiguration ..................................................................................... 126 7.6.3 vxbBusAnnounce( ) ........................................................................................... 126 7.6.4 vxbPciBusTypeInit( ) ......................................................................................... 127 7.7 Initialization .................................................................................................................... 127 7.7.1 Initialization Example ..................................................................................... 128 vxbBusAnnounce( ) ........................................................................................... 129 vxbDeviceAnnounce( ) ..................................................................................... 130 vxbDevStructAlloc( ) ........................................................................................ 130 vxbDevStructFree( ) .......................................................................................... 130 7.8 Debugging ........................................................................................................................ 130 8 Direct Memory Access Drivers .................................................................. 131 8.1 Introduction ..................................................................................................................... 131 8.2 Overview ........................................................................................................................... 131 8.3 VxBus Driver Methods ................................................................................................... 132 8.3.1 {vxbDmaResourceGet}( ) .................................................................................. 132 8.3.2 {vxbDmaResourceRelease}( ) ........................................................................... 133 8.3.3 {vxbDmaResDedicatedGet}( ) .......................................................................... 133 8.4 Header Files ...................................................................................................................... 133 8.5 BSP Configuration .......................................................................................................... 134 8.6 Available Utility Routines ............................................................................................. 134 8.7 Initialization ..................................................................................................................... 134 Contents ix 8.8 DMA System Structures and Routines ....................................................................... 134 8.8.1 (*dmaRead)( ) ..................................................................................................... 135 8.8.2 (*dmaReadAndWait)( ) ..................................................................................... 135 8.8.3 (*dmaWrite)( ) .................................................................................................... 135 8.8.4 (*dmaWriteAndWait)( ) .................................................................................... 136 8.8.5 (*dmaCancel)( ) .................................................................................................. 136 8.8.6 (*dmaPause)( ) ................................................................................................... 136 8.8.7 (*dmaResume)( ) ................................................................................................ 136 8.8.8 (*dmaStatus)( ) ................................................................................................... 136 8.9 Debugging ....................................................................................................................... 137 9 I2C Drivers ................................................................................................... 139 9.1 Introduction ...................................................................................................................... 139 9.2 Overview ........................................................................................................................... 139 9.3 VxBus Driver Methods ................................................................................................... 140 9.4 Header Files ...................................................................................................................... 141 9.5 BSP Configuration .......................................................................................................... 141 9.6 Initialization ..................................................................................................................... 143 9.7 Implementing Driver Service Routines ...................................................................... 144 (*VXB_I2C_LOCK_BUS_FUNC)( ) ................................................................. 145 (*VXB_I2C_UNLOCK_BUS_FUNC)( ) ........................................................... 145 (*VXB_I2C_START_FUNC)( ) .......................................................................... 145 (*VXB_I2C_STOP_FUNC)( ) ............................................................................ 146 (*VXB_I2C_READ_FUNC)( ) ........................................................................... 146 (*VXB_I2C_WRITE_FUNC)( ) ......................................................................... 146 (*VXB_I2C_DEV_READ)( ) .............................................................................. 147 (*VXB_I2C_DEV_WRITE)( ) ............................................................................ 147 9.8 Device Driver ................................................................................................................... 148 9.8.1 Generic I2C Devices .......................................................................................... 149 10 Interrupt Controller Drivers ........................................................................ 151 10.1 Introduction ..................................................................................................................... 151 10.2 Overview .......................................................................................................................... 152 Interrupt Identification .................................................................................... 152 Interrupt Controller Driver Responsibilities ................................................. 152 Interrupt Controller Configurations ............................................................... 153 Dynamic Vectors ................................................................................................ 153 Interrupt Controller Drivers and Multiprocessing ....................................... 154 VxBus Device Driver Developer's Guide, 6.9 x 10.3 VxBus Driver Methods .................................................................................................. 154 10.3.1 Basic Methods .................................................................................................... 154 {vxbIntCtlrAlloc}( ) ............................................................................................ 154 {vxbIntCtlrFree}( ) ............................................................................................. 155 {vxbIntCtlrConnect}( ) ...................................................................................... 155 {vxbIntCtlrDisconnect}( ) ................................................................................. 155 {vxbIntCtlrEnable}( ) ......................................................................................... 156 {vxbIntCtlrDisable}( ) ........................................................................................ 156 10.3.2 Dynamic Vector Methods ................................................................................ 156 {vxbIntDynaVecConnect}( ) ............................................................................. 156 10.3.3 Multiprocessor Methods ................................................................................. 157 {vxbIntCtlrIntReroute}( ) .................................................................................. 157 {vxbIntCtlrCpuReroute}( ) .............................................................................. 157 {vxIpiControlGet}( ) .......................................................................................... 157 10.4 Header Files ...................................................................................................................... 158 vxbIntrCtlr.h ....................................................................................................... 158 vxbIntCtlrLib.h .................................................................................................. 158 10.5 BSP Configuration .......................................................................................................... 158 10.5.1 Interrupt Input Table ........................................................................................ 159 10.5.2 Dynamic Vector Table ....................................................................................... 160 10.5.3 CPU Routing Table ............................................................................................ 162 10.5.4 Interrupt Priority ............................................................................................... 163 10.5.5 Crossbar Routing Table .................................................................................... 163 10.6 Available Utility Routines ............................................................................................. 164 10.6.1 intCtlrHwConfGet( ) ......................................................................................... 165 10.6.2 intCtlrISRAdd( ) ................................................................................................ 165 10.6.3 intCtlrISRDisable( ) ........................................................................................... 165 10.6.4 intCtlrISREnable( ) ............................................................................................ 166 10.6.5 intCtlrISRRemove( ) .......................................................................................... 166 10.6.6 intCtlrPinFind( ) ................................................................................................ 166 10.6.7 intCtlrTableArgGet( ) ........................................................................................ 166 10.6.8 intCtlrTableFlagsGet( ) ..................................................................................... 166 10.6.9 intCtlrTableIsrGet( ) .......................................................................................... 166 10.6.10 intCtlrHwConfShow( ) ..................................................................................... 166 10.6.11 intCtlrTableCreate( ) ......................................................................................... 167 10.6.12 intCtlrTableFlagsSet( ) ...................................................................................... 167 10.6.13 intCtlrTableUserSet( ) ....................................................................................... 167 10.6.14 VXB_INTCTLR_ISR_CALL( ) ......................................................................... 167 10.6.15 VXB_INTCTLR_PINENTRY_ENABLED( ) ................................................... 167 Contents xi 10.6.16 VXB_INTCTLR_PINENTRY_ALLOCATED( ) ............................................. 167 10.6.17 Dispatch Routines ............................................................................................. 168 vxbIntDynaCtlrInputInit( ) .............................................................................. 168 vxbIntDynaVecProgram( ) ............................................................................... 168 vxbIntDynaVecErase( ) ..................................................................................... 169 10.7 Initialization ..................................................................................................................... 169 10.8 Interrupt Controller Topologies and Hierarchies ..................................................... 169 10.9 Interrupt Priority ............................................................................................................. 170 10.10 ISR Dispatch .................................................................................................................... 171 10.11 Managing Dynamic Interrupt Vectors ........................................................................ 173 Configuring Dynamic Vectors Using the Service Driver Routines ............ 174 Configuring Dynamic Vectors in the BSP ..................................................... 174 Programming Dynamic Vectors ...................................................................... 175 Determining Dynamic Vector Values ............................................................ 175 10.12 Internal Representation of Interrupt Inputs .............................................................. 176 10.13 Multiprocessor Issues with VxWorks SMP ................................................................ 177 10.13.1 Routing Interrupt Inputs to Individual CPUs .............................................. 177 10.13.2 Interprocessor Interrupts ................................................................................. 178 10.13.3 Limitations in Multiprocessor Systems .......................................................... 182 10.14 Debugging ........................................................................................................................ 182 11 Multifunction Drivers .................................................................................. 185 11.1 Introduction ...................................................................................................................... 185 11.2 Overview ........................................................................................................................... 185 11.3 VxBus Driver Methods ................................................................................................... 186 11.4 Header Files ...................................................................................................................... 186 11.5 BSP Configuration .......................................................................................................... 186 11.6 Available Utility Routines ............................................................................................. 187 vxbDevStructAlloc( ) ........................................................................................ 187 vxbDeviceAnnounce( ) ..................................................................................... 187 vxbDevRemovalAnnounce( ) .......................................................................... 187 vxbDevStructFree( ) .......................................................................................... 188 vxbBusAnnounce( ) ........................................................................................... 188 11.7 Initialization ..................................................................................................................... 188 11.8 Device Interconnections ................................................................................................ 188 VxBus Device Driver Developer's Guide, 6.9 xii 11.8.1 Interleaved Registers ........................................................................................ 188 11.8.2 Shared Resources ............................................................................................... 189 11.8.3 Other Interactions ............................................................................................. 190 11.9 Logical Location of Subordinate Devices ................................................................... 190 11.10 Debugging ........................................................................................................................ 190 12 Network Drivers .......................................................................................... 191 12.1 Introduction ...................................................................................................................... 191 12.1.1 Terminology ....................................................................................................... 191 12.1.2 Networking Overview ..................................................................................... 192 Seven Layer OSI Model .................................................................................... 192 Transmission Media and VxWorks ................................................................. 192 Protocols ............................................................................................................. 193 12.2 Network Interface Drivers ............................................................................................. 193 12.2.1 Network Interface Driver Overview .............................................................. 193 IPNET-Native Drivers ...................................................................................... 193 Functional Modules .......................................................................................... 194 Network Driver Interrupts ............................................................................. 195 12.2.2 VxBus Driver Methods for Network Interface Drivers .............................. 196 {muxDevConnect}( ) ......................................................................................... 196 {muxDevConnect2}( ) ....................................................................................... 197 {vxbDrvUnlink}( ) .............................................................................................. 199 {miiMediaUpdate}( ) ......................................................................................... 199 {miiRead}( ) ........................................................................................................ 200 {miiWrite}( ) ........................................................................................................ 201 12.2.3 Header Files for Network Interface Drivers ................................................. 201 12.2.4 BSP Configuration for Network Interface Drivers ...................................... 202 12.2.5 Available Utility Routines for Network Interface Drivers ......................... 203 MUX Interactions .............................................................................................. 203 Job Queueing ..................................................................................................... 204 Buffer Management .......................................................................................... 205 DMA Support .................................................................................................... 209 PHY and MII bus interactions ......................................................................... 210 12.2.6 Initialization for Network Interface Drivers ................................................ 212 12.2.7 MUX: Connecting to Networking Code ........................................................ 212 12.2.8 jobQueueLib: Deferring ISRs ........................................................................... 213 12.2.9 Working with Ipcom_pkt Packets ................................................................... 214 Supporting Scatter-Gather with IPNET-Native Drivers .............................. 217 12.2.10 netBufLib: Transferring Data with M_BLKs ................................................ 218 12.2.11 Protocol Impact on Drivers .............................................................................. 220 Contents xiii 12.2.12 Other Network Interface Driver Issues .......................................................... 232 Receive Handling Method ............................................................................... 233 Receive Stall Handling ..................................................................................... 240 12.2.13 Debugging Network Interface Drivers .......................................................... 241 Using VxBus Show Routines ........................................................................... 241 Deferring Driver Registration ......................................................................... 241 Pairing with a PHY instance ............................................................................ 242 Stress Testing ...................................................................................................... 242 Netperf Test Suite .............................................................................................. 243 Interrupt Validation .......................................................................................... 243 Additional Tests ................................................................................................. 243 12.3 PHY Drivers ...................................................................................................................... 249 12.3.1 PHY Driver Overview ...................................................................................... 250 PHY Device Probing and Discovery .............................................................. 250 MAC and MII Bus Relationship ...................................................................... 251 Generic PHY Driver Support ........................................................................... 252 Generic TBI Driver Support ............................................................................. 252 12.3.2 VxBus Driver Methods for PHY Drivers ....................................................... 253 Upper Edge Methods ........................................................................................ 253 Lower Edge Methods ....................................................................................... 253 12.3.3 Header Files for PHY Drivers ......................................................................... 255 12.3.4 BSP Configuration for PHY Drivers ............................................................... 255 12.3.5 Available Utility Routines for PHY Drivers .................................................. 255 Upper Edge Utility Routines ........................................................................... 256 Lower Edge Utility Routines ........................................................................... 256 12.3.6 Initialization for PHY Drivers ......................................................................... 257 12.3.7 Debugging PHY Drivers .................................................................................. 257 12.4 Wireless Ethernet Drivers .............................................................................................. 258 12.5 Hierarchical END Drivers ............................................................................................. 258 13 Non-Volatile RAM Drivers .......................................................................... 259 13.1 Introduction ...................................................................................................................... 259 NVRAM Drivers and TrueFFS ........................................................................ 259 13.2 Non-Volatile RAM Drivers ........................................................................................... 260 13.2.1 NVRAM Driver Overview ............................................................................... 260 13.2.2 VxBus Driver Methods for NVRAM Drivers ................................................ 260 {nonVolGet}( ) .................................................................................................... 260 {nonVolSet}( ) ..................................................................................................... 261 13.2.3 Header Files ....................................................................................................... 261 13.2.4 BSP Configuration for NVRAM Drivers ....................................................... 261 VxBus Device Driver Developer's Guide, 6.9 xiv 13.2.5 Utility Routines for NVRAM Drivers ............................................................ 262 13.2.6 Initialization for NVRAM Drivers .................................................................. 262 13.2.7 NVRAM Block Sizes ......................................................................................... 262 13.2.8 Stacking NVRAM Instances ............................................................................ 263 13.2.9 Debugging NVRAM Drivers ........................................................................... 263 13.3 Flash File System Support with TrueFFS ................................................................... 263 13.3.1 TrueFFS Overview ............................................................................................. 264 Core Layer .......................................................................................................... 264 MTD Layer ........................................................................................................ 264 Socket Layer ....................................................................................................... 264 Flash Translation Layer .................................................................................... 265 13.3.2 TrueFFS Driver Development Process ........................................................... 265 Using MTD-Supported Flash Devices ........................................................... 265 Writing MTD Components .............................................................................. 269 Socket Drivers .................................................................................................... 276 Flash Translation Layer .................................................................................... 282 14 RapidIO Drivers ........................................................................................... 297 14.1 Introduction ...................................................................................................................... 297 14.2 Overview ........................................................................................................................... 297 14.3 VxBus Driver Methods ................................................................................................... 299 {vxbRapidIoCtlrInfoGet}( ) .............................................................................. 299 {sharedMemSupportAPIGet}( ) ....................................................................... 300 {vxbMsgApiGet}( ) ............................................................................................ 300 14.4 Header Files ...................................................................................................................... 301 14.5 BSP Configuration .......................................................................................................... 301 RapidIO Bus Controller Driver ....................................................................... 301 Virtual Message Network Device Driver ....................................................... 301 14.6 Initialization ..................................................................................................................... 302 Phase 1 ................................................................................................................ 302 Phase 2 ................................................................................................................ 302 Phase 3 ................................................................................................................ 303 14.7 Implementing Driver Service Routines ...................................................................... 303 RapidIO Bus Controller Driver ....................................................................... 303 Message Controller Driver ............................................................................... 307 15 Resource Drivers ........................................................................................ 311 15.1 Introduction ...................................................................................................................... 311 Contents xv 15.2 Overview ........................................................................................................................... 311 15.3 VxBus Driver Methods ................................................................................................... 312 15.4 Header Files ...................................................................................................................... 312 15.5 BSP Configuration .......................................................................................................... 312 15.6 Available Utility Routines ............................................................................................. 313 15.7 Initialization ..................................................................................................................... 313 15.8 Debugging ........................................................................................................................ 313 16 Serial Drivers ............................................................................................... 315 16.1 Introduction ...................................................................................................................... 315 16.2 Overview ........................................................................................................................... 315 16.3 VxBus Driver Methods ................................................................................................... 316 16.3.1 {sioChanGet}( ) ................................................................................................... 316 16.3.2 {sioChanConnect}( ) .......................................................................................... 317 16.4 Header Files ...................................................................................................................... 317 16.5 BSP Configuration .......................................................................................................... 318 16.6 Available Utility Routines ............................................................................................. 318 16.7 Initialization ..................................................................................................................... 318 16.8 Polled Mode Versus Interrupt-Driven Mode ............................................................. 318 16.9 SIO_CHAN and SIO_DRV_FUNCS ............................................................................ 319 16.10 WDB ................................................................................................................................... 321 16.10.1 WDB and Kernel Initialization ........................................................................ 321 16.11 Serial Drivers, Initialization, and Interrupts ............................................................. 321 16.11.1 WDB and Interrupts ......................................................................................... 322 16.11.2 Initialization Order and Interrupts ................................................................. 322 16.11.3 Initialization Order ........................................................................................... 323 16.12 Debugging ........................................................................................................................ 323 17 SPI Drivers ................................................................................................... 325 17.1 Introduction ...................................................................................................................... 325 17.2 Overview ........................................................................................................................... 325 VxBus Device Driver Developer's Guide, 6.9 xvi 17.3 VxBus Driver Methods ................................................................................................... 326 17.4 Header Files ...................................................................................................................... 326 17.5 BSP Configuration .......................................................................................................... 327 17.6 Initialization ..................................................................................................................... 328 17.7 Implementing Driver Service Routines ...................................................................... 329 17.8 Device Driver ................................................................................................................... 329 17.8.1 SPI_EEPROM ..................................................................................................... 330 17.8.2 SPI Flash ............................................................................................................. 330 18 Storage Drivers ........................................................................................... 333 18.1 Introduction ...................................................................................................................... 333 18.2 Overview ........................................................................................................................... 333 Updates in VxWorks 6.9, Update Pack 2, Service Pack 1 ............................ 334 Updates in VxWorks 6.9, Update Pack 3, Service Pack 3 ............................ 334 18.3 VxBus Driver Methods ................................................................................................... 335 18.4 Header Files ...................................................................................................................... 335 18.5 BSP Configuration .......................................................................................................... 336 18.6 Available Utility Routines ............................................................................................. 336 erfHandlerRegister( ) and erfHandlerUnregister( ) ..................................... 336 erfEventRaise( ) ................................................................................................. 336 xbdAttach( ) ....................................................................................................... 336 bio_done( ) .......................................................................................................... 337 18.7 Initialization ..................................................................................................................... 337 18.8 Interface with VxWorks File Systems ......................................................................... 337 18.8.1 Device Creation ................................................................................................. 337 ERF Registration ................................................................................................ 338 Advertisement of XBD Methods ..................................................................... 338 ERF New Device Notification ......................................................................... 339 18.8.2 Processing ........................................................................................................... 340 xbd_request processing .................................................................................... 340 18.8.3 Event Reporting ................................................................................................. 341 18.9 Writing New Storage Drivers ........................................................................................ 342 18.10 Writing New SD/MMC/SDIO host controller Drivers ............................................ 343 18.11 Device Driver ................................................................................................................... 344 Contents xvii 19 Timer Drivers ............................................................................................... 345 19.1 Introduction ...................................................................................................................... 345 19.2 Overview ........................................................................................................................... 345 19.3 VxBus Driver Methods ................................................................................................... 346 19.4 Header Files ...................................................................................................................... 349 19.5 BSP Configuration .......................................................................................................... 349 19.6 Available Utility Routines ............................................................................................. 349 19.7 Initialization ..................................................................................................................... 349 19.8 Data Structure Layout ..................................................................................................... 350 19.9 Implementing Driver Service Routines ...................................................................... 351 19.9.1 (*timerAllocate)( ) .............................................................................................. 351 19.9.2 (*timerRelease)( ) ............................................................................................... 351 19.9.3 (*timerRolloverGet)( ) ....................................................................................... 352 19.9.4 (*timerCountGet)( ) ........................................................................................... 352 19.9.5 (*timerDisable)( ) ............................................................................................... 353 19.9.6 (*timerEnable)( ) ................................................................................................ 354 19.9.7 (*timerISRSet)( ) ................................................................................................. 354 19.9.8 (*timerEnable64)( ) ............................................................................................ 355 19.9.9 (*timerRolloverGet64)( ) ................................................................................... 355 19.9.10 (*timerCountGet64)( ) ....................................................................................... 356 19.10 Integrating a Timer Driver ............................................................................................ 357 19.10.1 VxWorks System Clock .................................................................................... 357 19.10.2 VxWorks Auxiliary Clock ................................................................................ 359 19.10.3 VxWorks Timestamp Driver ............................................................................ 360 19.11 Debugging ........................................................................................................................ 361 19.12 SMP Considerations ....................................................................................................... 361 20 USB Drivers ................................................................................................. 363 20.1 Introduction ...................................................................................................................... 363 20.2 Wind River USB Overview ............................................................................................ 363 20.2.1 USB Host Stack Drivers .................................................................................... 364 VxBus Model Drivers ....................................................................................... 364 Other Host Drivers ............................................................................................ 364 VxBus Device Driver Developer's Guide, 6.9 xviii 20.2.2 USB Target Stack ............................................................................................... 364 20.3 Host Controller and Root Hub Class Drivers ............................................................ 365 20.3.1 VxBus Driver Methods ..................................................................................... 365 20.3.2 Header Files ....................................................................................................... 365 20.3.3 BSP Configuration ............................................................................................. 366 20.3.4 Available Utility Routines ................................................................................ 367 20.3.5 Initialization ....................................................................................................... 367 20.3.6 Debugging .......................................................................................................... 368 21 Other Driver Classes .................................................................................. 371 21.1 Introduction ...................................................................................................................... 371 21.2 Overview ........................................................................................................................... 371 21.3 VxBus Driver Methods ................................................................................................... 372 21.4 Header Files ...................................................................................................................... 373 21.5 BSP Configuration .......................................................................................................... 373 21.6 Available Utility Routines ............................................................................................. 373 21.7 Initialization ..................................................................................................................... 373 21.8 Debugging ........................................................................................................................ 374 PART III: DEVICE DRIVER PORTING 22 Legacy Drivers and Migration ................................................................... 377 22.1 Migration Overview ....................................................................................................... 377 22.2 Legacy Driver Overview ................................................................................................ 377 23 Migrating to VxBus ..................................................................................... 379 23.1 Overview ........................................................................................................................... 379 23.2 Available Resources ........................................................................................................ 379 Template Drivers ............................................................................................... 379 23.3 Porting an Existing VxWorks Driver to VxBus .......................................................... 380 23.3.1 Verifying Your Hardware and Driver Code .................................................. 380 23.3.2 Creating the VxBus Infrastructure ........
pdf
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 ............................................................................................
application/pdf
Paperback: 592 pages Publisher: Manning Publications; Second Edition edition (January 28, 2011) Part 1 What is Android? — The Big Picture 1 Targeting Android 1.1 Introducing Android 1.2 Stacking up Android 1.3 Booting Android development 1.4 An Android application 1.5 Summary 2 Development environment 2.1 The Android SDK 2.2 Fitting the pieces together 2.3 Building an Android application in Eclipse 2.4 The Android Emulator 2.5 Debugging 2.6 Summary Part 2 Exercising the Android SDK 3 User interfaces 3.1 Creating the Activity 3.2 Working with views 3.3 Using resources 3.4 Understanding the AndroidManifest file 3.5 Summary 4 Intents and services 4.1 Working with Intent classes 4.2 Listening in with broadcast receivers 4.3 Building a Service 4.4 Performing Inter-Process Communication 4.5 Summary 5 Storing and retrieving data 5.1 Using preferences 5.2 Using the filesystem 5.3 Persisting data to a database 5.4 Working with ContentProvider classes 5.5 Summary 6 Networking and web services 6.1 An overview of networking 6.2 Checking the network status 6.3 Communicating with a server socket 6.4 Working with HTTP 6.5 Web services 6.6 Summary 7 Telephony 7.1 Telephony background and terms 7.2 Accessing telephony information 7.3 Interacting with the phone 7.4 Working with messaging: SMS 7.5 Summary 8 Notifications and alarms 8.1 Introducing Toast 8.2 Introducing notifications 8.3 Alarms 8.4 Summary 9 Graphics and animation 9.1 Drawing graphics in Android 9.2 Animations 9.3 Summary 10 Multimedia 10.1 Introduction to multimedia and OpenCORE 10.2 Playing audio 10.3 Playing video 10.4 Capturing media 10.5 Summary 11 Location, location, location 11.1 Simulating your location within the emulator 11.2 Using LocationManager and LocationProvider 11.3 Working with maps 11.4 Converting places and addresses with Geocoder 11.5 Summary Part 3 Android applications 12 Putting it all together–the Field Service Application 12.1 Field Service Application requirements 12.2 Android application tour 12.3 Android code 12.4 Digging deeper into the code 12.5 Server code 12.6 Summary 13 Hacking Android 13.1 The Android/Linux:junction 13.2 A better way 13.3 What time is it? 13.4 Daytime Client 13.5 Summary
docx
一. 账号口令 1.1 检查设备密码复杂度策略(高危) 1.2 检查口令最小长度(高危) 1.3 检查是否设置口令更改最小间隔天数(高危) 1.4 检查是否设置口令生存周期(高危) 1.5 检查是否设置口令过期前警告天数(高危) 1.6 检查是否存在空口令账号(高危) 1.7 检查是否设置除root之外UID为0的用户(中危) 二. 认证授权 2.1 检查用户目录缺省访问权限设置(高危) 2.2 检查用户umask设置(中危) 2.3 检查重要文件属性设置(中危) 2.4 检查重要目录或文件权限设置(中危) 2.5 检查是否设置ssh登录前警告Banner(低危) 三. 日志审计 3.1 检查是否对登录进行日志记录(高危) 3.2 检查是否启用cron行为日志功能(低危) 3.3 检查是否配置su命令使用情况记录(低危) 3.4 检查日志文件是否非全局可写(低危) 3.5 检查安全事件日志配置(低危) 3.6 检查是否记录用户对设备的操作(低危) 3.7 检查是否配置远程日志功能(低危) 四. 协议安全 4.1 检查是否禁止root用户远程登录(高危) 4.2 检查是否禁止匿名用户登录FTP(高危) 4.3 检查使用IP协议远程维护的设备是否配置SSH协议,禁用telnet协议(高危) 4.4 检查是否修改snmp默认团体字(中危) 4.5 检查系统openssh安全配置(中危) 4.6 检查是否禁止root用户登录FTP(中危) 五. 其他安全 5.1 检查是否使用PAM认证模块禁止wheel组之外的用户su为root(高危) 5.2 检查是否设置命令行界面超时退出(高危) 5.3 检查是否关闭不必要的服务和端口(高危) 5.4 检查是否关闭系统信任机制(高危) 5.5 检查是否删除了潜在危险文件(高危) 5.6 检查系统core dump设置(中危) 5.7 检查root用户的path环境变量(中危) 5.8 检查系统是否禁用ctrl+alt+del组合键(中危) 5.9 检查密码重复使用次数限制(中危) 5.10 检查是否配置用户所需最小权限(中危) 5.11 检查系统内核参数配置(中危) 5.12 检查FTP用户上传的文件所具有的权限(低危) 5.13 检查/usr/bin/目录下可执行文件的拥有者属性(低危) 5.14 检查是否按用户分配账号(低危) 5.15 检查历史命令设置(低危) 5.16 检查系统磁盘分区使用率(低危) 5.17 检查日志文件权限设置(低危) 5.18 检查是否设置系统引导管理器密码(低危) 5.19 检查是否限制FTP用户登录后能访问的目录(低危) 5.20 检查是否设置ssh成功登录后Banner(低危) 5.21 检查是否使用NTP(网络时间协议)保持时间同步(低危) 5.22 检查是否关闭IP伪装和绑定多IP功能(低危) 5.23 检查是否限制远程登录IP范围(低危) 5.24 检查NFS(网络文件系统)服务配置(低危) 5.25 检查拥有suid和sgid权限的文件(低危) 5.26 检查是否配置定时自动屏幕锁定(适用于具备图形界面的设备)(低危) 5.27 检查是否安装chkrootkit进行系统监测(低危) 5.28 检查是否对系统账号进行登录限制(低危) 5.29 检查是否禁用不必要的系统服务(低危) 5.30 检查别名文件/etc/aliase(或/etc/mail/aliases)配置(低危) 5.31 检查账户认证失败次数限制(低危) 5.32 检查telnet Banner 设置(低危) 5.33 检查FTP Banner设置(低危) 5.34 检查是否关闭数据包转发功能(适用于不做路由功能的系统)(低危) 5.35 检查是否安装OS补丁(低危) 5.36 检查是否按组进行账号管理(低危) 5.37 检查是否删除与设备运行、维护等工作无关的账号(低危)
application/pdf
老资源。 目录 1 声明和初始化1 1.1 我如何决定使用那种整数类型? . . . . . . . . . . . . . . . . . . . 1 1.2 64 位机上的64 位类型是什么样的? . . . . . . . . . . . . . . . . 1 1.3 怎样定义和声明全局变量和函数最好? . . . . . . . . . . . . . . . 2 1.4 extern 在函数声明中是什么意思? . . . . . . . . . . . . . . . . . 2 1.5 关键字auto 到底有什么用途? . . . . . . . . . . . . . . . . . . . 2 1.6 我似乎不能成功定义一个链表。我试过typedef struct f char *item; NODEPTR next; g *NODEPTR; 但是编译器报了错误信 息。难道在C语言中一个结构不能包含指向自己的指针吗? . . . . 3 1.7 怎样建立和理解非常复杂的声明?例如定义一个包含N 个指向返 回指向字符的指针的函数的指针的数组? . . . . . . . . . . . . . . 3 1.8 函数只定义了一次, 调用了一次, 但编译器提示非法重定义了。. . 4 1.9 main() 的正确定义是什么? void main() 正确吗? . . . . . . . . . 4 1.10 对于没有初始化的变量的初始值可以作怎样的假定?如果一个全 局变量初始值为“零”, 它可否作为空指针或浮点零? . . . . . . . 4 1.11 代码int f() f char a[] = "Hello, world!";g 不能编译。. . . . . . . 5 1.12 这样的初始化有什么问题?char *p = malloc(10); 编译器提示“非 法初始式” 云云。. . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.13 以下的初始化有什么区别?char a[] = "string literal"; char *p = "string literal"; 当我向p[i] 赋值的时候, 我的程序崩溃了。. . . . 5 1.14 我总算弄清除函数指针的声明方法了, 但怎样才能初始化呢? . . 5 2 结构、联合和枚举7 2.1 声明struct x1 f . . . g; 和typedef struct f . . . g x2; 有什么不同? . 7 2.2 为什么struct x f . . . g; x thestruct; 不对? . . . . . . . . . . . . . 7 2.3 一个结构可以包含指向自己的指针吗? . . . . . . . . . . . . . . . 7 2.4 在C 语言中实现抽象数据类型什么方法最好? . . . . . . . . . . . 7 2.5 在C 中是否有模拟继承等面向对象程序设计特性的好方法? . . . 7 i 目录ii 2.6 我遇到这样声明结构的代码: struct name f int namelen; char namestr[1];g; 然后又使用一些内存分配技巧使namestr 数组用起 来好像有多个元素。这样合法和可移植吗? . . . . . . . . . . . . 8 2.7 是否有自动比较结构的方法? . . . . . . . . . . . . . . . . . . . . 8 2.8 如何向接受结构参数的函数传入常数值? . . . . . . . . . . . . . . 8 2.9 怎样从/向数据文件读/写结构? . . . . . . . . . . . . . . . . . . . 9 2.10 我的编译器在结构中留下了空洞, 这导致空间浪费而且无法与外 部数据文件进行”二进制” 读写。能否关掉填充, 或者控制结构域 的对齐方式? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.11 为什么sizeof 返回的值大于结构的期望值, 是不是尾部有填充? . . 9 2.12 如何确定域在结构中的字节偏移? . . . . . . . . . . . . . . . . . 9 2.13 怎样在运行时用名字访问结构中的域? . . . . . . . . . . . . . . . 10 2.14 程序运行正确, 但退出时却“core dump”了,怎么回事? . . . . . 10 2.15 可以初始化一个联合吗? . . . . . . . . . . . . . . . . . . . . . . . 10 2.16 枚举和一组预处理的#define 有什么不同? . . . . . . . . . . . . 10 2.17 有什么容易的显示枚举值符号的方法? . . . . . . . . . . . . . . . 11 3 表达式13 3.1 为什么这样的代码: a[i] = i++; 不能工作? . . . . . . . . . . . . 13 3.2 使用我的编译器,下面的代码int i=7; printf("%dnn", i++ * i++); 返回49?不管按什么顺序计算, 难道不该打印出56吗? . . . . . . 13 3.3 对于代码int i = 3; i = i++; 不同编译器给出不同的结果, 有的为 3, 有的为4, 哪个是正确的? . . . . . . . . . . . . . . . . . . . . . 14 3.4 这是个巧妙的表达式: a ˆ= b ˆ= a ˆ= b 它不需要临时变量就可 以交换a 和b 的值。. . . . . . . . . . . . . . . . . . . . . . . . . 14 3.5 我可否用括号来强制执行我所需要的计算顺序? . . . . . . . . . . 14 3.6 可是&& 和|| 运算符呢?我看到过类似while((c = getchar()) != EOF && c != ’nn’) 的代码⋯⋯ . . . . . . . . . . . . . . . . . . 14 3.7 我怎样才能理解复杂表达式?“序列点” 是什么? . . . . . . . . . 15 3.8 那么, 对于a[i] = i++; 我们不知道a[] 的哪一个分量会被改写,但i 的确会增加1, 对吗? . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.9 ++i 和i++ 有什么区别? . . . . . . . . . . . . . . . . . . . . . . 15 3.10 如果我不使用表达式的值, 我应该用++i 或i++ 来自增一个变量 吗? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.11 为什么如下的代码int a = 100, b = 100; long int c = a * b; 不能 工作? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.12 我需要根据条件把一个复杂的表达式赋值给两个变量中的一 个。可以用下边这样的代码吗? ((condition) ? a : b) = complicated expression; . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 目录iii 4 指针17 4.1 我想声明一个指针并为它分配一些空间, 但却不行。这些代码有 什么问题?char *p; *p = malloc(10); . . . . . . . . . . . . . . . . 17 4.2 *p++ 自增p 还是p 所指向的变量? . . . . . . . . . . . . . . . . 17 4.3 我有一个char * 型指针正巧指向一些int 型变量, 我想跳过它们。 为什么如下的代码((int *)p)++; 不行? . . . . . . . . . . . . . . 17 4.4 我有个函数,它应该接受并初始化一个指针void f(int *ip) f static int dummy = 5; ip = &dummy;g 但是当我如下调用时: int *ip; f(ip); 调用者的指针却没有任何变化。. . . . . . . . . . . . . . . 18 4.5 我能否用void** 指针作为参数, 使函数按引用接受一般指针? . . 18 4.6 我有一个函数extern int f(int *); 它接受指向int 型的指针。我怎 样用引用方式传入一个常数?下面这样的调用f(&5); 似乎不行。. 18 4.7 C 有“按引用传递” 吗? . . . . . . . . . . . . . . . . . . . . . . . 18 4.8 我看到了用指针调用函数的不同语法形式。到底怎么回事? . . . 19 4.9 我怎样把一个int 变量转换为char * 型?我试了类型转换, 但是不 行。. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 5 空(null) 指针21 5.1 臭名昭著的空指针到底是什么? . . . . . . . . . . . . . . . . . . . 21 5.2 怎样在程序里获得一个空指针? . . . . . . . . . . . . . . . . . . . 21 5.3 用缩写的指针比较“if(p)” 检查空指针是否可靠?如果空指针的内 部表达不是0 会怎么样? . . . . . . . . . . . . . . . . . . . . . . . 22 5.4 NULL 是什么, 它是怎么定义的? . . . . . . . . . . . . . . . . . . 23 5.5 在使用非全零作为空指针内部表达的机器上, NULL 是如何定义 的? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 5.6 如果NULL 定义成#define NULL ((char *)0) 难道不就可以向函 数传入不加转换的NULL 了吗? . . . . . . . . . . . . . . . . . . 23 5.7 如果NULL 和0 作为空指针常数是等价的, 那我到底该用哪一个 呢? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 5.8 但是如果NULL 的值改变了, 比如在使用非零内部空指针的机器 上, 难道用NULL (而不是0) 不是更好吗? . . . . . . . . . . . . . 24 5.9 用预定义宏#define Nullptr(type) (type *)0 帮助创建正确类型的 空指针。. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 5.10 这有点奇怪。NULL 可以确保是0, 但空(null) 指针却不一定? . . 24 5.11 为什么有那么多关于空指针的疑惑?为什么这些问题如此经常地 出现? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 5.12 我很困惑。我就是不能理解这些空指针一类的东西。. . . . . . . 25 5.13 考虑到有关空指针的所有这些困惑, 难道把要求它们内部表达都 必须为0 不是更简单吗? . . . . . . . . . . . . . . . . . . . . . . . 26 5.14 说真的, 真有机器用非零空指针吗, 或者不同类型用不同的表达? 26 目录iv 5.15 运行时的“空指针赋值” 错误是什么意思? . . . . . . . . . . . . . 26 6 数组和指针27 6.1 我在一个源文件中定义了char a[6], 在另一个中声明了extern char *a 。为什么不行? . . . . . . . . . . . . . . . . . . . . . . . 27 6.2 可是我听说char a[ ] 和char *a 是一样的。. . . . . . . . . . . . . 27 6.3 那么, 在C 语言中“指针和数组等价” 到底是什么意思? . . . . . 28 6.4 那么为什么作为函数形参的数组和指针申明可以互换呢? . . . . . 28 6.5 如果你不能给它赋值, 那么数组如何能成为左值呢? . . . . . . . . 29 6.6 现实地讲, 数组和指针地区别是什么? . . . . . . . . . . . . . . . 29 6.7 有人跟我讲, 数组不过是常指针。. . . . . . . . . . . . . . . . . . 29 6.8 我遇到一些“搞笑” 的代码, 包含5["abcdef"] 这样的“表达式”。 这为什么是合法的C 表达式呢? . . . . . . . . . . . . . . . . . . 29 6.9 既然数组引用会蜕化为指针, 如果arr 是数组, 那么arr 和&arr 又 有什么区别呢? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 6.10 我如何声明一个数组指针? . . . . . . . . . . . . . . . . . . . . . 30 6.11 我如何在运行期设定数组的大小?我怎样才能避免固定大小的数 组? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 6.12 我如何声明大小和传入的数组一样的局部数组? . . . . . . . . . . 30 6.13 我该如何动态分配多维数组? . . . . . . . . . . . . . . . . . . . . 31 6.14 有个灵巧的窍门: 如果我这样写int realarray[10]; int *array = &realarray[-1]; 我就可以把“array” 当作下标从1 开始的数组。. . 32 6.15 当我向一个接受指针的指针的函数传入二维数组的时候, 编译器 报错了。. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 6.16 我怎样编写接受编译时宽度未知的二维数组的函数? . . . . . . . 32 6.17 我怎样在函数参数传递时混用静态和动态多维数组? . . . . . . . 33 6.18 当数组是函数的参数时, 为什么sizeof 不能正确报告数组的大小? 34 7 内存分配35 7.1 为什么这段代码不行?char *answer; printf("Type something:nn"); gets(answer); printf("You typed n"%sn"nn", answer); . . . . . . . 35 7.2 我的strcat() 不行.我试了char *s1 = "Hello, "; char *s2 = "world!"; char *s3 = strcat(s1, s2); 但是我得到了奇怪的结果。. . . . . . . 35 7.3 但是strcat 的手册页说它接受两个char * 型参数。我怎么知道 (空间) 分配的事情呢? . . . . . . . . . . . . . . . . . . . . . . . . 36 7.4 我刚才试了这样的代码char *p; strcpy(p, "abc"); 而它运行正 常?怎么回事?为什么它没有崩溃? . . . . . . . . . . . . . . . . 36 7.5 一个指针变量分配多少内存? . . . . . . . . . . . . . . . . . . . . 36 7.6 我有个函数, 本该返回一个字符串, 但当它返回调用者的时候, 返 回串却是垃圾信息。. . . . . . . . . . . . . . . . . . . . . . . . . 36 目录v 7.7 那么返回字符串或其它集合的争取方法是什么呢? . . . . . . . . 37 7.8 为什么在调用malloc() 时, 我得到“警告: 整数赋向指针需要类型 转换”? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 7.9 为什么有些代码小心地把malloc 返回的值转换为分配的指针类型。37 7.10 在调用malloc() 的时候, 错误“不能把void * 转换为int *” 是什 么意思? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 7.11 我见到了这样的代码char *p = malloc(strlen(s) + 1); strcpy(p, s); 难道不应该是malloc((strlen(s) + 1) * sizeof(char))? . . . . . 37 7.12 我如何动态分配数组? . . . . . . . . . . . . . . . . . . . . . . . . 38 7.13 我听说有的操作系统程序使用的时候才真正分配malloc 申请的内 存。这合法吗? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 7.14 我用一行这样的代码分配一个巨大的数组, 用于数字运算: double *array = malloc(300 * 300 * sizeof( double )); malloc() 并没有返 回null, 但是程序运行得有些奇怪, 好像改写了某些内存, 或者 malloc() 并没有分配我申请的那么多内存, 云云。. . . . . . . . . 38 7.15 我的PC 有8 兆内存。为什么我只能分配640K 左右的内存? . . 38 7.16 我的程序总是崩溃, 显然在malloc 内部的某个地方。但是我看不 出哪里有问题。是malloc() 有bug 吗? . . . . . . . . . . . . . . . 38 7.17 动态分配的内存一旦释放之后你就不能再使用, 是吧? . . . . . . 38 7.18 为什么在调用free() 之后指针没有变空?使用(赋值, 比较) 释放 之后的指针有多么不安全? . . . . . . . . . . . . . . . . . . . . . 39 7.19 当我malloc() 为一个函数的局部指针分配内存时, 我还需要用 free() 明确的释放吗? . . . . . . . . . . . . . . . . . . . . . . . . 39 7.20 我在分配一些结构, 它们包含指向其它动态分配的对象的指针。 我在释放结构的时候, 还需要释放每一个下级指针吗? . . . . . . 39 7.21 我必须在程序退出之前释放分配的所有内存吗? . . . . . . . . . . 40 7.22 我有个程序分配了大量的内存, 然后又释放了。但是从操作系统 看, 内存的占用率却并没有回去。. . . . . . . . . . . . . . . . . . 40 7.23 free() 怎么知道有多少字节需要释放? . . . . . . . . . . . . . . . 40 7.24 那么我能否查询malloc 包, 可分配的最大块是多大? . . . . . . . 40 7.25 向realloc() 的第一个参数传入空指针合法吗?你为什么要这样做? 40 7.26 calloc() 和malloc() 有什么区别?利用calloc 的零填充功能安全 吗?free() 可以释放calloc() 分配的内存吗, 还是需要一个cfree()? 40 7.27 alloca() 是什么?为什么不提倡使用它? . . . . . . . . . . . . . . 41 8 字符和字符串43 8.1 为什么strcat(string, ’!’); 不行? . . . . . . . . . . . . . . . . . . 43 8.2 我在检查一个字符串是否跟某个值匹配。为什么这样不行?char *string; . . . if(string == "value") f /* string matches ”value” */ . . . g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 目录vi 8.3 如果我可以写char a[] = "Hello, world!"; 为什么我不能写char a[14]; a = "Hello, world!"; . . . . . . . . . . . . . . . . . . . . . . 43 8.4 我怎么得到对应字符的数字(字符集) 值, 或者相反? . . . . . . . 44 8.5 我认为我的编译器有问题: 我注意到sizeof(’a’) 是2 而不是1 (即, 不是sizeof(char))。. . . . . . . . . . . . . . . . . . . . . . . . . . 44 9 布尔表达式和变量45 9.1 C 语言中布尔值的候选类型是什么?为什么它不是一个标准类 型?我应该用#define 或enum 定义true 和false 值吗? . . . . . 45 9.2 因为在C 语言中所有的非零值都被看作“真”, 是不是把TRUE 定 义为1 很危险?如果某个内置的函数或关系操作符“返回” 不是1 的其它值怎么办? . . . . . . . . . . . . . . . . . . . . . . . . . . 45 9.3 当p 是指针时, if(p) 是合法的表达式吗? . . . . . . . . . . . . . 46 10 C 预处理器47 10.1 这些机巧的预处理宏: #define begin f #define end g 你觉得怎么 样? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 10.2 怎么写一个一般用途的宏交换两个值? . . . . . . . . . . . . . . . 47 10.3 书写多语句宏的最好方法是什么? . . . . . . . . . . . . . . . . . 47 10.4 我第一次把一个程序分成多个源文件, 我不知道该把什么放到.c 文件, 把什么放到.h 文件。(“.h” 到底是什么意思?) . . . . . . . 48 10.5 一个头文件可以包含另一头文件吗? . . . . . . . . . . . . . . . . 48 10.6 #include 和#include "" 有什么区别? . . . . . . . . . . . . 48 10.7 完整的头文件搜索规则是怎样的? . . . . . . . . . . . . . . . . . 49 10.8 我在文件的第一个声明就遇到奇怪的语法错误, 但是看上去没什 么问题。. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 10.9 我包含了我使用的库函数的正确头文件, 可是连接器还是说它没 有定义。. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 10.10 我在编译一个程序, 看起来我好像缺少需要的一个或多个头文 件。谁能发给我一份? . . . . . . . . . . . . . . . . . . . . . . . . 49 10.11 我怎样构造比较字符串的#if 预处理表达式? . . . . . . . . . . . 49 10.12 sizeof 操作符可以用于#if 预编译指令中吗? . . . . . . . . . . . . 50 10.13 我可以在#include 行里使用#ifdef 来定义两个不同的东西吗? . 50 10.14 对typdef 的类型定义有没有类似#ifdef的东西? . . . . . . . . . 50 10.15 我如何用#if 表达式来判断机器是高字节在前还是低字节在前? . 50 10.16 我得到了一些代码, 里边有太多的#ifdef。我不想使用预处理器 把所有的#include 和#ifdef 都扩展开, 有什么办法只保留一种条 件的代码呢? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 10.17 如何列出所有的预定义标识符? . . . . . . . . . . . . . . . . . . . 50 目录vii 10.18 我有些旧代码, 试图用这样的宏来构造标识符#define Paste(a, b) a/**/b 但是现在不行了。. . . . . . . . . . . . . . . . . . . . . . 51 10.19 为什么宏#define TRACE(n) printf("TRACE: %dnn", n) 报出警 告“用字符串常量代替宏”?它似乎应该把TRACE(count); 扩展 为printf("TRACE: %dncount", count); . . . . . . . . . . . . . . 51 10.20 使用# 操作符时, 我在字符串常量内使用宏参数有问题。. . . . . 51 10.21 我想用预处理做某件事情, 但却不知道如何下手。. . . . . . . . . 51 10.22 怎样写参数个数可变的宏? . . . . . . . . . . . . . . . . . . . . . 51 11 ANSI/ISO 标准C 53 11.1 什么是“ANSI C 标准”? . . . . . . . . . . . . . . . . . . . . . . . 53 11.2 我如何得到一份标准的副本? . . . . . . . . . . . . . . . . . . . . 53 11.3 我在哪里可以找到标准的更新? . . . . . . . . . . . . . . . . . . . 54 11.4 很多ANSI 编译器在遇到以下代码时都会警告类型不匹配。 extern int func(float); int func(x) float x; f . . . . . . . . . . . . . 54 11.5 能否混用旧式的和新型的函数语法? . . . . . . . . . . . . . . . . 55 11.6 为什么声明extern int f(struct x *p); 报出了一个奇怪的警告信 息“结构x 在参数列表中声明”? . . . . . . . . . . . . . . . . . . 55 11.7 我不明白为什么我不能象这样在初始化和数组维度中使用常量: const int n = 5; int a[n]; . . . . . . . . . . . . . . . . . . . . . . . 55 11.8 既然不能修改字符串常量, 为什么不把它们定义为字符常量的数 组? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 11.9 “const char *p” 和“char * const p” 有何区别? . . . . . . . . . . 56 11.10 为什么我不能向接受const char ** 的函数传入char **? . . . . . 56 11.11 怎样正确声明main()? . . . . . . . . . . . . . . . . . . . . . . . . 56 11.12 我能否把main() 定义为void, 以避免扰人的“main无返回值” 警 告? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 11.13 可main() 的第三个参数envp 是怎么回事? . . . . . . . . . . . . 57 11.14 我觉得把main() 声明为void 不会失败, 因为我调用了exit() 而不 是return , 况且我的操作系统也忽略了程序的退出/返回状态。. . 57 11.15 那么到底会出什么问题?真的有什么系统不支持void main() 吗? 57 11.16 我一直用的那本书《熟练傻瓜C语言》总是使用void main()。. . 57 11.17 从main() 中, exit(status) 和返回同样的status 真的等价吗? . . . 57 11.18 我试图用ANSI “字符串化” 预处理操作符# 向信息中插入符号 常量的值, 但它字符串化的总是宏的名字而不是它的值。. . . . . 58 11.19 警告信息“warning: macro replacement within a string literal” 是 什么意思? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 11.20 在我用#ifdef 去掉的代码里出现了奇怪的语法错误。. . . . . . . 58 11.21 #pragma 是什么, 有什么用? . . . . . . . . . . . . . . . . . . . . 59 11.22 “#pragma once” 是什么意思?我在一些头文件中看到了它。. . 59 11.23 a[3] = "abc"; 合法吗?它是什么意思? . . . . . . . . . . . . . . . 59 11.24 为什么我不能对void* 指针进行运算? . . . . . . . . . . . . . . . 59 11.25 memcpy() 和memmove() 有什么区别? . . . . . . . . . . . . . . 59 11.26 malloc(0) 有什么用?返回一个控指针还是指向0 字节的指针? . 59 11.27 为什么ANSI 标准规定了外部标示符的长度和大小写限制? . . . 60 11.28 我的编译对最简单的测试程序报出了一大堆的语法错误。. . . . . 60 11.29 为什么有些ASNI/ISO 标准库函数未定义?我明明使用的就是 ANSI 编译器。. . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 11.30 谁有把旧的C 程序转化为ANSI C 或相反的工具, 或者自动生成 原型的工具? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 11.31 为什么声称兼容ANSI 的Frobozz Magic C 编译器不能编译这些 代码?我知道这些代码是ANSI 的, 因为gcc 可以编译。. . . . . 60 11.32 人们好像有些在意实现定义(implementation-defin-ed)、未明确 (unspecified) 和无定义(undefined) 行为的区别。它们的区别到底 在哪里? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 11.33 一个程序的“合法”, “有效” 或“符合” 到底是什么意思? . . . . . 61 11.34 我很吃惊, ANSI 标准竟然有那么多没有定义的东西。标准的唯一 任务不就是让这些东西标准化吗? . . . . . . . . . . . . . . . . . 61 11.35 有人说i = i++ 的行为是未定义的, 但是我刚在一个兼容ANSI 的 编译器上测试, 得到了我希望的结果。. . . . . . . . . . . . . . . 62 12 标准输入输出库63 12.1 这样的代码有什么问题?char c; while((c = getchar()) != EOF) ... 63 12.2 我有个读取直到EOF 的简单程序, 但是我如何才能在键盘上输入 那个“EOF” 呢? . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 12.3 为什么这些代码while(!feof(infp)) f fgets(buf, MAXLINE, infp); fputs(buf, outfp); g 把最后一行复制了两遍? . . . . . . . . . . . 63 12.4 我的程序的屏幕提示和中间输出有时显示在屏幕上, 尤其是当我 用管道向另一个程序输出的时候。. . . . . . . . . . . . . . . . . 63 12.5 我怎样不等待回车键一次输入一个字符? . . . . . . . . . . . . . . 64 12.6 我如何在printf 的格式串中输出一个’%’?我试过n%, 但是不行。64 12.7 有人告诉我在printf 中使用%lf 不正确。那么, 如果scanf() 需要 %lf, 怎么可以用在printf() 中用%f 输出双精度数呢? . . . . . . . 64 12.8 对于size t 那样的类型定义, 当我不知道它到底是long 还是其它 类型的时候, 我应该使用什么样的printf 格式呢? . . . . . . . . . 64 12.9 我如何用printf 实现可变的域宽度?就是说, 我想在运行时确定 宽度而不是使用%8d? . . . . . . . . . . . . . . . . . . . . . . . . 64 12.10 如何输出在千位上用逗号隔开的数字?金额数字呢? . . . . . . . 65 12.11 为什么scanf("%d", i) 调用不行? . . . . . . . . . . . . . . . . . . 65 12.12 为什么char s[30]; scanf("%s", s); 不用& 也可以? . . . . . . . . 65 目录ix 12.13 为什么这些代码double d; scanf("%f", &d); 不行? . . . . . . . . 65 12.14 怎样在scanf() 格式串中指定可变的宽度? . . . . . . . . . . . . . 65 12.15 当我用“%dnn” 调用scanf 从键盘读取数字的时候, 好像要多输入 一行函数才返回。. . . . . . . . . . . . . . . . . . . . . . . . . . 65 12.16 我用scanf %d 读取一个数字, 然后再用gets() 读取字符串, 但是 编译器好像跳过了gets() 调用! . . . . . . . . . . . . . . . . . . . 66 12.17 我发现如果坚持检查返回值以确保用户输入的是我期待的数值, 则scanf() 的使用会安全很多, 但有的时候好像会陷入无限循环。. 66 12.18 为什么大家都说不要使用scanf()?那我该用什么来代替呢? . . . 66 12.19 我怎样才知道对于任意的sprintf 调用需要多大的目标缓冲区?怎 样才能避免sprintf() 目标缓冲区溢出? . . . . . . . . . . . . . . . 66 12.20 为什么大家都说不要使用gets()? . . . . . . . . . . . . . . . . . . 67 12.21 为什么调用printf() 之后errno 内有ENOTTY? . . . . . . . . . . 67 12.22 fgetops/fsetops 和ftell/fseek 之间有什么区别? fgetops() 和fsetops() 到底有什么用处? . . . . . . . . . . . . . . . . . . . . . . . 68 12.23 如何清除多余的输入, 以防止在下一个提示符下读入?fflush(stdin) 可以吗? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 12.24 既然fflush() 不能, 那么怎样才能清除输入呢? . . . . . . . . . . . 68 12.25 对某些路径文件名调用fopen() 总是失败。. . . . . . . . . . . . . 68 12.26 我想用“r+” 打开一个文件, 读出一个字符串, 修改之后再写入, 从 而就地更新一个文件。可是这样不行。. . . . . . . . . . . . . . . 69 12.27 怎样在程序里把stdin 或stdout 重定向到文件? . . . . . . . . . . 69 12.28 一旦使用freopen() 之后, 怎样才能恢复原来的stdout (或stdin)? 69 12.29 怎样同时向两个地方输出, 如同时输出到屏幕和文件? . . . . . . 69 12.30 怎样正确的读取二进制文件?我有时看到0x0a 和0x0d 混淆了, 而且如果数据中包含0x1a 的话, 我好像会提前遇到EOF。. . . . 70 13 库函数71 13.1 怎样把数字转为字符串(与atoi 相反)?有itoa() 函数吗? . . . . 71 13.2 为什么strncpy() 不能总在目标串放上终止符’n0’? . . . . . . . 71 13.3 为什么有些版本的toupper() 对大写字符会有奇怪的反应?为什 么有的代码在调用toupper() 前先调用tolower()? . . . . . . . . . 71 13.4 怎样把字符串分隔成用空白作间隔符的段?怎样实现类似传递给 main() 的argc 和argv? . . . . . . . . . . . . . . . . . . . . . . . 72 13.5 我需要一些处理正则表达式或通配符匹配的代码。. . . . . . . . 72 13.6 我想用strcmp() 作为比较函数, 调用qsort() 对一个字符串数组排 序, 但是不行。. . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 13.7 我想用qsort() 对一个结构数组排序。我的比较函数接受结构指 针, 但是编译器认为这个函数对于qsort() 是错误类型。我要怎样 转换这个函数指针才能避免这样的警告? . . . . . . . . . . . . . . 73 13.8 怎样对一个链表排序? . . . . . . . . . . . . . . . . . . . . . . . . 73 13.9 怎样对多于内存的数据排序? . . . . . . . . . . . . . . . . . . . . 73 13.10 怎样在C 程序中取得当前日期或时间? . . . . . . . . . . . . . . . 73 13.11 我知道库函数localtime() 可以把time t 转换成结构struct tm, 而 ctime() 可以把time t 转换成为可打印的字符串。怎样才能进行 反向操作, 把struct tm 或一个字符串转换成time t? . . . . . . . 74 13.12 怎样在日期上加N 天?怎样取得两个日期的时间间隔? . . . . . . 74 13.13 我需要一个随机数生成器。. . . . . . . . . . . . . . . . . . . . . 75 13.14 怎样获得在一定范围内的随机数? . . . . . . . . . . . . . . . . . 75 13.15 每次执行程序, rand() 都返回相同顺序的数字。. . . . . . . . . . 75 13.16 我需要随机的真/假值, 所以我用直接用rand() % 2, 可是我得到 交替的0, 1, 0, 1, 0 ⋯⋯ . . . . . . . . . . . . . . . . . . . . . . . 76 13.17 怎样产生标准分布或高斯分布的随机数? . . . . . . . . . . . . . . 76 13.18 我不断得到库函数未定义错误, 但是我已经#inlude 了所有用到 的头文件了。. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 13.19 虽然我在连接时明确地指定了正确的函数库, 我还是得到库函数 未定义错误。. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 13.20 连接器说end 未定义代表什么意思? . . . . . . . . . . . . . . . . 77 13.21 我的编译器提示printf 未定义!这怎么可能? . . . . . . . . . . . 77 14 浮点运算79 14.1 一个float 变量赋值为3.1 时, 为什么printf 输出的值为3.0999999? 79 14.2 执行一些开方根运算, 可是得到一些疯狂的数字。. . . . . . . . . 79 14.3 做一些简单的三角函数运算, 也引用了#include , 可是 一直得到编译错误“undefined: sin” (函数sin 未定义)。. . . . . . 79 14.4 浮点计算程序表现奇怪, 在不同的机器上给出不同的结果。. . . . 79 14.5 有什么好的方法来验对浮点数在“足够接近” 情况下的等值? . . . 80 14.6 怎样取整数? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 14.7 为什么C 不提供乘幂的运算符? . . . . . . . . . . . . . . . . . . 80 14.8 为什么我机器上的 没有预定义常数M PI? . . . . . . 80 14.9 怎样测试IEEE NaN 以及其它特殊值? . . . . . . . . . . . . . . . 81 14.10 在C 中如何很好的实现复数? . . . . . . . . . . . . . . . . . . . . 81 14.11 我要寻找一些实现以下功能的程序源代码:快速傅立叶变换 (FFT)、矩阵算术(乘法、倒置等函数)、复数算术。. . . . . . . 81 14.12 Turbo C 的程序崩溃, 显示错误为“floating point formats not linked” (浮点格式未连接)。. . . . . . . . . . . . . . . . . . . . . 81 15 可变参数83 15.1 为什么调用printf() 前, 必须要用#include ? . . . . . 83 15.2 为什么%f 可以在printf() 参数中, 同时表示float 和double?他们 难道不是不同类型吗? . . . . . . . . . . . . . . . . . . . . . . . . 83 15.3 为什么当n 为long int, printf("%d", n); 编译时没有匹配警告? 我以为ANSI 函数原型可以防止这样的类型不匹配。. . . . . . . 83 15.4 怎样写一个有可变参数的函数? . . . . . . . . . . . . . . . . . . . 83 15.5 怎样写类似printf() 的函数, 再把参数转传给printf() 去完成大部 分工作? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 15.6 怎样写类似scanf() 的函数, 再把参数转传给scanf() 去完成大部 分工作? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 15.7 怎样知道实际上有多少个参数传入函数? . . . . . . . . . . . . . . 85 15.8 为什么编译器不让我定义一个没有固定参数项的可变参数函数? . 86 15.9 我有个接受float 的可变参函数, 为什么va arg(argp, float) 不工作? 86 15.10 va arg() 不能得到类型为函数指针的参数。. . . . . . . . . . . . . 86 15.11 怎样实现一个可变参数函数, 它把参数再传给另一个可变参数函 数? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 15.12 怎样调用一个参数在执行是才建立的函数? . . . . . . . . . . . . 87 16 奇怪的问题89 16.1 遇到不可理解的不合理语法错误, 似乎大段的程序没有编译。. . 89 16.2 为什么过程调用不工作?编译器似乎直接跳过去了。. . . . . . . 89 16.3 程序在执行用之前就崩溃了, 用调试器单步跟进, 在main() 之前 就死了。. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 16.4 程序执行正确, 但退出时崩溃在main() 最后一个语句之后。为什 么会这样? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 16.5 程序在一台机器上执行完美, 但在另一台上却得到怪异的结果。 更奇怪的是, 增加或去除调试的打印语句, 就改变了症状⋯⋯ . . . 90 16.6 为什么代码: char *p = "hello, worl!"; p[0] = ’H’; 会崩溃? . . . 90 16.7 “Segmentation violation”, “Bus error” 和“General protection fault” 意味着什么? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 17 风格93 17.1 什么是C 最好的代码布局风格? . . . . . . . . . . . . . . . . . . 93 17.2 用if(!strcmp(s1, s2)) 比较两个字符串等值,是否是个好风格? . . . 93 17.3 为什么有的人用if (0 == x) 而不是if (x == 0)? . . . . . . . . . 93 17.4 原型说明extern int func ((int, int)); 中, 那些多出来的括号和下 划线代表了什么? . . . . . . . . . . . . . . . . . . . . . . . . . . 94 17.5 为什么有些代码在每次调用printf() 前, 加了类型转换(void)? . . 94 17.6 什么是“匈牙利标志法” (Hungarian Notation)?是否值得用? . . 94 17.7 哪里可以找到“印第安山风格指南” (Indian Hill Style Guide) 及 其它编码标准? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 17.8 有些人说goto 是邪恶的, 我应该永不用它。那是否太极端了? . . 95 18 工具和资源97 18.1 常用工具列表。. . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 18.2 怎样抓捕棘手的malloc 问题? . . . . . . . . . . . . . . . . . . . . 98 18.3 有什么免费或便宜的编译器可以使用? . . . . . . . . . . . . . . . 98 18.4 刚刚输入完一个程序, 但它表现的很奇怪。你可以发现有什么错 误的地方吗? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 18.5 哪里可以找到兼容ANSI 的lint? . . . . . . . . . . . . . . . . . . 99 18.6 难道ANSI 函数原型说明没有使lint 过时吗? . . . . . . . . . . . 99 18.7 网上有哪些C 的教程或其它资源? . . . . . . . . . . . . . . . . . 99 18.8 哪里可以找到好的源代码实例, 以供研究和学习? . . . . . . . . . 100 18.9 有什么好的学习C 的书?有哪些高级的书和参考? . . . . . . . . 100 18.10 哪里可以找到标准C 函数库的源代码? . . . . . . . . . . . . . . . 101 18.11 是否有一个在线的C 参考指南? . . . . . . . . . . . . . . . . . . 101 18.12 哪里可以得到ANSI/ISO C 标准? . . . . . . . . . . . . . . . . . 101 18.13 我需要分析和评估表达式的代码。. . . . . . . . . . . . . . . . . 101 18.14 哪里可以找到C 的BNF 或YACC 语法? . . . . . . . . . . . . . 101 18.15 谁有C 编译器的测试套件? . . . . . . . . . . . . . . . . . . . . . 102 18.16 哪里有一些有用的源代码片段和例子的收集? . . . . . . . . . . . 102 18.17 我需要执行多精度算术的代码。. . . . . . . . . . . . . . . . . . . 102 18.18 在哪里和怎样取得这些可自由发布的程序? . . . . . . . . . . . . 102 19 系统依赖105 19.1 怎样从键盘直接读入字符而不用等RETURN 键?怎样防止字符 输入时的回显? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 19.2 怎样知道有未读的字符, 如果有, 有多少?如果没有字符, 怎样使 读入不阻断? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 19.3 怎样显示一个百分比或“转动的短棒” 的进展表示器? . . . . . . 106 19.4 怎样清屏?怎样输出彩色文本?怎样移动光标到指定位置? . . . 106 19.5 怎样读入方向键, 功能键? . . . . . . . . . . . . . . . . . . . . . . 107 19.6 怎样读入鼠标输入? . . . . . . . . . . . . . . . . . . . . . . . . . 107 19.7 怎样做串口(“comm”) 的输入输出? . . . . . . . . . . . . . . . . 107 19.8 怎样直接输出到打印机? . . . . . . . . . . . . . . . . . . . . . . . 107 19.9 怎样发送控制终端或其它设备的逃逸指令序列? . . . . . . . . . . 108 19.10 怎样直接访问输入输出板? . . . . . . . . . . . . . . . . . . . . . 108 19.11 怎样做图形? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 19.12 怎样显示GIF 和JPEG 图象? . . . . . . . . . . . . . . . . . . . 108 19.13 怎样检验一个文件是否存在? . . . . . . . . . . . . . . . . . . . . 108 19.14 怎样在读入文件前, 知道文件大小? . . . . . . . . . . . . . . . . . 109 19.15 怎样得到文件的修改日期和时间? . . . . . . . . . . . . . . . . . 109 19.16 怎样缩短一个文件而不用清除或重写? . . . . . . . . . . . . . . . 109 19.17 怎样在文件中插入或删除一行(或记录)? . . . . . . . . . . . . . . 109 19.18 怎样从一个打开的流或文件描述符得到文件名? . . . . . . . . . . 110 19.19 怎样删除一个文件? . . . . . . . . . . . . . . . . . . . . . . . . . 110 19.20 怎样复制一个文件? . . . . . . . . . . . . . . . . . . . . . . . . . 110 19.21 为什么用了详尽的路径还不能打开文件? fopen("c:n newdir nfile.dat", "r") 返回错误。. . . . . . . . . . . . . . . . . . . . . . 110 19.22 fopen() 不让我打开文件: "$HOME/.profile" 和"˜/ .myrcfile"。. 111 19.23 怎样制止MS-DOS 下令人担忧的“Abort, Retry, Ignore?” 信息? 111 19.24 遇到“Too many open files (打开文件太多)” 的错误, 怎样增加同 时打开文件的允许数目? . . . . . . . . . . . . . . . . . . . . . . . 111 19.25 怎样在C 中读入目录? . . . . . . . . . . . . . . . . . . . . . . . . 111 19.26 怎样找出系统还有多少内存可用? . . . . . . . . . . . . . . . . . 111 19.27 怎样分配大于64K 的数组或结构? . . . . . . . . . . . . . . . . . 111 19.28 错误信息“DGROUP data allocation exceeds 64K (DGROUP 数 据分配内存超过64K)” 说明什么?我应该怎么做?我以为使用了 大内存模型, 那我就可以使用多于64K 的数据! . . . . . . . . . . 112 19.29 怎样访问位于某的特定地址的内存(内存映射的设备或图显内存)? 112 19.30 怎样在一个C 程序中调用另一个程序(独立可执行的程序, 或系统 命令)? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 19.31 怎样调用另一个程序或命令, 同时收集它的输出? . . . . . . . . . 113 19.32 怎样才能发现程序自己的执行文件的全路径? . . . . . . . . . . . 113 19.33 怎样找出和执行文件在同一目录的配置文件? . . . . . . . . . . . 113 19.34 一个进程如何改变它的调用者的环境变量? . . . . . . . . . . . . 113 19.35 怎样读入一个对象文件并跳跃到其中的地址? . . . . . . . . . . . 114 19.36 怎样实现精度小于秒的延时或记录用户回应的时间? . . . . . . . 114 19.37 怎样抓获或忽略像control-C 这样的键盘中断? . . . . . . . . . . 114 19.38 怎样很好地处理浮点异常? . . . . . . . . . . . . . . . . . . . . . 115 19.39 怎样使用socket?网络化?写客户/服务器程序? . . . . . . . . . 115 19.40 怎样调用BIOS 函数?写ISR?创建TSR? . . . . . . . . . . . . 115 19.41 编译程序, 编译器出示“union REGS” 未定义错误信息, 连接器出 示“int86()” 的未定义错误信息。. . . . . . . . . . . . . . . . . . 115 19.42 什么是“near” 和“far” 指针? . . . . . . . . . . . . . . . . . . . . 116 19.43 我不能使用这些非标准、依赖系统的函数, 程序需要兼容ANSI! . 116 20 杂项117 20.1 怎样从一个函数返回多个值? . . . . . . . . . . . . . . . . . . . . 117 20.2 怎样访问命令行参数? . . . . . . . . . . . . . . . . . . . . . . . . 117 20.3 怎样写数据文件, 使之可以在不同字大小、字节顺序或浮点格式 的机器上读入? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 20.4 怎样调用一个由char * 指针指向函数名的函数? . . . . . . . . . 117 20.5 怎样实现比特数组或集合? . . . . . . . . . . . . . . . . . . . . . 118 20.6 怎样判断机器的字节顺序是高字节在前还是低字节在前? . . . . . 118 20.7 怎样掉换字节? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 20.8 怎样转换整数到二进制或十六进制? . . . . . . . . . . . . . . . . 119 20.9 我可以使用二进制常数吗?有printf() 的二进制的格式符吗? . . 119 20.10 什么是计算整数中比特为1 的个数的最有效的方法? . . . . . . . 119 20.11 什么是提高程序效率的最好方法? . . . . . . . . . . . . . . . . . 119 20.12 指针真得比数组快吗?函数调用会拖慢程序多少? ++i 比i = i +1 快吗? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 20.13 人们说编译器优化的很好, 我们不在需要为速度而写汇编了, 但我 的编译器连用移位代替i/=2 都做不到。. . . . . . . . . . . . . . 120 20.14 怎样不用临时变量而交换两个值? . . . . . . . . . . . . . . . . . 120 20.15 是否有根据字符串做切换的方法? . . . . . . . . . . . . . . . . . 121 20.16 是否有使用非常量case 标志的方法(例如范围或任意的表达式)? 121 20.17 return 语句外层的括号是否真的可选择? . . . . . . . . . . . . . . 121 20.18 为什么C 注释不能嵌套?怎样注释掉含有注释的代码?引用字符 串内的注释是否合法? . . . . . . . . . . . . . . . . . . . . . . . . 121 20.19 C 是个伟大的语言还是别的?哪个其它语言可以写象a+++++b 这样的代码? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 20.20 为什么C 没有嵌套函数? . . . . . . . . . . . . . . . . . . . . . . 122 20.21 assert() 是什么?怎样用它? . . . . . . . . . . . . . . . . . . . . . 122 20.22 怎样从C 中调用FORTRAN (C++, BASIC, Pascal, Ada, LISP) 的函数?反之亦然? . . . . . . . . . . . . . . . . . . . . . . . . . 122 20.23 有什么程序可以做从Pascal 或Fortran (或LISP, Ada, awk, “老” C) 到C 的转换? . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 20.24 C++ 是C 的超集吗?可以用C++ 编译器来编译C 代码吗? . . 123 20.25 需要用到“近似” 的strcmp, 比较两个字符串的近似度, 并不需要 完全一样。. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 20.26 什么是散列法? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 20.27 由一个日期, 怎样知道是星期几? . . . . . . . . . . . . . . . . . . 124 20.28 (year%4 == 0) 是否足够判断润年?2000 年是闰年吗? . . . . . . 124 20.29 一个难题: 怎样写一个输出自己源代码的程序? . . . . . . . . . . 124 20.30 什么是“达夫设备” (Duff’s Device)? . . . . . . . . . . . . . . . . 125 20.31 下届国际C 混乱代码竞赛(IOCCC) 什么时候进行?哪里可以找 到当前和以前的获胜代码? . . . . . . . . . . . . . . . . . . . . . 125 20.32 [K&R1] 提到的关健字entry 是什么? . . . . . . . . . . . . . . . . 126 20.33 C 的名字从何而来? . . . . . . . . . . . . . . . . . . . . . . . . . 126 20.34 “char” 如何发音? . . . . . . . . . . . . . . . . . . . . . . . . . . 126 20.35 “lvalue” 和“rvalue” 代表什么意思? . . . . . . . . . . . . . . . . 126 20.36 哪里可以取得本FAQ (英文版) 的额外副本? . . . . . . . . . . . 126

最新推荐

DRM_LCM_Porting_Guide_DSI_V1.0.pdf

mtk drm lcm driver porting guide,for kernel-4.14 user drm core.

coredump文件的生成与解析.docx

本文模拟了除零错误发生时,嵌入式arm Linux平台生成的core文件,并在PC端采用arm-gdb解析该core文件,从中可以看出程序崩溃时的函数调用。

代码随想录最新第三版-最强八股文

这份PDF就是最强⼋股⽂! 1. C++ C++基础、C++ STL、C++泛型编程、C++11新特性、《Effective STL》 2. Java Java基础、Java内存模型、Java面向对象、Java集合体系、接口、Lambda表达式、类加载机制、内部类、代理类、Java并发、JVM、Java后端编译、Spring 3. Go defer底层原理、goroutine、select实现机制 4. 算法学习 数组、链表、回溯算法、贪心算法、动态规划、二叉树、排序算法、数据结构 5. 计算机基础 操作系统、数据库、计算机网络、设计模式、Linux、计算机系统 6. 前端学习 浏览器、JavaScript、CSS、HTML、React、VUE 7. 面经分享 字节、美团Java面、百度、京东、暑期实习...... 8. 编程常识 9. 问答精华 10.总结与经验分享 ......

无监督视觉表示学习中的时态知识一致性算法

无监督视觉表示学习中的时态知识一致性维信丰酒店1* 元江王2*†马丽华2叶远2张驰2北京邮电大学1旷视科技2网址:fengweixin@bupt.edu.cn,wangyuanjiang@megvii.com{malihua,yuanye,zhangchi} @ megvii.com摘要实例判别范式在无监督学习中已成为它通常采用教师-学生框架,教师提供嵌入式知识作为对学生的监督信号。学生学习有意义的表征,通过加强立场的空间一致性与教师的意见。然而,在不同的训练阶段,教师的输出可以在相同的实例中显著变化,引入意外的噪声,并导致由不一致的目标引起的灾难性的本文首先将实例时态一致性问题融入到现有的实例判别范式中 , 提 出 了 一 种 新 的 时 态 知 识 一 致 性 算 法 TKC(Temporal Knowledge Consis- tency)。具体来说,我们的TKC动态地集成的知识的时间教师和自适应地选择有用的信息,根据其重要性学习实例的时间一致性。

yolov5 test.py

您可以使用以下代码作为`test.py`文件中的基本模板来测试 YOLOv5 模型: ```python import torch from PIL import Image # 加载模型 model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # 选择设备 (CPU 或 GPU) device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu') # 将模型移动到所选设备上 model.to(device) # 读取测试图像 i

数据结构1800试题.pdf

你还在苦苦寻找数据结构的题目吗?这里刚刚上传了一份数据结构共1800道试题,轻松解决期末挂科的难题。不信?你下载看看,这里是纯题目,你下载了再来私信我答案。按数据结构教材分章节,每一章节都有选择题、或有判断题、填空题、算法设计题及应用题,题型丰富多样,共五种类型题目。本学期已过去一半,相信你数据结构叶已经学得差不多了,是时候拿题来练练手了,如果你考研,更需要这份1800道题来巩固自己的基础及攻克重点难点。现在下载,不早不晚,越往后拖,越到后面,你身边的人就越卷,甚至卷得达到你无法想象的程度。我也是曾经遇到过这样的人,学习,练题,就要趁现在,不然到时你都不知道要刷数据结构题好还是高数、工数、大英,或是算法题?学完理论要及时巩固知识内容才是王道!记住!!!下载了来要答案(v:zywcv1220)。

基于对比检测的高效视觉预训练

10086⇥⇥⇥⇥基于对比检测的高效视觉预训练Ol i vierJ. He´naf f SkandaKoppula Jean-BaptisteAlayracAaronvandenOord OriolVin yals JoaoCarreiraDeepMind,英国摘要自我监督预训练已被证明可以为迁移学习提供然而,这些性能增益是以大的计算成本来实现的,其中最先进的方法需要比监督预训练多一个数量级的计算。我们通过引入一种新的自监督目标,对比检测,任务表示与识别对象级功能跨增强来解决这个计算瓶颈。该目标可提取每幅图像的丰富学习信号,从而在各种下游任务上实现最先进的传输精度,同时需要高达10少训练特别是,我们最强的ImageNet预训练模型的性能与SEER相当,SEER是迄今为止最大的自监督系统之一,它使用了1000多个预训练数据。最后,我们的目标无缝地处理更复杂图像的预训练,例如COCO中的图像,缩小了从COCO到PASCAL的监督迁移学习的差距1. 介绍自从Al

You are not allowed to push code to this project.

回答: 当你遇到"You are not allowed to push code to this project"的错误提示时,可能有几个原因。首先,你需要确保你具有操作该项目的权限。你可以检查你的git账号是否有该项目的操作权限。如果没有权限,你需要联系管理员为你添加相应的权限。其次,你可以检查你的git凭证是否正确。你可以进入"控制面板" -> "用户帐户" -> "管理您的凭证" -> "Windows凭据 / 普通凭据",查看是否存在多个git凭证。你可以编辑查看你所push的网址的凭证,确保用户名和密码是正确的。另外,你也可以尝试在控制面板的凭据管理器中删除对应配置好的git网址,

TFT屏幕-ILI9486数据手册带命令标签版.pdf

ILI9486手册 官方手册 ILI9486 is a 262,144-color single-chip SoC driver for a-Si TFT liquid crystal display with resolution of 320RGBx480 dots, comprising a 960-channel source driver, a 480-channel gate driver, 345,600bytes GRAM for graphic data of 320RGBx480 dots, and power supply circuit. The ILI9486 supports parallel CPU 8-/9-/16-/18-bit data bus interface and 3-/4-line serial peripheral interfaces (SPI). The ILI9486 is also compliant with RGB (16-/18-bit) data bus for video image display. For high speed serial interface, the ILI9486 also provides one data and clock lane and supports up to 500Mbps on MIPI DSI link. And also support MDDI interface.

增量学习的分离Softmax用于解决类增量学习中的遗忘和分类偏差问题

844SS-IL:用于增量学习的分离SoftmaxHongjoon Ahn1 *、Jihwan Kwak4 *、Subin Lim3、Hyeonsu Bang1、Hyojun Kim2和TaesupMoon4†1人工智能系,2电子电气工程系3韩国水原成均馆大学计算机工程系4韩国首尔国立大学电气与计算机工程系{hong0805,tnqls985,bhs1996,leopard101}@ skku.edu{jihwan0508,tsoon}@ snu.ac.kr摘要我们认为类增量学习(CIL)的问题,其中学习代理不断学习新的类增量到达的训练数据批次,并旨在预测到目前为止学习的所有类。该问题的主要挑战是灾难性遗忘,并且对于基于样本记忆的CIL方法,通常已知的是,遗忘通常由由于新类和旧类之间的数据不平衡(在样本记忆中)而注入的分类得分偏差引起。虽然已经提出了几种方法来通过一些附加的后处理来校正这种分数偏差,然而,尽管存在着对分数重新调整或平衡微调的不确定性,但尚未对这种偏差的根本原因进行系统�