lab5 added.
[mit-jos.git] / inc / lib.h
blob3de2b085246075806d7fa01c16e8d22332b65690
1 // Main public header file for our user-land support library,
2 // whose code lives in the lib directory.
3 // This library is roughly our OS's version of a standard C library,
4 // and is intended to be linked into all user-mode applications
5 // (NOT the kernel or boot loader).
7 #ifndef JOS_INC_LIB_H
8 #define JOS_INC_LIB_H 1
10 #include <inc/types.h>
11 #include <inc/stdio.h>
12 #include <inc/stdarg.h>
13 #include <inc/string.h>
14 #include <inc/error.h>
15 #include <inc/assert.h>
16 #include <inc/env.h>
17 #include <inc/memlayout.h>
18 #include <inc/syscall.h>
19 #include <inc/trap.h>
20 #include <inc/fs.h>
21 #include <inc/fd.h>
22 #include <inc/args.h>
24 #define USED(x) (void)(x)
26 // libos.c or entry.S
27 extern char *binaryname;
28 extern volatile struct Env *env;
29 extern volatile struct Env envs[NENV];
30 extern volatile struct Page pages[];
31 void exit(void);
33 // pgfault.c
34 void set_pgfault_handler(void (*handler)(struct UTrapframe *utf));
36 // readline.c
37 char* readline(const char *buf);
39 // syscall.c
40 void sys_cputs(const char *string, size_t len);
41 int sys_cgetc(void);
42 envid_t sys_getenvid(void);
43 int sys_env_destroy(envid_t);
44 void sys_yield(void);
45 static envid_t sys_exofork(void);
46 int sys_env_set_status(envid_t env, int status);
47 int sys_env_set_trapframe(envid_t env, struct Trapframe *tf);
48 int sys_env_set_pgfault_upcall(envid_t env, void *upcall);
49 int sys_page_alloc(envid_t env, void *pg, int perm);
50 int sys_page_map(envid_t src_env, void *src_pg,
51 envid_t dst_env, void *dst_pg, int perm);
52 int sys_page_unmap(envid_t env, void *pg);
53 int sys_ipc_try_send(envid_t to_env, uint32_t value, void *pg, int perm);
54 int sys_ipc_recv(void *rcv_pg);
55 int sys_phy_page(envid_t envid, void *va);
57 // This must be inlined. Exercise for reader: why?
58 static __inline envid_t sys_exofork(void) __attribute__((always_inline));
59 static __inline envid_t
60 sys_exofork(void)
62 envid_t ret;
63 __asm __volatile("int %2"
64 : "=a" (ret)
65 : "a" (SYS_exofork),
66 "i" (T_SYSCALL)
68 return ret;
71 // ipc.c
72 void ipc_send(envid_t to_env, uint32_t value, void *pg, int perm);
73 int32_t ipc_recv(envid_t *from_env_store, void *pg, int *perm_store);
75 // fork.c
76 #define PTE_SHARE 0x400
77 envid_t fork(void);
78 envid_t sfork(void); // Challenge!
80 // fd.c
81 int close(int fd);
82 ssize_t read(int fd, void *buf, size_t nbytes);
83 ssize_t write(int fd, const void *buf, size_t nbytes);
84 int seek(int fd, off_t offset);
85 void close_all(void);
86 ssize_t readn(int fd, void *buf, size_t nbytes);
87 int dup(int oldfd, int newfd);
88 int fstat(int fd, struct Stat *statbuf);
89 int stat(const char *path, struct Stat *statbuf);
91 // file.c
92 int open(const char *path, int mode);
93 int read_map(int fd, off_t offset, void **blk);
94 int ftruncate(int fd, off_t size);
95 int remove(const char *path);
96 int sync(void);
98 // fsipc.c
99 int fsipc_open(const char *path, int omode, struct Fd *fd);
100 int fsipc_map(int fileid, off_t offset, void *dst_va);
101 int fsipc_set_size(int fileid, off_t size);
102 int fsipc_close(int fileid);
103 int fsipc_dirty(int fileid, off_t offset);
104 int fsipc_remove(const char *path);
105 int fsipc_sync(void);
107 // pageref.c
108 int pageref(void *addr);
110 // spawn.c
111 envid_t spawn(const char *program, const char **argv);
112 envid_t spawnl(const char *program, const char *arg0, ...);
114 /* File open modes */
115 #define O_RDONLY 0x0000 /* open for reading only */
116 #define O_WRONLY 0x0001 /* open for writing only */
117 #define O_RDWR 0x0002 /* open for reading and writing */
118 #define O_ACCMODE 0x0003 /* mask for above modes */
120 #define O_CREAT 0x0100 /* create if nonexistent */
121 #define O_TRUNC 0x0200 /* truncate to zero length */
122 #define O_EXCL 0x0400 /* error if already exists */
123 #define O_MKDIR 0x0800 /* create directory, not regular file */
125 #endif // !JOS_INC_LIB_H