[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
syscall.c File Reference
#include "userprog/syscall.h"
#include <stdio.h>
#include <syscall-nr.h>
#include "threads/interrupt.h"
#include "threads/thread.h"
#include "threads/loader.h"
#include "userprog/gdt.h"
#include "threads/flags.h"
#include "intrinsic.h"
#include "filesys/filesys.h"
#include "filesys/file.h"
#include "threads/vaddr.h"
#include "threads/palloc.h"
#include "lib/stdio.h"
#include "threads/synch.h"
#include "vm/vm.h"
Include dependency graph for syscall.c:

Macros

#define MSR_STAR   0xc0000081 /* Segment selector msr */
 
#define MSR_LSTAR   0xc0000082 /* Long mode SYSCALL target */
 
#define MSR_SYSCALL_MASK   0xc0000084 /* Mask for the eflags */
 

Typedefs

typedef int pid_t
 

Functions

void syscall_entry (void)
 
void syscall_handler (struct intr_frame *)
 
void get_argument (void *rsp, int argc, void *argv[])
 
void halt (void)
 핀토스 자체를 종료시키는 시스템 콜 More...
 
void exit (int status)
 현재 프로세스를 종료시키는 시스템 콜 More...
 
pid_t fork (const char *thread_name, struct intr_frame *f)
 부모 프로세스로 부터 자식 프로세스를 복제한다. More...
 
int exec (const char *file)
 cmd_line으로 들어온 실행 파일을 실행한다. More...
 
int wait (tid_t pid)
 pid에 해당하는 자식 프로세스가 종료될 때까지 기다린다. More...
 
bool create (const char *file, unsigned initial_size)
 파일을 생성하는 시스템 콜 More...
 
bool remove (const char *file)
 파일을 샂게하는 시스템 콜 More...
 
int open (const char *file)
 파일을 열 때 사용하는 시스템 콜 More...
 
int filesize (int fd)
 파일의 크기를 알려주는 시스템 콜 More...
 
int read (int fd, void *buffer, unsigned size)
 열린 파일의 데이터를 읽는 시스템 콜 More...
 
int write (int fd, const void *buffer, unsigned size)
 열린 파일에 데이터를 쓰는 시스템 콜 More...
 
void seek (int fd, unsigned position)
 열린 파일의 위치를 이동하는 시스템 콜 More...
 
unsigned tell (int fd)
 열린 파일의 위치를 알려주는 시스템 콜 More...
 
void close (int fd)
 열린 파일을 닫는 시스템 콜 More...
 
void * mmap (void *addr, size_t length, int writable, int fd, off_t offset)
 열린 파일을 가상 주소 공간에 매핑한다. More...
 
void munmap (void *addr)
 mmap으로 매핑된 주소를 해제한다. More...
 
static int fdt_add_fd (struct file *f)
 fd table에 해당 파일 저장, fd 생성 More...
 
static struct filefdt_get_file (int fd)
 fd table에서 param fd 검색 More...
 
static void fdt_remove_fd (int fd)
 fd table에서 param fd 제거 More...
 
static void check_address (void *addr)
 주소 값이 유효한 주소 영역인지 확인 More...
 
void syscall_init (void)
 
void syscall_handler (struct intr_frame *f UNUSED)
 
static void check_buffer (void *buffer, unsigned size, bool writable)
 

Macro Definition Documentation

◆ MSR_LSTAR

#define MSR_LSTAR   0xc0000082 /* Long mode SYSCALL target */

◆ MSR_STAR

#define MSR_STAR   0xc0000081 /* Segment selector msr */

◆ MSR_SYSCALL_MASK

#define MSR_SYSCALL_MASK   0xc0000084 /* Mask for the eflags */

Typedef Documentation

◆ pid_t

typedef int pid_t

Function Documentation

◆ check_address()

static void check_address ( void *  addr)
static

주소 값이 유효한 주소 영역인지 확인

Null 포인터
매핑되지 않은 가상 메모리에 대한 포인터
커널 가상 주소 공간에 대한 포인터(KERN_BASE)

Parameters
addr
466 {
467 struct thread *curr = thread_current();
468 if (!is_user_vaddr(addr) || pml4_get_page(curr -> pml4, addr) == NULL || addr == NULL) // 유저 영역인지 NULL 포인터인지 확인
469 exit(-1);
470}
void exit(int status)
현재 프로세스를 종료시키는 시스템 콜
Definition: syscall.c:78
void * pml4_get_page(uint64_t *pml4, const void *upage)
Definition: mmu.c:214
#define NULL
Definition: stddef.h:4
Definition: thread.h:100
uint64_t * pml4
Definition: thread.h:121
struct thread * thread_current(void)
Definition: thread.c:301
#define is_user_vaddr(vaddr)
Definition: vaddr.h:41
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_buffer()

static void check_buffer ( void *  buffer,
unsigned  size,
bool  writable 
)
static
485 {
486 // struct page* page = check_address(buffer + size);
487 for (int i = 0; i < size; i++) {
488 struct page* page = check_address(buffer + i); // 하나씩 다 확인
489
490 if(page == NULL)
491 exit(-1);
492 if(!writable && page->writable == false) // true : writable, false : read-only
493 exit(-1);
494 }
495 // if(page == NULL)
496 // exit(-1);
497 // if(!writable && page->writable == false) // true : writable, false : read-only
498 // exit(-1);
499}
static struct intq buffer
Definition: input.c:7
uint16_t size
Definition: mmu.h:0
Definition: vm.h:51
bool writable
Definition: vm.h:60
static void check_address(void *addr)
주소 값이 유효한 주소 영역인지 확인
Definition: syscall.c:466
Here is the call graph for this function:
Here is the caller graph for this function:

◆ close()

void close ( int  fd)

열린 파일을 닫는 시스템 콜

파일을 닫고 fd를 제거한다.

Parameters
fd
392 {
393 struct file *target_file = fdt_get_file(fd);
394
395 if (fd <= STDOUT_FILENO || target_file == NULL || target_file <= 2)
396 return;
397
398 fdt_remove_fd(fd); // fd table에서 해당 fd값을 제거한다.
399
400 file_close(target_file); // 열었던 파일을 닫는다.
401}
void file_close(struct file *file)
Definition: file.c:53
#define STDOUT_FILENO
Definition: stdio.h:16
Definition: file.c:7
static struct file * fdt_get_file(int fd)
fd table에서 param fd 검색
Definition: syscall.c:532
static void fdt_remove_fd(int fd)
fd table에서 param fd 제거
Definition: syscall.c:546
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create()

bool create ( const char *  file,
unsigned  initial_size 
)

파일을 생성하는 시스템 콜

filesys_create (const char *name, off_t initial_size)

Parameters
file생성할 파일의 이름 및 경로 정보
initial_size생성할 파일의 크기
Returns
true 성공
false 실패
233 {
235 return filesys_create(file, initial_size);
236}
bool filesys_create(const char *name, off_t initial_size)
Definition: filesys.c:61
Here is the call graph for this function:
Here is the caller graph for this function:

◆ exec()

int exec ( const char *  file)

cmd_line으로 들어온 실행 파일을 실행한다.

Parameters
file실행하려는 파일 이름
Returns
int 성공 시 0, 실패 시 -1
198 {
200
201 int size = strlen(file) + 1; // 파일 사이즈(NULL 포함하기 위해 +1)
202 char *fn_copy = palloc_get_page(PAL_ZERO);
203
204 if (fn_copy == NULL)// 메모리 할당 불가 시
205 exit(-1);
206 strlcpy(fn_copy, file, size);
207
208 if (process_exec(fn_copy) == -1) // [process_exec] 'load (file_name, &_if);' -> load 실패 시
209 return -1;
210
211 return 0;
212}
@ PAL_ZERO
Definition: palloc.h:10
void * palloc_get_page(enum palloc_flags)
Definition: palloc.c:301
int process_exec(void *f_name)
Definition: process.c:241
size_t strlen(const char *)
Definition: string.c:271
size_t strlcpy(char *, const char *, size_t)
Definition: string.c:302
Here is the call graph for this function:

◆ exit()

void exit ( int  status)

현재 프로세스를 종료시키는 시스템 콜

종료 시 출력 : "${프로세스 명}: exit(${프로세스 상태})\n"
process_exit()에 존재

Parameters
status정상 종료 시, 0
173 {
174 struct thread *curr = thread_current();
175 curr->exit_status = status;
176 printf("%s: exit(%d)\n", curr->name, status);
177 thread_exit();
178}
int printf(const char *,...) PRINTF_FORMAT(1
char name[16]
Definition: thread.h:104
enum thread_status status
Definition: thread.h:103
int exit_status
Definition: thread.h:131
void thread_exit(void) NO_RETURN
Definition: thread.c:325
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fdt_add_fd()

static int fdt_add_fd ( struct file f)
static

fd table에 해당 파일 저장, fd 생성

Hanyang Univ. process_add_file 각색

Parameters
f새로 fd를 생성하려는 파일 객체(*file)
Returns
int 성공 시 fd, 실패 시 -1(STDERR_FILENO)
508 {
509 struct thread *curr = thread_current();
510 struct file **fdt = curr->fdt;
511
512 // fd가 제한 범위를 넘지 않고 fdt의 인덱스 위치와 일치 시
513 while (curr->next_fd < FDCOUNT_LIMIT && fdt[curr->next_fd]) {
514 curr->next_fd++;
515 }
516
517 // fdt가 가득 찼을 때 return -1
518 if (curr->next_fd >= FDCOUNT_LIMIT)
519 return -1;
520
521 fdt[curr->next_fd] = f; // fdt에 해당 fd 새로 넣어줌
522 return curr->next_fd;
523}
int next_fd
Definition: thread.h:123
struct file ** fdt
Definition: thread.h:122
#define FDCOUNT_LIMIT
Definition: thread.h:35
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fdt_get_file()

static struct file * fdt_get_file ( int  fd)
static

fd table에서 param fd 검색

Hanyang Univ. process_get_file 각색

Parameters
fd
Returns
struct file* 성공 시 찾은 fd에 대한 파일 객체, 실패 시 NULL
532 {
533 struct thread *curr = thread_current();
534 if (fd < STDIN_FILENO || fd >= FDCOUNT_LIMIT) { // 실패
535 return NULL;
536 }
537 return curr->fdt[fd]; // 성공
538}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fdt_remove_fd()

static void fdt_remove_fd ( int  fd)
static

fd table에서 param fd 제거

Hanyang Univ. process_close_file 각색

Parameters
fd
546 {
547 struct thread *curr = thread_current();
548
549 if (fd < STDIN_FILENO || fd >= FDCOUNT_LIMIT) // 실패
550 return;
551
552 curr->fdt[fd] = NULL; // 성공
553}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ filesize()

int filesize ( int  fd)

파일의 크기를 알려주는 시스템 콜

Parameters
fd
Returns
int 성공 시 파일 크기, 실패 시 -1
283 {
284 struct file *target_file = fdt_get_file(fd);
285 if (target_file == NULL)
286 return -1;
287 return file_length(target_file);
288}
off_t file_length(struct file *file)
Definition: file.c:141
Here is the call graph for this function:

◆ fork()

pid_t fork ( const char *  thread_name,
struct intr_frame f 
)

부모 프로세스로 부터 자식 프로세스를 복제한다.

Parameters
thread_name새로 생성될 자식 프로세스의 이름
f부모의 인터럽트 프레임
Returns
pid_t 생성된 자식 프로세스의 pid
187 {
189 return process_fork(thread_name, f);
190}
tid_t process_fork(const char *name, struct intr_frame *if_)
const char * thread_name(void)
Definition: thread.c:293
Here is the call graph for this function:

◆ get_argument()

void get_argument ( void *  rsp,
int  argc,
void *  argv[] 
)

◆ halt()

void halt ( void  )

핀토스 자체를 종료시키는 시스템 콜

163 {
164 power_off();
165}
void power_off(void) NO_RETURN
Definition: init.c:340
Here is the call graph for this function:

◆ mmap()

void * mmap ( void *  addr,
size_t  length,
int  writable,
int  fd,
off_t  offset 
)

열린 파일을 가상 주소 공간에 매핑한다.

Parameters
addr
length
writable
fd
offset
Returns
void*
413 {
414
415 /* Return NULL의 경우
416 * CASE 1. `addr` 가 0인 경우
417 * CASE 2. `addr` 가 커널 가상 주소인 경우
418 * CASE 3. `addr` 가 page-aligned 되지 않은 경우
419 * CASE 4. 기존에 매핑된 페이지 집합(stack, 페이지)과 겹치는 경우
420 * CASE 5. 읽으려는 파일의 offset 위치가 PGSIZE 보다 큰 경우
421 * CASE 6. 읽으려는 파일의 길이가 0보다 작거나 같은 경우
422 * CASE 7. STDIN, STDOUT 인 경우
423 * CASE 8. 파일 객체가 존재하지 않는 경우
424 * CASE 9. fd로 열린 파일의 길이가 0인 경우 */
425
426 // CASE 1 - 6
427 if (addr == NULL || is_kernel_vaddr(addr) || is_kernel_vaddr(pg_round_up(addr)) || pg_round_down(addr) != addr || spt_find_page(&thread_current()->spt, addr) \
428 || offset > PGSIZE \
429 || (long) length <= 0) // ? 형 변환 안하면 통과 못함 (Input : 음수)
430 return NULL;
431
432 /* mmap-kernel TC
433 *
434 * kernel = (void *) 0x8004000000 - 0x1000;
435 * CHECK (mmap (kernel, -0x8004000000 + 0x1000, 0, handle, 0) == MAP_FAILED,
436 * "try to mmap over kernel 2"); */
437
438 struct file *file = fdt_get_file(fd);
439
440 // CASE 7 - 9
441 if (fd <= STDOUT_FILENO || file == NULL || file_length(file) == 0)
442 return NULL;
443
444 // do_mmap의 4번째 인자가 파일 객체이므로 fd로 부터 파일 객체를 얻은 값을 넣어준다.
445 return do_mmap(addr, length, writable, file, offset);
446}
#define pg_round_up(va)
Definition: vaddr.h:29
#define is_kernel_vaddr(vaddr)
Definition: vaddr.h:44
#define PGSIZE
Definition: vaddr.h:20
#define pg_round_down(va)
Definition: vaddr.h:32
void * do_mmap(void *addr, size_t length, int writable, struct file *file, off_t offset)
Definition: file.c:89
struct page * spt_find_page(struct supplemental_page_table *spt, void *va)
Here is the call graph for this function:

◆ munmap()

void munmap ( void *  addr)

mmap으로 매핑된 주소를 해제한다.

Parameters
addr
453 {
454 do_munmap(addr);
455}
void do_munmap(void *va)
Definition: file.c:124
Here is the call graph for this function:

◆ open()

int open ( const char *  file)

파일을 열 때 사용하는 시스템 콜

Parameters
file파일의 이름 및 경로 정보
Returns
int 성공 시 fd, 실패 시 -1
258 {
261 struct file *target_file = filesys_open(file);
262
263 if (target_file == NULL) {
264 return -1;
265 }
266 int fd = fdt_add_fd(target_file); // fdt : file data table
267
268 // fd table이 가득 찼다면
269 if (fd == -1) {
270 file_close(target_file);
271 }
273 return fd;
274}
struct file * filesys_open(const char *name)
Definition: filesys.c:81
void lock_release(struct lock *)
Definition: synch.c:243
void lock_acquire(struct lock *)
Definition: synch.c:202
static int fdt_add_fd(struct file *f)
fd table에 해당 파일 저장, fd 생성
Definition: syscall.c:508
struct lock filesys_lock
Definition: syscall.h:10
Here is the call graph for this function:

◆ read()

int read ( int  fd,
void *  buffer,
unsigned  size 
)

열린 파일의 데이터를 읽는 시스템 콜

Parameters
fd
buffer읽은 데이터를 저장할 버퍼의 주소 값
length읽을 데이터 크기
Returns
int
299 {
300 int read_bytes = -1;
301
302 if(fd == STDIN_FILENO){ // fd 0 reads from the keyboard using input_getc()._gitbook
303 int i;
304 unsigned char *buf = buffer;
305
306 for (i = 0; i < size; i++)
307 {
308 char c = input_getc();
309 *buf++ = c;
310 if (c == '\0')
311 break;
312 }
313 return i;
314
315 }
316 else{
317 struct file *file = fdt_get_file(fd);
318 if (file != NULL && fd != STDOUT_FILENO){ // STDOUT_FILENO
319 lock_acquire(&filesys_lock); // 파일을 읽는 동안은 접근 못하게 락 걸어줌
320 read_bytes = file_read(file, buffer, size);
321 lock_release(&filesys_lock); // 락 해제
322 }
323 }
324 return read_bytes;
325}
off_t file_read(struct file *file, void *buffer, off_t size)
Definition: file.c:73
uint8_t input_getc(void)
Definition: input.c:29
#define STDIN_FILENO
Definition: stdio.h:15
Here is the call graph for this function:

◆ remove()

bool remove ( const char *  file)

파일을 샂게하는 시스템 콜

Parameters
file제거할 파일의 이름 및 경로 정보
Returns
true 성공
false 실패
246 {
248 return filesys_remove(file);
249}
bool filesys_remove(const char *name)
Definition: filesys.c:97
Here is the call graph for this function:

◆ seek()

void seek ( int  fd,
unsigned  position 
)

열린 파일의 위치를 이동하는 시스템 콜

Parameters
fd
position현재 위치(offset)를 기준으로 이동할 거리
361 {
362 struct file *target_file = fdt_get_file(fd);
363
364 if (fd <= STDOUT_FILENO || target_file == NULL)
365 return;
366
367 file_seek(target_file, position);
368}
void file_seek(struct file *file, off_t new_pos)
Definition: file.c:149
Here is the call graph for this function:

◆ syscall_entry()

void syscall_entry ( void  )
Here is the caller graph for this function:

◆ syscall_handler() [1/2]

void syscall_handler ( struct intr_frame )

◆ syscall_handler() [2/2]

void syscall_handler ( struct intr_frame *f  UNUSED)
92 {
93 // TODO: Your implementation goes here.
94 struct thread *curr = thread_current();
95 switch (f->R.rax) // 시스템 콜 번호에 따라 분기
96 {
97 case SYS_HALT:
98 halt ();
99 break;
100 case SYS_EXIT:
101 exit (f->R.rdi);
102 break;
103 case SYS_FORK:
104 f->R.rax = fork (f->R.rdi, f);
105 break;
106 case SYS_EXEC:
107 if (exec (f->R.rdi) == -1)
108 exit (-1);
109 break;
110 case SYS_WAIT:
111 f->R.rax = wait (f->R.rdi);
112 break;
113 case SYS_CREATE:
114 f->R.rax = create (f->R.rdi, f->R.rsi);
115 break;
116 case SYS_REMOVE:
117 f->R.rax = remove (f->R.rdi);
118 break;
119 case SYS_OPEN:
120 f->R.rax = open (f->R.rdi);
121 break;
122 case SYS_FILESIZE:
123 f->R.rax = filesize (f->R.rdi);
124 break;
125 case SYS_READ:
126 check_buffer(f->R.rsi, f->R.rdx, 0);
127 f->R.rax = read (f->R.rdi, f->R.rsi, f->R.rdx);
128 break;
129 case SYS_WRITE:
130 check_buffer(f->R.rsi, f->R.rdx, 1);
131 f->R.rax = write (f->R.rdi, f->R.rsi, f->R.rdx);
132 break;
133 case SYS_SEEK:
134 seek (f->R.rdi, f->R.rsi);
135 break;
136 case SYS_TELL:
137 f->R.rax = tell (f->R.rdi);
138 break;
139 case SYS_CLOSE:
140 close (f->R.rdi);
141 break;
142 case SYS_MMAP:
143 f->R.rax = mmap(f->R.rdi, f->R.rsi, f->R.rdx, f->R.r10, f->R.r8);
144 break;
145 case SYS_MUNMAP:
146 munmap(f->R.rdi);
147 break;
148 default:
149 exit (-1);
150 break;
151 }
152 // printf ("system call!\n");
153 // thread_exit ();
154}
int filesize(int fd)
파일의 크기를 알려주는 시스템 콜
Definition: syscall.c:114
bool create(const char *file, unsigned initial_size)
파일을 생성하는 시스템 콜
Definition: syscall.c:99
void close(int fd)
열린 파일을 닫는 시스템 콜
Definition: syscall.c:139
void * mmap(void *addr, size_t length, int writable, int fd, off_t offset)
열린 파일을 가상 주소 공간에 매핑한다.
Definition: syscall.c:149
int wait(pid_t pid)
pid에 해당하는 자식 프로세스가 종료될 때까지 기다린다.
Definition: syscall.c:94
pid_t fork(const char *thread_name)
Definition: syscall.c:84
int open(const char *file)
파일을 열 때 사용하는 시스템 콜
Definition: syscall.c:109
bool remove(const char *file)
파일을 샂게하는 시스템 콜
Definition: syscall.c:104
int write(int fd, const void *buffer, unsigned size)
열린 파일에 데이터를 쓰는 시스템 콜
Definition: syscall.c:124
int exec(const char *file)
cmd_line으로 들어온 실행 파일을 실행한다.
Definition: syscall.c:89
void seek(int fd, unsigned position)
열린 파일의 위치를 이동하는 시스템 콜
Definition: syscall.c:129
unsigned tell(int fd)
열린 파일의 위치를 알려주는 시스템 콜
Definition: syscall.c:134
int read(int fd, void *buffer, unsigned size)
열린 파일의 데이터를 읽는 시스템 콜
Definition: syscall.c:119
void munmap(void *addr)
mmap으로 매핑된 주소를 해제한다.
Definition: syscall.c:154
void halt(void)
핀토스 자체를 종료시키는 시스템 콜
Definition: syscall.c:72
@ SYS_MMAP
Definition: syscall-nr.h:23
@ SYS_WRITE
Definition: syscall-nr.h:17
@ SYS_TELL
Definition: syscall-nr.h:19
@ SYS_HALT
Definition: syscall-nr.h:7
@ SYS_READ
Definition: syscall-nr.h:16
@ SYS_CREATE
Definition: syscall-nr.h:12
@ SYS_CLOSE
Definition: syscall-nr.h:20
@ SYS_EXEC
Definition: syscall-nr.h:10
@ SYS_MUNMAP
Definition: syscall-nr.h:24
@ SYS_EXIT
Definition: syscall-nr.h:8
@ SYS_OPEN
Definition: syscall-nr.h:14
@ SYS_FILESIZE
Definition: syscall-nr.h:15
@ SYS_FORK
Definition: syscall-nr.h:9
@ SYS_WAIT
Definition: syscall-nr.h:11
@ SYS_REMOVE
Definition: syscall-nr.h:13
@ SYS_SEEK
Definition: syscall-nr.h:18
static void check_buffer(void *buffer, unsigned size, bool writable)
Definition: syscall.c:485
Here is the call graph for this function:

◆ syscall_init()

void syscall_init ( void  )
74 {
75 write_msr(MSR_STAR, ((uint64_t)SEL_UCSEG - 0x10) << 48 |
76 ((uint64_t)SEL_KCSEG) << 32);
77 write_msr(MSR_LSTAR, (uint64_t) syscall_entry);
78
79 /* The interrupt service rountine should not serve any interrupts
80 * until the syscall_entry swaps the userland stack to the kernel
81 * mode stack. Therefore, we masked the FLAG_FL. */
82 write_msr(MSR_SYSCALL_MASK,
84
85 /*------------------------- [P2] System Call --------------------------*/
86 lock_init(&filesys_lock); // 파일 읽고 쓰기에 필요한 락 초기화 _defined "userprog/syscall.h"
87}
#define FLAG_DF
Definition: flags.h:7
#define FLAG_IOPL
Definition: flags.h:8
#define FLAG_IF
Definition: flags.h:6
#define FLAG_AC
Definition: flags.h:9
#define FLAG_TF
Definition: flags.h:5
#define FLAG_NT
Definition: flags.h:10
#define SEL_UCSEG
Definition: loader.h:39
#define SEL_KCSEG
Definition: loader.h:36
unsigned long long int uint64_t
Definition: stdint.h:29
void lock_init(struct lock *)
Definition: synch.c:186
#define MSR_SYSCALL_MASK
Definition: syscall.c:71
#define MSR_STAR
Definition: syscall.c:69
#define MSR_LSTAR
Definition: syscall.c:70
void syscall_entry(void)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tell()

unsigned tell ( int  fd)

열린 파일의 위치를 알려주는 시스템 콜

Parameters
fd
Returns
unsigned 성공 시 파일의 위치(offset), 실패 시 -1
377 {
378 struct file *target_file = fdt_get_file(fd);
379
380 if (fd <= STDOUT_FILENO || target_file == NULL)
381 return;
382
383 file_tell(target_file);
384}
off_t file_tell(struct file *file)
Definition: file.c:158
Here is the call graph for this function:

◆ wait()

int wait ( tid_t  pid)

pid에 해당하는 자식 프로세스가 종료될 때까지 기다린다.

Parameters
pid기다리려는 자식 프로세스의 pid
Returns
int 성공 시 자식 프로세스의 종료 상태, 실패 시 -1
220 {
221 process_wait(pid);
222}
int process_wait(tid_t)
Here is the call graph for this function:

◆ write()

int write ( int  fd,
const void *  buffer,
unsigned  size 
)

열린 파일에 데이터를 쓰는 시스템 콜

Parameters
fd
buffer
size
Returns
int
336 {
337 int write_bytes = -1;
338
339 if (fd == STDOUT_FILENO){
340 putbuf (buffer, size);
341 return size;
342 }
343 else {
344 struct file *file = fdt_get_file(fd);
345 if (file != NULL && fd != STDIN_FILENO){ // STDIN_FILENO
346 lock_acquire(&filesys_lock); // 파일을 쓰는 동안은 접근 못하게 락 걸어줌
347 write_bytes = file_write(file, buffer, size);
348 lock_release(&filesys_lock); // 락 해제
349 }
350 }
351 return write_bytes;
352}
off_t file_write(struct file *file, const void *buffer, off_t size)
Definition: file.c:97
void putbuf(const char *, size_t)
Definition: console.c:143
Here is the call graph for this function:
Here is the caller graph for this function: