escape
play

Escape Nils Asmussen MKC, 07/12/2018 1 / 43 Introduction Tasks - PowerPoint PPT Presentation

Introduction Tasks Memory VFS IPC Security UI Escape Nils Asmussen MKC, 07/12/2018 1 / 43 Introduction Tasks Memory VFS IPC Security UI Outline Introduction 1 Tasks 2 Memory 3 VFS 4 IPC 5 Security 6 UI 7 2 / 43


  1. Introduction Tasks Memory VFS IPC Security UI Escape Nils Asmussen MKC, 07/12/2018 1 / 43

  2. Introduction Tasks Memory VFS IPC Security UI Outline Introduction 1 Tasks 2 Memory 3 VFS 4 IPC 5 Security 6 UI 7 2 / 43

  3. Introduction Tasks Memory VFS IPC Security UI Outline Introduction 1 Tasks 2 Memory 3 VFS 4 IPC 5 Security 6 UI 7 3 / 43

  4. Introduction Tasks Memory VFS IPC Security UI Motivation Beginning Writing an OS alone? That’s way too much work! Port of UNIX32V to ECO32 during my studies Started with Escape in October 2008 Goals Learn about operating systems and related topics Experiment: What works well and what doesn’t? What problems occur and how can they be solved? 4 / 43

  5. Introduction Tasks Memory VFS IPC Security UI Overview Basic Properties UNIX-like microkernel-based OS Open source, available on github.com/Nils-TUD/Escape Mostly written in C++ , some parts in C Runs on x86, x86 64, ECO32 and MMIX Only third-party code: libgcc , libsupc++ , x86emu, inflate ECO32 MIPS-like, 32-bit big-endian RISC architecture, developed by Prof. Geisse for lectures and research MMIX 64-bit big-endian RISC architecture of Donald Knuth as a successor for MIX (the abstract machine from TAOCP) 5 / 43

  6. Introduction Tasks Memory VFS IPC Security UI Overview Drivers Applications ext2 ata vterm ls cat fi leman user mode tcpip ps ping guishell winmng uimng ... ... vesa ps2 head less ... libc libcpp libgui libesc libfs µ-kernel privileged mode VFS Tasks Memory Hardware 6 / 43

  7. Introduction Tasks Memory VFS IPC Security UI Outline Introduction 1 Tasks 2 Memory 3 VFS 4 IPC 5 Security 6 UI 7 7 / 43

  8. Introduction Tasks Memory VFS IPC Security UI Processes and Threads Process Virtual address space File descriptors Mountspace Threads (at least one) . . . Thread User and kernel stack State (running, ready, blocked, . . . ) Scheduled by a round-robin scheduler with priorities Signals . . . 8 / 43

  9. Introduction Tasks Memory VFS IPC Security UI Processes and Threads Synchronization Process-local semaphores (can also be created for interrupts) Global semaphores, named by a path to a file Userspace builds other synchronization primitives on top Combination of atomic ops and process-local semaphores Readers writer lock . . . Priority Management Priorities are dynamically adjusted based on compute intensity High CPU usage → downgrade, low CPU usage → upgrade 9 / 43

  10. Introduction Tasks Memory VFS IPC Security UI Outline Introduction 1 Tasks 2 Memory 3 VFS 4 IPC 5 Security 6 UI 7 10 / 43

  11. Introduction Tasks Memory VFS IPC Security UI Memory Management Physical Memory Mostly, memory is managed by a stack (fast for single frames) A small part handled by a bitmap for contiguous phys. memory Virtual Memory Kernel part is shared among all processes User part is managed by a region-based concept mmap -like interface for the userspace 11 / 43

  12. Introduction Tasks Memory VFS IPC Security UI Virtual Memory Management VM (proc 1) VM (proc 2) /lib/libc.so 0xBFFFFFFF libc.so (text) fl ags=shared,exec size=16K, procs=1,2 free area free area libc.so (text) MMIO dynlink (text) dynlink (text) 0xA0000000 stack1 stack1 fl ags=write,grow,stack size=12K, procs=2 stack2 layouted area layouted area fl ags=write,grow size=16K, procs=1 data data fl ags=shared,exec size=20K, procs=1,2 text text /bin/hello 0x00000000 12 / 43

  13. Introduction Tasks Memory VFS IPC Security UI Outline Introduction 1 Tasks 2 Memory 3 VFS 4 IPC 5 Security 6 UI 7 13 / 43

  14. Introduction Tasks Memory VFS IPC Security UI Basics The kernel provides the virtual file system System-calls: open , read , mkdir , mount , . . . It’s used for: Provide information about the state of the system 1 Access userspace filesystems 2 Access devices 3 Access interrupts 4 14 / 43

  15. Introduction Tasks Memory VFS IPC Security UI Drivers and Devices Drivers are ordinary user programs They create devices via the system call createdev These are usually put into /dev Devices can also be used to implement on-demand-generated files (such as /sys/net/sockets) Communication is based on asynchronous message passing 15 / 43

  16. Introduction Tasks Memory VFS IPC Security UI Message Passing Channel inbox send(id,msg) recv(id | 42,msg) id | 42 id | 43 Client Driver outbox send(id | 42,msg) recv(id | 42,msg) id | 43 id | 42 16 / 43

  17. Introduction Tasks Memory VFS IPC Security UI Devices Can Behave Like Files As in UNIX: Devices should be accessable like files Messages: FILE OPEN , FILE READ , FILE WRITE , FILE CLOSE Devices may support a subset of these message Kernel handles communication for open / read / write / close Type of file transparent for applications 17 / 43

  18. Introduction Tasks Memory VFS IPC Security UI Devices Can Behave Like Filesystems Messages: FS OPEN , FS READ , FS WRITE , FS CLOSE , FS STAT , FS SYNC , FS LINK , FS UNLINK , FS RENAME , FS MKDIR , FS RMDIR , FS CHMOD , FS CHOWN Kernel handles communication, if syscall refers to userspace fs Filesystems are mounted using the mount system call 18 / 43

  19. Introduction Tasks Memory VFS IPC Security UI Achieving Higher Throughput Copying everything twice hurts for large amounts of data sharebuf establishes shmem between client and driver Easy to use: just call sharebuf once and use this as the buffer Clients don’t need to care whether a driver supports it or not Drivers need to handle DEV SHFILE to support it In read / write , they check if SHM should be used 19 / 43

  20. Introduction Tasks Memory VFS IPC Security UI Achieving Higher Throughput – Code Example i n t fd = open ( ”/ dev / zero ” ,IO READ) ; s t a t i c char buf [ SIZE ] ; while ( read ( fd , buf , SIZE ) ) > 0) { // . . . } c l o s e ( fd ) ; 20 / 43

  21. Introduction Tasks Memory VFS IPC Security UI Achieving Higher Throughput – Code Example i n t fd = open ( ”/ dev / zero ” ,IO READ) ; i n t fd = open ( ”/ dev / zero ” ,IO READ) ; s t a t i c char buf [ SIZE ] ; void ∗ buf ; i f ( s h a r e b u f ( fd , SIZE ,& buf , 0 ) < 0) { i f ( buf == NULL) e r r o r ( ” Unable to mmap buf ” ) ; } while ( read ( fd , buf , SIZE ) ) > 0) { while ( read ( fd , buf , SIZE ) > 0) { // . . . // . . . } } d e s t r o y b u f ( buf ) ; c l o s e ( fd ) ; c l o s e ( fd ) ; 20 / 43

  22. Introduction Tasks Memory VFS IPC Security UI Achieving Higher Throughput – Usage Example cp ext2 ata 21 / 43

  23. Introduction Tasks Memory VFS IPC Security UI Achieving Higher Throughput – Usage Example cp cp ftpfs ext2 tcpip ata e1000 22 / 43

  24. Introduction Tasks Memory VFS IPC Security UI File Exchange Files (=capabilities) can be exchanged via channel Client can delegate/obtain files from driver: int delegate(int chan,int fd,uint perm,int arg) int obtain(int chan,int arg) Used for: Establishing shared memory Connecting control and event channel of uimng Accepting incoming network connections ( accept ) . . . 23 / 43

  25. Introduction Tasks Memory VFS IPC Security UI File Descriptors For Everything Interrupts Escape uses semaphores for interrupts For each interrupt, Escape creates a file /sys/irq/$irq Syscall semirqcrt expects fd for IRQ file On an IRQ, all semaphores in the list are up’ed Signals The kill syscall expects fd for process directory Only if it has write permission, the signal can be sent 24 / 43

  26. Introduction Tasks Memory VFS IPC Security UI Outline Introduction 1 Tasks 2 Memory 3 VFS 4 IPC 5 Security 6 UI 7 25 / 43

  27. Introduction Tasks Memory VFS IPC Security UI IPC between Client and Driver (Low Level) driver int id = createdev("/dev/foo",...); creates dev foo 26 / 43

  28. Introduction Tasks Memory VFS IPC Security UI IPC between Client and Driver (Low Level) driver int id = createdev("/dev/foo",...); creates creates dev points to client foo int fd = open("/dev/foo",IO_MSGS); channel inbox outbox 27 / 43

  29. Introduction Tasks Memory VFS IPC Security UI IPC between Client and Driver (Low Level) driver int id = createdev("/dev/foo",...); creates creates dev points to client foo int fd = open("/dev/foo",IO_MSGS); channel msg.arg1 = 10; mid = send(fd,42,&msg,sizeof(msg)); inbox receive(fd,&mid,&msg,sizeof(msg)); outbox 28 / 43

  30. Introduction Tasks Memory VFS IPC Security UI IPC between Client and Driver (Low Level) driver int id = createdev("/dev/foo",...); creates creates dev points to client foo int fd = open("/dev/foo",IO_MSGS); channel points to msg.arg1 = 10; mid = send(fd,42,&msg,sizeof(msg)); inbox receive(fd,&mid,&msg,sizeof(msg)); outbox driver int fd = getwork(id,&mid,&msg,sizeof(msg),0); 29 / 43

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend