Win32 API Emulation on UNIX for Software DSM



Similar documents
Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Shared Address Space Computing: Programming

CS222: Systems Programming

Recursion C++ DSP Toolkit Libraries DM6437 Cross Development

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Operating Systems. 05. Threads. Paul Krzyzanowski. Rutgers University. Spring 2015

COS 318: Operating Systems

How To Write A Windows Operating System (Windows) (For Linux) (Windows 2) (Programming) (Operating System) (Permanent) (Powerbook) (Unix) (Amd64) (Win2) (X

Outline. Review. Inter process communication Signals Fork Pipes FIFO. Spotlights

MatrixSSL Porting Guide

Introduction to Virtual Machines

VMware and CPU Virtualization Technology. Jack Lo Sr. Director, R&D

Windows CE Programming For Pocket PC In A Nutshell

A Unified Approach for Cross-Platform Software Development

CSE 120 Principles of Operating Systems. Modules, Interfaces, Structure

Systemnahe Programmierung KU

Performance Comparison of RTOS

Kernel comparison of OpenSolaris, Windows Vista and. Linux 2.6

CS 33. Multithreaded Programming V. CS33 Intro to Computer Systems XXXVII 1 Copyright 2015 Thomas W. Doeppner. All rights reserved.

OPERATING SYSTEMS STRUCTURES

IBM Software Group. Lotus Domino 6.5 Server Enablement

MatrixSSL Developer s Guide

1 Posix API vs Windows API

Session NM059. TCP/IP Programming on VMS. Geoff Bryant Process Software

Advanced topics: reentrant function

3 - Lift with Monitors

The Plan Today... System Calls and API's Basics of OS design Virtual Machines

Multi-Threading Performance on Commodity Multi-Core Processors

Multi-core Programming System Overview

How To Write Portable Programs In C

Operating System Overview. Otto J. Anshus

Chapter 6, The Operating System Machine Level

High Performance Computing in Aachen

CS3600 SYSTEMS AND NETWORKS

POSIX. RTOSes Part I. POSIX Versions. POSIX Versions (2)

Crash Course in Java

Operating Systems for Parallel Processing Assistent Lecturer Alecu Felician Economic Informatics Department Academy of Economic Studies Bucharest

Debugging with TotalView

Red Hat Linux Internals

SYSTEM ecos Embedded Configurable Operating System

REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-12: Real Time Linux

Real-Time Systems Prof. Dr. Rajib Mall Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

The POSIX Socket API

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Libmonitor: A Tool for First-Party Monitoring

Virtuozzo Virtualization SDK

Intel P6 Systemprogrammering 2007 Föreläsning 5 P6/Linux Memory System

Encryption Wrapper. on OSX

Efficient Implementation of the bare-metal Hypervisor MetalSVM for the SCC

CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson

Designing and Building Portable Systems in C++

Performance Evaluation and Optimization of A Custom Native Linux Threads Library

Operating Systems and Networks

FAME Operating Systems

Writing a C-based Client/Server

Building Applications Using Micro Focus COBOL

An Overview of Java. overview-1

ReactOS is (not) Windows. Windows internals and why ReactOS couldn t just use a Linux kernel

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

Specific Simple Network Management Tools

Chapter 16: Virtual Machines. Operating System Concepts 9 th Edition

Operating System Components and Services

Middleware and Distributed Systems. Design of Scalable Servers. Martin v. Löwis. Donnerstag, 16. Februar 12

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Chapter 2 System Structures

RTEMS Porting Guide. On-Line Applications Research Corporation. Edition , for RTEMS July 2015

Operating System Structures

Why Threads Are A Bad Idea (for most purposes)

Operating System Structures

Project Report on Implementation and Testing of an HTTP/1.0 Webserver

Virtual Servers. Virtual machines. Virtualization. Design of IBM s VM. Virtual machine systems can give everyone the OS (and hardware) that they want.

Lecture 1 Operating System Overview

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

What is an RTOS? Introduction to Real-Time Operating Systems. So what is an RTOS?(contd)

Shared Memory Introduction

Integration with Active Directory. Jeremy Allison Samba Team

Windows NT. Chapter 11 Case Study 2: Windows Windows 2000 (2) Windows 2000 (1) Different versions of Windows 2000

Using NSM for Event Notification. Abstract. with DM3, R4, and Win32 Devices

Virtualization is set to become a key requirement

CSE 452: Programming Languages. Acknowledgements. Contents. Java and its Evolution

Frysk The Systems Monitoring and Debugging Tool. Andrew Cagney

Client-server Sockets

Pemrograman Dasar. Basic Elements Of Java

IBM CICS Transaction Gateway for Multiplatforms, Version 7.0

C++ Programming Language

Virtualization. Types of Interfaces

3.5. cmsg Developer s Guide. Data Acquisition Group JEFFERSON LAB. Version

Control 2004, University of Bath, UK, September 2004

CS414 SP 2007 Assignment 1

Chapter 3 Operating-System Structures

CSC230 Getting Starting in C. Tyler Bletsch

Web Server Architectures

RIOS: A Lightweight Task Scheduler for Embedded Systems

Experimental Evaluation of Distributed Middleware with a Virtualized Java Environment

HULFT7e for i5os(ver.7.3.0) Effective on 3 Apr HULFT7e for UNIX-M(Ver.7.3.0) HULFT7e for UNIX-L(Ver.7.3.0) Effective on 3 Apr.

Between Mutual Trust and Mutual Distrust: Practical Fine-grained Privilege Separation in Multithreaded Applications

Enabling Technologies for Distributed Computing

GTask Developing asynchronous applications for multi-core efficiency

ELEC 377. Operating Systems. Week 1 Class 3

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Transcription:

Win32 API Emulation on UNIX for Software DSM Agenda: Sven M. Paas, Thomas Bemmerl, Karsten Scholtyssik, RWTH Aachen, Germany http://www.lfbs.rwth-aachen.de/ contact@lfbs.rwth-aachen.de Background Our approach: emulating a reasonable Win32 API subset Implementation details of nt2unix (multithreading, memory mapped I/O,...) A case study: SVMlib: Shared Virtual Memory Library Conclusions

Background The Problem: Given a console application written in C / C++ for Win32; --> Visual C++ 5.0 + STL, Windows NT 4.0 / Windows 95 Compile (and execute) the same code on a UNIX system --> gcc 2.8.1 + STL, Solaris 2.6 [SPARC/x86], Linux 2.0 [x86] Available Solutions: Wind/U (Bristol Technology, Inc., http://www.bristol.com/) MainWin XDE (MainSoft Corp., http://www.mainsoft.com/) Willows Twin API (Canopy Group, http://www.willows.com/)

A reasonable Win32 Subset NT Multithreading Creating / Destroying / Suspending / Resuming preemptive threads Synchronization and Thread Local Storage (TLS) functions; Virtual Memory (VM) Management Allocating / Committing / Protecting VM on page level Memory Mapping I/O, File Mapping NT Structured Exception Handling (SEH) User Level Page Fault Handling by SEH Networking using WinSock Windows Sockets API for TCP/IP

Windows NT Multithreading Creating a Thread under NT: WINBASEAPI HANDLE WINAPI CreateThread( LPSECURITY_ATTRIBUTES lpthreadattributes, DWORD dwstacksize, LPTHREAD_START_ROUTINE lpstartaddress, LPVOID lpparameter, DWORD dwcreationflags, LPDWORD lpthreadid); with typedef DWORD (WINAPI *PTHREAD_START_ROUTINE)( LPVOID lpthreadparameter); typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE;

UNIX Multithreading Creating a Thread using POSIX API: int pthread_create( pthread_t *new_thread_id, const pthread_attr_t *attr, void *(*start_func)(void *), void *arg);... and using the Solaris Thread API: int thr_create(void *stack_base, size_t stack_size, void *(*start_func)(void *), void *arg, long flags, thread_t *new_thread_id); --> we must ignore LPSECURITY_ATTRIBUTES. (like Windows 95 / 98 does)

Problems: NT Thread Synchronization Susending / Resuming Threads is not possible within the POSIX Thead API! (-> SuspendThread(), ResumeThread()) This fact implies that some Win32 thread concepts are hard to implement efficiently within POSIX environments: struct ThreadInfo { DWORD state, suspendcount, exitcode; #ifdef POSIX_THREADS pthread_cond_t cond, pthread_mutex_t mutex; #else volatile BOOL threadhasbeenresumed; #endif };

Virtual Memory (VM) Management Emulating a Windows NT File Mapping Object: struct FileMapping { LPVOID lpbaseaddress; // the virtual base address of the mapping DWORD dwnumberofbytestomap; // the mapping size in bytes HANDLE hfilemappingobject; // the file handle char FileName[MAX_PATH]; // the file name DWORD refcnt; // the number of references to the mapping }; static vector<filemapping> FileMappings;

NT Structured Exception Handling Two methods: by embracing code with a try{}... except(){} block; by installing a user level exception handler by calling SetUnhandledExceptionFilter(). Translation of NT Exception Codes to UNIX signals: Windows NT EXCEPTION_* Code UNIX Signal ACCESS_VIOLATION SIGSEGV FLT_INVALID_OPERATION SIGFPE ILLEGAL_INSTRUCTION SIGILL IN_PAGE_ERROR SIGBUS SINGLE_STEP SIGTRAP

Catching Page Faults 1st problem: where was the fault? switch (sig) { case SIGSEGV: // A segmentation violation. ExceptionInfo.ExceptionRecord-> ExceptionCode = EXCEPTION_ACCESS_VIOLATION; ExceptionInfo.ExceptionRecord-> ExceptionInformation[0] = #if defined( SPARC) (*(unsigned *)((ucontext_t*)uap) ->uc_mcontext.gregs[reg_pc] & (1<<21)); #elif defined( X86) (((ucontext_t*)uap)-> uc_mcontext.gregs[err] & 2); #elif defined( LINUXX86) stack[14] & 2; #endif

Catching Page Faults (cont d) 2nd problem: what was the reason for the fault? if (ExceptionInfo.ExceptionRecord-> ExceptionInformation[0]) ExceptionInfo.ExceptionRecord-> ExceptionInformation[0] = 1; // 1 == write access; 0 == read access ExceptionInfo.ExceptionRecord-> ExceptionInformation[1] = #ifdef LINUXX86 stack[22]; #else (DWORD)sip->si_addr; #endif break; } // other signals processed here...

TCP/IP Networking using WinSock Ideas:- Restrict WinSock 2.0 to BSD Socket API - Translate data types, definitions, and error codes For example: typedef int SOCKET; #define INVALID_SOCKET(SOCKET)(-1) #define SOCKET_ERROR (-1) Pitfalls: - some types are hard to map (e.g. fd_set) - WinSock s select() is not BSD select()!

A Case Study: SVMlib SVMlib: Shared Virtual Memory Library all software, user-level, page based about 15.000 lines of (Visual) C++ code, natively for Win32 SVMlib API [SMI, SPLASH, CVM...] MemoryManager Page Fault Handling LockManager IntervalManager Communicator Win32 API Windows NT 4.0 nt2unix

SVMlib Performance (1) Page Fault Detection Time: Windows NT 4.0 Server / WS Solaris 2.5.1 (native) Solaris 2.5.1 & nt2unix Super- SPARC, 50 MHz Pentium, 133 MHz --> UNIX Signal handling is expensive. Pentium Pro, 200 MHz - 28 µs 19 µs 105 µs 70 µs 40 µs 135 µs 92 µs 48 µs

SVMlib Performance (2) Page Fault Handling Times: N o d e s R / W / Avrg Fault Time [ms] CVM on Solaris (Sun SS20) Test Application: FFT R / W / Avrg Fault Time [ms] SVMlib on nt2unix (Sun SS20) R / W / Avrg Fault Time [ms] SVMlib on Windows NT (Intel Pentium 133) 2 11.3 / 0.8 / 4.4 4.5 / 1.3 / 2.2 3.4 / 1.1 / 1.8 3 12.0 / 0.8 / 5.8 4.6 / 1.8 / 2.7 3.4 / 1.4 / 2.3 4 16.7 / 0.9 / 7.1 4.9 / 1.8 / 3.1 4.0 / 1.5 / 2.4

Conclusions Win32 API Emulation under UNIX is possible. If the Emulation is application driven, it can be implemented within finite time (3 MM for SVMlib); nt2unix is a reasonable first step to develop portable low level applications. Next Steps: More complete implementation of Win32 base services; More applications (NT Services <-> UNIX Daemons)

Further Information nt2unix Project Homepage: http://www.lfbs.rwth-aachen.de/~sven/nt2unix/ SVMlib Project Homepage: http://www.lfbs.rwth-aachen.de/~sven/svmlib/ E-Mail: contact@lfbs.rwth-aachen.de Phone/Fax: +49-241-7634, +49-241-8888-339