[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
syscall.h
Go to the documentation of this file.
1#ifndef __LIB_USER_SYSCALL_H
2#define __LIB_USER_SYSCALL_H
3
4#include <stdbool.h>
5#include <debug.h>
6#include <stddef.h>
7
8/* Process identifier. */
9typedef int pid_t;
10#define PID_ERROR ((pid_t) -1)
11
12/* Map region identifier. */
13typedef int off_t;
14#define MAP_FAILED ((void *) NULL)
15
16/* Maximum characters in a filename written by readdir(). */
17#define READDIR_MAX_LEN 14
18
19/* Typical return values from main() and arguments to exit(). */
20#define EXIT_SUCCESS 0 /* Successful execution. */
21#define EXIT_FAILURE 1 /* Unsuccessful execution. */
22
23/* Projects 2 and later. */
24void halt (void) NO_RETURN;
25void exit (int status) NO_RETURN;
26pid_t fork (const char *thread_name);
27int exec (const char *file);
28int wait (pid_t);
29bool create (const char *file, unsigned initial_size);
30bool remove (const char *file);
31int open (const char *file);
32int filesize (int fd);
33int read (int fd, void *buffer, unsigned length);
34int write (int fd, const void *buffer, unsigned length);
35void seek (int fd, unsigned position);
36unsigned tell (int fd);
37void close (int fd);
38
39int dup2(int oldfd, int newfd);
40
41/* Project 3 and optionally project 4. */
42void *mmap (void *addr, size_t length, int writable, int fd, off_t offset);
43void munmap (void *addr);
44
45/* Project 4 only. */
46bool chdir (const char *dir);
47bool mkdir (const char *dir);
48bool readdir (int fd, char name[READDIR_MAX_LEN + 1]);
49bool isdir (int fd);
50int inumber (int fd);
51int symlink (const char* target, const char* linkpath);
52
53static inline void* get_phys_addr (void *user_addr) {
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}
60
61static inline long long
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}
70
71static inline long long
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}
80
81#endif /* lib/user/syscall.h */
#define NO_RETURN
Definition: debug.h:8
static struct intq buffer
Definition: input.c:7
static int64_t write_cnt
Definition: console.c:60
int read(int fd, void *buffer, unsigned length)
열린 파일의 데이터를 읽는 시스템 콜
Definition: syscall.c:299
bool readdir(int fd, char name[READDIR_MAX_LEN+1])
Definition: syscall.c:169
int dup2(int oldfd, int newfd)
Definition: syscall.c:144
bool chdir(const char *dir)
Definition: syscall.c:159
int pid_t
Definition: syscall.h:9
int filesize(int fd)
파일의 크기를 알려주는 시스템 콜
Definition: syscall.c:283
bool create(const char *file, unsigned initial_size)
파일을 생성하는 시스템 콜
Definition: syscall.c:233
int off_t
Definition: syscall.h:13
void close(int fd)
열린 파일을 닫는 시스템 콜
Definition: syscall.c:392
void * mmap(void *addr, size_t length, int writable, int fd, off_t offset)
열린 파일을 가상 주소 공간에 매핑한다.
Definition: syscall.c:413
pid_t fork(const char *thread_name)
Definition: syscall.c:84
int open(const char *file)
파일을 열 때 사용하는 시스템 콜
Definition: syscall.c:258
bool remove(const char *file)
파일을 샂게하는 시스템 콜
Definition: syscall.c:246
int inumber(int fd)
Definition: syscall.c:179
void exit(int status) NO_RETURN
현재 프로세스를 종료시키는 시스템 콜
Definition: syscall.c:173
int exec(const char *file)
cmd_line으로 들어온 실행 파일을 실행한다.
Definition: syscall.c:198
void seek(int fd, unsigned position)
열린 파일의 위치를 이동하는 시스템 콜
Definition: syscall.c:361
int symlink(const char *target, const char *linkpath)
Definition: syscall.c:184
unsigned tell(int fd)
열린 파일의 위치를 알려주는 시스템 콜
Definition: syscall.c:377
static void * get_phys_addr(void *user_addr)
Definition: syscall.h:53
bool isdir(int fd)
Definition: syscall.c:174
static long long get_fs_disk_write_cnt(void)
Definition: syscall.h:72
void halt(void) NO_RETURN
핀토스 자체를 종료시키는 시스템 콜
Definition: syscall.c:163
#define READDIR_MAX_LEN
Definition: syscall.h:17
int write(int fd, const void *buffer, unsigned length)
열린 파일에 데이터를 쓰는 시스템 콜
Definition: syscall.c:336
void munmap(void *addr)
mmap으로 매핑된 주소를 해제한다.
Definition: syscall.c:453
bool mkdir(const char *dir)
Definition: syscall.c:164
int wait(pid_t)
pid에 해당하는 자식 프로세스가 종료될 때까지 기다린다.
Definition: syscall.c:220
static long long get_fs_disk_read_cnt(void)
Definition: syscall.h:62
int32_t off_t
Definition: off_t.h:9
Definition: directory.c:10
Definition: file.c:7
const char * thread_name(void)
Definition: thread.c:293