vxworks application programmers guide 6.9

376
VxWorks APPLICATION PROGRAMMER'S GUIDE 6.9 ® VxWorks Application Programmer's Guide, 6.9

Upload: tulip77

Post on 07-Sep-2015

3.035 views

Category:

Documents


410 download

DESCRIPTION

vxworks programmers guide version 6.9

TRANSCRIPT

  • VxWorks

    APPLICATION PROGRAMMER'S GUIDE

    6.9

    VxWorks Application Programmer's Guide, 6.9

  • Copyright 2011 Wind River Systems, Inc.

    All rights reserved. No part of this publication may be reproduced or transmitted in any form or by any means without the prior written permission of Wind River Systems, Inc.

    Wind River, Tornado, and VxWorks are registered trademarks of Wind River Systems, Inc. The Wind River logo is a trademark of Wind River Systems, Inc. Any third-party trademarks referenced are the property of their respective owners. For further information regarding Wind River trademarks, please see:

    www.windriver.com/company/terms/trademark.html

    This product may include software licensed to Wind River by third parties. Relevant notices (if any) are provided in your product installation at one of the following locations:

    installDir/product_name/3rd_party_licensor_notice.pdf installDir/legal-notices/

    Wind River may refer to third-party documentation by listing publications or providing links to third-party Web sites for informational purposes. Wind River accepts no responsibility for the information provided in such third-party documentation.

    Corporate HeadquartersWind River500 Wind River WayAlameda, CA 94501-1153U.S.A.

    Toll free (U.S.A.): 800-545-WINDTelephone: 510-748-4100Facsimile: 510-749-2010

    For additional contact information, see the Wind River Web site:

    www.windriver.com

    For information on how to contact Customer Support, see:

    www.windriver.com/support

    VxWorksApplication Programmer's Guide6.9

    25 Jan 11

  • iii

    Contents

    1 Overview ...................................................................................................... 1

    1.1 Introduction ...................................................................................................................... 1

    1.2 Kernel Architecture ......................................................................................................... 1

    1.3 Related Documentation Resources .............................................................................. 2

    1.4 VxWorks Configuration and Build .............................................................................. 3

    2 Real-Time Processes: RTPs ...................................................................... 5

    2.1 Introduction ...................................................................................................................... 6

    2.2 About Real-time Processes ............................................................................................ 6

    2.2.1 RTPs and Scheduling ........................................................................................ 7

    2.2.2 RTP Creation ...................................................................................................... 7

    2.2.3 RTP Termination ............................................................................................... 8

    2.2.4 RTPs and Memory ............................................................................................ 9

    2.2.5 RTPs and Tasks .................................................................................................. 10

    Numbers of Tasks and RTPs ........................................................................... 10Initial Task in an RTP ....................................................................................... 10RTP Tasks and Memory ................................................................................... 10

    2.2.6 RTPs and Inter-Process Communication ....................................................... 11

    2.2.7 RTPs, Inheritance, Zombies, and Resource Reclamation ............................ 11

    Inheritance .......................................................................................................... 11Zombie Processes .............................................................................................. 11Resource Reclamation ...................................................................................... 12

    2.2.8 RTPs and Environment Variables ................................................................... 12

    Setting Environment Variables From Outside a Process ............................ 12Setting Environment Variables From Within a Process .............................. 13

    2.2.9 RTPs and POSIX ................................................................................................ 13

    POSIX PSE52 Support ....................................................................................... 13

  • VxWorksApplication Programmer's Guide, 6.9

    iv

    2.3 Configuring VxWorks For Real-time Processes ....................................................... 14

    2.3.1 Basic RTP Support ............................................................................................. 14

    2.3.2 RTP Virtual Memory Management ................................................................ 15

    2.3.3 MMU Support for RTPs ................................................................................... 15

    2.3.4 Additional Component Options ..................................................................... 15

    2.3.5 Configuration and Build Facilities .................................................................. 16

    2.4 About RTP Overlapped Virtual Memory ................................................................... 16

    2.5 RTP Overlapped Virtual Memory for 32-Bit VxWorks ........................................... 19

    2.5.1 About Overlapped RTP VM for Absolutely-Linked Executables .............. 19

    2.5.2 Using Overlapped RTP VM for Absolutely-Linked Executables with 32-Bit VxWorks ............................................................................................................. 19

    About User Regions and the RTP Code Region .......................................... 20Defining the RTP Code Region ...................................................................... 22

    2.6 RTP Overlapped Virtual Memory for 64-Bit VxWorks ........................................... 27

    2.7 Other RTP Virtual Memory Options for 32-Bit VxWorks ...................................... 27

    2.7.1 About Default RTP Overlapped Virtual Memory for 32-Bit VxWorks ..... 28

    Using Default Overlapped RTP VM .............................................................. 29

    2.7.2 Flat RTP Virtual Memory for 32-Bit VxWorks .............................................. 29

    System Memory Map with RTPs Running .................................................... 30Using Flat RTP Virtual Memory ..................................................................... 33Using RTPs Without MMU Support .............................................................. 33

    3 RTP Applications ........................................................................................ 35

    3.1 Introduction ...................................................................................................................... 35

    3.2 Configuring VxWorks For RTP Applications .......................................................... 36

    3.3 Developing RTP Applications ...................................................................................... 36

    RTP Applications With Shared Libraries and Plug-Ins ............................... 37RTP Applications for UP and SMP Configurations of VxWorks ............... 37Migrating Kernel Applications to RTP Applications ................................... 37

    3.3.1 RTP Application Structure ............................................................................... 37

    3.3.2 VxWorks Header Files ...................................................................................... 38

    POSIX Header Files ........................................................................................... 38VxWorks Header File: vxWorks.h .................................................................. 38Other VxWorks Header Files .......................................................................... 39ANSI Header Files ............................................................................................ 39ANSI C++ Header Files .................................................................................... 39Compiler -I Flag ................................................................................................. 39VxWorks Nested Header Files ........................................................................ 39VxWorks Private Header Files ........................................................................ 40

  • Contents

    v

    3.3.3 Custom Header Files ........................................................................................ 40

    3.3.4 RTP Application APIs: System Calls and Library Routines ....................... 41

    VxWorks System Calls ..................................................................................... 41VxWorks Libraries ............................................................................................ 42Dinkum C and C++ Libraries .......................................................................... 42Custom Libraries ............................................................................................... 42API Documentation .......................................................................................... 42

    3.3.5 RTP Applications and Multitasking ............................................................... 42

    3.3.6 Checking for Required Kernel Support ......................................................... 43

    3.3.7 Using Hook Routines ........................................................................................ 43

    3.3.8 Developing C++ Applications ......................................................................... 43

    3.3.9 Using POSIX Facilities ...................................................................................... 43

    3.3.10 Tools for Building RTP Applications ............................................................. 43

    3.3.11 Using Absolutely-Linked RTP Applications ................................................ 44

    Absolutely-Linked RTP Executables for 64-Bit VxWorks ........................... 44Absolutely-Linked RTP Executables for 32-Bit VxWorks ........................... 44

    3.3.12 Reducing Executable File Size With the strip Facility ................................. 45

    3.4 Developing Static Libraries, Shared Libraries and Plug-Ins .................................. 46

    3.5 Creating and Using Shared Data Regions .................................................................. 46

    3.5.1 Configuring VxWorks for Shared Data Regions .......................................... 47

    3.5.2 Creating Shared Data Regions ........................................................................ 47

    3.5.3 Accessing Shared Data Regions ...................................................................... 48

    3.5.4 Deleting Shared Data Regions ......................................................................... 49

    3.6 Executing RTP Applications ......................................................................................... 49

    Caveat for Using Stripped Executables With 32-bit VxWorks ................... 50Starting an RTP Application ............................................................................ 51Stopping an RTP Application .......................................................................... 51Storing Application Executables ..................................................................... 52

    3.6.1 Running Applications Interactively ............................................................... 52

    Starting Applications ........................................................................................ 52Terminating Applications ................................................................................ 53

    3.6.2 Running Applications Automatically ............................................................ 53

    Startup Facility Options ................................................................................... 54Application Startup String Syntax .................................................................. 55Specifying Applications with a Startup Configuration Parameter ............ 56Specifying Applications with a Boot Loader Parameter ............................. 56Specifying Applications with a VxWorks Shell Script ................................. 57Specifying Applications with usrRtpAppInit( ) .......................................... 57

    3.6.3 Spawning Tasks and Executing Routines in an RTP Application ............. 58

    3.6.4 Applications and Symbol Registration .......................................................... 59

  • VxWorksApplication Programmer's Guide, 6.9

    vi

    3.7 Bundling RTP Applications in a System using ROMFS ......................................... 59

    3.7.1 Configuring VxWorks with ROMFS .............................................................. 60

    3.7.2 Building a System With ROMFS and Applications ..................................... 60

    3.7.3 Accessing Files in ROMFS ............................................................................... 61

    3.7.4 Using ROMFS to Start Applications Automatically .................................... 61

    4 Static Libraries, Shared Libraries, and Plug-Ins ...................................... 63

    4.1 Introduction ...................................................................................................................... 63

    4.2 About Static Libraries, Shared Libraries, and Plug-ins ........................................... 63

    Advantages and Disadvantages of Shared Libraries and Plug-Ins ........... 64

    4.3 Additional Documentation ........................................................................................... 66

    4.4 Configuring VxWorks for Shared Libraries and Plug-ins ...................................... 66

    4.5 Common Development Issues: Initialization and Termination ............................ 67

    4.5.1 Library and Plug-in Initialization ................................................................... 67

    4.5.2 C++ Initialization .............................................................................................. 68

    4.5.3 Handling Initialization Failures ...................................................................... 68

    4.5.4 Shared Library and Plug-in Termination ...................................................... 69

    Using Cleanup Routines .................................................................................. 69

    4.6 Common Development Facilities ................................................................................. 69

    4.7 Developing Static Libraries ........................................................................................... 70

    4.7.1 Initialization and Termination ........................................................................ 70

    4.8 Developing Shared Libraries ........................................................................................ 70

    4.8.1 About Dynamic Linking ................................................................................ 71

    Dynamic Linker ................................................................................................. 71Position Independent Code: PIC ..................................................................... 72

    4.8.2 Configuring VxWorks for Shared Libraries .................................................. 72

    4.8.3 Initialization and Termination ........................................................................ 72

    4.8.4 About Shared Library Names and ELF Records .......................................... 72

    4.8.5 Creating Shared Object Names for Shared Libraries ................................... 73

    Options for Defining Shared Object Names and Versions ......................... 73Match Shared Object Names and Shared Library File Names ................... 73

    4.8.6 Using Different Versions of Shared Libraries ............................................... 74

    4.8.7 Locating and Loading Shared Libraries at Run-time ................................... 74

    Specifying Shared Library Locations: Options and Search Order ............. 74Using the LD_LIBRARY_PATH Environment Variable ............................. 75Using the ld.so.conf Configuration File ......................................................... 76

  • Contents

    vii

    Using the ELF RPATH Record ........................................................................ 76Using the Application Directory ..................................................................... 76Pre-loading Shared Libraries ........................................................................... 77

    4.8.8 Using Lazy Binding With Shared Libraries .................................................. 77

    4.8.9 Getting Runtime Information About Shared Libraries ............................... 78

    4.8.10 Debugging Problems With Shared Library Use ........................................... 79

    Shared Library Not Found ............................................................................... 79Incorrectly Started Application ....................................................................... 79Using readelf to Examine Dynamic ELF Files .............................................. 79

    4.8.11 Working With Shared Libraries From a Windows Host ............................. 81

    Using NFS .......................................................................................................... 81Installing NFS on Windows ............................................................................. 81Configuring VxWorks With NFS .................................................................... 82Testing the NFS Connection ............................................................................ 82

    4.9 Developing RTP Applications That Use Shared Libraries ..................................... 82

    4.9.1 Compiler Option for Dynamic Executable .................................................... 83

    4.10 Developing Plug-Ins ....................................................................................................... 83

    4.10.1 Configuring VxWorks for Plug-Ins ................................................................ 84

    4.10.2 Initialization and Termination ........................................................................ 84

    4.10.3 Debugging Plug-Ins .......................................................................................... 84

    4.11 Developing RTP Applications That Use Plug-Ins .................................................... 84

    4.11.1 Code Requirements For RTP Applications That Use Plug-Ins ................... 84

    Locating Plug-Ins at Run-time ........................................................................ 85Using Lazy Binding With Plug-ins ................................................................. 85Example of Dynamic Linker API Use ............................................................ 85Example Application Using a Plug-In ........................................................... 86Routines for Managing Plug-Ins ..................................................................... 87

    4.11.2 Build Requirements For RTP Applications That Use Plug-Ins .................. 87

    4.12 Using the VxWorks Run-time C Shared Library libc.so ......................................... 88

    5 C++ Development ....................................................................................... 89

    5.1 Introduction ...................................................................................................................... 89

    5.2 Configuring VxWorks for C++ ..................................................................................... 90

    5.3 C++ Header Files ............................................................................................................. 90

    5.4 Spawning Tasks That Use C++ .................................................................................... 90

    5.5 Calls Between C and C++ Code .................................................................................... 91

    5.6 C++ Compiler Caveats .................................................................................................... 91

  • VxWorksApplication Programmer's Guide, 6.9

    viii

    5.7 C++ Compiler Differences ............................................................................................ 91

    5.7.1 Template Instantiation ..................................................................................... 92

    5.7.2 Run-Time Type Information ............................................................................ 93

    5.8 Namespaces ...................................................................................................................... 93

    5.9 C++ Exception Handling ................................................................................................ 94

    5.10 C++ Demo Example ........................................................................................................ 94

    6 Multitasking ................................................................................................. 95

    6.1 Introduction ...................................................................................................................... 95

    6.2 About Tasks and Multitasking ..................................................................................... 96

    6.2.1 Task States and Transitions ............................................................................. 96

    Tasks States and State Symbols ....................................................................... 97Illustration of Basic Task State Transitions .................................................... 98

    6.3 VxWorks System Tasks .................................................................................................. 99

    Basic VxWorks Tasks ........................................................................................ 100Tasks for Optional Components ..................................................................... 102

    6.4 Task Scheduling .............................................................................................................. 104

    6.4.1 Task Priorities .................................................................................................... 105

    6.4.2 VxWorks Traditional Scheduler ...................................................................... 105

    Priority-Based Preemptive Scheduling .......................................................... 105Scheduling and the Ready Queue ................................................................. 106Round-Robin Scheduling ................................................................................. 106

    6.5 Task Creation and Management .................................................................................. 108

    6.5.1 Task Creation and Activation .......................................................................... 108

    6.5.2 Task Names and IDs ......................................................................................... 109

    Task Naming Rules ........................................................................................... 109Task Name and ID Routines ............................................................................ 110

    6.5.3 Inter-Process Communication With Public Tasks ........................................ 110

    6.5.4 Task Creation Options ...................................................................................... 111

    6.5.5 Task Stack ........................................................................................................... 112

    Task Stack Protection ........................................................................................ 112

    6.5.6 Task Information ............................................................................................... 113

    6.5.7 Task Deletion and Deletion Safety ................................................................. 114

    6.5.8 Task Execution Control .................................................................................... 115

    6.5.9 Task Scheduling Control .................................................................................. 116

    6.5.10 Tasking Extensions: Hook Routines ............................................................... 116

  • Contents

    ix

    6.6 Task Error Status: errno ................................................................................................. 117

    6.6.1 A Separate errno Value for Each Task ........................................................... 117

    6.6.2 Error Return Convention ................................................................................. 117

    6.6.3 Assignment of Error Status Values ................................................................. 117

    6.7 Task Exception Handling .............................................................................................. 118

    6.8 Shared Code and Reentrancy ........................................................................................ 118

    6.8.1 Dynamic Stack Variables ................................................................................. 119

    6.8.2 Guarded Global and Static Variables ............................................................. 120

    6.8.3 Task-Specific Variables .................................................................................... 120

    Thread-Local Variables: __thread Storage Class .......................................... 121tlsOldLib and Task Variables ......................................................................... 121

    6.8.4 Multiple Tasks with the Same Main Routine ................................................ 122

    7 Intertask and Interprocess Communication ............................................. 123

    7.1 Introduction ...................................................................................................................... 123

    7.2 About Intertask and Interprocess Communication .................................................. 124

    7.3 Shared Data Structures ................................................................................................... 125

    7.4 Semaphores ...................................................................................................................... 126

    7.4.1 Inter-Process Communication With Public Semaphores ............................ 127

    7.4.2 Semaphore Creation and Use .......................................................................... 127

    7.4.3 Binary Semaphores ........................................................................................... 128

    Mutual Exclusion .............................................................................................. 129Synchronization ................................................................................................. 130

    7.4.4 Mutual-Exclusion Semaphores ....................................................................... 130

    Priority Inversion and Priority Inheritance ................................................... 131Deletion Safety ................................................................................................... 133Recursive Resource Access .............................................................................. 133

    7.4.5 Counting Semaphores ...................................................................................... 134

    7.4.6 Read/Write Semaphores ................................................................................. 134

    Specification of Read or Write Mode ............................................................. 135Precedence for Write Access Operations ....................................................... 136Read/Write Semaphores and System Performance .................................... 136

    7.4.7 Special Semaphore Options ............................................................................. 136

    Semaphore Timeout .......................................................................................... 136Semaphores and Queueing .............................................................................. 137Semaphores Interruptible by Signals ............................................................ 137Semaphores and VxWorks Events .................................................................. 137

    7.5 Message Queues .............................................................................................................. 138

  • VxWorksApplication Programmer's Guide, 6.9

    x

    7.5.1 Inter-Process Communication With Public Message Queues .................... 138

    7.5.2 Message Creation and Use ............................................................................... 139

    Message Queue Timeout .................................................................................. 139Message Queue Urgent Messages .................................................................. 139Message Queues Interruptible by Signals ..................................................... 140Message Queues and Queuing Options ........................................................ 140

    7.5.3 Displaying Message Queue Attributes .......................................................... 141

    7.5.4 Servers and Clients with Message Queues .................................................... 141

    7.5.5 Message Queues and VxWorks Events .......................................................... 142

    7.6 Pipes ................................................................................................................................... 142

    7.7 VxWorks Events .............................................................................................................. 143

    7.7.1 Configuring VxWorks for Events ................................................................... 143

    7.7.2 About Event Flags and the Task Events Register ......................................... 143

    7.7.3 Receiving Events ............................................................................................... 145

    7.7.4 Sending Events .................................................................................................. 146

    7.7.5 Inter-Process Communication With Events .................................................. 147

    7.7.6 Events Routines ................................................................................................. 147

    7.7.7 Show Routines and Events .............................................................................. 148

    7.8 Inter-Process Communication With Public Objects ................................................. 149

    Creating and Naming Public and Private Objects ....................................... 149

    7.9 Object Ownership and Resource Reclamation ......................................................... 150

    8 Signals ......................................................................................................... 151

    8.1 Introduction ...................................................................................................................... 151

    8.2 Signals .............................................................................................................................. 152

    8.2.1 Configuring VxWorks for Signals ................................................................. 153

    8.2.2 Basic Signal Routines ........................................................................................ 154

    8.2.3 Queued Signal Routines .................................................................................. 155

    8.2.4 Signal Events ...................................................................................................... 159

    8.2.5 Signal Handlers ................................................................................................. 159

    9 POSIX Facilities .......................................................................................... 163

    9.1 Introduction ...................................................................................................................... 164

    9.2 Configuring VxWorks with POSIX Facilities ............................................................ 165

    9.2.1 POSIX PSE52 Support ...................................................................................... 165

    9.2.2 VxWorks Components for POSIX Facilities .................................................. 167

  • Contents

    xi

    9.3 General POSIX Support ................................................................................................. 168

    9.4 Standard C Library: libc ................................................................................................. 169

    9.5 POSIX Header Files ........................................................................................................ 169

    9.6 POSIX Namespace .......................................................................................................... 171

    9.7 POSIX Process Privileges .............................................................................................. 173

    9.8 POSIX Process Support .................................................................................................. 173

    9.9 POSIX Clocks and Timers ............................................................................................. 173

    9.10 POSIX Asynchronous I/O .............................................................................................. 177

    9.11 POSIX Advisory File Locking ....................................................................................... 177

    9.12 POSIX Page-Locking Interface ..................................................................................... 178

    9.13 POSIX Threads ................................................................................................................ 179

    9.13.1 POSIX Thread Stack Guard Zones ................................................................. 179

    9.13.2 POSIX Thread Attributes ................................................................................. 180

    9.13.3 VxWorks-Specific Pthread Attributes ............................................................ 180

    9.13.4 Specifying Attributes when Creating Pthreads ........................................... 180

    9.13.5 POSIX Thread Creation and Management .................................................... 182

    9.13.6 POSIX Thread Attribute Access ...................................................................... 182

    9.13.7 POSIX Thread Private Data ............................................................................. 183

    9.13.8 POSIX Thread Cancellation ............................................................................. 184

    9.14 POSIX Thread Mutexes and Condition Variables .................................................... 185

    9.14.1 Thread Mutexes ................................................................................................. 185

    Type Mutex Attribute ....................................................................................... 186Protocol Mutex Attribute ................................................................................ 187Priority Ceiling Mutex Attribute .................................................................... 187

    9.14.2 Condition Variables .......................................................................................... 188

    9.15 POSIX and VxWorks Scheduling ................................................................................ 189

    9.15.1 Differences in POSIX and VxWorks Scheduling .......................................... 190

    9.15.2 POSIX and VxWorks Priority Numbering .................................................... 191

    9.15.3 Default Scheduling Policy ................................................................................ 191

    9.15.4 VxWorks Traditional Scheduler ...................................................................... 191

    9.15.5 POSIX Threads Scheduler ................................................................................ 193

    9.15.6 POSIX Scheduling Routines ............................................................................ 196

    9.15.7 Getting Scheduling Parameters: Priority Limits and Time Slice ................ 196

  • VxWorksApplication Programmer's Guide, 6.9

    xii

    9.16 POSIX Semaphores ......................................................................................................... 197

    9.16.1 Comparison of POSIX and VxWorks Semaphores ...................................... 198

    9.16.2 Using Unnamed Semaphores .......................................................................... 199

    9.16.3 Using Named Semaphores .............................................................................. 201

    9.17 POSIX Message Queues ................................................................................................. 204

    9.17.1 Comparison of POSIX and VxWorks Message Queues .............................. 205

    9.17.2 POSIX Message Queue Attributes .................................................................. 206

    9.17.3 Communicating Through a Message Queue ................................................ 207

    9.17.4 Notification of Message Arrival ..................................................................... 210

    9.18 POSIX Signals .................................................................................................................. 214

    9.19 POSIX Memory Management ....................................................................................... 215

    9.20 POSIX Trace ..................................................................................................................... 215

    Trace Events, Streams, and Logs ..................................................................... 215Trace Operation ................................................................................................. 216Trace APIs .......................................................................................................... 216Trace Code and Record Example .................................................................... 218

    10 Memory Management ................................................................................. 221

    10.1 Introduction ...................................................................................................................... 221

    10.2 About VxWorks Memory Allocation Facilities ......................................................... 221

    10.3 Heap and Memory Partition Management ................................................................. 222

    10.4 Memory Pools .................................................................................................................. 223

    10.5 POSIX Memory Management ....................................................................................... 224

    10.5.1 POSIX Memory Management APIs ................................................................ 224

    10.5.2 POSIX Memory Mapping ................................................................................ 226

    10.5.3 POSIX Memory Protection ............................................................................... 226

    10.5.4 POSIX Memory Locking .................................................................................. 226

    10.6 Memory Mapping Facilities .......................................................................................... 226

    10.6.1 POSIX Memory-Mapped Files ........................................................................ 228

    10.6.2 POSIX Shared Memory Objects ...................................................................... 228

    10.6.3 Anonymous Memory Mapping ...................................................................... 229

    10.6.4 Device Memory Objects ................................................................................... 230

    10.6.5 Shared Data Regions ......................................................................................... 230

    10.7 Memory Error Detection ................................................................................................ 230

    10.7.1 Heap and Partition Memory Instrumentation .............................................. 231

  • Contents

    xiii

    10.7.2 Compiler Instrumentation: 32-Bit VxWorks ................................................. 236

    11 I/O System ................................................................................................... 241

    11.1 Introduction ...................................................................................................................... 241

    11.2 About the VxWorks I/O System ................................................................................... 242

    Differences Between VxWorks and Host System I/O ................................. 242

    11.3 Configuring VxWorks With I/O Facilities ................................................................. 243

    11.4 I/O Devices, Named Files, and File Systems ............................................................ 244

    11.5 Remote File System Access From VxWorks .............................................................. 245

    11.6 Basic I/O ............................................................................................................................ 247

    11.6.1 File Descriptors .................................................................................................. 247

    File Descriptor Table ......................................................................................... 248

    11.6.2 Standard Input, Standard Output, and Standard Error .............................. 248

    11.6.3 Standard I/O Redirection ................................................................................ 248

    11.6.4 Open and Close ................................................................................................. 249

    11.6.5 Create and Remove ........................................................................................... 251

    11.6.6 Read and Write .................................................................................................. 252

    11.6.7 File Truncation ................................................................................................... 252

    11.6.8 I/O Control ........................................................................................................ 253

    11.6.9 Pending on Multiple File Descriptors with select( ) ..................................... 253

    11.6.10 POSIX File System Routines ............................................................................ 256

    11.7 Standard I/O ..................................................................................................................... 256

    11.7.1 About Standard I/O and Buffering ................................................................ 256

    11.7.2 About Standard Input, Standard Output, and Standard Error .................. 257

    11.8 Other Formatted I/O ....................................................................................................... 258

    11.9 Asynchronous Input/Output ......................................................................................... 258

    11.9.1 The POSIX AIO Routines ................................................................................. 258

    11.9.2 AIO Control Block ............................................................................................. 259

    11.9.3 Using AIO ........................................................................................................... 260

    Alternatives for Testing AIO Completion ..................................................... 260

    12 Devices ........................................................................................................ 261

    12.1 Introduction ...................................................................................................................... 261

    12.2 About Devices in VxWorks ........................................................................................... 262

  • VxWorksApplication Programmer's Guide, 6.9

    xiv

    12.3 Serial I/O Devices: Terminal and Pseudo-Terminal Devices ................................. 262

    tty Options .......................................................................................................... 263

    12.3.1 Raw Mode and Line Mode .............................................................................. 263

    12.3.2 tty Special Characters ....................................................................................... 264

    12.4 Pipe Devices ..................................................................................................................... 265

    12.4.1 Creating Pipes .................................................................................................... 265

    12.4.2 I/O Control Functions ...................................................................................... 265

    12.5 Pseudo I/O Device ........................................................................................................... 266

    12.5.1 I/O Control Functions ...................................................................................... 266

    12.6 Null Devices .................................................................................................................... 266

    TRFS Code Example ........................................................................................ 267

    12.7 Network File System (NFS) Devices ........................................................................... 267

    12.7.1 I/O Control Functions for NFS Clients .......................................................... 267

    12.8 Non-NFS Network Devices ........................................................................................... 268

    12.8.1 I/O Control Functions ...................................................................................... 268

    12.9 Sockets ............................................................................................................................... 269

    13 Local File Systems ..................................................................................... 271

    13.1 Introduction ...................................................................................................................... 271

    13.2 File System Monitor ...................................................................................................... 273

    13.3 Virtual Root File System: VRFS ................................................................................... 274

    13.4 Highly Reliable File System: HRFS ............................................................................ 275

    13.4.1 Configuring VxWorks for HRFS ..................................................................... 275

    13.4.2 Configuring HRFS ............................................................................................ 276

    13.4.3 HRFS and POSIX PSE52 ................................................................................... 277

    13.4.4 Creating an HRFS File System ....................................................................... 277

    13.4.5 Optimizing HRFS Performance ...................................................................... 278

    13.4.6 Transactional Operations and Commit Policies ......................................... 278

    Automatic Commit Policy ............................................................................... 278High-Speed Commit Policy ............................................................................. 279Mandatory Commits ......................................................................................... 279Rollbacks ............................................................................................................. 279Programmatically Initiating Commits ........................................................... 279

    13.4.7 File Access Time Stamps .................................................................................. 280

    13.4.8 Maximum Number of Files and Directories ................................................. 280

  • Contents

    xv

    13.4.9 Working with Directories ................................................................................ 280

    Creating Subdirectories .................................................................................... 280Removing Subdirectories ................................................................................. 280Reading Directory Entries ................................................................................ 281

    13.4.10 Working with Files ............................................................................................ 281

    File I/O Routines ............................................................................................... 281File Linking and Unlinking ............................................................................. 281File Permissions ................................................................................................. 281

    13.4.11 I/O Control Functions Supported by HRFS ................................................. 281

    13.4.12 Crash Recovery and Volume Consistency .................................................... 283

    13.4.13 File Management and Full Devices ................................................................ 283

    13.5 MS-DOS-Compatible File System: dosFs .................................................................. 283

    13.5.1 Configuring VxWorks for dosFs ..................................................................... 284

    13.5.2 Configuring dosFs ............................................................................................ 285

    13.5.3 Creating a dosFs File System ........................................................................... 286

    13.5.4 Optimizing dosFs Performance ...................................................................... 286

    13.5.5 Working with Volumes and Disks ................................................................. 286

    Accessing Volume Configuration Information ............................................. 287Synchronizing Volumes ................................................................................... 287

    13.5.6 Working with Directories ................................................................................ 287

    Creating Subdirectories .................................................................................... 287Removing Subdirectories ................................................................................. 287Reading Directory Entries ................................................................................ 288

    13.5.7 Working with Files ............................................................................................ 288

    File I/O Routines ............................................................................................... 288File Attributes .................................................................................................... 288

    13.5.8 Disk Space Allocation Options ........................................................................ 290

    Choosing an Allocation Method ..................................................................... 290Using Cluster Group Allocation ..................................................................... 291Using Absolutely Contiguous Allocation ...................................................... 291

    13.5.9 Crash Recovery and Volume Consistency .................................................... 293

    13.5.10 I/O Control Functions Supported by dosFsLib ........................................... 293

    13.5.11 Booting from a Local dosFs File System Using SCSI ................................... 294

    13.6 Transaction-Based Reliable File System Support for dosFs: TRFS ....................... 294

    13.6.1 Configuring VxWorks With TRFS .................................................................. 295

    13.6.2 Automatic Instantiation of TRFS .................................................................... 295

    13.6.3 Using TRFS in Applications ............................................................................ 295

    TRFS Code Example ........................................................................................ 296

    13.7 Raw File System: rawFs ................................................................................................. 296

  • VxWorksApplication Programmer's Guide, 6.9

    xvi

    13.7.1 Configuring VxWorks for rawFs .................................................................... 297

    13.7.2 Creating a rawFs File System .......................................................................... 297

    13.7.3 Mounting rawFs Volumes ............................................................................... 297

    13.7.4 rawFs File I/O ................................................................................................... 297

    13.7.5 I/O Control Functions Supported by rawFsLib ........................................... 298

    13.8 CD-ROM File System: cdromFs ................................................................................... 298

    13.8.1 Configuring VxWorks for cdromFs ................................................................ 300

    13.8.2 Creating and Using cdromFs ........................................................................... 300

    13.8.3 I/O Control Functions Supported by cdromFsLib ...................................... 300

    13.8.4 Version Numbers .............................................................................................. 301

    13.9 Read-Only Memory File System: ROMFS ................................................................. 301

    13.9.1 Configuring VxWorks with ROMFS .............................................................. 302

    13.9.2 Building a System With ROMFS and Files .................................................... 302

    13.9.3 Accessing Files in ROMFS ............................................................................... 302

    13.9.4 Using ROMFS to Start Applications Automatically .................................... 303

    13.10 Target Server File System: TSFS .................................................................................. 303

    Socket Support ................................................................................................... 304Error Handling .................................................................................................. 304Configuring VxWorks for TSFS Use ............................................................... 304Security Considerations ................................................................................... 305Using the TSFS to Boot a Target ...................................................................... 305

    14 Error Detection and Reporting .................................................................. 307

    14.1 Introduction ...................................................................................................................... 307

    14.2 Configuring Error Detection and Reporting Facilities ............................................ 308

    14.2.1 Configuring VxWorks ...................................................................................... 308

    14.2.2 Configuring the Persistent Memory Region ................................................. 308

    14.2.3 Configuring Responses to Fatal Errors .......................................................... 309

    14.3 Error Records .................................................................................................................... 309

    14.4 Displaying and Clearing Error Records ...................................................................... 311

    14.5 About Fatal Error Response Modes ............................................................................. 312

    14.6 Setting Fatal Error Handling Mode ............................................................................. 313

    14.7 Other Error Handling Options for Processes ............................................................ 313

    14.8 Using Error Reporting APIs in Application Code .................................................... 314

    14.9 Sample Error Record ....................................................................................................... 314

  • Contents

    xvii

    15 RTP Core Dumps ....................................................................................... 317

    15.1 Introduction ...................................................................................................................... 317

    15.2 About VxWorks RTP Core Dumps .............................................................................. 318

    Limitations of Core Dumps for VxWorks SMP ............................................ 319

    15.3 Configuring VxWorks With RTP Core Dump Support ........................................... 319

    Basic Configuration ........................................................................................... 320Core Dump Compression ................................................................................ 320

    15.4 Enabling File Compression ........................................................................................... 321

    15.5 Eliminating Areas of Memory Captured by Core Dumps ...................................... 321

    15.6 Setting Core Dump File Names .................................................................................... 321

    15.7 Setting Core Dump File Locations ............................................................................... 322

    15.8 Generating RTP Core Dumps ....................................................................................... 322

    15.9 Getting Information about RTP Core Dumps ........................................................... 323

    15.10 Retrieving RTP Core Dump Files ................................................................................ 323

    15.11 Analyzing RTP Core Dumps ........................................................................................ 324

    A Kernel to RTP Application Migration ....................................................... 325

    A.1 Introduction ..................................................................................................................... 325

    A.2 Migrating Kernel Applications to Processes ............................................................. 325

    A.2.1 Reducing Library Size ...................................................................................... 326

    A.2.2 Limiting Process Scope ..................................................................................... 326

    Communicating Between Applications ......................................................... 326 Communicating Between an Application and the Kernel ......................... 326

    A.2.3 Using C++ Initialization and Finalization Code ........................................... 327

    A.2.4 Eliminating Hardware Access ......................................................................... 327

    A.2.5 Eliminating Interrupt Contexts In Processes ................................................ 328

    POSIX Signals .................................................................................................... 328Watchdogs .......................................................................................................... 328Drivers ................................................................................................................ 329

    A.2.6 Redirecting I/O ................................................................................................. 329

    A.2.7 Process and Task API Differences .................................................................. 330

    Task Naming ...................................................................................................... 330Differences in Scope Between Kernel and User Modes ............................... 331Private and Public Objects ............................................................................... 331

    A.2.8 Semaphore Differences ..................................................................................... 331

  • VxWorksApplication Programmer's Guide, 6.9

    xviii

    A.2.9 POSIX Signal Differences ................................................................................. 332

    Signal Generation .............................................................................................. 332Signal Delivery .................................................................................................. 332Scope Of Signal Handlers ................................................................................ 332Default Handling Of Signals ........................................................................... 333Default Signal Mask for New Tasks ............................................................... 333Signals Sent to Blocked Tasks .......................................................................... 333Signal API Behavior .......................................................................................... 333

    A.2.10 Networking Issues ........................................................................................... 334

    Socket APIs ......................................................................................................... 334routeAdd( ) ......................................................................................................... 334

    A.2.11 Header File Differences .................................................................................... 334

    A.2.12 Object IDs as Pointers to Memory .................................................................. 335

    A.3 Differences in Kernel and RTP APIs .......................................................................... 335

    A.3.1 APIs Not Present in User Mode ...................................................................... 335

    A.3.2 APIs Added for User Mode Only ................................................................... 336

    A.3.3 APIs that Work Differently in Processes ....................................................... 336

    A.3.4 Kernel Calls Require Kernel Facilities ............................................................ 336

    A.3.5 Other API Differences ...................................................................................... 337

    B Porting C Code from 32-Bit to 64-Bit ........................................................ 339

    B.1 Introduction ...................................................................................................................... 339

    B.2 About the VxWorks 32-Bit and 64-Bit Data Models ................................................. 339

    B.3 Using the Compiler to Identify Porting Issues ......................................................... 341

    B.4 Making C Code 32-bit/64-Bit Portable ........................................................................ 342

    B.4.1 Check int and long Declarations ..................................................................... 343

    B.4.2 Check All Assignments .................................................................................... 343

    B.4.3 Check for Data Type Promotion ..................................................................... 343

    B.4.4 Check Use of Pointers ....................................................................................... 343

    B.4.5 Check use of sizeof( ) ........................................................................................ 344

    B.4.6 Check Use of Type Casting .............................................................................. 344

    B.4.7 Check Format String Conversions .................................................................. 344

    B.4.8 Check Use of Constants .................................................................................... 344

    B.4.9 Check Structures and Unions .......................................................................... 345

    B.4.10 Use Function Prototypes .................................................................................. 346

    B.4.11 Use Portable Data Types .................................................................................. 346

    B.4.12 As a Last Resort: Use Conditional Compilation Macro ............................... 346

    Index ..................................................................................................................... 347

  • 1 1Overview

    1.1 Introduction 1

    1.2 Kernel Architecture 1

    1.3 Related Documentation Resources 2

    1.4 VxWorks Configuration and Build 3

    1.1 Introduction

    This guide describes how to use VxWorks facilities in the development of real-time systems and applications.

    1.2 Kernel Architecture

    Prior to VxWorks 6.0, the operating system provided a single memory space with no segregation of the operating system from user applications. All tasks ran in supervisor mode.1 Although this model afforded performance and flexibility when developing applications, only skilled programming could ensure that kernel facilities and applications coexisted in the same memory space without interfering with one another.

    With the release of VxWorks 6.0, the operating system provides support for real-time processes (RTPs) that includes execution of applications in user mode and other features common to operating systems with a clear delineation between

    NOTE: This guide provides information about facilities available for real-time processes. For information about facilities available in the VxWorks kernel, see the the VxWorks Kernel Programmers Guide.

    1. Exceptions to this generalization include the VxWorks 5.x optional product VxVMI and the legacy VxWorks variant VxWorks AE.

  • VxWorksApplication Programmer's Guide, 6.9

    2

    kernel and applications. This architecture is often referred to as the process model. VxWorks has adopted this model with a design specifically aimed to meet the requirements of determinism and speed that are required for hard real-time systems. (For information about VxWorks processes and developing applications to run in processes, see VxWorks Application Programmers Guide.) VxWorks 6.x provides full MMU-based protection of both kernel and user space.

    At the same time, VxWorks 6.x maintains a high level of backward compatibility with VxWorks 5.5. Applications developed for earlier versions of VxWorks, and designed to run in kernel space, can be migrated to VxWorks 6.x kernel space with minimal effort (in most cases, merely re-compilation). For more information on this topic, see the VxWorks Application Programmers Guide.

    Naturally, new applications can be designed for kernel space as well, when other considerations outweigh the advantages of protection that executing applications as processes affords. These considerations might include:

    Size. The overall size of a system is smaller without components that provided for processes and MMU support.

    Speed. Depending on the number of system calls an application might make, or how much I/O it is doing when running as a process in user space, it might be faster running in the kernel.

    Kernel-only features. Features such as watchdog timers, ISRs, and VxMP are available only in the kernel. In some cases, however, there are alternatives for process-based applications (POSIX timers, for example).

    Hardware access. If the application requires direct access to hardware, it can only do so from within the kernel.

    VxWorks is flexible in terms of both the modularity of its features and extensibility. It can be configured as a minimal kernel, or a full-featured operating system with user mode applications, file systems, networking, error detection and reporting, and so on, or anything in between.

    The operating system can also be extended by adding custom components or application modules to the kernel itself (for example, for new file systems, networking protocols, or drivers). The system call interface can also be extended by adding custom APIs, which makes them available to process-based applications.

    1.3 Related Documentation Resources

    The companion volume to this guide, the VxWorks Kernel Programmers Guide, provides material specific to kernel features and kernel-based development.

    Detailed information about VxWorks libraries and routines is provided in the VxWorks API references. Information specific to target architectures is provided in the VxWorks BSP references and in the VxWorks Architecture Supplement.

    For information about BSP and driver development, see the VxWorks BSP Developers Guide and the VxWorks Device Driver Guide.

  • 1 Overview1.4 VxWorks Configuration and Build

    3

    The VxWorks networking facilities are documented in the Wind River Network Stack Programmers Guide and the VxWorks PPP Programmers Guide.

    For information about migrating applications, BSPs, drivers, and projects from previous versions of VxWorks and the host development environment, see the VxWorks Migration Guide and the Wind River Workbench Migration Guide.

    The Wind River IDE and command-line tools are documented in the Wind River Workbench by Example guide, your Platform users guide, the Wind River compiler and GNU compiler guides, and the Wind River tools API and command-line references.

    1.4 VxWorks Configuration and Build

    This document describes VxWorks features; it does not go into detail about the mechanisms by which VxWorks-based systems and applications are configured and built. The tools and procedures used for configuration and build are described in the Wind River Workbench by Example guide and your Platform users guide.

    NOTE: In this guide, as well as in the VxWorks API references, VxWorks components and their configuration parameters are identified by the names used in component description files. The names take the form, for example, of INCLUDE_FOO and NUM_FOO_FILES (for components and parameters, respectively).

    You can use these names directly to configure VxWorks using the command-line configuration facilities.

    Wind River Workbench displays descriptions of components and parameters, as well as their names, in the Components tab of the Kernel Configuration Editor. You can use the Find dialog to locate a component or parameter using its name or description. To access the Find dialog from the Components tab, type CTRL+F, or right-click and select Find.

    ! CAUTION: Code built for variants of VxWorks or for different releases of VxWorks is not binary compatible between variants or releases. Code must be built specifically for uniprocessor (UP) VxWorks, VxWorks SMP, 32-bit VxWorks, 64-bit VxWorks, or for a VxWorks system based on variant libraries produced with a VxWorks source build (VSB) projector for any supported combination of these variants. The only exception to this rule is that RTP application executables can be run on both UP VxWorks and VxWorks SMP (when all else is the same).

  • VxWorksApplication Programmer's Guide, 6.9

    4

  • 5 2Real-Time Processes: RTPs

    2.1 Introduction 6

    2.2 About Real-time Processes 6

    2.3 Configuring VxWorks For Real-time Processes 14

    2.4 About RTP Overlapped Virtual Memory 16

    2.5 RTP Overlapped Virtual Memory for 32-Bit VxWorks 19

    2.6 RTP Overlapped Virtual Memory for 64-Bit VxWorks 27

    2.7 Other RTP Virtual Memory Options for 32-Bit VxWorks 27

  • VxWorksApplication Programmer's Guide, 6.9

    6

    2.1 Introduction

    VxWorks real-time processes (RTPs) are in many respects similar to processes in other operating systemssuch as UNIX and Linuxincluding extensive POSIX compliance.1 The ways in which they are created, execute applications, and terminate will be familiar to developers who understand the UNIX process model.

    The VxWorks process model is, however, designed for use with real-time embedded systems. The features that support this model include system-wide scheduling of tasks (processes themselves are not scheduled), preemption of processes in kernel mode as well as user mode, process-creation in two steps to separate loading from instantiation, and loading applications in their entirety.

    VxWorks real-time processes provide the means for executing applications in user mode. Each process has its own address space, which contains the executable program, the programs data, stacks for each task, the heap, and resources associated with the management of the process itself (such as memory-allocation tracking). Many processes may be present in memory at once, and each process may contain more than one task (sometimes known as a thread in other operating systems).

    For 64-bit VxWorks, RTP virtual memory is overlapped, and RTP applications are built as absolutely-linked executables. For 32-bit VxWorks, the default is simply RTP overlapped virtual memory, but Wind River recommends taking additional configuration steps to support RTPs as absolutely-linked executables. The legacy flat RTP virtual memory configuration can also be used with 32-bit VxWorks.

    For information about developing RTP applications, see 3. RTP Applications.

    2.2 About Real-time Processes

    A common definition of a process is a program in execution, and VxWorks processes are no different in this respect. In fact, the life-cycle of VxWorks real-time processes is largely consistent with the POSIX process model (see 2.2.9 RTPs and POSIX, p.13).

    VxWorks processes, however, are called real-time processes (RTPs) precisely because they are designed to support the determinism required of real-time systems. They do so in the following ways:

    The VxWorks task-scheduling model is maintained. Processes are not scheduledtasks are scheduled globally throughout the system.

    Processes can be preempted in kernel mode as well as in user mode. Every task has both a user mode and a kernel mode stack. (The VxWorks kernel is fully preemptive.)

    Processes are created without the overhead of performing a copy of the address space for the new process and then performing an exec operation to load the file. With VxWorks, a new address space is simply created and the file loaded.

    1. VxWorks can be configured to provide POSIX PSE52 support for individual processes.

  • 2 Real-Time Processes: RTPs2.2 About Real-time Processes

    7

    Process creation takes place in two phases that clearly separate instantiation of the process from loading and executing the application. The first phase is performed in the context of the task that calls rtpSpawn( ). The second phase is carried out by a separate task that bears the cost of loading the application text and data before executing it, and which operates at its own priority level distinct from the parent task. The parent task, which called rtpSpawn( ), is not impacted and does not have wait for the application to begin execution, unless it has been coded to wait.

    Processes load applications in their entiretythere is no demand paging.

    All of these differences are designed to make VxWorks particularly suitable for hard real-time applications by ensuring determinism, as well as providing a common programming model for systems that run with an MMU and those that do not. As a result, there are differences between the VxWorks process model and that of server-style operating systems such as UNIX and Linux. The reasons for these differences are discussed as the relevant topic arises throughout this chapter.

    2.2.1 RTPs and Scheduling

    The primary way in which VxWorks processes support determinism is that they themselves are simply not scheduled. Only tasks are scheduled in VxWorks systems, using a priority-based, preemptive policy. Based on the strong preemptibility of the VxWorks kernel, this ensures that at any given time, the highest priority task in the system that is ready to run will execute, regardless of whether the task is in the kernel or in any process in the system.

    By way of contrast, the scheduling policy for non-real-time systems is based on time-sharing, as well as a dynamic determination of process priority that ensures that no process is denied use of the CPU for too long, and that no process monopolizes the CPU.

    VxWorks does provide an optional time-sharing capabilityround-robin schedulingbut it does not interfere with priority-based preemption, and is therefore deterministic. VxWorks round-robin scheduling simply ensures that when there is more than one task with the highest priority ready to run at the same time, the CPU is shared between those tasks. No one of them, therefore, can usurp the processor until it is blocked.

    For more information about VxWorks scheduling see 6.4 Task Scheduling, p.104.

    2.2.2 RTP Creation

    The manner in which real-time processes are created supports the determinism required of real-time systems. The creation of an RTP takes place in two distinct phases, and the executable is loaded in its entirety when the process is created. In the first phase, the rtpSpawn( ) call creates the process object in the system, allocates virtual and physical memory to it, and creates the initial process task (see 2.2.5 RTPs and Tasks, p.10). In the second phase, the initial process task loads the entire executable and starts the main routine.

    This approach provides for system determinism in two ways:

    First, the work of process creation is divided between the rtpSpawn( ) task and the initial process taskeach of which has its own distinct task priority. This

  • VxWorksApplication Programmer's Guide, 6.9

    8

    means that the activity of loading applications does not occur at the priority, or with the CPU time, of the task requesting the creation of the new process. Therefore, the initial phase of starting a process is discrete and deterministic, regardless of the application that is going to run in it. And for the second phase, the developer can assign the task priority appropriate to the significance of the application, or to take into account necessarily indeterministic constraints on loading the application (for example, if the application is loaded from networked host system, or local disk). The application is loaded with the same task priority as the priority with which it will run. In a way, this model is analogous to asynchronous I/O, as the task that calls rtpSpawn( ) just initiates starting the process and can concurrently perform other activities while the application is being loaded and started.

    Second, the entire application executable is loaded when the process is created, which means that the determinacy of its execution is not compromised by incremental loading during execution. This feature is obviously useful when systems are configured to start applications automatically at boot timeall executables are fully loaded and ready to execute when the system comes up.

    The rtpSpawn( ) routine has an option that provides for synchronizing for the successful loading and instantiation of the new process.

    At startup time, the resources internally required for the process (such as the heap) are allocated on demand. The application's text is guaranteed to be write-protected, and the application's data readable and writable, as long as an MMU is present and the operating system is configured to manage it. While memory protection is provided by MMU-enforced partitions between processes, there is no mechanism to provide resource protection by limiting memory usage of processes to a specified amount. For more information, see 10. Memory Management.

    Note that creation of VxWorks processes involves no copying or sharing of the parent processes page frames (copy-on-write), as is the case with some versions of UNIX and Linux. The flat virtual memory model provided by VxWorks prohibits this approach and the overlapped virtual memory model does not currently support this feature. For information about the issue of inheritance of attributes from parent processes, see 2.2.7 RTPs, Inheritance, Zombies, and Resource Reclamation, p.11.

    For information about what operations are possible on a process in each phase of its instantiation, see the VxWorks API reference for rtpLib. Also see 3.3.7 Using Hook Routines, p.43.

    VxWorks processes can be started in the following ways:

    interactively from the kernel shell

    interactively from the host shell and debugger

    automatically at boot time, using a startup facility

    programmatically from applications or the kernel

    Form more information in this regard, see 3.6 Executing RTP Applications, p.49.

    2.2.3 RTP Termination

    Processes are terminated under the following circumstances:

  • 2 Real-Time Processes: RTPs2.2 About Real-time Processes

    9

    When the last task in the process exits.

    If any task in the process calls exit( ), regardless of whether or not other tasks are running in the process.

    If the process main( ) routine returns.

    This is because exit( ) is called implicitly when main( ) returns. An application in which main( ) spawns tasks can be written to avoid this behaviorand to allow its other tasks to continue operationby including a taskExit( ) call as the last statement in main( ). See 3.3 Developing RTP Applications, p.36.

    If the kill( ) routine is used to terminate the process.

    If rtpDelete( ) is called on the processfrom a program, a kernel module, the C interpreter of the shell, or from Workbench. Or if the rtp delete command is used from the shells command interpreter.

    If a process takes an exception during its execution.

    This default behavior can be changed for debugging purposes. When the error detection and reporting facilities are included in the system, and they are set to debug mode, processes are not terminated when an exception occurs.

    Note that if a process fails while a shell is running, a message is printed to the shell console. Error messages can be recorded with the VxWorks error detection and reporting facilities (see 14. Error Detection and Reporting).

    For information about attribute inheritance and what happens to a process resources when it terminates, see 2.2.7 RTPs, Inheritance, Zombies, and Resource Reclamation, p.11.

    2.2.4 RTPs and Memory

    Each process has its own address space, which contains the executable program, the program's data, stacks for each task, the heap, and resources associated with the management of the process itself (such as local heap management). Many processes may be present in memory at once. For information about virtual memory management, see 2.5 RTP Overlapped Virtual Memory for 32-Bit VxWorks, p.19, 2.7 Other RTP Virtual Memory Options for 32-Bit VxWorks, p.27, and 2.6 RTP Overlapped Virtual Memory for 64-Bit VxWorks, p.27.

    Memory Protection

    Each process is protected from any other process that is running on the system, whenever the target system has an MMU, and MMU support has been configured into VxWorks. Operations involving the code, data, and memory of a process are accessible only to code executing in that process. It is possible, therefore, to run several instances of the same application in separate processes without any undesired side effects occurring between them. The name and symbol spaces of the kernel and processes are isolated.

    As processes run a fully linked image without external references, a process cannot call a routine in another process, or a kernel routine that is not exported as a system callwhether or not the MMU is enabled. However, if the MMU is not enabled (which can only be done with the flat RTP virtual memory configuration on 32-bit VxWorks), a process can read and write memory external to its own address space, and could cause the system to malfunction.

  • VxWorksApplication Programmer's Guide, 6.9

    10

    2.2.5 RTPs and Tasks

    VxWorks can run many processes at once, and any number of processes can run the same application executable. That is, many instances of an application can be run concurrently.

    For general information about tasks, see 6. Multitasking.

    Numbers of Tasks and RTPs

    Each process can execute one or more tasks. When a process is created, the system spawns a single task to initiate execution of the application. The application may then spawn additional tasks to perform various functions. There is no limit to the number of tasks in a process, other than that imposed by the amount of available memory. Similarly, there is no limit to the number of processes in the systembut only for architectures that do not have (or do not use) a hardware mechanism that manages concurrent address spaces (this mechanism is usually known as an address space identifier, or ASID). For target architectures that do use ASIDs or equivalent mechanisms, the number of processes is limited to that of the ASID (usually 255). For more information, see the VxWorks Architecture Supplement.

    Initial Task in an RTP

    When a process is created, an initial task is spawned to begin execution of the application. The name of the processs initial task is based on the name of the executable file, with the following modifications:

    The letter i is prefixed. The first letter of the filename capitalized. The filename extension is removed.

    For example, when foobar.vxe is run, the name of the initial task is iFoobar.

    The initial task provides the execution context for the programs main( ) routine, which it then calls. The application itself may then spawn additional tasks.

    RTP Tasks and Memory

    Task creation includes allocation of space for the task's stack from process memory. As needed, memory is automatically added to the process as tasks are created from the kernel free memory pool.

    Heap management routines are available in user-level libraries for tasks in processes. These libraries provide the various ANSI APIs such as malloc( ) and free( ). The kernel provides a pool of memory for each process in user space for these routines to manage.

    Providing heap management in user space provides for speed and improved performance because the application does not incur the overhead of a system call for memory during its execution. However, if