[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
process.h File Reference
#include "threads/thread.h"
#include "filesys/off_t.h"
Include dependency graph for process.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  segment_aux
 

Functions

tid_t process_create_initd (const char *file_name)
 
tid_t process_fork (const char *name, struct intr_frame *if_)
 
int process_exec (void *f_name)
 
int process_wait (tid_t)
 
void process_exit (void)
 
void process_activate (struct thread *next)
 
bool setup_stack (struct intr_frame *if_)
 
bool lazy_load_segment (struct page *page, void *aux)
 

Function Documentation

◆ lazy_load_segment()

bool lazy_load_segment ( struct page page,
void *  aux 
)
Here is the caller graph for this function:

◆ process_activate()

void process_activate ( struct thread next)
379 {
380 /* Activate thread's page tables. */
381 pml4_activate (next->pml4);
382
383 /* Set thread's kernel stack for use in processing interrupts. */
385}
static int next(int pos)
Definition: intq.c:74
void pml4_activate(uint64_t *pml4)
Definition: mmu.c:205
void tss_update(struct thread *next)
Definition: tss.c:71
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_create_initd()

tid_t process_create_initd ( const char *  file_name)
52 {
53 char *fn_copy, *save_ptr;
54 tid_t tid;
55
56 /* Make a copy of FILE_NAME.
57 * Otherwise there's a race between the caller and load(). */
58 fn_copy = palloc_get_page (0);
59 if (fn_copy == NULL)
60 return TID_ERROR;
61 strlcpy (fn_copy, file_name, PGSIZE);
62 /* Create a new thread to execute FILE_NAME. */
63 strtok_r (file_name, " ", &save_ptr); // 실행 파일 이름 파싱
64 // ↳해당 라인을 추가하지 않으면 커맨드 라인 전체가 스레드 이름으로 지정된다.
65 tid = thread_create (file_name, PRI_DEFAULT, initd, fn_copy);
66 if (tid == TID_ERROR)
67 palloc_free_page (fn_copy);
68 return tid;
69}
void * palloc_get_page(enum palloc_flags)
Definition: palloc.c:301
void palloc_free_page(void *)
Definition: palloc.c:333
static void initd(void *f_name)
Definition: process.c:73
#define NULL
Definition: stddef.h:4
size_t strlcpy(char *, const char *, size_t)
Definition: string.c:302
char * strtok_r(char *, const char *, char **)
Definition: string.c:219
#define PRI_DEFAULT
Definition: thread.h:30
#define TID_ERROR
Definition: thread.h:26
int tid_t
Definition: thread.h:25
tid_t thread_create(const char *name, int priority, thread_func *, void *)
Definition: thread.c:197
#define PGSIZE
Definition: vaddr.h:20
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_exec()

int process_exec ( void *  f_name)
241 {
242 char *file_name = f_name; // 실행할 파일 이름(argv[0])
243 // char *file_name_copy[48];
244 bool success;
245
246 /* We cannot use the intr_frame in the thread structure.
247 * This is because when current thread rescheduled,
248 * it stores the execution information to the member. */
249 struct intr_frame _if;
250 _if.ds = _if.es = _if.ss = SEL_UDSEG;
251 _if.cs = SEL_UCSEG;
252 _if.eflags = FLAG_IF | FLAG_MBS;
253
254 int argc = 0;
255 char *argv[128]; // 64bit computer(uint64_t : 8byte)
256
257 /* We first kill the current context */
259
260 /*-------------------------[P3]hash table---------------------------------*/
261 #ifdef VM
263 #endif
264 /*-------------------------[P3]hash table---------------------------------*/
265
266 /* 커맨드 라인을 파싱한다. */
267 argument_parse(file_name, &argc, argv);
268
269 /* And then load the binary */
270 success = load (file_name, &_if);
271
272
273 /* If load failed, quit. */
274 if (!success){
275 palloc_free_page (file_name);
276 return -1;
277 }
278
279 argument_stack(argc, argv, &_if); // argc, argv로 커맨드 라인 파싱
280 // hex_dump(_if.rsp, _if.rsp, USER_STACK - _if.rsp, true); // 메모리에 적재된 상태 출력
281 palloc_free_page (file_name);
282
283 /* Start switched process. */
284 do_iret (&_if);
285 NOT_REACHED ();
286}
#define NOT_REACHED()
Definition: debug.h:34
#define FLAG_IF
Definition: flags.h:6
#define FLAG_MBS
Definition: flags.h:4
#define SEL_UCSEG
Definition: loader.h:39
#define SEL_UDSEG
Definition: loader.h:38
static bool load(const char *file_name, struct intr_frame *if_)
Definition: process.c:451
static void process_cleanup(void)
Definition: process.c:350
static void argument_parse(char *file_name, int *argc_ptr, char *argv[])
Definition: process.c:865
static void argument_stack(int argc, char **argv, struct intr_frame *if_)
Definition: process.c:874
Definition: interrupt.h:37
uint16_t ds
Definition: interrupt.h:44
struct thread * thread_current(void)
Definition: thread.c:301
void do_iret(struct intr_frame *tf)
Definition: thread.c:577
void supplemental_page_table_init(struct supplemental_page_table *spt)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_exit()

void process_exit ( void  )
328 {
329 struct thread *curr = thread_current ();
330 /* TODO: Your code goes here.
331 * TODO: Implement process termination message (see
332 * TODO: project2/process_termination.html).
333 * TODO: We recommend you to implement process resource cleanup here. */
334
335 for (int i = 0; i < FDCOUNT_LIMIT; i++) // 프로세스 종료 시, 해당 프로세스의 fdt의 모든 값을 0으로 만들어준다.
336 close(i);
337 palloc_free_multiple(curr->fdt, FDT_PAGES); // fd table 메모리 해제
338
339 file_close(curr->running); // 현재 프로세스가 실행중인 파일을 종료한다.
340
342
343 sema_up(&curr->wait_sema); // 부모 프로세스가 자식 프로세스의 종료상태를 확인하게 한다.
344 thread_sleep(500);
345 // sema_down(&curr->free_sema); // 부모 프로세스가 자식 프로세스의 종료 상태를 받을때 까지 대기한다.
346}
void file_close(struct file *file)
Definition: file.c:53
void close(int fd)
열린 파일을 닫는 시스템 콜
Definition: syscall.c:392
void palloc_free_multiple(void *, size_t page_cnt)
Definition: palloc.c:307
Definition: thread.h:100
struct file * running
Definition: thread.h:130
struct file ** fdt
Definition: thread.h:122
struct semaphore wait_sema
Definition: thread.h:135
void sema_up(struct semaphore *)
Definition: synch.c:114
void thread_sleep(int64_t ticks)
Definition: thread.c:365
#define FDT_PAGES
Definition: thread.h:34
#define FDCOUNT_LIMIT
Definition: thread.h:35
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_fork()

tid_t process_fork ( const char *  name,
struct intr_frame if_ 
)
Here is the caller graph for this function:

◆ process_wait()

int process_wait ( tid_t  )
Here is the caller graph for this function:

◆ setup_stack()

bool setup_stack ( struct intr_frame if_)
673 {
674 uint8_t *kpage;
675 bool success = false;
676
678 if (kpage != NULL) {
679 success = install_page (((uint8_t *) USER_STACK) - PGSIZE, kpage, true);
680 if (success)
681 if_->rsp = USER_STACK;
682 else
683 palloc_free_page (kpage);
684 }
685 return success;
686}
@ PAL_ZERO
Definition: palloc.h:10
@ PAL_USER
Definition: palloc.h:11
static bool install_page(void *upage, void *kpage, bool writable)
Definition: process.c:698
unsigned char uint8_t
Definition: stdint.h:20
uintptr_t rsp
Definition: interrupt.h:60
#define USER_STACK
Definition: vaddr.h:38
Here is the call graph for this function:
Here is the caller graph for this function: