source: mainline/uspace/lib/c/generic/as.c@ 0b37882

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 0b37882 was 0b37882, checked in by Martin Decky <martin@…>, 14 years ago

memory management work

  • implement as_get_mappable_page() as a new syscall (SYS_AS_GET_UNMAPPED_AREA), the kernel has a full knowledge of the address space areas, there is no need to duplicate this management in uspace)
  • make sure all address space/address space area manipulating functions use proper page alignment on base addresses and sizes (discrepancy with respect to this caused inconsistent behaviour, although no fatal bugs were probably present)
  • add forgotten tests (area != avoid) to check_area_conflicts()
  • unify size/page conversions (use always use bitwise shifts by PAGE_WIDTH)
  • new uspace heap allocator
    • basic next fit algorithm for better scalability (there is still space for optimizations)
    • support for multiple discontinuous heap areas (inspired by Jiri Tlach's implementation in lp:~jiri-tlach/helenos/nommu, but independent)
    • the "_heap" linker script symbol has been removed, the initial heap area is allocated according to as_get_mappable_page() (which uses the address of entry as the lower bound of the address space area base)
    • the hardwired 1 GB (4 GB respectivelly) heap size limit has been removed
    • the heap areas can be freely intermixed with other address space areas (e.g. mapped physical memory of devices, shared memory, etc.), the address space holes can be reused later (but still merging of adjunct address space areas is missing)
  • minor cstyle changes
  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2006 Jakub Jermar
3 * All rights reserved.
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 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libc
30 * @{
31 */
32/** @file
33 */
34
35#include <as.h>
36#include <libc.h>
37#include <unistd.h>
38#include <align.h>
39#include <sys/types.h>
40#include <bitops.h>
41#include <malloc.h>
42#include "private/libc.h"
43
44/** Create address space area.
45 *
46 * @param address Virtual address where to place new address space area.
47 * @param size Size of the area.
48 * @param flags Flags describing type of the area.
49 *
50 * @return address on success, (void *) -1 otherwise.
51 *
52 */
53void *as_area_create(void *address, size_t size, int flags)
54{
55 return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t) address,
56 (sysarg_t) size, (sysarg_t) flags);
57}
58
59/** Resize address space area.
60 *
61 * @param address Virtual address pointing into already existing address space
62 * area.
63 * @param size New requested size of the area.
64 * @param flags Currently unused.
65 *
66 * @return zero on success or a code from @ref errno.h on failure.
67 *
68 */
69int as_area_resize(void *address, size_t size, int flags)
70{
71 return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t) address,
72 (sysarg_t) size, (sysarg_t) flags);
73}
74
75/** Destroy address space area.
76 *
77 * @param address Virtual address pointing into the address space area being
78 * destroyed.
79 *
80 * @return zero on success or a code from @ref errno.h on failure.
81 *
82 */
83int as_area_destroy(void *address)
84{
85 return __SYSCALL1(SYS_AS_AREA_DESTROY, (sysarg_t) address);
86}
87
88/** Change address-space area flags.
89 *
90 * @param address Virtual address pointing into the address space area being
91 * modified.
92 * @param flags New flags describing type of the area.
93 *
94 * @return zero on success or a code from @ref errno.h on failure.
95 *
96 */
97int as_area_change_flags(void *address, int flags)
98{
99 return __SYSCALL2(SYS_AS_AREA_CHANGE_FLAGS, (sysarg_t) address,
100 (sysarg_t) flags);
101}
102
103/** Return pointer to unmapped address space area
104 *
105 * @param size Requested size of the allocation.
106 *
107 * @return Pointer to the beginning of unmapped address space area.
108 *
109 */
110void *as_get_mappable_page(size_t size)
111{
112 return (void *) __SYSCALL2(SYS_AS_GET_UNMAPPED_AREA,
113 (sysarg_t) __entry, (sysarg_t) size);
114}
115
116/** @}
117 */
Note: See TracBrowser for help on using the repository browser.