Last-Modified: Fri, 23 Jul 2009 23:27:43 GMT Content-Type: text/html; charset=iso-8859-1
|
[ source navigation ] [ diff markup ] [ identifier search ] [ general search ] |
|||||
|
||||||
001 /* Simple operating system interface */ 002 003 #ifndef _SOS_H 004 #define _SOS_H 005 006 #include <l4/types.h> 007 008 /* System calls for SOS */ 009 010 /* Limits */ 011 #define PROCESS_MAX_FILES 16 012 #define MAX_IO_BUF 0x1000 013 #define N_NAME 32 014 015 /* file modes */ 016 #define FM_WRITE 1 017 #define FM_READ 2 018 #define FM_EXEC 4 019 typedef uint8_t fmode_t; 020 021 #define O_RDONLY FM_READ 022 #define O_WRONLY FM_WRITE 023 #define O_RDWR (FM_READ|FM_WRITE) 024 025 /* stat file types */ 026 #define ST_FILE 1 /* plain file */ 027 #define ST_SPECIAL 2 /* special (console) file */ 028 typedef uint8_t st_type_t; 029 030 031 typedef struct { 032 st_type_t st_type; /* file type */ 033 fmode_t st_fmode; /* access mode */ 034 size_t st_size; /* file size in bytes */ 035 long st_ctime; /* file creation time (ms since booting) */ 036 long st_atime; /* file last access (open) time (ms since booting) */ 037 } stat_t; 038 039 typedef int fildes_t; 040 typedef int pid_t; 041 042 /* The FD to which printf() will ultimately write() */ 043 extern fildes_t stdout_fd; 044 045 typedef struct { 046 pid_t pid; 047 unsigned size; /* in pages */ 048 unsigned stime; /* start time in msec since booting */ 049 unsigned ctime; /* CPU time accumulated in msec */ 050 char command[N_NAME]; /* Name of exectuable */ 051 } process_t; 052 053 054 /* I/O system calls */ 055 056 fildes_t open(const char *path, fmode_t mode); 057 /* Open file and return file descriptor, -1 if unsuccessful 058 * (too many open files, console already open for reading). 059 * A new file should be created if 'path' does not already exist. 060 * A failed attempt to open the console for reading (because it is already 061 * open) will result in a context switch to reduce the cost of busy waiting 062 * for the console. 063 * "path" is file name, "mode" is one of O_RDONLY, O_WRONLY, O_RDWR. 064 */ 065 066 int close(fildes_t file); 067 /* Closes an open file. Returns 0 if successful, -1 if not (invalid "file"). 068 */ 069 070 int read(fildes_t file, char *buf, size_t nbyte); 071 /* Read from an open file, into "buf", max "nbyte" bytes. 072 * Returns the number of bytes read. 073 * Will block when reading from console and no input is presently 074 * available. Returns -1 on error (invalid file). 075 */ 076 077 int write(fildes_t file, const char *buf, size_t nbyte); 078 /* Write to an open file, from "buf", max "nbyte" bytes. 079 * Returns the number of bytes written. <nbyte disk is full. 080 * Returns -1 on error (invalid file). 081 */ 082 083 int getdirent(int pos, char *name, size_t nbyte); 084 /* Reads name of entry "pos" in directory into "name", max "nbyte" bytes. 085 * Returns number of bytes returned, zero if "pos" is next free entry, 086 * -1 if error (non-existent entry). 087 */ 088 089 int stat(const char *path, stat_t *buf); 090 /* Returns information about file "path" through "buf". 091 * Returns 0 if successful, -1 otherwise (invalid name). 092 */ 093 094 pid_t process_create(const char *path); 095 /* Create a new process running the executable image "path". 096 * Returns ID of new process, -1 if error (non-executable image, nonexisting 097 * file). 098 */ 099 100 int process_delete(pid_t pid); 101 /* Delete process (and close all its file descriptors). 102 * Returns 0 if successful, -1 otherwise (invalid process). 103 */ 104 105 pid_t my_id(void); 106 /* Returns ID of caller's process. */ 107 108 int process_status(process_t *processes, unsigned max); 109 /* Returns through "processes" status of active processes (at most "max"), 110 * returns number of process descriptors actually returned. 111 */ 112 113 pid_t process_wait(pid_t pid); 114 /* Wait for process "pid" to exit. If "pid" is -1, wait for any process 115 * to exit. Returns the pid of the process which exited. 116 */ 117 118 long time_stamp(void); 119 /* Returns time in microseconds since booting. 120 */ 121 122 void sleep(int msec); 123 /* Sleeps for the specified number of milliseconds. 124 */ 125 126 127 /*************************************************************************/ 128 /* */ 129 /* Optional (bonus) system calls */ 130 /* */ 131 /*************************************************************************/ 132 133 int share_vm(void *adr, size_t size, int writable); 134 /* Make VM region ["adr","adr"+"size") sharable by other processes. 135 * If "writable" is non-zero, other processes may have write access to the 136 * shared region. Both, "adr" and "size" must be divisible by the page size. 137 * 138 * In order for a page to be shared, all participating processes must execute 139 * the system call specifying an interval including that page. 140 * Once a page is shared, a process may write to it if and only if all 141 * _other_ processes have set up the page as shared writable. 142 * 143 * Returns 0 if successful, -1 otherwise (invalid address or size). 144 */ 145 146 #endif
| [ source navigation ] | [ diff markup ] | [ identifier search ] | [ general search ] |
| This page was automatically generated by the LXR engine. The LXR team |
|