Igor Zhirkov

Low-Level Programming

C, Assembly, and Program Execution on Intel ® 64 Architecture

Igor Zhirkov

Saint Petersburg, Russia

Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/9781484224021 . For more detailed information, please visit http://www.apress.com/source-code .

ISBN 978-1-4842-2402-1

e-ISBN 978-1-4842-2403-8

DOI 10.1007/978-1-4842-2403-8

Library of Congress Control Number: 2017945327

© Igor Zhirkov 2017

This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.

Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.

While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.

Printed on acid-free paper

Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.

Introduction

This book aims to help you develop a consistent vision of the domain of low-level programming. We want to enable a careful reader to

  • Freely write in assembly language.

  • Understand the Intel 64 programming model.

  • Write maintainable and robust code in C11.

  • Understand the compilation process and decipher assembly listings.

  • Debug errors in compiled assembly code.

  • Use appropriate models of computation to greatly reduce program complexity.

  • Write performance-critical code.

There are two kinds of technical books: those used as a reference and those used to learn. This book is, without doubt, the second kind. It is pretty dense on purpose, and in order to successfully digest the information we highly suggest continuous reading. To quickly memorize new information you should try to connect it with the information with which you are already familiar. That is why we tried, whenever possible, to base our explanation of each topic on the information you received from previous topics.

This book is written for programming students, intermediate-to-advanced programmers, and low-level programming enthusiasts. The prerequisites are a basic understanding of binary and hexadecimal systems and a basic knowledge of Unix commands.

Questions and Answers

Throughout this book you will encounter numerous questions. Most of them are meant to make you think again about what you have just learned, but some of them encourage you to do additional research, pointing to the relevant keywords.

We propose the answers to these questions in our GitHub page, which also hosts all listings and starting code for assignments, updates and other goodies.

Refer to the book’s page on Apress site for additional information: http://www.apress.com/us/book/9781484224021 .

There you can also find several preconfigured virtual machines with Debian Linux installed, with and without a graphical user interface (GUI), which allows you to start practicing right away without spending time setting up your system. You can find more information in section 2.1.

We start with the very simple core ideas of what a computer is, explaining concepts of model of computation and computer architecture. We expand the core model with extensions until it becomes adequate enough to describe a modern processor as a programmer sees it. From Chapter 2 onward we start programming in the real assembly language for Intel 64 without resorting to older 16-bit architectures, that are often taught for historical reasons. It allows us to see the interactions between applications and operating system through the system calls interface and the specific architecture details such as endianness. After a brief overview of legacy architecture features, some of which are still in use, we study virtual memory in great detail and illustrate its usage with the help of procfs and examples of using mmap system call in assembly. Then we dive into the process of compilation, overviewing preprocessing, static, and dynamic linking. After exploring interrupts and system calls mechanisms in greater detail, we finish the first part with a chapter about different models of computations, studying examples of finite state machines, stack machines, and implementing a fully functional compiler of Forth language in pure assembly.

The second part is dedicated to the C language. We start from the language overview, building a core understanding of its model of computation necessary to start writing programs. In the next chapter we study the type system of C and illustrate different kinds of typing, ending with about a discussion of polymorphism and providing exemplary implementations for different kinds of polymorphism in C. Then we study the ways of correctly structuring the program by splitting it into multiple files and also viewing its effect on the linking process. The next chapter is dedicated to the memory management, input and output. After that, we elaborate three facets of each language: syntax, semantics, and pragmatics and concentrate on the first and the third ones. We see how the language propositions are transformed into abstract syntax trees, the difference between undefined and unspecified behavior in C, and the effect of language pragmatics on the assembly code produced by the compiler. In the end of the second part, we dedicate a chapter to the good code practices to give readers an idea of how the code should be written depending on its specific requirements. The sequence of the assignments for this part is ended by the rotation of a bitmap file and a custom memory allocator.

The final part is a bridge between the two previous ones. It dives into the translation details such as calling conventions and stack frames and advanced C language features, requiring a certain understanding of assembly, such as volatile and restrict keywords. We provide an overview of several classic low-level bugs such as stack buffer overflow, which can be exploited to induce an unwanted behavior in the program. The next chapter tells about shared objects in great details and studies them on the assembly level, providing minimal working examples of shared libraries written in C and assembly. Then, we discuss a relatively rare topic of code models. The chapter studies the optimizations that modern compilers are capable of and how that knowledge can be used to produce readable and fast code. We also provide an overview of performance-amplifying techniques such as specialized assembly instructions usage and cache usage optimization. This is followed by an assignment where you will implement a sepia filter for an image using specialized SSE instructions and measure its performance. The last chapter introduces multithreading via pthreads library usage, memory models, and reorderings, which anyone doing multithreaded programming should be aware of, and elaborates the need for memory barriers.

The appendices include short tutorials on gdb (debugger), make (automated build system), and a table of the most frequently used system calls for reference and system information to make performance tests given throughout the book easier to reproduce. They should be read when necessary, but we recommend that you get used to gdb as soon as you start assembly programming in Chapter 2 .

Most illustrations were produced using VSVG library aimed to produce complex interactive vector graphics, written by Alexey Velikiy ( http://www.corpglory.com ). The sources for the library and book illustrations are available at VSVG Github page: https://github.com/corpglory/vsvg .

We hope that you find this book useful and wish you an enjoyable read!

Acknowledgments

I was blessed to meet a great number of persons, both very gifted and extremely dedicated, who helped me and often guided me toward the areas of knowledge I could never have imagined myself.

I thank Vladimir Nekrasov, my most beloved math teacher, for his course and his influence on me, which enabled me to think better and more logically.

I thank Andrew Dergachev, who entrusted me to create and teach my course and helped me so much during these years, Boris Timchenko, Arkady Kluchev, Ivan Loginov (who also kindly agreed to be the technical reviewer for this book), and all my colleagues from ITMO university, who helped me to shape this course in one way or another.

I thank all my students who provided feedback or even helped me in teaching. You are the very reason I am doing this. Several students helped by reviewing the draft of this book, I want to note the most useful remarks of Dmitry Khalansky and Valery Kireev.

For me, the years I have spent in Saint-Petersburg Academic University are easily the best of my life. Never have I had more opportunities to study with world-class specialists working in the leading companies along with other students, much smarter than me. I want to express my deepest gratitude to Alexander Omelchenko, Alexander Kulikov, Andrey Ivanov, and everyone contributing to the quality of computer science education in Russia. I also thank Dmitry Boulytchev, Andrey Breslav, and Sergey Sinchuk from JetBrains, my supervisors who have taught me a lot.

I am also very grateful to my french colleagues: Ali Ed-Dbali, Frédéric Loulergue, Rémi Douence, and Julien Cohen.

I also want to thank Sergei Gorlatch and Tim Humernbrum for providing much necessary feedback on Chapter 17 , which helped me shape it into a much more consistent and understandable version. Special thanks go to Dmitry Shubin for his most useful impact on fixing the imperfections of this book.

I am very grateful to my friend Alexey Velikiy and to his agency CorpGlory.com, which focused on data visualizations and infographics and crafted the best illustrations in this book.

Behind every little success of mine is an infinite amount of support from my family and friends. I would not have achieved anything without you.

Last, but not least, I thank the Apress team, including Robert Hutchinson, Rita Fernando, Laura Berendson, and Susan McDermott, for putting their trust in me and this project and doing everything they could to bring this book into reality.

Contents

  1. Part I: Assembly Language and Computer Architecture
    1. Chapter 1:​ Basic Computer Architecture
      1. 1.​1 The Core Architecture
        1. 1.​1.​1 Model of Computation
        2. 1.​1.​2 von Neumann Architecture
      2. 1.​2 Evolution
        1. 1.​2.​1 Drawbacks of von Neumann Architecture
        2. 1.​2.​2 Intel 64 Architecture
        3. 1.​2.​3 Architecture Extensions
      3. 1.​3 Registers
        1. 1.​3.​1 General Purpose Registers
        2. 1.​3.​2 Other Registers
        3. 1.​3.​3 System Registers
      4. 1.​4 Protection Rings
      5. 1.​5 Hardware Stack
      6. 1.​6 Summary
    2. Chapter 2:​ Assembly Language
      1. 2.​1 Setting Up the Environment
        1. 2.​1.​1 Working with Code Examples
      2. 2.​2 Writing “Hello, world”
        1. 2.​2.​1 Basic Input and Output
        2. 2.​2.​2 Program Structure
        3. 2.​2.​3 Basic Instructions
      3. 2.​3 Example:​ Output Register Contents
        1. 2.​3.​1 Local Labels
        2. 2.​3.​2 Relative Addressing
        3. 2.​3.​3 Order of Execution
      4. 2.​4 Function Calls
      5. 2.​5 Working with Data
        1. 2.​5.​1 Endianness
        2. 2.​5.​2 Strings
        3. 2.​5.​3 Constant Precomputation
        4. 2.​5.​4 Pointers and Different Addressing Types
      6. 2.​6 Example:​ Calculating String Length
      7. 2.​7 Assignment:​ Input/​Output Library
        1. 2.​7.​1 Self-Evaluation
      8. 2.​8 Summary
    3. Chapter 3:​ Legacy
      1. 3.​1 Real mode
      2. 3.​2 Protected Mode
      3. 3.​3 Minimal Segmentation in Long Mode
      4. 3.​4 Accessing Parts of Registers
        1. 3.​4.​1 An Unexpected Behavior
        2. 3.​4.​2 CISC and RISC
        3. 3.​4.​3 Explanation
      5. 3.​5 Summary
    4. Chapter 4:​ Virtual Memory
      1. 4.​1 Caching
      2. 4.​2 Motivation
      3. 4.​3 Address Spaces
      4. 4.​4 Features
      5. 4.​5 Example:​ Accessing Forbidden Address
      6. 4.​6 Efficiency
      7. 4.​7 Implementation
        1. 4.​7.​1 Virtual Address Structure
        2. 4.​7.​2 Address Translation in Depth
        3. 4.​7.​3 Page Sizes
      8. 4.​8 Memory Mapping
      9. 4.​9 Example:​ Mapping File into Memory
        1. 4.​9.​1 Mnemonic Names for Constants
        2. 4.​9.​2 Complete Example
      10. 4.​10 Summary
    5. Chapter 5:​ Compilation Pipeline
      1. 5.​1 Preprocessor
        1. 5.​1.​1 Simple Substitutions
        2. 5.​1.​2 Substitutions with Arguments
        3. 5.​1.​3 Simple Conditional Substitution
        4. 5.​1.​4 Conditioning on Definition
        5. 5.​1.​5 Conditioning on Text Identity
        6. 5.​1.​6 Conditioning on Argument Type
        7. 5.​1.​7 Evaluation Order:​ Define, xdefine, Assign
        8. 5.​1.​8 Repetition
        9. 5.​1.​9 Example:​ Computing Prime Numbers
        10. 5.​1.​10 Labels Inside Macros
        11. 5.​1.​11 Conclusion
      2. 5.​2 Translation
      3. 5.​3 Linking
        1. 5.​3.​1 Executable and Linkable Format
        2. 5.​3.​2 Relocatable Object Files
        3. 5.​3.​3 Executable Object Files
        4. 5.​3.​4 Dynamic Libraries
        5. 5.​3.​5 Loader
      4. 5.​4 Assignment:​ Dictionary
      5. 5.​5 Summary
    6. Chapter 6:​ Interrupts and System Calls
      1. 6.​1 Input and Output
        1. 6.​1.​1 TR register and Task State Segment
      2. 6.​2 Interrupts
      3. 6.​3 System Calls
        1. 6.​3.​1 Model-Specific Registers
        2. 6.​3.​2 syscall and sysret
      4. 6.​4 Summary
    7. Chapter 7:​ Models of Computation
      1. 7.​1 Finite State Machines
        1. 7.​1.​1 Definition
        2. 7.​1.​2 Example:​ Bits Parity
        3. 7.​1.​3 Implementation in Assembly Language
        4. 7.​1.​4 Practical Value
        5. 7.​1.​5 Regular Expressions
      2. 7.​2 Forth Machine
        1. 7.​2.​1 Architecture
        2. 7.​2.​2 Tracing an Exemplary Forth Program
        3. 7.​2.​3 Dictionary
        4. 7.​2.​4 How Words Are Implemented
        5. 7.​2.​5 Compiler
      3. 7.​3 Assignment:​ Forth Compiler and Interpreter
        1. 7.​3.​1 Static Dictionary, Interpreter
        2. 7.​3.​2 Compilation
        3. 7.​3.​3 Forth with Bootstrap
      4. 7.​4 Summary
  2. Part II: The C Programming Language
    1. Chapter 8:​ Basics
      1. 8.​1 Introduction
      2. 8.​2 Program Structure
        1. 8.​2.​1 Data Types
      3. 8.​3 Control Flow
        1. 8.​3.​1 if
        2. 8.​3.​2 while
        3. 8.​3.​3 for
        4. 8.​3.​4 goto
        5. 8.​3.​5 switch
        6. 8.​3.​6 Example:​ Divisor
        7. 8.​3.​7 Example:​ Is It a Fibonacci Number?​
      4. 8.​4 Statements and Expressions
        1. 8.​4.​1 Statement Types
        2. 8.​4.​2 Building Expressions
      5. 8.​5 Functions
      6. 8.​6 Preprocessor
      7. 8.​7 Summary
    2. Chapter 9:​ Type System
      1. 9.​1 Basic Type System of C
        1. 9.​1.​1 Numeric Types
        2. 9.​1.​2 Type Casting
        3. 9.​1.​3 Boolean Type
        4. 9.​1.​4 Implicit Conversions
        5. 9.​1.​5 Pointers
        6. 9.​1.​6 Arrays
        7. 9.​1.​7 Arrays as Function Arguments
        8. 9.​1.​8 Designated Initializers in Arrays
        9. 9.​1.​9 Type Aliases
        10. 9.​1.​10 The Main Function Revisited
        11. 9.​1.​11 Operator sizeof
        12. 9.​1.​12 Const Types
        13. 9.​1.​13 Strings
        14. 9.​1.​14 Functional Types
        15. 9.​1.​15 Coding Well
        16. 9.​1.​16 Assignment:​ Scalar Product
        17. 9.​1.​17 Assignment:​ Prime Number Checker
      2. 9.​2 Tagged Types
        1. 9.​2.​1 Structures
        2. 9.​2.​2 Unions
        3. 9.​2.​3 Anonymous Structures and Unions
        4. 9.​2.​4 Enumerations
      3. 9.​3 Data Types in Programming Languages
        1. 9.​3.​1 Kinds of Typing
        2. 9.​3.​2 Polymorphism
      4. 9.​4 Polymorphism in C
        1. 9.​4.​1 Parametric Polymorphism
        2. 9.​4.​2 Inclusion
        3. 9.​4.​3 Overloading
        4. 9.​4.​4 Coercions
      5. 9.​5 Summary
    3. Chapter 10:​ Code Structure
      1. 10.​1 Declarations and Definitions
        1. 10.​1.​1 Function Declarations
        2. 10.​1.​2 Structure Declarations
      2. 10.​2 Accessing Code from Other Files
        1. 10.​2.​1 Functions from Other Files
        2. 10.​2.​2 Data in Other Files
        3. 10.​2.​3 Header Files
      3. 10.​3 Standard Library
      4. 10.​4 Preprocessor
        1. 10.​4.​1 Include Guard
        2. 10.​4.​2 Why Is Preprocessor Evil?​
      5. 10.​5 Example:​ Sum of a Dynamic Array
        1. 10.​5.​1 Sneak Peek into Dynamic Memory Allocation
        2. 10.​5.​2 Example
      6. 10.​6 Assignment:​ Linked List
        1. 10.​6.​1 Assignment
      7. 10.​7 The Static Keyword
      8. 10.​8 Linkage
      9. 10.​9 Summary
    4. Chapter 11:​ Memory
      1. 11.​1 Pointers Revisited
        1. 11.​1.​1 Why Do We Need Pointers?​
        2. 11.​1.​2 Pointer Arithmetic
        3. 11.​1.​3 The void* Type
        4. 11.​1.​4 NULL
        5. 11.​1.​5 A Word on ptrdiff_​t
        6. 11.​1.​6 Function Pointers
      2. 11.​2 Memory Model
        1. 11.​2.​1 Memory Allocation
      3. 11.​3 Arrays and Pointers
        1. 11.​3.​1 Syntax Details
      4. 11.​4 String Literals
        1. 11.​4.​1 String Interning
      5. 11.​5 Data Models
      6. 11.​6 Data Streams
      7. 11.​7 Assignment:​ Higher-Order Functions and Lists
        1. 11.​7.​1 Common Higher-Order Functions
        2. 11.​7.​2 Assignment
      8. 11.​8 Summary
    5. Chapter 12:​ Syntax, Semantics, and Pragmatics
      1. 12.​1 What Is a Programming Language?​
      2. 12.​2 Syntax and Formal Grammars
        1. 12.​2.​1 Example:​ Natural Numbers
        2. 12.​2.​2 Example:​ Simple Arithmetics
        3. 12.​2.​3 Recursive Descent
        4. 12.​2.​4 Example:​ Arithmetics with Priorities
        5. 12.​2.​5 Example:​ Simple Imperative Language
        6. 12.​2.​6 Chomsky Hierarchy
        7. 12.​2.​7 Abstract Syntax Tree
        8. 12.​2.​8 Lexical Analysis
        9. 12.​2.​9 Summary on Parsing
      3. 12.​3 Semantics
        1. 12.​3.​1 Undefined Behavior
        2. 12.​3.​2 Unspecified Behavior
        3. 12.​3.​3 Implementation-Defined Behavior
        4. 12.​3.​4 Sequence Points
      4. 12.​4 Pragmatics
        1. 12.​4.​1 Alignment
        2. 12.​4.​2 Data Structure Padding
      5. 12.​5 Alignment in C11
      6. 12.​6 Summary
    6. Chapter 13:​ Good Code Practices
      1. 13.​1 Making Choices
      2. 13.​2 Code Elements
        1. 13.​2.​1 General Naming
        2. 13.​2.​2 File Structure
        3. 13.​2.​3 Types
        4. 13.​2.​4 Variables
        5. 13.​2.​5 On Global Variables
        6. 13.​2.​6 Functions
      3. 13.​3 Files and Documentation
      4. 13.​4 Encapsulation
      5. 13.​5 Immutability
      6. 13.​6 Assertions
      7. 13.​7 Error Handling
      8. 13.​8 On Memory Allocation
      9. 13.​9 On Flexibility
      10. 13.​10 Assignment:​ Image Rotation
        1. 13.​10.​1 BMP File Format
        2. 13.​10.​2 Architecture
      11. 13.​11 Assignment:​ Custom Memory Allocator
      12. 13.​12 Summary
  3. Part III: Between C and Assembly
    1. Chapter 14:​ Translation Details
      1. 14.​1 Function Calling Sequence
        1. 14.​1.​1 XMM Registers
        2. 14.​1.​2 Calling Convention
        3. 14.​1.​3 Example:​ Simple Function and Its Stack
        4. 14.​1.​4 Red Zone
        5. 14.​1.​5 Variable Number of Arguments
        6. 14.​1.​6 vprintf and Friends
      2. 14.​2 volatile
        1. 14.​2.​1 Lazy Memory Allocation
        2. 14.​2.​2 Generated Code
      3. 14.​3 Non-Local jumps–setjmp
        1. 14.​3.​1 Volatile and setjmp
      4. 14.​4 inline
      5. 14.​5 restrict
      6. 14.​6 Strict Aliasing
      7. 14.​7 Security Issues
        1. 14.​7.​1 Stack Buffer Overrun
        2. 14.​7.​2 return-to-libc
        3. 14.​7.​3 Format Output Vulnerabilities
      8. 14.​8 Protection Mechanisms
        1. 14.​8.​1 Security Cookie
        2. 14.​8.​2 Address Space Layout Randomization
        3. 14.​8.​3 DEP
      9. 14.​9 Summary
    2. Chapter 15:​ Shared Objects and Code Models
      1. 15.​1 Dynamic Loading
      2. 15.​2 Relocations and PIC
      3. 15.​3 Example:​ Dynamic Library in C
      4. 15.​4 GOT and PLT
        1. 15.​4.​1 Accessing External Variables
        2. 15.​4.​2 Calling External Functions
        3. 15.​4.​3 PLT Example
      5. 15.​5 Preloading
      6. 15.​6 Symbol Addressing Summary
      7. 15.​7 Examples
        1. 15.​7.​1 Calling a Function
        2. 15.​7.​2 On Various Dynamic Linkers
        3. 15.​7.​3 Accessing an External Variable
        4. 15.​7.​4 Complete Assembly Example
        5. 15.​7.​5 Mixing C and Assembly
      8. 15.​8 Which Objects Are Linked?​
      9. 15.​9 Optimizations
      10. 15.​10 Code Models
        1. 15.​10.​1 Small Code Model (No PIC)
        2. 15.​10.​2 Large Code Model (No PIC)
        3. 15.​10.​3 Medium Code Model (No PIC)
        4. 15.​10.​4 Small PIC Code Model
        5. 15.​10.​5 Large PIC Code Model
        6. 15.​10.​6 Medium PIC Code Model
      11. 15.​11 Summary
    3. Chapter 16:​ Performance
      1. 16.​1 Optimizations
        1. 16.​1.​1 Myth About Fast Languages
        2. 16.​1.​2 General Advice
        3. 16.​1.​3 Omit Stack Frame Pointer
        4. 16.​1.​4 Tail recursion
        5. 16.​1.​5 Common Subexpressions Elimination
        6. 16.​1.​6 Constant Propagation
        7. 16.​1.​7 (Named) Return Value Optimization
        8. 16.​1.​8 Influence of Branch Prediction
        9. 16.​1.​9 Influence of Execution Units
        10. 16.​1.​10 Grouping Reads and Writes in Code
      2. 16.​2 Caching
        1. 16.​2.​1 How Do We use Cache Effectively?​
        2. 16.​2.​2 Prefetching
        3. 16.​2.​3 Example:​ Binary Search with Prefetching
        4. 16.​2.​4 Bypassing Cache
        5. 16.​2.​5 Example:​ Matrix Initialization
      3. 16.​3 SIMD Instruction Class
      4. 16.​4 SSE and AVX Extensions
        1. 16.​4.​1 Assignment:​ Sepia Filter
      5. 16.​5 Summary
    4. Chapter 17:​ Multithreading
      1. 17.​1 Processes and Threads
      2. 17.​2 What Makes Multithreading Hard?​
      3. 17.​3 Execution Order
      4. 17.​4 Strong and Weak Memory Models
      5. 17.​5 Reordering Example
      6. 17.​6 What Is Volatile and What Is Not
      7. 17.​7 Memory Barriers
      8. 17.​8 Introduction to pthreads
        1. 17.​8.​1 When to U se Multithreading
        2. 17.​8.​2 Creating Threads
        3. 17.​8.​3 Managing Threads
        4. 17.​8.​4 Example:​ Distributed Factorization
        5. 17.​8.​5 Mutexes
        6. 17.​8.​6 Deadlocks
        7. 17.​8.​7 Livelocks
        8. 17.​8.​8 Condition Variables
        9. 17.​8.​9 Spinlocks
      9. 17.​9 Semaphores
      10. 17.​10 How Strong Is Intel 64?​
      11. 17.​11 What Is Lock-Free Programming?​
      12. 17.​12 C11 Memory Model
        1. 17.​12.​1 Overview
        2. 17.​12.​2 Atomics
        3. 17.​12.​3 Memory Orderings in C11
        4. 17.​12.​4 Operations
      13. 17.​13 Summary
  4. Part IV: Appendices
    1. Chapter 18:​ Appendix A.​ Using gdb
    2. Chapter 19:​ Appendix B.​ Using Make
      1. 19.​1 Simple Makefile
      2. 19.​2 Throwing in Variables
      3. 19.​3 Automatic Variables
    3. Chapter 20:​ Appendix C.​ System Calls
      1. 20.​1 read
        1. 20.​1.​1 Arguments
      2. 20.​2 write
        1. 20.​2.​1 Arguments
      3. 20.​3 open
        1. 20.​3.​1 Arguments
        2. 20.​3.​2 Flags
      4. 20.​4 close
        1. 20.​4.​1 Arguments
      5. 20.​5 mmap
        1. 20.​5.​1 Arguments
        2. 20.​5.​2 Protection Flags
        3. 20.​5.​3 Behavior Flags
      6. 20.​6 munmap
        1. 20.​6.​1 Arguments
      7. 20.​7 exit
        1. 20.​7.​1 Arguments
    4. Chapter 21:​ Appendix D.​ Performance Tests Information
    5. Chapter 22:​ Bibliography
  5. Index

About the Author and About the Technical Reviewer

About the Author

A418868_1_En_BookFrontmatter_Figb_HTML.jpg

Igor Zhirkov teaches his highly successful “System Programming Languages” course in ITMO University in Saint-Petersburg, which is a six-time winner of the ACM-ICPC Intercollegiate World Programming Championship. He studied at Saint Petersburg Academic University and received his master’s degree from ITMO University. Currently he is doing research in verified C refactorings as part of his PhD thesis and formalization of Bulk Synchronous Parallelism library in C at IMT Atlantique in Nantes, France. His main interests are low-level programming, programming language theory, and type theory.

His other interests include playing piano, calligraphy, art, and the philosophy of science.

About the Technical Reviewer

A418868_1_En_BookFrontmatter_Figc_HTML.jpg

Ivan Loginov is a researcher and lecturer at ITMO University of Saint Petersburg, Russia (University of Information Technologies, Mechanics and Optics), teaching the course “Introduction to Programming Languages” to bachelor degree students of computer science.

He received his master’s degree from ITMO University. His research focuses on compiler theory, language workbenches, and distributed and parallel programming as well as new teaching techniques and their application to IT (information technology).

Currently, he is writing his PhD dissertation on a cloud-based modeling toolkit for system dynamics.

His hobbies include playing the trumpet and reading classic (Russian) literature.