전공/시스템프로그래밍 15

[12] BufferOverflow

movl $0x100, %eax // int* eax = (int*)0x100; movl $0x4050, (%eax) // *eax = 0x4050; IA-32/Linux Memory Layout application을 실행시키면 process가 되고 4G메모리 공간 할당받음 윗부분은 kernel 공간, 아랫부분은 application 공간 프로그램은 code(->text영역)+data Stack • Runtime stack (8MB limit) / int arr[100000큰수] => 에러 Heap • Dynamically allocated storage • When call malloc(), calloc(), new() DLLs (shared libraries) 다른 프로세서와 공유되는 라이브러리 •..

[13] Linking

Program Translation ● ○ 간단한 방법으로 한 번에 translate하지 않음 ○ 문제 : Efficiency : small change requires complete recompilation Modularity : hard to share common functions (e.g. printf) ○ 해결 : (Static) linker ● 오브젝트 파일 : 기계어로 번역된 상태 relocatable : address가 정해지지 않아서 나중에 정함 ● Compiler driver /coordinates /all steps in the translation and linking process - Typically included with each compilation system (gcc)..

[09] ASM2 : Control Flow

IA-32 Processor State 32bit compiler general purpose 6개는 범용으로 용도가 정해져 있지 않음. 컴파일러가 그때그때 결정 저장공간 6개를 (레)로 쓸 수 있다 %eax accumulate temporary data %ecx counter %edx data %ebx base %esi source index (배열 idx 관련) %edi destination index (배열 idx 관련) 특별한 목적의 (레) 범용 안 됨 %esp Current stack top stack pointer (스택이 어디까지 사용됐는지) Location of runtime stack %ebp Current stack frame 의 첫번째 위치(base address) base point..

[03-3] Integer(정수) / Representing and Manipulating Integers

Bit-Level Operations in C Operations &, |, ~, ^ available in C • Apply to any "integral" data type - long, int, short, char, unsigned Q) 나옴 ~0x00 -> 0xFF Logic Operations in C T/F? • &&, ||, ! • View 0 as "False" • Anything nonzero as "True" • Always return 0 or 1 Early termination // 앞부터 비교하기 때문에 적게 비교하는 게 더 좋음 Q) 나옴 char형 !0x41 0x00 !0x00 0x01 !!0x41 0x01 0x69 && 0x55 0x01 0x69 || 0x55 0x01 if..

[05] BYTE ORDERING

Memory model Physical memory - DRAM chips can read/write 4, 8, 16 bits - DRAM modules can read/write 64 bits Programmer's view of memory • Conceptually very large array of bytes 굉장히 큰 공간을 연속적으로 할당받고 있다 • Stored-program computers: keeps program codes and data in memory • Running programs share the physical memory • OS handles memory allocation and mangement word size • Nominal size of integer-val..

[08] ASM1

Moving data (데이터를 옮기기) : CPU와 Mem 사이, CPU-CPU movl source, dest ~복사 ● Move 4B("long") word - intel 32b 기준 그냥 mov는 16b Operand types 1) Immediate - constant integer data 상수값(C에서는 숫자값, Intel 어셈블리어는 $로 시작) - 1,2,4B로 2) Register - 8개의 범용 R중 하나 - %esp, %ebp는 스택을 나타내기 위해 특별한 용도로 사용 3) Memory - 4 consecutive bytes of memory - address movl operand combinations - Cannot do memory-memory transfers with si..