Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
script3r
GitHub Repository: script3r/os161
Path: blob/master/kern/include/addrspace.h
2093 views
1
/*
2
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
3
* The President and Fellows of Harvard College.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. Neither the name of the University nor the names of its contributors
14
* may be used to endorse or promote products derived from this software
15
* without specific prior written permission.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
18
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
21
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
* SUCH DAMAGE.
28
*/
29
30
#ifndef _ADDRSPACE_H_
31
#define _ADDRSPACE_H_
32
33
/*
34
* Address space structure and operations.
35
*/
36
37
38
#include <vm.h>
39
#include <vm/region.h>
40
#include "opt-dumbvm.h"
41
42
struct vnode;
43
44
45
/*
46
* Address space - data structure associated with the virtual memory
47
* space of a process.
48
*
49
* You write this.
50
*/
51
52
struct addrspace {
53
#if OPT_DUMBVM
54
vaddr_t as_vbase1;
55
paddr_t as_pbase1;
56
size_t as_npages1;
57
vaddr_t as_vbase2;
58
paddr_t as_pbase2;
59
size_t as_npages2;
60
paddr_t as_stackpbase;
61
#else
62
struct vm_region_array *as_regions;
63
vaddr_t as_heap_start;
64
vaddr_t as_heap_end;
65
#endif
66
};
67
68
/*
69
* Functions in addrspace.c:
70
*
71
* as_create - create a new empty address space. You need to make
72
* sure this gets called in all the right places. You
73
* may find you want to change the argument list. May
74
* return NULL on out-of-memory error.
75
*
76
* as_copy - create a new address space that is an exact copy of
77
* an old one. Probably calls as_create to get a new
78
* empty address space and fill it in, but that's up to
79
* you.
80
*
81
* as_activate - make the specified address space the one currently
82
* "seen" by the processor. Argument might be NULL,
83
* meaning "no particular address space".
84
*
85
* as_destroy - dispose of an address space. You may need to change
86
* the way this works if implementing user-level threads.
87
*
88
* as_define_region - set up a region of memory within the address
89
* space.
90
*
91
* as_prepare_load - this is called before actually loading from an
92
* executable into the address space.
93
*
94
* as_complete_load - this is called when loading from an executable
95
* is complete.
96
*
97
* as_define_stack - set up the stack region in the address space.
98
* (Normally called *after* as_complete_load().) Hands
99
* back the initial stack pointer for the new process.
100
*/
101
102
struct addrspace *as_create(void);
103
int as_copy(struct addrspace *src, struct addrspace **ret);
104
void as_activate(struct addrspace *);
105
void as_destroy(struct addrspace *);
106
107
int as_define_region(struct addrspace *as,
108
vaddr_t vaddr, size_t sz,
109
int readable,
110
int writeable,
111
int executable);
112
int as_prepare_load(struct addrspace *as);
113
int as_complete_load(struct addrspace *as);
114
int as_define_stack(struct addrspace *as, vaddr_t *initstackptr);
115
116
int as_fault( struct addrspace *, int, vaddr_t );
117
118
119
/*
120
* Functions in loadelf.c
121
* load_elf - load an ELF user program executable into the current
122
* address space. Returns the entry point (initial PC)
123
* in the space pointed to by ENTRYPOINT.
124
*/
125
126
int load_elf(struct vnode *v, vaddr_t *entrypoint);
127
128
129
#endif /* _ADDRSPACE_H_ */
130
131