spawn implemented.
[mit-jos.git] / inc / env.h
blob7fae47f929f441428b255bc8938cb38e28964a1b
1 /* See COPYRIGHT for copyright information. */
3 #ifndef JOS_INC_ENV_H
4 #define JOS_INC_ENV_H
6 #include <inc/types.h>
7 #include <inc/queue.h>
8 #include <inc/trap.h>
9 #include <inc/memlayout.h>
11 typedef int32_t envid_t;
13 // An environment ID 'envid_t' has three parts:
15 // +1+---------------21-----------------+--------10--------+
16 // |0| Uniqueifier | Environment |
17 // | | | Index |
18 // +------------------------------------+------------------+
19 // \--- ENVX(eid) --/
21 // The environment index ENVX(eid) equals the environment's offset in the
22 // 'envs[]' array. The uniqueifier distinguishes environments that were
23 // created at different times, but share the same environment index.
25 // All real environments are greater than 0 (so the sign bit is zero).
26 // envid_ts less than 0 signify errors. The envid_t == 0 is special, and
27 // stands for the current environment.
29 #define LOG2NENV 10
30 #define NENV (1 << LOG2NENV)
31 #define ENVX(envid) ((envid) & (NENV - 1))
33 // Values of env_status in struct Env
34 #define ENV_FREE 0
35 #define ENV_RUNNABLE 1
36 #define ENV_NOT_RUNNABLE 2
38 struct Env {
39 struct Trapframe env_tf; // Saved registers
40 LIST_ENTRY(Env) env_link; // Free list link pointers
41 envid_t env_id; // Unique environment identifier
42 envid_t env_parent_id; // env_id of this env's parent
43 unsigned env_status; // Status of the environment
44 uint32_t env_runs; // Number of times environment has run
46 // Address space
47 pde_t *env_pgdir; // Kernel virtual address of page dir
48 physaddr_t env_cr3; // Physical address of page dir
50 // Exception handling
51 void *env_pgfault_upcall; // page fault upcall entry point
53 // Lab 4 IPC
54 bool env_ipc_recving; // env is blocked receiving
55 void *env_ipc_dstva; // va at which to map received page
56 uint32_t env_ipc_value; // data value sent to us
57 envid_t env_ipc_from; // envid of the sender
58 int env_ipc_perm; // perm of page mapping received
61 #endif // !JOS_INC_ENV_H