Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

week6.md

Blame
  • system_calls.h 2.51 KiB
    #include "filesys/file.h"
    #include "threads/interrupt.h"
    
    /*
     * Terminates Pintos by calling shutdown_power_off()
     * (declared in devices/shutdown.h).
     */
    void syscall_halt(struct intr_frame *f);
    
    /*
     * Terminates the current user program, returning status to the kernel. If the
     * process's parent waits for it (see below), this is the status that will be
     * returned. Conventionally, a status of 0 indicates success and nonzero
     * values indicate errors. 
     */
    void syscall_exit(struct intr_frame *f);
    
    /*
     * Runs the executable whose name is given in cmd_line, passing any given
     * arguments, and returns the new process's program id (pid). Must return pid
     * -1, which otherwise should not be a valid pid, if the program cannot load or
     * run for any reason. Thus, the parent process cannot return from the exec
     * until it knows whether the child process successfully loaded its executable.
     * You must use appropriate synchronization to ensure this.
     */
    void syscall_exec(struct intr_frame *f);
    
    /*
     * Waits for a child process pid and retrieves the child's exit status. 
     */
    void syscall_wait(struct intr_frame *f);
    
    /*
     * Creates a new file called file initially initial_size bytes in size.
     * Returns true if successful, false otherwise.
     */
    void syscall_create(struct intr_frame *f);
    
    /*
     * Writes size bytes from buffer to the open file fd.
     * Returns the number of bytes actually written, which may be less than size if
     * some bytes could not be written.
     */
    void syscall_write(struct intr_frame *f);
    
    /*
     * Opens the file called file. Returns a nonnegative integer handle called a
     * "file descriptor" (fd), or -1 if the file could not be opened.
     */
    void syscall_open(struct intr_frame *f);
    
    /*
     * Deletes the file called file. Returns true if successful, false otherwise.
     * A file may be removed regardless of whether it is open or closed, and
     * Removing an open file does not close it. See Removing an Open File, for
     * Details.
     */
    void syscall_remove(struct intr_frame *f);
    
    /*
     * special additional stuff for handling file descriptors because they're annoying
     */
    
    // returns NULL if the given file descriptor does not match a known file
    struct file * get_associated_file_pointer(int fd);
    // remembers the given file, and returns int of file descriptor
    // returns -1 if could not store it (means we've opened too many files)
    int associate_new_file_descriptor(struct file* file_pointer);
    // disassociates the given file descriptor (and its associated pointer)
    // returns false if this failed for some reason
    bool disassociate_file_descriptor(int fd);