CSAPP - Ch 1 - computer system roaming

0 Preamble and Summary

(1) Preamble:

CS: APP - Computer Systems: A Programmer's Perspective, in translation entitled: "In-depth understanding of computer systems."

It can be learned from the title:

Most systems are books from the perspective of the builder to write, how to implement hardware or system software, including operating systems, compilers and network interface;
and CS: APP from a programmer's point of view, how about the application programmers to use of system knowledge to write better programs related to fundamental aspects of the system hardware architecture, operating systems, compilers, and other networks.

(2) Summary:

The computer system is composed of a system of hardware and software components that work together to run the application. Information inside the computer is represented as a bit of a set of components, depending on the context they have a different way of explanation. Program is translated into various other programs form, beginning ASCII text, then the compiler and linker translated into binary executable files.

The processor reads and interprets stored in main memory where the binary instructions. Since the computer takes a lot of time to copy data between memory, I / O device and the CPU register, a storage device in the system is divided into a hierarchy - CPU registers at the top, followed by a multilayer hardware cache memory, a DRAM main memory and disk storage.

Higher-level storage device faster than the low-level memory read-write device, the unit cost is a bit higher.
Higher-level cache memory device can be used as a low-level devices.

The operating system kernel is the intermediary between the application and the hardware that provides three basic abstractions:

. A is an abstract file I / O devices;

. B Virtual memory is an abstraction of the storage and disk;

C. Process processor, abstract main memory and I / O devices.

The network provides a means of communication between computer systems - it can be used as a network I / O device.

Context information is 1 bit +

C program in the following hello.cexample:

#include <stdio.h>
int main() {
    printf("hello, world\n");
    return 0;
}

In fact, the source bit ( 'bit, bits) composed of a sequence of 0,1, 8 bits are grouped together, is a byte (Byte). Each byte text characters are denoted program.

Most modern computer systems are applicable standard ASCII text characters to represent - in fact, with a unique integer value of single-byte to represent each character, for example #由35表示, i由105表示.

hello.c program is a sequence of bytes is stored in a file in the embodiment, each byte has an integer value, corresponding to certain characters.

Note: Each row is invisible to a newline \nend, the corresponding ASCII code is 10.

hello.c representation illustrates a basic idea:

系统中的所有信息——包括磁盘文件、内存中的程序、内存中存放的用户数据, 以及网络上传输的数据, 都是由一串比特表示的.
区分不同数据对象的唯一方法就是我们读到这些数据对象时的上下文.

Reading Notes: context : can be compared before and after the text of the article, a single int, we can not know exactly what its practical effect, given that only adjacent bits, we can determine its specific meaning, such as hello.c in. can be known from the context of the int, int specified here is the return value of the current function of type int (integer).

2 program is translated into a different format other programs

Hello.c is written like the above, we can understand the developer of high-level language source code files, to run on the system, must pass another program to convert it into a series of low-level machine language instructions, then these instructions surrounded by large executable object program (object files) , and store it in the form of a binary disk file.

On Unix systems, conversion from the source file to the destination is determined by the compiler driver completed:

gcc hello.c -o hello

Here GCC compiler read by the driver source file hello.c, and put it into an executable object file variation hello, the specific steps:

Build system

(1) pretreatment stage: preprocessor (CPP) in accordance with the command beginning with # character, modify the original C program: Here the system will read the header file stdio.h introduced, it is inserted into the source code of this Chinese give another procedure C, typically hello.i;

(2) compile phase: the compiler (ccl) text file hello.i translated into a text file hello.s, is an assembly language program;

(3) Assembly Stage: assembler (as) the hello.s translated into machine language instructions, these instructions called packaged into relocatable object program format, and stores the result in the destination file in hello.o - is a binary file;

(4) linking phase: hello.c call the printfprint function, which is the C compiler provides the standard C library of pre-compiled exists in printf.o a good target file, at this stage by the linker (ld) will be merged into printf.o hello.o, and finally get the file hello - executable object file that can be loaded into memory and executed by the system.

3 Learn how to build system to work is a great advantage

(1) Performance Optimizer

such as:

A switch statement is always more efficient than if-else statement?
Overhead of a function call how much? While circulating efficient than the for loop it?
Pointer references more effective than the array index it?
Why is the summation of the results of the cycle into a local variable parameters, than put it into a pass over through references, it runs much faster?

An error occurred while (2) understand the links

Some of the most troubling, difficult to locate bugs are often related to the operation and links such as:

The linker can not resolve a reference to reports that What does it mean?
What is the difference between static and global variables is that?
What is the difference between static and dynamic libraries is that?
What is the impact of the library order on the command line?

(3) avoid security breaches

Buffer overflow error is the main cause of most networks and Internet server security vulnerabilities - because few developers can understand the need to limit the number and format of untrusted source to receive data from .

The first step is to understand the programming security consequences of the way data and control information stored on the program stack will cause .

To be continued ...

Guess you like

Origin www.cnblogs.com/shoufeng/p/11442718.html