text stringlengths 1 7.76k | source stringlengths 17 81 |
|---|---|
684 SECURITY CHAP. 9 studied the extent and discovered that computers on over 500,000 networks world- wide had been infected by the rootkit. When the news broke, Sony’s initial reaction was that it had every right to pro- tect its intellectual property. In an interview on National Public Radio, Thomas Hesse, the presid... | clipped_os_Page_684_Chunk6901 |
SEC. 9.10 DEFENSES 685 Properly secured computer systems are like this house, with multiple layers of se- curity. We will now look at some of the layers. The defenses are not really hierar- chical, but we will start roughly with the more general outer ones and work our way to more specific ones. 9.10.1 Firewalls The ab... | clipped_os_Page_685_Chunk6902 |
686 SECURITY CHAP. 9 interface (most firewalls have a mini-Web server built in to allow this). In the sim- plest kind of firewall, the stateless firewall, the header of each packet passing through is inspected and a decision is made to pass or discard the packet based solely on the information in the header and the fir... | clipped_os_Page_686_Chunk6903 |
SEC. 9.10 DEFENSES 687 In addition to stateless firewalls, there are also stateful firewalls, which keep track of connections and what state they are in. These firewalls are better at defeat- ing certain kinds of attacks, especially those relating to establishing connections. Yet other kinds of firewalls implement an I... | clipped_os_Page_687_Chunk6904 |
688 SECURITY CHAP. 9 up false alarms (false positives), that is, warnings about legitimate files that just happen to contain some code vaguely similar to a virus reported in Pakistan 7 years ago. What is the user supposed to do with the message: WARNING! File xyz.exe may contain the lahore-9x virus. Delete? The more vi... | clipped_os_Page_688_Chunk6905 |
SEC. 9.10 DEFENSES 689 | clipped_os_Page_689_Chunk6906 |
690 SECURITY CHAP. 9 MOV A,R1 MOV A,R1 MOV A,R1 MOV A,R1 MOV A,R1 ADD B,R1 NOP ADD #0,R1 OR R1,R1 TST R1 ADD C,R1 ADD B,R1 ADD B,R1 ADD B,R1 ADD C,R1 SUB #4,R1 NOP OR R1,R1 MOV R1,R5 MOV R1,R5 MOV R1,X ADD C,R1 ADD C,R1 ADD C,R1 ADD B,R1 NOP SHL #0,R1 SHL R1,0 CMP R2,R5 SUB #4,R1 SUB #4,R1 SUB #4,R1 SUB #4,R1 NOP JMP .... | clipped_os_Page_690_Chunk6907 |
SEC. 9.10 DEFENSES 691 built-in device drivers for SATA, USB, SCSI, and other common disks, making the antivirus program less portable and subject to failure on computers with unusual disks. Furthermore, since bypassing the operating system to read the boot sector is possible, but bypassing it to read all the executabl... | clipped_os_Page_691_Chunk6908 |
692 SECURITY CHAP. 9 Viruses do not have to passively lie around waiting for an antivirus program to kill them, like cattle being led off to slaughter. They can fight back. A particularly exciting battle can occur if a memory-resident virus and a memory-resident antivirus meet up on the same computer. Years ago there w... | clipped_os_Page_692_Chunk6909 |
SEC. 9.10 DEFENSES 693 Finally, sixth, resist the temptation to download and run glitzy new free soft- ware from an unknown source. Maybe there is a reason it is free—the maker wants your computer to join his zombie army. If you have virtual machine soft- ware, running unknown software inside a virtual machine is safe,... | clipped_os_Page_693_Chunk6910 |
694 SECURITY CHAP. 9 guarding the latter. In order to sign a piece of software, the vendor first computes a hash function of the code to get a 160-bit or 256-bit number, depending on whether SHA-1 or SHA-256 is used. It then signs the hash value by encrypting it with its private key (actually, decrypting it using the n... | clipped_os_Page_694_Chunk6911 |
SEC. 9.10 DEFENSES 695 the signature merely proves where it came from, not what it does. A technique for doing this is called jailing and illustrated in Fig. 9-36. Kernel Jailer Prisoner Sys Figure 9-36. The operation of a jail. The newly acquired program is run as a process labeled ‘‘prisoner’’ in the fig- ure. The ‘‘... | clipped_os_Page_695_Chunk6912 |
696 SECURITY CHAP. 9 In Fig. 9-37(a) we see a small program that opens a file called data and reads it one character at a time until it hits a zero byte, at which time it prints the number of nonzero bytes at the start of the file and exits. In Fig. 9-37(b) we see a graph of the system calls made by this program (where... | clipped_os_Page_696_Chunk6913 |
SEC. 9.10 DEFENSES 697 When this kind of static model-based intrusion detection is used, the jailer has to know the model (i.e., the system-call graph). The most straightforward way for it to learn it is to have the compiler generate it and have the author of the program sign it and attach its certificate. In this way,... | clipped_os_Page_697_Chunk6914 |
698 SECURITY CHAP. 9 to draw certain curves and then fill them in, but it can do anything else it wants to as well. Applets, agents, and PostScript files are just three examples of mobile code, but there are many others. Given the long discussion about viruses and worms earlier, it should be clear that allowing foreign... | clipped_os_Page_698_Chunk6915 |
SEC. 9.10 DEFENSES 699 usually is. Each applet is given two sandboxes, one for the code and one for the data, as illustrated in Fig. 9-38(a) for the case of 16 sandboxes of 16 MB each. (a) (b) 256 224 192 160 128 96 64 32 0 Ref. Mon. Code 1 Data 1 Code 2 Data 2 Reference monitor for checking system Applet 2 Applet 1 MO... | clipped_os_Page_699_Chunk6916 |
700 SECURITY CHAP. 9 example of such a test is shown in Fig. 9-38(b). Remember that all valid addresses have the same upper k bits, so this prefix can be stored in a scratch register, say S2. Such a register cannot be used by the applet itself, which may require rewriting it to avoid this register. The code works as fo... | clipped_os_Page_700_Chunk6917 |
SEC. 9.10 DEFENSES 701 Untrusted applet Trusted applet Web browser Sandbox Interpreter Virtual address space 0xFFFFFFFF 0 Figure 9-39. Applets can be interpreted by a Web browser. also caught and interpreted. How these calls are handled is a matter of the security policy. For example, if an applet is trusted (e.g., it ... | clipped_os_Page_701_Chunk6918 |
702 SECURITY CHAP. 9 Java, constructions that mix types like this are forbidden by the grammar. In addi- tion, Java has no pointer variables, casts, or user-controlled storage allocation (such as malloc and free), and all array references are checked at run time. Java programs are compiled to an intermediate binary cod... | clipped_os_Page_702_Chunk6919 |
SEC. 9.10 DEFENSES 703 Each rule may list a URL, a signer, an object, and an action that the applet may perform on the object if the applet’s URL and signer match the rule. Conceptually, the information provided is shown in the table of Fig. 9-40, although the actual for- matting is different and is related to the Java... | clipped_os_Page_703_Chunk6920 |
704 SECURITY CHAP. 9 in security, both in academia and in industry, is not likely to wav er in the next few years either. One important topic is the protection of binary programs. Control Flow Integ- rity (CFI) is a fairly old technique to stop all control flow div ersions and, hence, all ROP exploits. Unfortunately, t... | clipped_os_Page_704_Chunk6921 |
SEC. 9.12 SUMMARY 705 not tampered with, which rapidly leads to the requirement that operating systems must provide good security. In general, the security of a system is inversely propor- tional to the size of the trusted computing base. A fundamental component of security for operating systems concerns access control... | clipped_os_Page_705_Chunk6922 |
706 SECURITY CHAP. 9 PROBLEMS 1. Confidentiality, integrity, and availability are three components of security. Describe an application that integrity and availability but not confidentiality, an application that requires confidentiality and integrity but not (high) availability, and an application that requires confid... | clipped_os_Page_706_Chunk6923 |
CHAP. 9 PROBLEMS 707 10. Modify the ACL from the previous problem for one file to grant or deny an access that cannot be expressed using the UNIX rwx system. Explain this modification. 11. Suppose there are four security levels, 1, 2 and 3. Objects A and B are at level 1, C and D are at level 2, and E and F are at leve... | clipped_os_Page_707_Chunk6924 |
708 SECURITY CHAP. 9 B[i], A[1] is copied to B[ j], A[2] is copied to B[k], etc. After all n bytes are copied to the B array, that array is written to the output file and n more bytes are read into A. This procedure continues until the entire file has been encrypted. Note that here en- cryption is not being done by rep... | clipped_os_Page_708_Chunk6925 |
CHAP. 9 PROBLEMS 709 27. After getting your degree, you apply for a job as director of a large university computer center that has just put its ancient mainframe system out to pasture and switched over to a large LAN server running UNIX. You get the job. Fifteen minutes after you start work, your assistant bursts into ... | clipped_os_Page_709_Chunk6926 |
710 SECURITY CHAP. 9 38. Can the Trojan-horse attack work in a system protected by capabilities? 39. When a file is removed, its blocks are generally put back on the free list, but they are not erased. Do you think it would be a good idea to have the operating system erase each block before releasing it? Consider both ... | clipped_os_Page_710_Chunk6927 |
CHAP. 9 PROBLEMS 711 52. Section 9.10.1 describes a set of firewall rules that limit outside access to only three services. Describe another set of rules that you can add to this firewall to further restrict access to these services. 53. On some machines, the SHR instruction used in Fig. 9-38(b) fills the unused bits w... | clipped_os_Page_711_Chunk6928 |
712 SECURITY CHAP. 9 62. Write a program that emulates overwriting viruses outlined in Sec. 9.9.2 under the heading ‘‘Executable Program Viruses’’. Choose an existing executable file that you know can be overwritten without any harm. For the virus binary, choose any harmless executable binary. | clipped_os_Page_712_Chunk6929 |
10 CASE STUDY 1: UNIX, LINUX, AND ANDROID In the previous chapters, we took a close look at many operating system prin- ciples, abstractions, algorithms, and techniques in general. Now it is time to look at some concrete systems to see how these principles are applied in the real world. We will begin with Linux, a popu... | clipped_os_Page_713_Chunk6930 |
714 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 and data structures are similar, but there are some differences. To make the ex- amples concrete, it is best to choose one of them and describe it consistently. Since most readers are more likely to have encountered Linux than any of the others, we will use it as our ... | clipped_os_Page_714_Chunk6931 |
SEC. 10.1 HISTORY OF UNIX AND LINUX 715 discarded PDP-7 minicomputer. Despite the tiny size of the PDP-7, Thompson’s system actually worked and could support Thompson’s dev elopment effort. Conse- quently, one of the other researchers at Bell Labs, Brian Kernighan, somewhat jok- ingly called it UNICS (UNiplexed Informa... | clipped_os_Page_715_Chunk6932 |
716 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 speakers getting up in front of the room to tell about some obscure kernel bug they had found and fixed. An Australian professor, John Lions, wrote a commentary on the UNIX source code of the type normally reserved for the works of Chaucer or Shakespeare (reprinted as... | clipped_os_Page_716_Chunk6933 |
SEC. 10.1 HISTORY OF UNIX AND LINUX 717 located on the fifth floor at Bell Labs. The Interdata was on the first floor. Gener- ating a new version meant compiling it on the fifth floor and then physically carry- ing a magnetic tape down to the first floor to see if it worked. After several months of tape carrying, an un... | clipped_os_Page_717_Chunk6934 |
718 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 Berkeley also added a substantial number of utility programs to UNIX, includ- ing a new editor (vi), a new shell (csh), Pascal and Lisp compilers, and many more. All these improvements caused Sun Microsystems, DEC, and other computer ven- dors to base their versions o... | clipped_os_Page_718_Chunk6935 |
SEC. 10.1 HISTORY OF UNIX AND LINUX 719 BSD, namely Version 7. The 1003.1 document is written in such a way that both operating system implementers and software writers can understand it, another novelty in the standards world, although work is already underway to remedy this. Although the 1003.1 standard addresses onl... | clipped_os_Page_719_Chunk6936 |
720 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 quickly became a collective undertaking by large numbers of users over the Inter- net. It was a prototype of other collaborative efforts that came later. In 1997, Ver- sion 2.0 of MINIX, was released and the base system, now including networking, had grown to 62,200 l... | clipped_os_Page_720_Chunk6937 |
SEC. 10.1 HISTORY OF UNIX AND LINUX 721 Linux rapidly grew in size and evolved into a full, production UNIX clone, as virtual memory, a more sophisticated file system, and many other features were added. Although it originally ran only on the 386 (and even had embedded 386 as- sembly code in the middle of C procedures)... | clipped_os_Page_721_Chunk6938 |
722 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 One unusual feature of Linux is its business model: it is free software. It can be downloaded from various sites on the Internet, for example: www.kernel.org. Linux comes with a license devised by Richard Stallman, founder of the Free Soft- ware Foundation. Despite th... | clipped_os_Page_722_Chunk6939 |
SEC. 10.2 OVERVIEW OF LINUX 723 10.2 OVERVIEW OF LINUX In this section we will provide a general introduction to Linux and how it is used, for the benefit of readers not already familiar with it. Nearly all of this mater- ial applies to just about all UNIX variants with only small deviations. Although Linux has several... | clipped_os_Page_723_Chunk6940 |
724 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 is a complete waste of valuable hacking time. To extract all the lines containing the string ‘‘ard’’ from the file f, the Linux programmer merely types grep ard f The opposite approach is to have the programmer first select the grep program (with no arguments), and th... | clipped_os_Page_724_Chunk6941 |
SEC. 10.2 OVERVIEW OF LINUX 725 proper place, then executes the trap instruction. Thus to execute the read system call, a C program can call the read library procedure. As an aside, it is the library interface, and not the system call interface, that is specified by POSIX. In other words, POSIX tells which library proc... | clipped_os_Page_725_Chunk6942 |
726 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 10.2.3 The Shell Although Linux systems have a graphical user interface, most programmers and sophisticated users still prefer a command-line interface, called the shell. Often they start one or more shell windows from the graphical user interface and just work in the... | clipped_os_Page_726_Chunk6943 |
SEC. 10.2 OVERVIEW OF LINUX 727 To make it easy to specify multiple file names, the shell accepts magic charac- ters, sometimes called wild cards. An asterisk, for example, matches all possible strings, so ls *.c tells ls to list all the files whose name ends in .c. If files named x.c, y.c, and z.c all exist, the above... | clipped_os_Page_727_Chunk6944 |
728 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 temp and print them on standard output, which defaults to the terminal. Finally, the temporary file is removed. It is not recycled. It is gone with the wind, forever. It frequently occurs that the first program in a command line produces output that is used as input t... | clipped_os_Page_728_Chunk6945 |
SEC. 10.2 OVERVIEW OF LINUX 729 10.2.4 Linux Utility Programs The command-line (shell) user interface to Linux consists of a large number of standard utility programs. Roughly speaking, these programs can be divided into six categories, as follows: 1. File and directory manipulation commands. 2. Filters. 3. Program dev... | clipped_os_Page_729_Chunk6946 |
730 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 columns of text to be cut and pasted into files; od, which converts its (usually bina- ry) input to ASCII text, in octal, decimal, or hexadecimal; tr, which does character translation (e.g., lowercase to uppercase), and pr, which formats output for the printer, includ... | clipped_os_Page_730_Chunk6947 |
SEC. 10.2 OVERVIEW OF LINUX 731 10.2.5 Kernel Structure In Fig. 10-1 we saw the overall structure of a Linux system. Now let us zoom in and look more closely at the kernel as a whole before examining the various parts, such as process scheduling and the file system. System calls Interrupts Dispatcher Virtual file syste... | clipped_os_Page_731_Chunk6948 |
732 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 memory or on disk, is the same as performing a read operation to retrieve a charac- ter from a terminal input. At the lowest level, all I/O operations pass through some device driver. All Linux drivers are classified as either character-device drivers or block-device ... | clipped_os_Page_732_Chunk6949 |
SEC. 10.2 OVERVIEW OF LINUX 733 While the three components are represented separately in the figure, they are highly interdependent. File systems typically access files through the block de- vices. However, in order to hide the large latencies of disk accesses, files are cop- ied into the page cache in main memory. Som... | clipped_os_Page_733_Chunk6950 |
734 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 Linux is a multiprogramming system, so multiple, independent processes may be running at the same time. Furthermore, each user may have sev eral active proc- esses at once, so on a large system, there may be hundreds or even thousands of processes running. In fact, on... | clipped_os_Page_734_Chunk6951 |
SEC. 10.3 PROCESSES IN LINUX 735 pid = for k( ); /* if the for k succeeds, pid > 0 in the parent */ if (pid < 0) { handle error( ); /* fork failed (e.g., memory or some table is full) */ } else if (pid > 0) { /* parent code goes here. /*/ } else { /* child code goes here. /*/ } Figure 10-4. Process creation in Linux. j... | clipped_os_Page_735_Chunk6952 |
736 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 Signal Cause SIGABRT Sent to abort a process and force a core dump SIGALRM The alar m clock has gone off SIGFPE A floating-point error has occurred (e.g., division by 0) SIGHUP The phone line the process was using has been hung up SIGILL The user has hit the DEL key t... | clipped_os_Page_736_Chunk6953 |
SEC. 10.3 PROCESSES IN LINUX 737 System call Description pid = for k( ) Create a child process identical to the parent pid = waitpid(pid, &statloc, opts) Wait for a child to terminate s = execve(name, argv, envp) Replace a process’ core image exit(status) Ter minate process execution and return status s = sigaction(sig... | clipped_os_Page_737_Chunk6954 |
738 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 while (TRUE) { /* repeat forever /*/ type prompt( ); /* display prompt on the screen */ read command(command, params); /* read input line from keyboard */ pid = for k( ); /* fork off a child process */ if (pid < 0) { pr intf("Unable to for k0); /* error condition */ c... | clipped_os_Page_738_Chunk6955 |
SEC. 10.3 PROCESSES IN LINUX 739 Several system calls relate to signals, which are used in a variety of ways. For example, if a user accidentally tells a text editor to display the entire contents of a very long file, and then realizes the error, some way is needed to interrupt the edi- tor. The usual choice is for the... | clipped_os_Page_739_Chunk6956 |
740 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 10.3.3 Implementation of Processes and Threads in Linux A process in Linux is like an iceberg: you only see the part above the water, but there is also an important part underneath. Every process has a user part that runs the user program. However, when one of its thr... | clipped_os_Page_740_Chunk6957 |
SEC. 10.3 PROCESSES IN LINUX 741 1. Scheduling parameters. Process priority, amount of CPU time con- sumed recently, amount of time spent sleeping recently. Together, these are used to determine which process to run next. 2. Memory image. Pointers to the text, data, and stack segments, or page tables. If the text segme... | clipped_os_Page_741_Chunk6958 |
742 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 with the address of the process descriptor. By storing the process descriptor’s ad- dress at a fixed location, Linux needs only few eff icient operations to locate the task structure for a running process. The majority of the process-descriptor contents are filled out... | clipped_os_Page_742_Chunk6959 |
SEC. 10.3 PROCESSES IN LINUX 743 sh sh ls fork code New process Same process 1. Fork call 3. exec call 4. sh overlaid with ls PID = 501 PID = 748 PID = 748 Allocate child’s task structure Fill child’s task structure from parent Allocate child’s stack and user area Fill child’s user area from parent Allocate PID for chi... | clipped_os_Page_743_Chunk6960 |
744 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 File I/O is another problem area. Suppose that one thread is blocked reading from a file and another thread closes the file or does an lseek to change the current file pointer. What happens next? Who knows? Signal handling is another thorny issue. Should signals be di... | clipped_os_Page_744_Chunk6961 |
SEC. 10.3 PROCESSES IN LINUX 745 structure or shares it with the calling thread. Fig. 10-9 shows some of the items that can be shared or copied according to bits in sharing flags. Flag Meaning when set Meaning when cleared CLONE VM Create a new thread Create a new process CLONE FS Share umask, root, and wor king dirs D... | clipped_os_Page_745_Chunk6962 |
746 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 is easy to make a new task structure for each cloned thread and have it point either to the old thread’s scheduling, memory, and other data structures or to copies of them. The fact that such fine-grained sharing is possible does not mean that it is useful, however, e... | clipped_os_Page_746_Chunk6963 |
SEC. 10.3 PROCESSES IN LINUX 747 In Linux, time is measured as the number of clock ticks. In older Linux ver- sions, the clock ran at 1000Hz and each tick was 1ms, called a jiffy. In newer ver- sions, the tick frequency can be configured to 500, 250 or even 1Hz. In order to avoid wasting CPU cycles for servicing the ti... | clipped_os_Page_747_Chunk6964 |
748 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 Flags CPU Static_prio < > Active Expired < > Priority 0 Array[0] Priority 139 Priority 0 Array[1] Priority 139 P P P P P P P P P P P P (a) Per CPU runqueue in the Linux O(1) scheduler 35 26 47 10 30 38 62 3 27 45 86 NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL (b) ... | clipped_os_Page_748_Chunk6965 |
SEC. 10.3 PROCESSES IN LINUX 749 to dynamically map the task’s bonus to values from −5 to +5. The scheduler recal- culates the new priority level as a thread is moved from the active to the expired list. The O(1) scheduling algorithm refers to the scheduler made popular in the early versions of the 2.6 kernel, and was ... | clipped_os_Page_749_Chunk6966 |
750 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 of tasks in the system. Given the levels of load in current systems, this continues to be acceptable, but as the compute capacity of the nodes, and the number of tasks they can run, increase, particularly in the server space, it is possible that new scheduling algorit... | clipped_os_Page_750_Chunk6967 |
SEC. 10.3 PROCESSES IN LINUX 751 multicore systems. Threads that are allowed to or need to block use constructs like mutexes and semaphores. Linux supports nonblocking calls like mutex tr ylock and sem tr ywait to determine the status of the synchronization variable without block- ing. Other types of synchronization va... | clipped_os_Page_751_Chunk6968 |
752 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 see which ones actually are present. If a probed device responds to the probe, it is added to a table of attached devices. If it fails to respond, it is assumed to be absent and ignored henceforth. Unlike traditional UNIX versions, Linux device drivers do not need to ... | clipped_os_Page_752_Chunk6969 |
SEC. 10.3 PROCESSES IN LINUX 753 Process 0 Process 1 Process 2 Page daemon Terminal 0 Terminal 1 Terminal 2 Login: Password: % cp f1 f2 login sh cp getty init Figure 10-11. The sequence of processes used to boot some Linux systems. In the figure, the getty process running for terminal 0 is still waiting for input. On t... | clipped_os_Page_753_Chunk6970 |
754 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 10.4.1 Fundamental Concepts Every Linux process has an address space that logically consists of three seg- ments: text, data, and stack. An example process’ address space is illustrated in Fig. 10-12(a) as process A. The text segment contains the machine instructions ... | clipped_os_Page_754_Chunk6971 |
SEC. 10.4 MEMORY MANAGEMENT IN LINUX 755 initial value is 0. In practice, most global variables are not initialized explicitly, and are thus 0. This could be implemented by simply having a section of the ex- ecutable binary file exactly equal to the number of bytes of data, and initializing all of them, including the o... | clipped_os_Page_755_Chunk6972 |
756 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 When two users are running the same program, such as the editor, it would be possible, but inefficient, to keep two copies of the editor’s program text in memory at once. Instead, Linux systems support shared text segments. In Fig. 10-12(a) and Fig. 10-12(c) we see tw... | clipped_os_Page_756_Chunk6973 |
SEC. 10.4 MEMORY MANAGEMENT IN LINUX 757 Text | clipped_os_Page_757_Chunk6974 |
758 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 the file to be mapped. Only open files can be mapped, so to map a file in, it must first be opened. Finally, offset tells where in the file to begin the mapping. It is not necessary to start the mapping at byte 0; any page boundary will do. The other call, unmap, remo... | clipped_os_Page_758_Chunk6975 |
SEC. 10.4 MEMORY MANAGEMENT IN LINUX 759 operations, and ZONE DMA32 marks this region. In addition, if the hardware, like older-generation i386, cannot directly map memory addresses above 896 MB, ZONE HIGHMEM corresponds to anything above this mark. ZONE NORMAL is anything in between them. Therefore, on 32-bit x86 plat... | clipped_os_Page_759_Chunk6976 |
760 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 First of all, Linux maintains an array of page descriptors, of type page one for each physical page frame in the system, called mem map. Each page descriptor contains a pointer to the address space that it belongs to, in case the page is not free, a pair of pointers w... | clipped_os_Page_760_Chunk6977 |
SEC. 10.4 MEMORY MANAGEMENT IN LINUX 761 Global directory Upper directory Middle directory Page Offset Page Page table Page middle directory Page upper directory Page global directory Virtual address Figure 10-16. Linux uses four-level page tables. Physical memory is used for various purposes. The kernel itself is full... | clipped_os_Page_761_Chunk6978 |
762 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 The basic idea for managing a chunk of memory is as follows. Initially memo- ry consists of a single contiguous piece, 64 pages in the simple example of Fig. 10-17(a). When a request for memory comes in, it is first rounded up to a power of 2, say eight pages. The ful... | clipped_os_Page_762_Chunk6979 |
SEC. 10.4 MEMORY MANAGEMENT IN LINUX 763 slab is available, it looks through the list of empty slabs. Finally, if necessary, it will allocate a new slab, place the new task structure there, and link this slab with the task-structure object cache. The kmalloc kernel service, which allocates physi- cally contiguous memor... | clipped_os_Page_763_Chunk6980 |
764 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 The vm area struct also records whether the area has backing storage on disk assigned, and if so, where. Text segments use the executable binary as backing storage and memory-mapped files use the disk file as backing storage. Other areas, such as the stack, do not hav... | clipped_os_Page_764_Chunk6981 |
SEC. 10.4 MEMORY MANAGEMENT IN LINUX 765 may be needed soon, in the hope it will be there when needed). Te xt segments and mapped files are paged to their respective files on disk. Everything else is paged to either the paging partition (if present) or one of the fixed-length paging files, called the swap area. Paging ... | clipped_os_Page_765_Chunk6982 |
766 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 Each time PFRA executes, it first tries to reclaim easy pages, then proceeds with the harder ones. Many people also grab the low-hanging fruit first. Dis- cardable and unreferenced pages can be reclaimed immediately by moving them onto the zone’s freelist. Next it loo... | clipped_os_Page_766_Chunk6983 |
SEC. 10.4 MEMORY MANAGEMENT IN LINUX 767 Inactive Used Used Used Timeout Timeout Refill Refill Refill PG_active = 0 PG_referenced = 0 PG_active = 0 PG_referenced = 1 PG_active = 1 PG_referenced = 0 PG_active = 1 PG_referenced = 1 Active Figure 10-18. Page states considered in the page-frame replacement algorithm. back ... | clipped_os_Page_767_Chunk6984 |
768 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 device is assigned a path name, usually in /dev. For example, a disk might be /dev/hd1, a printer might be /dev/lp, and the network might be /dev/net. These special files can be accessed the same way as any other files. No special commands or system calls are needed. ... | clipped_os_Page_768_Chunk6985 |
SEC. 10.5 INPUT/OUTPUT IN LINUX 769 handles tab expansion, enabling and disabling of character echoing, conversion be- tween carriage return and line feed, and similar items. The system call is not per- mitted on regular files or block special files. 10.5.2 Networking Another example of I/O is networking, as pioneered ... | clipped_os_Page_769_Chunk6986 |
770 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 The second type is rather similar to the first one, except that it preserves packet boundaries. If the sender makes fiv e separate calls to wr ite, each for 512 bytes, and the receiver asks for 2560 bytes, with a type 1 socket all 2560 bytes will be re- turned at once... | clipped_os_Page_770_Chunk6987 |
SEC. 10.5 INPUT/OUTPUT IN LINUX 771 functions into separate function calls primarily for terminal devices. In Linux and modern UNIX systems, whether each one is a separate system call or they share a single system call or something else is implementation dependent. The first four calls listed in Fig. 10-20 are used to ... | clipped_os_Page_771_Chunk6988 |
772 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 a parameter. Adding a new device type to Linux means adding a new entry to one of these tables and supplying the corresponding procedures to handle the various operations on the device. Some of the operations which may be associated with different character de- vices ... | clipped_os_Page_772_Chunk6989 |
SEC. 10.5 INPUT/OUTPUT IN LINUX 773 the cache, the block is taken from there and a disk access is avoided, thereby re- sulting in great improvements in system performance. Block device driver Char device driver Network device driver I/O scheduler Regular file Char special file Network socket Cache Virtual File System (... | clipped_os_Page_773_Chunk6990 |
774 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 and 5 sec for writes. If a system-defined deadline for the oldest write operation is about to expire, that write request will be serviced before any of the requests on the main doubly linked list. In addition to regular disk files, there are also block special files, ... | clipped_os_Page_774_Chunk6991 |
SEC. 10.5 INPUT/OUTPUT IN LINUX 775 high-end workstations, with their small and unchanging sets of I/O devices, this scheme worked well. Basically, a computer center built a kernel containing drivers for the I/O devices and that was it. If next year the center bought a new disk, it relinked the kernel. No big deal. Wit... | clipped_os_Page_775_Chunk6992 |
776 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 disks of its era), there was interest in better file systems almost from the beginning of the Linux development, which began about 5 years after MINIX 1 was released. The first improvement was the ext file system, which allowed file names of 255 characters and files o... | clipped_os_Page_776_Chunk6993 |
SEC. 10.6 THE LINUX FILE SYSTEM 777 example of an absolute path is /usr/ast/books/mos4/chap-10. This tells the system to look in the root directory for a directory called usr, then look there for another directory, ast. In turn, this directory contains a directory books, which contains the directory mos4, which contain... | clipped_os_Page_777_Chunk6994 |
778 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 In the example just discussed, we suggested that before linking, the only way for Fred to refer to Lisa’s file x was by using its absolute path. Actually, this is not really true. When a directory is created, two entries, . and .., are automatically made in it. The fo... | clipped_os_Page_778_Chunk6995 |
SEC. 10.6 THE LINUX FILE SYSTEM 779 / a b a c p q r q q r d / c d b DVD / Hard disk Hard disk x y z x y z Figure 10-25. (a) Separate file systems. (b) After mounting. critical regions. However, if the processes belong to independent users who do not ev en know each other, this kind of coordination is generally inconven... | clipped_os_Page_779_Chunk6996 |
780 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 lock on bytes 6 through 9, as shown in Fig. 10-26(b). Finally, C locks bytes 2 through 11. As long as all these locks are shared, they can coexist. 0 (a) 1 2 3 8 9 10 11 12 13 14 15 0 1 2 3 10 11 12 13 14 15 0 1 12 13 14 15 (b) (c) Process A's shared lock A's shared l... | clipped_os_Page_780_Chunk6997 |
SEC. 10.6 THE LINUX FILE SYSTEM 781 nonnegative integer called a file descriptor, fd in the example above. If a creat is done on an existing file, that file is truncated to length 0 and its contents are dis- carded. Files can also be created using the open call with appropriate arguments. Now let us continue looking at... | clipped_os_Page_781_Chunk6998 |
782 CASE STUDY 1: UNIX, LINUX, AND ANDROID CHAP. 10 pointer that indicates the current position in the file. When reading (or writing) se- quentially, it normally points to the next byte to be read (written). If the pointer is at, say, 4096, before 1024 bytes are read, it will automatically be moved to 5120 after a suc... | clipped_os_Page_782_Chunk6999 |
SEC. 10.6 THE LINUX FILE SYSTEM 783 being aware that these have been redirected. If they hav e not been redirected, sort will automatically read from the keyboard and write to the screen (the default de- vices). Similarly, when head reads from file descriptor 0, it is reading the data sort put into the pipe buffer with... | clipped_os_Page_783_Chunk7000 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.