Rev 1363 | Rev 1505 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1363 | Rev 1501 | ||
---|---|---|---|
Line 24... | Line 24... | ||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
- | 29 | #include <stdlib.h> |
|
- | 30 | #include <unistd.h> |
|
- | 31 | #include <string.h> |
|
- | 32 | #include <ddi.h> |
|
- | 33 | #include <sysinfo.h> |
|
- | 34 | #include <align.h> |
|
- | 35 | #include <as.h> |
|
- | 36 | #include <ipc/fb.h> |
|
- | 37 | #include <ipc/ipc.h> |
|
- | 38 | #include <ipc/ns.h> |
|
- | 39 | #include <ipc/services.h> |
|
- | 40 | #include <kernel/errno.h> |
|
- | 41 | ||
- | 42 | ||
29 | #include <as.h> |
43 | #include <as.h> |
30 | #include <libc.h> |
44 | #include <libc.h> |
31 | #include <unistd.h> |
45 | #include <unistd.h> |
32 | #include <task.h> |
46 | #include <align.h> |
33 | 47 | ||
34 | /** Create address space area. |
48 | /** Create address space area. |
35 | * |
49 | * |
36 | * @param address Virtual address where to place new address space area. |
50 | * @param address Virtual address where to place new address space area. |
37 | * @param size Size of the area. |
51 | * @param size Size of the area. |
Line 68... | Line 82... | ||
68 | return __SYSCALL1(SYS_AS_AREA_DESTROY, (sysarg_t ) address); |
82 | return __SYSCALL1(SYS_AS_AREA_DESTROY, (sysarg_t ) address); |
69 | } |
83 | } |
70 | 84 | ||
71 | static size_t heapsize = 0; |
85 | static size_t heapsize = 0; |
72 | static size_t maxheapsize = (size_t)(-1); |
86 | static size_t maxheapsize = (size_t)(-1); |
- | 87 | ||
- | 88 | static void * last_allocated = 0; |
|
- | 89 | ||
73 | /* Start of heap linker symbol */ |
90 | /* Start of heap linker symbol */ |
74 | extern char _heap; |
91 | extern char _heap; |
75 | 92 | ||
76 | /** Sbrk emulation |
93 | /** Sbrk emulation |
77 | * |
94 | * |
Line 105... | Line 122... | ||
105 | heapsize += incr; |
122 | heapsize += incr; |
106 | 123 | ||
107 | return res; |
124 | return res; |
108 | } |
125 | } |
109 | 126 | ||
- | 127 | /** Set maximum heap size and return pointer just after the heap */ |
|
110 | void *set_maxheapsize(size_t mhs) |
128 | void *set_maxheapsize(size_t mhs) |
111 | { |
129 | { |
112 | maxheapsize=mhs; |
130 | maxheapsize=mhs; |
113 | /* Return pointer to area not managed by sbrk */ |
131 | /* Return pointer to area not managed by sbrk */ |
114 | return (void *)&_heap + maxheapsize; |
132 | return (void *)&_heap + maxheapsize; |
115 | 133 | ||
116 | } |
134 | } |
- | 135 | ||
- | 136 | /** Return pointer to some unmapped area, where fits new as_area |
|
- | 137 | * |
|
- | 138 | * TODO: make some first_fit/... algorithm, we are now just incrementing |
|
- | 139 | * the pointer to last area |
|
- | 140 | */ |
|
- | 141 | void * as_get_mappable_page(size_t sz) |
|
- | 142 | { |
|
- | 143 | void *res; |
|
- | 144 | ||
- | 145 | /* Set heapsize to some meaningful value */ |
|
- | 146 | if (maxheapsize == -1) |
|
- | 147 | set_maxheapsize(ALIGN_UP(USER_ADDRESS_SPACE_SIZE_ARCH>>1,PAGE_SIZE)); |
|
- | 148 | if (!last_allocated) |
|
- | 149 | last_allocated = ALIGN_UP((void *)&_heap + maxheapsize, PAGE_SIZE); |
|
- | 150 | ||
- | 151 | sz = ALIGN_UP(sz, PAGE_SIZE); |
|
- | 152 | res = last_allocated; |
|
- | 153 | last_allocated += sz; |
|
- | 154 | ||
- | 155 | return res; |
|
- | 156 | } |