00001 /* 00002 * Copyright (c) 2013 00003 * The President and Fellows of Harvard College. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the University nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 */ 00029 00030 #ifndef _PROC_H_ 00031 #define _PROC_H_ 00032 00033 /* 00034 * Definition of a process. 00035 * 00036 * Note: curproc is defined by <current.h>. 00037 */ 00038 00039 #include <spinlock.h> 00040 #include <thread.h> /* required for struct threadarray */ 00041 00042 struct addrspace; 00043 struct vnode; 00044 #ifdef UW 00045 struct semaphore; 00046 #endif // UW 00047 00048 /* 00049 * Process structure. 00050 */ 00051 struct proc { 00052 char *p_name; /* Name of this process */ 00053 struct spinlock p_lock; /* Lock for this structure */ 00054 struct threadarray p_threads; /* Threads in this process */ 00055 00056 /* VM */ 00057 struct addrspace *p_addrspace; /* virtual address space */ 00058 00059 /* VFS */ 00060 struct vnode *p_cwd; /* current working directory */ 00061 00062 #ifdef UW 00063 /* a vnode to refer to the console device */ 00064 /* this is a quick-and-dirty way to get console writes working */ 00065 /* you will probably need to change this when implementing file-related 00066 system calls, since each process will need to keep track of all files 00067 it has opened, not just the console. */ 00068 struct vnode *console; /* a vnode for the console device */ 00069 #endif 00070 00071 /* add more material here as needed */ 00072 }; 00073 00074 /* This is the process structure for the kernel and for kernel-only threads. */ 00075 extern struct proc *kproc; 00076 00077 /* Semaphore used to signal when there are no more processes */ 00078 #ifdef UW 00079 extern struct semaphore *no_proc_sem; 00080 #endif // UW 00081 00082 /* Call once during system startup to allocate data structures. */ 00083 void proc_bootstrap(void); 00084 00085 /* Create a fresh process for use by runprogram(). */ 00086 struct proc *proc_create_runprogram(const char *name); 00087 00088 /* Destroy a process. */ 00089 void proc_destroy(struct proc *proc); 00090 00091 /* Attach a thread to a process. Must not already have a process. */ 00092 int proc_addthread(struct proc *proc, struct thread *t); 00093 00094 /* Detach a thread from its process. */ 00095 void proc_remthread(struct thread *t); 00096 00097 /* Fetch the address space of the current process. */ 00098 struct addrspace *curproc_getas(void); 00099 00100 /* Change the address space of the current process, and return the old one. */ 00101 struct addrspace *curproc_setas(struct addrspace *); 00102 00103 00104 #endif /* _PROC_H_ */