Project 1 ELF, Program loading. elf.c Parameter – Char *exeFileData : executable file 을 read 한 버퍼 – struct elfHeader : GeekOS 의 ELF Header 구조체 – Struct.

Slides:



Advertisements
Similar presentations
Florida State UniversityCOP5570 – Advanced Unix Programming IPC mechanisms Pipes Sockets System V IPC –Message Queues –Semaphores –Shared Memory.
Advertisements

Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Christo Wilson Project 2: User Programs in Pintos
Process management Information maintained by OS for process management  process context  process control block OS virtualization of CPU for each process.
Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.
Project 2 Roadmap. Segmentation Review Intel docs, fig. 3-1 and 3-5.
1 Processes Professor Jennifer Rexford
Project 1 Prerequisites read the project description check the newsgroup read the ELF specification –(pages , , )
Project 2 Roadmap. Background – Context Switching One processor and multiple threads running concurrently – How?!! Give each thread a small time quantum.
Project 1 Roadmap. Address Space Protection in GeekOS User Process 1 Base 1 Size 1 User Process 2 Base 2 Size 2 User Process n Base n Size n Kernel User.
Project 1 Roadmap.
Introduction to Kernel
Project 1 Roadmap.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Project 4 Roadmap. x86 Paging Overview ftp://download.intel.com/design/Pentium4/manuals/ pdf figures on pages 3-2, 3-21.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
CMSC412 Fall’05 CMSC412 Project 0/1. CMSC412 Fall’05 The usual Info: csd.cmsc412 Recitation: CSI 2118; Mon.
Protected Mode. Protected Mode (1 of 2) 4 GB addressable RAM –( to FFFFFFFFh) Each program assigned a memory partition which is protected from.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Phones OFF Please Processes Parminder Singh Kang Home:
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
Outline Introduction to MQX Initializing and starting MQX
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Introduction to Processes CS Intoduction to Operating Systems.
Lecture 5 Process, Thread and Task September 22, 2015 Kyu Ho Park.
Exec Function calls Used to begin a processes execution. Accomplished by overwriting process imaged of caller with that of called. Several flavors, use.
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
Thread Synchronization with Semaphores
Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
CNIT 127: Exploit Development Ch 3: Shellcode. Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object.
1 Chapter 4 Processes R. C. Chang. 2 Linux Processes n Each process is represented by a task_struct data structure (task and process are terms that Linux.
Operating Systems Process Creation
Multi-Tasking The Multi-Tasking service is offered by VxWorks with its real- time kernel “WIND”.
LINUX System : Lecture 7 Process Bong-Soo Sohn Lecture notes acknowledgement : The design of UNIX Operating System.
4300 Lines Added 1800 Lines Removed 1500 Lines Modified PER DAY DURING SUSE Lab.
Chapter 4 Process Abstraction Chien-Chung Shen CIS, UD
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Programs and Processes Jeff Chase Duke University.
1 Structure of Processes Chapter 6 Process State and Transition Data Structure for Process Layout of System Memory THE DESIGN OF THE UNIX OPERATING SYSTEM.
Project 1 Roadmap read the project description ? read the newsgroup ? read the ELF specification ? –( , , ) read the elfHeader correctly.
Information Security - 2. Descriptor Tables Descriptors are stored in three tables: – Global descriptor table (GDT) Maintains a list of most segments.
IBM’s OS/2 by Chris Axford Chris Evans Elizabeth McGinnis Erik Swensson.
WORKING OF SCHEDULER IN OS
Introduction to Kernel
Descriptor Table & Register
Process concept.
16.317: Microprocessor System Design I
Operating Systems Engineering
143A: Principles of Operating Systems Lecture 7: System boot
Microprocessor Systems Design I
Protection of System Resources
Anton Burtsev February, 2017
Linux Processes & Threads
Process management Information maintained by OS for process management
Processes in Unix, Linux, and Windows
Lecture 5: Process Creation
Memory Management Chapter 10 11/24/2018 Crowley OS Chap. 10.
More examples How many processes does this piece of code create?
Processes in Unix, Linux, and Windows
System Structure and Process Model
PROCESS MANAGEMENT Information maintained by OS for process management
Lecture 37 Syed Mansoor Sarwar
Lecture 6: Multiprogramming and Context Switching
Programming Language C Language.
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
System Calls System calls are the user API to the OS
Presentation transcript:

Project 1 ELF, Program loading

elf.c Parameter – Char *exeFileData : executable file 을 read 한 버퍼 – struct elfHeader : GeekOS 의 ELF Header 구조체 – Struct programHeader : GeekOS 의 Program Header 구조체 – struct Exe_format : GeekOS 에서 Program 을 Load 하기 위한 Segment 정보를 포함하는 구조체 – EXE_MAX_SEGMENTS : GeekOS 의 최대 Segment 개수 (3) Exe_format exeFileData(buffer) Int Parsr_ELF_Executable (char *exeFileData, ulong_t exeFileLength, struct Exe_Format *exeFormat) Elfhdr = (elfHeader*) exeFileData ; 1. If(elfhdr -> phnum <= EXE_MAX_SEGMENT) exeFormat -> numSegments = elfhdr -> phnum; exeFormat -> entryAddr = elfhdr -> entry; for( i=0; i phnum; i++) programhdr = (programHeader *)(exeFileData + elfhdr->phoff + (i * elfhdr->phentsize)); exeFormat->segmentList[i].offsetInfile = programgdr->offset;

userseg.c int Load_User_Program(char *exeFileData, ulong_t exeFileLength, struct Exe_Format *exeFormat, const char *command, struct User_Context **pUserContext) 1. 각각의 Segment( Text, Data) 들의 정보를 담은 struct Exe_format 을 이용 2.Segment 가 시작하는 memory 주소, segment 크기, Stack Size 들을 산술하여 stack 시작주소, command 시작주소를 정함 3.Process 가 가지는 memory 영역의 size 를 계산  Process memory 할당 4.Process memory 의 시작주소를 기준으로 각 Segment 들을 Process 의 memory 에 Loading (memcpy) Exe_format 주소참조주소참조 exeFileData(buffer) 복사복사 DEFAULT_USER_STACK_SIZEDEFAULT_USER_STACK_SIZE command 복사복사 Total size User process 시작주소

userseg.c Exe_format 주소참조주소참조 DEFAULT_USER_STACK_SIZEDEFAULT_USER_STACK_SIZE command 복사복사 Total size User process 시작주소 for( i=0; i numSegments; i++) struct Exe_Segment *segment = &(exeFormat->segmentList[i]); tmp = segment->startAddress + segment->sizeInMenory; if(maxsegsize <= tmp) meaxsegsize = tmp; stackvaddr = Round_Up_To_Page(maxsegsize); Get_Argument_Block_Size(); : 결과값 argblocksize totvaddrsize = argvaddr + Round_Up_To_Page(argblocksize) argvaddr = stackvaddr + DEFAULT_USER_STACK_SIZE; Project 2 1 ~ 3

userseg.c for( i=0; i numSegments; i++) struct Exe_Segment *segment = &(exeFormat->segmentList[i]); memcpy( (*pUserContext)->memory) + (segment->startAddress), exeFileData + (segment->offsetInFile), Segmet->lengthInFile); Format_Argument_Block((*pUserContext->memory + argvaddr, numarg, argvaddr, command); 4 exeFileData(buffer) 복사복사 DEFAULT_USER_STACK_SIZEDEFAULT_USER_STACK_SIZE command 복사복사 Total size User process 시작주소 stackvaddr argvaddr Dest src len (*pUserContext) -> entryAddr = exeFormat -> entryAddr;

Project 2 User context

userseg2.c struct User_Context* Create_User_Context (ulong_t size)

Local Descriptor Table : Process 에 대한 Segment Descriptor 들을 보관 LDTR 을 통해 접근, Context Switching 과 관련성이 있음 LDT 의 위치를 나타내는 Segment Descriptor 를 GDT 내부에 저장한 뒤, 해당 Index 를 LDTR Register 에 넣어주면 CPU 는 LDT 를 읽어들여 Process 의 Segment 들에 대한 정보에 접근가능 32bit 이상의 OS 에서 Segment Register 에는 Segment 에 관한 LDT 의 Descriptor Number 가 들어가게 되어 Segment Selector 라는 명칭으로 바뀌게 된다 User context Descriptor Table - LDT

userseg2.c struct User_Context* Create_User_Context (ulong_t size) pUserContext = (struct pUserContext*) Malloc( sizeof(struct User_Context) ); pUserContext -> memory = (char*) Malloc (size); pUsetContext -> size = size; pUserContext -> ldtDescriptor = Allocate_Segment_Descriptor(); Init_LDT_Descriptor(pUserContext->ldtDescriptor, pUserContext->ldt, NUM_USER_LDT_ENTRIES);

userseg2.c struct User_Context* Create_User_Context (ulong_t size) Init_Code_Segment_Descriptor( ~ ); Init_Data_Segment_Descriptor( ~ ); pUserContext->ldtSelector = Selector( ~ ); pUserContext->csSelector = Selector( ~ ); pUserContext->dsSelector = Selector( ~ ); pUserContext->refCount = 0;

Project 3 EDF-Scheduling

timer.c static void Timer_Interrupt_Handler(struct Interrupt_State* state) if(policy == 2 && spawned) { g_needReschedule = true; } Kernel thread User thread - EDF - Round Robin Dead line - 20Dead line

kthread.c

kthread.c struct Kernel_Thread* Get_Next_Runnable(void) Kernel thread User thread - EDF - Round Robin Dead line - 20Dead line case 2: // EDF if(spawned || K_or_U_sched) { best = Find_Best_User(&s_runQueue[0]); spawned = 0; K_or_U_sched = 0; } else if(!K_or_U_sched) { best = Find_Best(&s_runQueue[0]); K_or_U_sched = 1; } if(best != 0) Remove_Thread(&s_runQueue[0], best); break; struct Kernel_Thread* Find_Best(struct Thread_Queue* queue) if(policy == 2) { while (kthread != 0) { if ((best == 0 && kthread -> K_or_U) || (kthread -> K_or_U && kthread->priority > best->priority)) best = kthread; kthread = Get_Next_In_Thread_Queue(kthread); } struct Kernel_Thread* Find_Best_User(struct Thread_Queue* queue) struct Kernel_Thread *kthread = queue->head, *best = 0; while (kthread != 0) { if ((best == 0 && kthread -> K_or_U == 0) || (kthread -> K_or_U == 0 && kthread->deadline deadline)) best = kthread; kthread = Get_Next_In_Thread_Queue(kthread); } if(!best) best = Find_Best(queue); return best;

Project 4 Semaphore

Semaphore Sys_CreateSemaphore() Sys_P() Sys_V() 인자로 받은 Semaphore ID 로 해당 Semaphore 를 검색 인자로 받은 Semaphore ID 로 해당 Semaphore 를 검색 해당 Semaphore 의 count 값을 조회하여 thread 가 wait 또는 임계영역 자원획득 허가를 판단 해당 Semaphore 의 count 값을 조회하여 thread 가 wait 또는 임계영역 자원획득 허가를 판단

syscall.c static int Sys_CreateSemaphore(struct Interrupt_State* state) char sem_name[25]; int length = state->ecx; Copy_From_User(sem_name, state->ebx, length); if(sem == NULL) sem = (struct semaphore**)Malloc(NUM_SEMAPHORE * sizeof(struct semaphore*)); for(i=0; i<NUM_SEMAPHORE; i++) { sem[i] = (struct semaphore*)Malloc(sizeof(struct semaphore)); sem[i] 초기화 Clear_Thread_Queue( (sem[i] waitqueue) ); } for(i=0 ; i<NUM_SEMAPHORE; i++) if(sem[i]->avail) { sem[i]->count = state -> edx; sem[i]->avail = 0; memcpy(sem[i]->sem_name,sem_name,length+1); return i; } else for(i=0 ; i<NUM_SEMAPHORE; i++) { if(strcmp(sem_name,sem[i]->sem_name)==0) return i;

syscall.c static int Sys_P(struct Interrupt_State* state)static int Sys_V(struct Interrupt_State* state) int sem_id = state -> ebx; if(sem[sem_id]->count <= 0) Wait; else sem[sem_id]->count--; int sem_id = state -> ebx; if(!Is_Thread_Queue_Empty(&(sem[sem_id]->waitQueue))) Wake_Up else sem[sem_id]->count++;

syscall.c static int Sys_DestroySemaphore(struct Interrupt_State* state) int sem_id = state->ebx; if(sem[sem_id]->avail == 0) { return -1; } else { sem[sem_id]->count = 0; sem[sem_id]->avail = 1; Clear_Thread_Queue; }

Project 제출 제출 제출기한 : 기말고사 1 주 후 제출방법 : Geek-OS 압축파일 + 소스 설명을 포함한 Report – 제출 질문사항 또는 자연과학관 515 호