[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
syscall.h File Reference
#include <stdbool.h>
#include <debug.h>
#include <stddef.h>
Include dependency graph for syscall.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PID_ERROR   ((pid_t) -1)
 
#define MAP_FAILED   ((void *) NULL)
 
#define READDIR_MAX_LEN   14
 
#define EXIT_SUCCESS   0 /* Successful execution. */
 
#define EXIT_FAILURE   1 /* Unsuccessful execution. */
 

Typedefs

typedef int pid_t
 
typedef int off_t
 

Functions

void halt (void) NO_RETURN
 핀토스 자체를 종료시키는 시스템 콜 More...
 
void exit (int status) NO_RETURN
 현재 프로세스를 종료시키는 시스템 콜 More...
 
pid_t fork (const char *thread_name)
 
int exec (const char *file)
 cmd_line으로 들어온 실행 파일을 실행한다. More...
 
int wait (pid_t)
 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 length)
 열린 파일의 데이터를 읽는 시스템 콜 More...
 
int write (int fd, const void *buffer, unsigned length)
 열린 파일에 데이터를 쓰는 시스템 콜 More...
 
void seek (int fd, unsigned position)
 열린 파일의 위치를 이동하는 시스템 콜 More...
 
unsigned tell (int fd)
 열린 파일의 위치를 알려주는 시스템 콜 More...
 
void close (int fd)
 열린 파일을 닫는 시스템 콜 More...
 
int dup2 (int oldfd, int newfd)
 
void * mmap (void *addr, size_t length, int writable, int fd, off_t offset)
 열린 파일을 가상 주소 공간에 매핑한다. More...
 
void munmap (void *addr)
 mmap으로 매핑된 주소를 해제한다. More...
 
bool chdir (const char *dir)
 
bool mkdir (const char *dir)
 
bool readdir (int fd, char name[READDIR_MAX_LEN+1])
 
bool isdir (int fd)
 
int inumber (int fd)
 
int symlink (const char *target, const char *linkpath)
 
static void * get_phys_addr (void *user_addr)
 
static long long get_fs_disk_read_cnt (void)
 
static long long get_fs_disk_write_cnt (void)
 

Macro Definition Documentation

◆ EXIT_FAILURE

#define EXIT_FAILURE   1 /* Unsuccessful execution. */

◆ EXIT_SUCCESS

#define EXIT_SUCCESS   0 /* Successful execution. */

◆ MAP_FAILED

#define MAP_FAILED   ((void *) NULL)

◆ PID_ERROR

#define PID_ERROR   ((pid_t) -1)

◆ READDIR_MAX_LEN

#define READDIR_MAX_LEN   14

Typedef Documentation

◆ off_t

typedef int off_t

◆ pid_t

typedef int pid_t

Function Documentation

◆ chdir()

bool chdir ( const char *  dir)
159 {
160 return syscall1 (SYS_CHDIR, dir);
161}
#define syscall1(NUMBER, ARG0)
Definition: syscall.c:39
Definition: directory.c:10
@ SYS_CHDIR
Definition: syscall-nr.h:27

◆ 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 NULL
Definition: stddef.h:4
#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
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:

◆ dup2()

int dup2 ( int  oldfd,
int  newfd 
)
144 {
145 return syscall2 (SYS_DUP2, oldfd, newfd);
146}
#define syscall2(NUMBER, ARG0, ARG1)
Definition: syscall.c:44
@ SYS_DUP2
Definition: syscall-nr.h:35

◆ 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}
void exit(int status)
현재 프로세스를 종료시키는 시스템 콜
Definition: syscall.c:78
uint16_t size
Definition: mmu.h:0
@ 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:
Here is the caller 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
Definition: thread.h:100
char name[16]
Definition: thread.h:104
enum thread_status status
Definition: thread.h:103
int exit_status
Definition: thread.h:131
struct thread * thread_current(void)
Definition: thread.c:301
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:

◆ 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:
Here is the caller graph for this function:

◆ fork()

pid_t fork ( const char *  thread_name)
84 {
86}
int pid_t
Definition: syscall.h:9
@ SYS_FORK
Definition: syscall-nr.h:9
const char * thread_name(void)
Definition: thread.c:293
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_fs_disk_read_cnt()

static long long get_fs_disk_read_cnt ( void  )
inlinestatic
62 {
63 long long read_cnt;
64 asm volatile ("movq $0, %rdx");
65 asm volatile ("movq $1, %rcx");
66 asm volatile ("int $0x43");
67 asm volatile ("\t movq %%rax, %0": "=r" (read_cnt));
68 return read_cnt;
69}

◆ get_fs_disk_write_cnt()

static long long get_fs_disk_write_cnt ( void  )
inlinestatic
72 {
73 long long write_cnt;
74 asm volatile ("movq $0, %rdx");
75 asm volatile ("movq $1, %rcx");
76 asm volatile ("int $0x44");
77 asm volatile ("\t movq %%rax, %0": "=r" (write_cnt));
78 return write_cnt;
79}
static int64_t write_cnt
Definition: console.c:60

◆ get_phys_addr()

static void * get_phys_addr ( void *  user_addr)
inlinestatic
53 {
54 void* pa;
55 asm volatile ("movq %0, %%rax" ::"r"(user_addr));
56 asm volatile ("int $0x42");
57 asm volatile ("\t movq %%rax, %0": "=r" (pa));
58 return pa;
59}

◆ 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:
Here is the caller graph for this function:

◆ inumber()

int inumber ( int  fd)
179 {
180 return syscall1 (SYS_INUMBER, fd);
181}
@ SYS_INUMBER
Definition: syscall-nr.h:31

◆ isdir()

bool isdir ( int  fd)
174 {
175 return syscall1 (SYS_ISDIR, fd);
176}
@ SYS_ISDIR
Definition: syscall-nr.h:30

◆ mkdir()

bool mkdir ( const char *  dir)
164 {
165 return syscall1 (SYS_MKDIR, dir);
166}
@ SYS_MKDIR
Definition: syscall-nr.h:28

◆ 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:
Here is the caller 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:
Here is the caller 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:
Here is the caller 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
static struct intq buffer
Definition: input.c:7
uint8_t input_getc(void)
Definition: input.c:29
#define STDIN_FILENO
Definition: stdio.h:15
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readdir()

bool readdir ( int  fd,
char  name[READDIR_MAX_LEN+1] 
)
169 {
170 return syscall2 (SYS_READDIR, fd, name);
171}
@ SYS_READDIR
Definition: syscall-nr.h:29

◆ 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:
Here is the caller 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:
Here is the caller graph for this function:

◆ symlink()

int symlink ( const char *  target,
const char *  linkpath 
)
184 {
185 return syscall2 (SYS_SYMLINK, target, linkpath);
186}
@ SYS_SYMLINK
Definition: syscall-nr.h:32

◆ 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:
Here is the caller 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:
Here is the caller 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: