MKS Toolkit
UNIX to Windows Porting Guide



MKS Inc.
12701 Fair Lakes Circle, Suite 350
Fairfax VA 22033-3831 USA
Support: +1-703-803-7660
+1-703-803-3343
http://www.mkssoftware.com/

July 2005

Table of Contents

  1. Introduction
  2. A Note About Compilers

  3. Windows Concepts

    Process Management

    Process Control

    Process And Thread Scheduling

    Process Identification

    Memory Management

    Signal Management

    Security

    Windows Security Overview

    Security Identifiers

    Security of Objects

    Object Access

    Rights and Permissions

    Impersonation

    Users and Groups

    Mapping of User- and Group-IDs

    The root User and Group

    User and Group Database

    File Security

    Mapping UNIX Access Modes to NTFS Permissions

    Determining Ownership

    File Mode Initialization

    File Management

    File Systems

    Path Names

    Path Names Containing Spaces

    Path Names Corresponding To DOS Device Names

    Text Files and Binary Files

    File I/O and Control

    Special Files

    Shared Libraries

    Files

    Dynamic Linking vs. Static Linking

    Exporting Symbols from DLLs

    Data Exported From DLLs

    Locating DLLs at Run Time

    Interprocess Communications and Networking

    Locales

    Screen Management

  4. The Porting Process
  5. Overview of the Porting Process

    Preparing to Port

    Determining the Scope of the Port

    Accessing Source Files

    Line Termination

    File System Differences

    Transferring and Sharing Source Files

    Selecting a Work Environment

    Preparing to Build

    Make File Issues

    Header File Issues

    MKS Toolkit UNIX API Header Files

    Compilation Environments

    Source Code Issues

    Text and Binary Modes

    ANSI Prototypes

    Global System Variables

    Conditional Compilation

    Using Data Exported From DLLs

    Path Names

    Device Files

    Globbing

    Byte Ordering

    Calling Back Into NuTCRACKER Code From Win32 Code

    Compiling and Linking the Application

    Debugging the Application

    Porting Scripts

    Integrating with Windows

    Packaging and Deploying the Application

    Porting to Windows Me

    Strategies for Maintaining a Single Executable

    Differences Between Windows Versions

    Daemons/Services

    Security

    Event Logging

    Process IDs

  6. API-Specific Porting Issues
  7. Process Management

    Process Control

    atexit()

    clock()

    exec() Family

    _exit()/exit()

    fork()

    getitimer()/setitimer()

    longjmp()/siglongjmp()

    _NutForkExecXXX() Family

    popen()

    pthread_atfork()

    sleep()/nap()/usleep()/nanosleep()

    system()

    times()

    vfork()

    waitpid()/wait3()/wait4()

    Process And Thread Scheduling

    getpriority()/setpriority()

    nice()

    pthread_attr_setpolicy()/pthread_setschedparam()

    Process Identification

    getpgid()/getpgrp()/getsid()

    getpid()

    getppid()

    _NutIsNuTCProcess()

    _NutQueryPid()

    pthread_self()

    setpgrp()/setsid()

    Memory Management

    brk()/sbrk()

    malloc()

    mmap()

    mprotect()

    msync()

    munmap()

    Signal Management

    bsd_signal()

    kill()

    sigaction()

    sigaltstack()/sigstack()

    sigqueue()

    sigvec()

    Security

    Users and Groups

    getgroups()

    getpwnam()/getpwuid()/getgrnam()/getgrgid()

    getuid()/getgid()/geteuid()/getegid()

    _NutValidatePassword()

    setuid()/setgid()/seteuid()/setegid()

    File Security

    File Mode Flags

    access()

    chmod()/fchmod()

    chown()/fchown()

    umask()

    File Management

    File Systems

    link()

    mount()/umount()

    statvfs()/fstatvfs()

    lstat()/lchown()/readlink()/symlink()

    Path Names

    chdir()

    chroot()

    getcwd()

    _NutPathToXXX() Family

    _NutQueryXXXDir() Family

    File I/O and Control

    creat()/open()/fopen()

    fcntl()

    _NutFastStat()

    _NutFdToHandle()/_NutHandleToFd()

    read()/write()

    readdir()/readdir_r()

    rename()

    stat()/fstat()

    utimes()/utime()

    Special Files

    ctermid()

    mknod()

    pipe()

    ttyname()/ttyname_r()

    Interprocess Communications and Networking

    bind()

    gethostbyname()/gethostbyaddr()

    mkfifo()

    poll()

    select()

    sendmsg()/recvmsg()

    socketpair()

    shmat()

    Math Libraries

    Math Library Modes

    Changing Math Library Modes

    Optimization Issues

    Miscellaneous Functions

    confstr()/_NutConfStr()

    ctime() Family

    dlopen() Family

    errno/h_errno/perror()/strerror()

    getenv()/putenv()/environ

    mktemp()

    _NutDebugBreak()

    sysconf()

    syslog() Family

  8. Language Support
  9. Using C

    Using C++

    Using FORTRAN

  10. Using the Visual C++ IDE
  11. Create a New Project

    Visual Studio 5.x and 6.x

    Visual Studio .NET 7.x

    Set Compiler Options

    Visual Studio 5.x and 6.x

    Visual Studio .NET 7.x

    Set Linker Options

    Visual Studio 5.x and 6.x

    Visual Studio .NET 7.x

    Build the Application

    Run the Application

  12. Porting X Applications
  13. Using imake

    Choosing the Appropriate Subsystem

    Linking X Applications

    Locations of X Windows Files

    Using Icons

    Using Wintif

    Switching Between Motif and Windows Modes

    Runtime Detection of Mode

    Changes to Motif Resource Defaults

    New Wintif Resources

    Changes to Motif Widget Behavior

    Changes to Motif Widget Resources

    File Selection

    Easing the Transition from Motif to Wintif

    Simultaneous Installation of Motif and Wintif

  14. Porting Shared Libraries
  15. Building DLLs for NuTCRACKER Platform Applications

    Building Basic DLLs

    Avoiding the Module Definition File

    Exporting C++ Functions from DLLs

    Performing Actions at DLL Initialization and Shutdown

    Dynamically Loadable DLLs

    Exporting Data from DLLs

    Building Standalone DLLs

    Issues

    Preparing DLL Interfaces

    Special Scenarios

    MKS Toolkit UNIX API Differences

  16. Porting Threaded Applications
  17. NuTCRACKER Platform POSIX Threads Implementation

    NuTCRACKER Platform Threads

    Optional POSIX Threads Features

    UNIX 98 (Aspen) Threads Extensions

    UNIX 03 Threads Extensions

    NuTCRACKER Platform POSIX Threads Extensions

    Threaded X Applications

    Threads Implementations on Popular UNIX Platforms

    Other POSIX Threads Implementations

    UNIX International (Solaris) Threads

    Other Threading Packages

    Porting Threaded Software from UNIX to NuTCRACKER Platform

    Porting Draft 10 POSIX Threads

    Porting Draft 7 POSIX Threads

    Porting Draft 4 (DCE) POSIX Threads

    Porting UNIX International (Solaris) Threads

    Porting Other Threading Packages

    NuTCRACKER Platform POSIX Threads and Win32 Threads

    Reducing Porting Complexity

    Implementing Signal Handlers

    Using Threads In Place of fork()

  18. Porting Daemons
  19. Concepts

    Windows NT
    2000/XP/2003

    Windows Me

    Converting a Daemon to a Service

    Porting an Application

    The NuTCRACKER Platform Service Framework 123

    Debugging a Service

    Installing and Testing a Service

    Distributing a Service

  20. Porting Applications to 64-bit Windows
  21. The Microsoft Platform SDK

    Overview of the Process

    Determining the Scope of the Port

    Source Code Issues

    Compiling and Linking a 64-bit application

    Debugging a 64-bit Application

    Porting Issues

    Porting to 64-bit UNIX Platforms

    Best Practices

  22. Deploying Applications
  23. Concepts

    Runtime Components

    Packaging/Licensing

    Deployment Mechanisms

    Definitions

    Deployment Overview

    Ensuring an Application Can Coexist

    Installing the Deployment License Key

    Running the NuTCRACKER Deployment Wizard

    Selecting Components

    Staging the Components

    Writing an Installer

    Using the Installation API

    Installation Overview

    Files

    The Installation API

    Error Handling

    Checking Permissions

    Installing the Components

    Registering Your Application

    Selecting a Preferred X Server

    Installing Files in the Root Directory

    Distributing Third-Party Options

    Uninstalling Your Application

  24. Environment Variables
  25. Console Escape Sequences
  26. Keyboard Keycaps

    Screen Functions

  27. Evolving Applications with COM
  28. Introduction

    COM Overview

    COM Benefits

    Using the NuTCRACKER Platform and COM

    Using Components

  29. The Communications Port Interface
  30. Com Port Devices

    Com Port Control

    The termios and termiox Structures

    Supported ioctl() Operations

    Supported fcntl() Operations

    Other Operations

   Index