Programs – Loading and Running an Executable

Slides:



Advertisements
Similar presentations
Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.
Advertisements

Lecture 10: Linking and loading. Lecture 10 / Page 2AE4B33OSS 2011 Contents Linker vs. loader Linking the executable Libraries Loading executable ELF.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access memory.
Week 4 - Friday.  What did we talk about last time?  Some extra systems programming stuff  Scope.
Copyright 2013 – Noah Mendelsohn Process Memory Noah Mendelsohn Tufts University Web:
Chapter 3 Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access.
Chapter 3.1:Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Section 3.1: Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random.
Topic 2d High-Level languages and Systems Software
CSE451 Linking and Loading Autumn 2002 Gary Kimura Lecture #21 December 9, 2002.
CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Processes Introduction to Operating Systems: Module 3.
Lecture 5 Page 1 CS 111 Online Processes CS 111 On-Line MS Program Operating Systems Peter Reiher.
Lecture Topics: 11/24 Sharing Pages Demand Paging (and alternative) Page Replacement –optimal algorithm –implementable algorithms.
Week 4 - Friday.  What did we talk about last time?  Some extra systems programming stuff  Scope.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Copyright © Curt Hill More on Operating Systems Continuation of Introduction.
Lecture 10 Page 1 CS 111 Online Memory Management CS 111 On-Line MS Program Operating Systems Peter Reiher.
Lecture 1 Page 1 CS 111 Summer 2013 Important OS Properties For real operating systems built and used by real people Differs depending on who you are talking.
Lecture 5 Page 1 CS 111 Online Process Creation Processes get created (and destroyed) all the time in a typical computer Some by explicit user command.
Memory – Virtual Memory, Virtual Machines
Introduction to Operating Systems Concepts
Programs – Preprocessing, Compilation and Linking
CS/COE 0449 (term 2174) Jarrett Billingsley
Virtual Memory: Implementing Paging
CS/COE 0447 (term 2181) Jarrett Billingsley
Virtual Memory: the Page Table and Page Swapping
Process Memory COMP 40: Machine Structure and
Programs – Loading and Running an Executable
Process Creation Processes get created (and destroyed) all the time in a typical computer Some by explicit user command Some by invocation from other running.
Memory Management and Virtual Memory
Operating System Structure
Program Execution in Linux
Process Realization In OS
Swapping Segmented paging allows us to have non-contiguous allocations
Software Development with uMPS
Programs – Dynamic Linking and Loading
Form Validation and AJAX
KERNEL ARCHITECTURE.
Intro to Multiprocessing
Processes in Unix, Linux, and Windows
Intro. To Operating Systems
Bitwise Operations and Bitfields
Memory Allocation CS 217.
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Memory Management Overview
Lecture 3: Main Memory.
CSCE 313 – Introduction to UNIx process
CSE 451: Operating Systems Autumn 2005 Memory Management
Linking & Loading CS-502 Operating Systems
CS/COE 0449 Jarrett Billingsley
Operating System Chapter 7. Memory Management
Programs – Preprocessing, Compilation and Linking
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Program Execution in Linux
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Operating Systems: A Modern Perspective, Chapter 6
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Lecture 7: Flexible Address Translation
Processes in Unix and Windows
CS510 Operating System Foundations
CSE 153 Design of Operating Systems Winter 2019
CS703 – Advanced Operating Systems
COMP755 Advanced Operating Systems
Outline Introduction Memory protection Buffer overflows
Presentation transcript:

Programs – Loading and Running an Executable CS/COE 0449 Jarrett Billingsley

Class announcements welcome back and from now until may, all of our momentum has gone CS449

Executables and Loading CS449

What the heck is in an executable file? pretty much the same stuff as an object file machine code ("text") data symbol table(s) OS-specific info objdump can inspect executables as well! this is because they use the same file format well, on most flavors of UNIX anyway... .text .data .bss .rodata CS449

Executable formats different OSes use different formats for their executable… things each of these formats is broadly similar, but each operating system works differently and so can require different information don't remember this table, it's just here for demonstration OS Format Executables Static Libraries Objects Shared Objects UNIXes ELF <nothing> *.a *.o *.so macOS Mach-O *.dylib Windows PE/COFF *.exe *.lib *.obj *.dll - there's no real standard on Windows for object and library files. - COFF is the format the MS compilers use, but gcc uses ELF. - but no matter what, .exe and .dll files are PE. - development on Windows is hell. CS449

load shared objects and copy into RAM copy code/data into RAM The final countdown the last step is loading the loader is the part of the OS that, uh, loads the executable any dynamic libs? load shared objects and copy into RAM yes open executable file copy code/data into RAM set up OS resources no start the new process! CS449

Processes CS449

All my children OS Kernel Code Memory Code Memory a process is the in-memory representation of a program, all its data, its resources (like open files), etc. the OS's main responsibility is controlling access to resources the OS wants everyone to play nicely and if they don't... it's lights out for the process ps and pstree let you see what processes are running Code Memory Process 1 Code Memory Process 2 Ugh, I'm dead. HEY! NO TOUCHING! OS Kernel CS449

Stuck in your teeth OS Kernel the kernel is a process too, but… it's special we'll talk a lot more about it later but basically, this is the program that makes the OS work it makes every other process believe that they are the only program running on the whole computer. it's also allowed to do anything it wants. …which means a malicious program gaining access to the kernel is a very bad situation OS Kernel - there are many kinds of kernels – monolithic kernels, microkernels, exokernels, real-time kernels – but whatever CS449

Address Spaces each process gets its own address space its own little memory compartment processes can't access each other's address spaces or the OS's old CPU architectures did this with memory segmentation this is where "segfault" comes from they literally sliced up the memory and gave each process a piece but these days we do something a little more complicated (and flexible) CS449

Virtual Memory CS449

this is impossible, but the programs believe it's true. Virtual memory virtual memory abstracts memory addresses. the addresses each process accesses are not the real addresses sent to the memory. Physical Memory Code Memory Process 1 0x8000 0xFFFF 0x9FFF 0xA000 Process 2 ... Process 2's memory Process 1's memory 0x00667FFF 0x00660000 0x0040FFFF this is impossible, but the programs believe it's true. - virtual memory is the basis for so many things: process isolation, security, paging (pretending to have more RAM than is actually on the computer), interprocess communication, memory-mapped files, hardware emulation… soooooo much. (this is an entire unit in CS1550.) 0x00408000 CS449

ok here's 0x8000, honest ;))))) How…? virtual memory is a feature of the CPU hardware Physical Memory hey memory... gimme 0x00408000 hey, gimme 0x8000 Code Process 1 CPU ok, let's see… here you go Code Process 2 ok here's 0x8000, honest ;))))) Page table Process Virt.Addr Phys.Addr 1 0x8000 0x00408000 2 0x00660000 - this is (obviously) a gross simplification but it's basically what's going on. (this is an entire unit in CS1541.) CS449

Shattered memories physical memory is a scarce resource the OS splits memory into pages: small chunks that can be given to processes usually these days, a page is 4KiB the OS keeps track of which parts of memory belong to which process since we have equally-sized chunks… how do you think the OS keeps track of which pages are used/free? ;) a bitmap! sorta. Page Physical Address Owning Process ... 10 0000A000 <OS> 9 00009000 8 00008000 bash 7 00007000 6 00006000 5 00005000 ls 4 00004000 ps 3 00003000 id3edit 2 00002000 1 00001000 00000000 CS449

One process's address space here's an address space that a process sees the code (or the text segment) usually resides at the bottom of memory (the lowest addresses). (not usually at address 0, though) (0 is NULL and we want that to be invalid) then comes the global (static) data segment the code and globals are basically copied directly from the executable file but the stack and heap weren't in the executable where'd they come from? the loader also set those up for us! Stack Heap Globals Code CS449

Looking at a process's memory map the memory map is the arrangement of the address space. you can get a process's pid with ps… ...and then use this to print its memory map: pmap -x pid 0x00000000 0xFFFFFFFF down here is the code, globals, shared libraries… …up here is the stack and all the blue space is segfault territory! memory maps are usually pretty sparse. rarely will a program have most/all of the memory used. CS449

thanks! someone else can use it. Honey, I blew up the heap processes can ask the OS for new pages when they're done with them, they can give pages back this is what [s]brk() is actually doing! Stack Heap a more modern way of asking for pages is with mmap(). gimme a page! OK! I'm done with this. OS Kernel thanks! someone else can use it. CS449