MKS Toolkit UNIX to Windows Porting Guide
Total Page:16
File Type:pdf, Size:1020Kb
MKS Toolkit UNIX to Windows Porting Guide MKS Inc. MKS Toolkit: UNIX to Windows Porting Guide ©2004 MKS Software Inc.; in Canada copyright owned by MKS Inc. All rights reserved. MKS, MKS Toolkit, and AlertCentre are registered trademarks of MKS Inc. NuTCRACKER is a registered trademark of MKS Software Inc. All other trademarks referenced are the property of their respective owners. MKS Inc. 12450 Fair Lakes Circle Suite 400 Fairfax, Virginia 22033 Phone: +1 703 803-3343 Fax: +1 703 803-3344 E-mail: [email protected] 8.7-0604 Technical Support To request customer support, please contact us by one of the means listed below and in your request include the name and version number of the product, your serial number, and the operating system and version/patch level that you are using. Contact MKS customer support at: Web: http://www.mkssoftware.com/support E-mail: [email protected] Telephone: +1-703-803-7660 (9:00am to 7:00pm Eastern, Mon-Fri) Fax: +1-703-803-3344 When reporting problems, please provide a test case and test procedure, if possible. If you are following up on a previously reported problem, please include the problem tracking number in your correspondence. Finally, tell us how we can contact you. Please give us your e-mail address and telephone number. UNIX to Windows Porting Guide iii iv MKS Toolkit Table of Contents 1 Introduction...............................................................1 A Note About Compilers ........................................................................2 2 Windows Concepts ..................................................3 Process Management ..............................................................................3 Process Control................................................................................3 Process And Thread Scheduling......................................................5 Process Identification ......................................................................6 Memory Management......................................................................6 Signal Management .........................................................................7 Security ...................................................................................................8 Windows Security Overview...........................................................9 Security Identifiers ...................................................................9 Security of Objects .................................................................10 Object Access .........................................................................11 Rights and Permissions ..........................................................11 Impersonation.........................................................................11 Users and Groups...........................................................................12 Mapping of User- and Group-IDs ..........................................12 The root User and Group........................................................13 User and Group Database.......................................................13 File Security...................................................................................14 Mapping UNIX Access Modes to NTFS Permissions ...........14 Determining Ownership .........................................................14 File Mode Initialization .................................................................16 File Management ..................................................................................16 File Systems...................................................................................16 Path Names ....................................................................................18 Path Names Containing Spaces .....................................................20 Path Names Corresponding To DOS Device Names ....................20 Text Files and Binary Files............................................................20 File I/O and Control.......................................................................21 Special Files...................................................................................22 Shared Libraries....................................................................................24 Files ...............................................................................................24 Dynamic Linking vs. Static Linking..............................................24 Exporting Symbols from DLLs .....................................................25 UNIX to Windows Porting Guide v Data Exported From DLLs ............................................................25 Locating DLLs at Run Time..........................................................25 Interprocess Communications and Networking....................................26 Locales ..................................................................................................28 Screen Management..............................................................................28 3 The Porting Process...............................................31 Overview of the Porting Process ..........................................................31 Preparing to Port ...................................................................................33 Determining the Scope of the Port ................................................33 Accessing Source Files..................................................................33 Line Termination....................................................................34 File System Differences .........................................................34 Transferring and Sharing Source Files...................................34 Selecting a Work Environment......................................................35 Preparing to Build.................................................................................36 Make File Issues ............................................................................36 Header File Issues..........................................................................37 MKS Toolkit UNIX API Header Files...................................37 Compilation Environments.....................................................38 Source Code Issues........................................................................40 Text and Binary Modes ..........................................................41 ANSI Prototypes.....................................................................41 Global System Variables ........................................................41 Conditional Compilation ........................................................42 Using Data Exported From DLLs ..........................................42 Path Names.............................................................................43 Device Files............................................................................43 Globbing.................................................................................43 Byte Ordering .........................................................................44 Calling Back Into NuTCRACKER Code From Win32 Code .......44 Compiling and Linking the Application ...............................................46 Debugging the Application...................................................................47 Porting Scripts.......................................................................................49 Integrating with Windows ....................................................................50 Packaging and Deploying the Application ...........................................51 Porting to Windows Me........................................................................51 Strategies for Maintaining a Single Executable ............................51 Differences Between Windows Versions ......................................52 Daemons/Services ..................................................................52 Security...................................................................................52 Event Logging ........................................................................53 Process IDs .............................................................................53 vi MKS Toolkit 4 API-Specific Porting Issues...................................55 Process Management ............................................................................55 Process Control..............................................................................55 atexit().....................................................................................55 clock().....................................................................................55 exec() Family..........................................................................55 _exit()/exit()............................................................................56 fork().......................................................................................56 getitimer()/setitimer() .............................................................56 longjmp()/siglongjmp() ..........................................................57 _NutForkExecXXX() Family.................................................57 popen()....................................................................................57 pthread_atfork()......................................................................58 sleep()/nap()/usleep()/nanosleep()..........................................58 system() ..................................................................................58