Subversion Repositories HelenOS

Rev

Rev 1426 | Rev 1550 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1426 Rev 1546
1
/*
1
/*
2
 * Copyright (C) 2006 Jakub Jermar
2
 * Copyright (C) 2006 Jakub Jermar
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
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
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.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
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
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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
/**
29
/**
30
 * @file    backend_elf.c
30
 * @file    backend_elf.c
31
 * @brief   Backend for address space areas backed by an ELF image.
31
 * @brief   Backend for address space areas backed by an ELF image.
32
 */
32
 */
33
 
33
 
34
#include <elf.h>
34
#include <elf.h>
35
#include <debug.h>
35
#include <debug.h>
36
#include <arch/types.h>
36
#include <arch/types.h>
37
#include <typedefs.h>
37
#include <typedefs.h>
38
#include <mm/as.h>
38
#include <mm/as.h>
39
#include <mm/frame.h>
39
#include <mm/frame.h>
40
#include <mm/slab.h>
40
#include <mm/slab.h>
41
#include <mm/page.h>
41
#include <mm/page.h>
42
#include <genarch/mm/page_pt.h>
42
#include <genarch/mm/page_pt.h>
43
#include <genarch/mm/page_ht.h>
43
#include <genarch/mm/page_ht.h>
44
#include <align.h>
44
#include <align.h>
45
#include <memstr.h>
45
#include <memstr.h>
46
#include <macros.h>
46
#include <macros.h>
47
#include <arch.h>
47
#include <arch.h>
48
 
48
 
49
static int elf_page_fault(as_area_t *area, __address addr, pf_access_t access);
49
static int elf_page_fault(as_area_t *area, __address addr, pf_access_t access);
50
static void elf_frame_free(as_area_t *area, __address page, __address frame);
50
static void elf_frame_free(as_area_t *area, __address page, __address frame);
51
static void elf_share(as_area_t *area);
51
static void elf_share(as_area_t *area);
52
 
52
 
53
mem_backend_t elf_backend = {
53
mem_backend_t elf_backend = {
54
    .page_fault = elf_page_fault,
54
    .page_fault = elf_page_fault,
55
    .frame_free = elf_frame_free,
55
    .frame_free = elf_frame_free,
56
    .share = elf_share
56
    .share = elf_share
57
};
57
};
58
 
58
 
59
/** Service a page fault in the ELF backend address space area.
59
/** Service a page fault in the ELF backend address space area.
60
 *
60
 *
61
 * The address space area and page tables must be already locked.
61
 * The address space area and page tables must be already locked.
62
 *
62
 *
63
 * @param area Pointer to the address space area.
63
 * @param area Pointer to the address space area.
64
 * @param addr Faulting virtual address.
64
 * @param addr Faulting virtual address.
65
 * @param access Access mode that caused the fault (i.e. read/write/exec).
65
 * @param access Access mode that caused the fault (i.e. read/write/exec).
66
 *
66
 *
67
 * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e. serviced).
67
 * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e. serviced).
68
 */
68
 */
69
int elf_page_fault(as_area_t *area, __address addr, pf_access_t access)
69
int elf_page_fault(as_area_t *area, __address addr, pf_access_t access)
70
{
70
{
71
    elf_header_t *elf = area->backend_data.elf;
71
    elf_header_t *elf = area->backend_data.elf;
72
    elf_segment_header_t *entry = area->backend_data.segment;
72
    elf_segment_header_t *entry = area->backend_data.segment;
73
    btree_node_t *leaf;
73
    btree_node_t *leaf;
74
    __address base, frame;
74
    __address base, frame;
75
    index_t i;
75
    index_t i;
76
 
76
 
77
    if (!as_area_check_access(area, access))
77
    if (!as_area_check_access(area, access))
78
        return AS_PF_FAULT;
78
        return AS_PF_FAULT;
79
 
79
 
80
    ASSERT((addr >= entry->p_vaddr) && (addr < entry->p_vaddr + entry->p_memsz));
80
    ASSERT((addr >= entry->p_vaddr) && (addr < entry->p_vaddr + entry->p_memsz));
81
    i = (addr - entry->p_vaddr) >> PAGE_WIDTH;
81
    i = (addr - entry->p_vaddr) >> PAGE_WIDTH;
82
    base = (__address) (((void *) elf) + entry->p_offset);
82
    base = (__address) (((void *) elf) + entry->p_offset);
83
    ASSERT(ALIGN_UP(base, FRAME_SIZE) == base);
83
    ASSERT(ALIGN_UP(base, FRAME_SIZE) == base);
84
 
84
 
85
    if (area->sh_info) {
85
    if (area->sh_info) {
86
        bool found = false;
86
        bool found = false;
87
 
87
 
88
        /*
88
        /*
89
         * The address space area is shared.
89
         * The address space area is shared.
90
         */
90
         */
91
         
91
         
92
        mutex_lock(&area->sh_info->lock);
92
        mutex_lock(&area->sh_info->lock);
93
        frame = (__address) btree_search(&area->sh_info->pagemap,
93
        frame = (__address) btree_search(&area->sh_info->pagemap,
94
            ALIGN_DOWN(addr, PAGE_SIZE) - area->base, &leaf);
94
            ALIGN_DOWN(addr, PAGE_SIZE) - area->base, &leaf);
95
        if (!frame) {
95
        if (!frame) {
96
            int i;
96
            int i;
97
 
97
 
98
            /*
98
            /*
99
             * Workaround for valid NULL address.
99
             * Workaround for valid NULL address.
100
             */
100
             */
101
 
101
 
102
            for (i = 0; i < leaf->keys; i++) {
102
            for (i = 0; i < leaf->keys; i++) {
103
                if (leaf->key[i] == ALIGN_DOWN(addr, PAGE_SIZE)) {
103
                if (leaf->key[i] == ALIGN_DOWN(addr, PAGE_SIZE)) {
104
                    found = true;
104
                    found = true;
105
                    break;
105
                    break;
106
                }
106
                }
107
            }
107
            }
108
        }
108
        }
109
        if (frame || found) {
109
        if (frame || found) {
-
 
110
            frame_reference_add(ADDR2PFN(frame));
110
            page_mapping_insert(AS, addr, frame, as_area_get_flags(area));
111
            page_mapping_insert(AS, addr, frame, as_area_get_flags(area));
-
 
112
            frame_reference_add(ADDR2PFN(PTE_GET_FRAME(pte)));
111
            if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1))
113
            if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1))
112
                panic("Could not insert used space.\n");
114
                panic("Could not insert used space.\n");
113
            mutex_unlock(&area->sh_info->lock);
115
            mutex_unlock(&area->sh_info->lock);
114
            return AS_PF_OK;
116
            return AS_PF_OK;
115
        }
117
        }
116
    }
118
    }
117
   
119
   
118
    /*
120
    /*
119
     * The area is either not shared or the pagemap does not contain the mapping.
121
     * The area is either not shared or the pagemap does not contain the mapping.
120
     */
122
     */
121
   
123
   
122
    if (ALIGN_DOWN(addr, PAGE_SIZE) + PAGE_SIZE < entry->p_vaddr + entry->p_filesz) {
124
    if (ALIGN_DOWN(addr, PAGE_SIZE) + PAGE_SIZE < entry->p_vaddr + entry->p_filesz) {
123
        /*
125
        /*
124
         * Initialized portion of the segment. The memory is backed
126
         * Initialized portion of the segment. The memory is backed
125
         * directly by the content of the ELF image. Pages are
127
         * directly by the content of the ELF image. Pages are
126
         * only copied if the segment is writable so that there
128
         * only copied if the segment is writable so that there
127
         * can be more instantions of the same memory ELF image
129
         * can be more instantions of the same memory ELF image
128
         * used at a time. Note that this could be later done
130
         * used at a time. Note that this could be later done
129
         * as COW.
131
         * as COW.
130
         */
132
         */
131
        if (entry->p_flags & PF_W) {
133
        if (entry->p_flags & PF_W) {
132
            frame = PFN2ADDR(frame_alloc(ONE_FRAME, 0));
134
            frame = PFN2ADDR(frame_alloc(ONE_FRAME, 0));
133
            memcpy((void *) PA2KA(frame), (void *) (base + i*FRAME_SIZE), FRAME_SIZE);
135
            memcpy((void *) PA2KA(frame), (void *) (base + i*FRAME_SIZE), FRAME_SIZE);
134
           
136
           
135
            if (area->sh_info) {
137
            if (area->sh_info) {
-
 
138
                frame_reference_add(ADDR2PFN(frame));
136
                btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base,
139
                btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base,
137
                    (void *) frame, leaf);
140
                    (void *) frame, leaf);
138
            }
141
            }
139
 
142
 
140
        } else {
143
        } else {
141
            frame = KA2PA(base + i*FRAME_SIZE);
144
            frame = KA2PA(base + i*FRAME_SIZE);
142
        }  
145
        }  
143
    } else if (ALIGN_DOWN(addr, PAGE_SIZE) >= ALIGN_UP(entry->p_vaddr + entry->p_filesz, PAGE_SIZE)) {
146
    } else if (ALIGN_DOWN(addr, PAGE_SIZE) >= ALIGN_UP(entry->p_vaddr + entry->p_filesz, PAGE_SIZE)) {
144
        /*
147
        /*
145
         * This is the uninitialized portion of the segment.
148
         * This is the uninitialized portion of the segment.
146
         * It is not physically present in the ELF image.
149
         * It is not physically present in the ELF image.
147
         * To resolve the situation, a frame must be allocated
150
         * To resolve the situation, a frame must be allocated
148
         * and cleared.
151
         * and cleared.
149
         */
152
         */
150
        frame = PFN2ADDR(frame_alloc(ONE_FRAME, 0));
153
        frame = PFN2ADDR(frame_alloc(ONE_FRAME, 0));
151
        memsetb(PA2KA(frame), FRAME_SIZE, 0);
154
        memsetb(PA2KA(frame), FRAME_SIZE, 0);
152
 
155
 
153
        if (area->sh_info) {
156
        if (area->sh_info) {
-
 
157
            frame_reference_add(ADDR2PFN(frame));
154
            btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base,
158
            btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base,
155
                (void *) frame, leaf);
159
                (void *) frame, leaf);
156
        }
160
        }
157
 
161
 
158
    } else {
162
    } else {
159
        size_t size;
163
        size_t size;
160
        /*
164
        /*
161
         * The mixed case.
165
         * The mixed case.
162
         * The lower part is backed by the ELF image and
166
         * The lower part is backed by the ELF image and
163
         * the upper part is anonymous memory.
167
         * the upper part is anonymous memory.
164
         */
168
         */
165
        size = entry->p_filesz - (i<<PAGE_WIDTH);
169
        size = entry->p_filesz - (i<<PAGE_WIDTH);
166
        frame = PFN2ADDR(frame_alloc(ONE_FRAME, 0));
170
        frame = PFN2ADDR(frame_alloc(ONE_FRAME, 0));
167
        memsetb(PA2KA(frame) + size, FRAME_SIZE - size, 0);
171
        memsetb(PA2KA(frame) + size, FRAME_SIZE - size, 0);
168
        memcpy((void *) PA2KA(frame), (void *) (base + i*FRAME_SIZE), size);
172
        memcpy((void *) PA2KA(frame), (void *) (base + i*FRAME_SIZE), size);
169
 
173
 
170
        if (area->sh_info) {
174
        if (area->sh_info) {
-
 
175
            frame_reference_add(ADDR2PFN(frame));
171
            btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base,
176
            btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base,
172
                (void *) frame, leaf);
177
                (void *) frame, leaf);
173
        }
178
        }
174
 
179
 
175
    }
180
    }
176
   
181
   
177
    if (area->sh_info)
182
    if (area->sh_info)
178
        mutex_unlock(&area->sh_info->lock);
183
        mutex_unlock(&area->sh_info->lock);
179
   
184
   
180
    page_mapping_insert(AS, addr, frame, as_area_get_flags(area));
185
    page_mapping_insert(AS, addr, frame, as_area_get_flags(area));
181
    if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1))
186
    if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1))
182
        panic("Could not insert used space.\n");
187
        panic("Could not insert used space.\n");
183
 
188
 
184
    return AS_PF_OK;
189
    return AS_PF_OK;
185
}
190
}
186
 
191
 
187
/** Free a frame that is backed by the ELF backend.
192
/** Free a frame that is backed by the ELF backend.
188
 *
193
 *
189
 * The address space area and page tables must be already locked.
194
 * The address space area and page tables must be already locked.
190
 *
195
 *
191
 * @param area Pointer to the address space area.
196
 * @param area Pointer to the address space area.
192
 * @param page Page that is mapped to frame. Must be aligned to PAGE_SIZE.
197
 * @param page Page that is mapped to frame. Must be aligned to PAGE_SIZE.
193
 * @param frame Frame to be released.
198
 * @param frame Frame to be released.
194
 *
199
 *
195
 */
200
 */
196
void elf_frame_free(as_area_t *area, __address page, __address frame)
201
void elf_frame_free(as_area_t *area, __address page, __address frame)
197
{
202
{
198
    elf_header_t *elf = area->backend_data.elf;
203
    elf_header_t *elf = area->backend_data.elf;
199
    elf_segment_header_t *entry = area->backend_data.segment;
204
    elf_segment_header_t *entry = area->backend_data.segment;
200
    __address base;
205
    __address base;
201
    index_t i;
206
    index_t i;
202
   
207
   
203
    ASSERT((page >= entry->p_vaddr) && (page < entry->p_vaddr + entry->p_memsz));
208
    ASSERT((page >= entry->p_vaddr) && (page < entry->p_vaddr + entry->p_memsz));
204
    i = (page - entry->p_vaddr) >> PAGE_WIDTH;
209
    i = (page - entry->p_vaddr) >> PAGE_WIDTH;
205
    base = (__address) (((void *) elf) + entry->p_offset);
210
    base = (__address) (((void *) elf) + entry->p_offset);
206
    ASSERT(ALIGN_UP(base, FRAME_SIZE) == base);
211
    ASSERT(ALIGN_UP(base, FRAME_SIZE) == base);
207
   
212
   
208
    if (page + PAGE_SIZE < ALIGN_UP(entry->p_vaddr + entry->p_filesz, PAGE_SIZE)) {
213
    if (page + PAGE_SIZE < ALIGN_UP(entry->p_vaddr + entry->p_filesz, PAGE_SIZE)) {
209
        if (entry->p_flags & PF_W) {
214
        if (entry->p_flags & PF_W) {
210
            /*
215
            /*
211
             * Free the frame with the copy of writable segment data.
216
             * Free the frame with the copy of writable segment data.
212
             */
217
             */
213
            frame_free(ADDR2PFN(frame));
218
            frame_free(ADDR2PFN(frame));
214
        }
219
        }
215
    } else {
220
    } else {
216
        /*
221
        /*
217
         * The frame is either anonymous memory or the mixed case (i.e. lower
222
         * The frame is either anonymous memory or the mixed case (i.e. lower
218
         * part is backed by the ELF image and the upper is anonymous).
223
         * part is backed by the ELF image and the upper is anonymous).
219
         * In any case, a frame needs to be freed.
224
         * In any case, a frame needs to be freed.
220
         */
225
         */
221
        frame_free(ADDR2PFN(frame));
226
        frame_free(ADDR2PFN(frame));
222
    }
227
    }
223
}
228
}
224
 
229
 
225
/** Share ELF image backed address space area.
230
/** Share ELF image backed address space area.
226
 *
231
 *
227
 * If the area is writable, then all mapped pages are duplicated in the pagemap.
232
 * If the area is writable, then all mapped pages are duplicated in the pagemap.
228
 * Otherwise only portions of the area that are not backed by the ELF image
233
 * Otherwise only portions of the area that are not backed by the ELF image
229
 * are put into the pagemap.
234
 * are put into the pagemap.
230
 *
235
 *
231
 * The address space and address space area must be locked prior to the call.
236
 * The address space and address space area must be locked prior to the call.
232
 *
237
 *
233
 * @param area Address space area.
238
 * @param area Address space area.
234
 */
239
 */
235
void elf_share(as_area_t *area)
240
void elf_share(as_area_t *area)
236
{
241
{
237
    elf_segment_header_t *entry = area->backend_data.segment;
242
    elf_segment_header_t *entry = area->backend_data.segment;
238
    link_t *cur;
243
    link_t *cur;
239
    btree_node_t *leaf, *node;
244
    btree_node_t *leaf, *node;
240
    __address start_anon = entry->p_vaddr + entry->p_filesz;
245
    __address start_anon = entry->p_vaddr + entry->p_filesz;
241
 
246
 
242
    /*
247
    /*
243
     * Find the node in which to start linear search.
248
     * Find the node in which to start linear search.
244
     */
249
     */
245
    if (area->flags & AS_AREA_WRITE) {
250
    if (area->flags & AS_AREA_WRITE) {
246
        node = list_get_instance(area->used_space.leaf_head.next, btree_node_t, leaf_link);
251
        node = list_get_instance(area->used_space.leaf_head.next, btree_node_t, leaf_link);
247
    } else {
252
    } else {
248
        (void) btree_search(&area->sh_info->pagemap, start_anon, &leaf);
253
        (void) btree_search(&area->sh_info->pagemap, start_anon, &leaf);
249
        node = btree_leaf_node_left_neighbour(&area->sh_info->pagemap, leaf);
254
        node = btree_leaf_node_left_neighbour(&area->sh_info->pagemap, leaf);
250
        if (!node)
255
        if (!node)
251
            node = leaf;
256
            node = leaf;
252
    }
257
    }
253
 
258
 
254
    /*
259
    /*
255
     * Copy used anonymous portions of the area to sh_info's page map.
260
     * Copy used anonymous portions of the area to sh_info's page map.
256
     */
261
     */
257
    mutex_lock(&area->sh_info->lock);
262
    mutex_lock(&area->sh_info->lock);
258
    for (cur = &node->leaf_link; cur != &area->used_space.leaf_head; cur = cur->next) {
263
    for (cur = &node->leaf_link; cur != &area->used_space.leaf_head; cur = cur->next) {
259
        int i;
264
        int i;
260
       
265
       
261
        node = list_get_instance(cur, btree_node_t, leaf_link);
266
        node = list_get_instance(cur, btree_node_t, leaf_link);
262
       
267
       
263
        for (i = 0; i < node->keys; i++) {
268
        for (i = 0; i < node->keys; i++) {
264
            __address base = node->key[i];
269
            __address base = node->key[i];
265
            count_t count = (count_t) node->value[i];
270
            count_t count = (count_t) node->value[i];
266
            int j;
271
            int j;
267
           
272
           
268
            /*
273
            /*
269
             * Skip read-only areas of used space that are backed
274
             * Skip read-only areas of used space that are backed
270
             * by the ELF image.
275
             * by the ELF image.
271
             */
276
             */
272
            if (!(area->flags & AS_AREA_WRITE))
277
            if (!(area->flags & AS_AREA_WRITE))
273
                if (base + count*PAGE_SIZE <= start_anon)
278
                if (base + count*PAGE_SIZE <= start_anon)
274
                    continue;
279
                    continue;
275
           
280
           
276
            for (j = 0; j < count; j++) {
281
            for (j = 0; j < count; j++) {
277
                pte_t *pte;
282
                pte_t *pte;
278
           
283
           
279
                /*
284
                /*
280
                 * Skip read-only pages that are backed by the ELF image.
285
                 * Skip read-only pages that are backed by the ELF image.
281
                 */
286
                 */
282
                if (!(area->flags & AS_AREA_WRITE))
287
                if (!(area->flags & AS_AREA_WRITE))
283
                    if (base + (j + 1)*PAGE_SIZE <= start_anon)
288
                    if (base + (j + 1)*PAGE_SIZE <= start_anon)
284
                        continue;
289
                        continue;
285
               
290
               
286
                page_table_lock(area->as, false);
291
                page_table_lock(area->as, false);
287
                pte = page_mapping_find(area->as, base + j*PAGE_SIZE);
292
                pte = page_mapping_find(area->as, base + j*PAGE_SIZE);
288
                ASSERT(pte && PTE_VALID(pte) && PTE_PRESENT(pte));
293
                ASSERT(pte && PTE_VALID(pte) && PTE_PRESENT(pte));
289
                btree_insert(&area->sh_info->pagemap, (base + j*PAGE_SIZE) - area->base,
294
                btree_insert(&area->sh_info->pagemap, (base + j*PAGE_SIZE) - area->base,
290
                    (void *) PTE_GET_FRAME(pte), NULL);
295
                    (void *) PTE_GET_FRAME(pte), NULL);
291
                page_table_unlock(area->as, false);
296
                page_table_unlock(area->as, false);
-
 
297
                frame_reference_add(ADDR2PFN(PTE_GET_FRAME(pte)));
292
            }
298
            }
293
               
299
               
294
        }
300
        }
295
    }
301
    }
296
    mutex_unlock(&area->sh_info->lock);
302
    mutex_unlock(&area->sh_info->lock);
297
}
303
}
298
 
304