Subversion Repositories HelenOS

Rev

Rev 2131 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2131 Rev 2292
Line 70... Line 70...
70
 *
70
 *
71
 * @param area Pointer to the address space area.
71
 * @param area Pointer to the address space area.
72
 * @param addr Faulting virtual address.
72
 * @param addr Faulting virtual address.
73
 * @param access Access mode that caused the fault (i.e. read/write/exec).
73
 * @param access Access mode that caused the fault (i.e. read/write/exec).
74
 *
74
 *
75
 * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e. serviced).
75
 * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e.
-
 
76
 *     serviced).
76
 */
77
 */
77
int anon_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access)
78
int anon_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access)
78
{
79
{
79
    uintptr_t frame;
80
    uintptr_t frame;
-
 
81
    bool dirty = false;
80
 
82
 
81
    if (!as_area_check_access(area, access))
83
    if (!as_area_check_access(area, access))
82
        return AS_PF_FAULT;
84
        return AS_PF_FAULT;
83
 
85
 
84
    if (area->sh_info) {
86
    if (area->sh_info) {
85
        btree_node_t *leaf;
87
        btree_node_t *leaf;
86
       
88
       
87
        /*
89
        /*
88
         * The area is shared, chances are that the mapping can be found
90
         * The area is shared, chances are that the mapping can be found
89
         * in the pagemap of the address space area share info structure.
91
         * in the pagemap of the address space area share info
-
 
92
         * structure.
90
         * In the case that the pagemap does not contain the respective
93
         * In the case that the pagemap does not contain the respective
91
         * mapping, a new frame is allocated and the mapping is created.
94
         * mapping, a new frame is allocated and the mapping is created.
92
         */
95
         */
93
        mutex_lock(&area->sh_info->lock);
96
        mutex_lock(&area->sh_info->lock);
94
        frame = (uintptr_t) btree_search(&area->sh_info->pagemap,
97
        frame = (uintptr_t) btree_search(&area->sh_info->pagemap,
95
            ALIGN_DOWN(addr, PAGE_SIZE) - area->base, &leaf);
98
            ALIGN_DOWN(addr, PAGE_SIZE) - area->base, &leaf);
96
        if (!frame) {
99
        if (!frame) {
97
            bool allocate = true;
100
            bool allocate = true;
98
            int i;
101
            int i;
99
           
102
           
100
            /*
103
            /*
101
             * Zero can be returned as a valid frame address.
104
             * Zero can be returned as a valid frame address.
102
             * Just a small workaround.
105
             * Just a small workaround.
103
             */
106
             */
104
            for (i = 0; i < leaf->keys; i++) {
107
            for (i = 0; i < leaf->keys; i++) {
-
 
108
                if (leaf->key[i] ==
105
                if (leaf->key[i] == ALIGN_DOWN(addr, PAGE_SIZE)) {
109
                    ALIGN_DOWN(addr, PAGE_SIZE)) {
106
                    allocate = false;
110
                    allocate = false;
107
                    break;
111
                    break;
108
                }
112
                }
109
            }
113
            }
110
            if (allocate) {
114
            if (allocate) {
111
                frame = (uintptr_t) frame_alloc(ONE_FRAME, 0);
115
                frame = (uintptr_t) frame_alloc(ONE_FRAME, 0);
112
                memsetb(PA2KA(frame), FRAME_SIZE, 0);
116
                memsetb(PA2KA(frame), FRAME_SIZE, 0);
-
 
117
                dirty = true;
113
               
118
               
114
                /*
119
                /*
115
                 * Insert the address of the newly allocated frame to the pagemap.
120
                 * Insert the address of the newly allocated
-
 
121
                 * frame to the pagemap.
116
                 */
122
                 */
-
 
123
                btree_insert(&area->sh_info->pagemap,
117
                btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base, (void *) frame, leaf);
124
                    ALIGN_DOWN(addr, PAGE_SIZE) - area->base,
-
 
125
                    (void *) frame, leaf);
118
            }
126
            }
119
        }
127
        }
120
        frame_reference_add(ADDR2PFN(frame));
128
        frame_reference_add(ADDR2PFN(frame));
121
        mutex_unlock(&area->sh_info->lock);
129
        mutex_unlock(&area->sh_info->lock);
122
    } else {
130
    } else {
Line 135... Line 143...
135
         *   do not forget to distinguish between
143
         *   do not forget to distinguish between
136
         *   the different causes
144
         *   the different causes
137
         */
145
         */
138
        frame = (uintptr_t) frame_alloc(ONE_FRAME, 0);
146
        frame = (uintptr_t) frame_alloc(ONE_FRAME, 0);
139
        memsetb(PA2KA(frame), FRAME_SIZE, 0);
147
        memsetb(PA2KA(frame), FRAME_SIZE, 0);
-
 
148
        dirty = true;
140
    }
149
    }
141
   
150
   
142
    /*
151
    /*
143
     * Map 'page' to 'frame'.
152
     * Map 'page' to 'frame'.
144
     * Note that TLB shootdown is not attempted as only new information is being
153
     * Note that TLB shootdown is not attempted as only new information is
145
     * inserted into page tables.
154
     * being inserted into page tables.
146
     */
155
     */
147
    page_mapping_insert(AS, addr, frame, as_area_get_flags(area));
156
    page_mapping_insert(AS, addr, frame, as_area_get_flags(area));
148
    if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1))
157
    if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1))
149
        panic("Could not insert used space.\n");
158
        panic("Could not insert used space.\n");
150
       
159
       
Line 160... Line 169...
160
 * @param frame Frame to be released.
169
 * @param frame Frame to be released.
161
 */
170
 */
162
void anon_frame_free(as_area_t *area, uintptr_t page, uintptr_t frame)
171
void anon_frame_free(as_area_t *area, uintptr_t page, uintptr_t frame)
163
{
172
{
164
    frame_free(frame);
173
    frame_free(frame);
165
#ifdef CONFIG_VIRT_IDX_DCACHE
-
 
166
    dcache_flush_frame(page, frame);
-
 
167
#endif
-
 
168
}
174
}
169
 
175
 
170
/** Share the anonymous address space area.
176
/** Share the anonymous address space area.
171
 *
177
 *
172
 * Sharing of anonymous area is done by duplicating its entire mapping
178
 * Sharing of anonymous area is done by duplicating its entire mapping
Line 182... Line 188...
182
 
188
 
183
    /*
189
    /*
184
     * Copy used portions of the area to sh_info's page map.
190
     * Copy used portions of the area to sh_info's page map.
185
     */
191
     */
186
    mutex_lock(&area->sh_info->lock);
192
    mutex_lock(&area->sh_info->lock);
-
 
193
    for (cur = area->used_space.leaf_head.next;
187
    for (cur = area->used_space.leaf_head.next; cur != &area->used_space.leaf_head; cur = cur->next) {
194
        cur != &area->used_space.leaf_head; cur = cur->next) {
188
        btree_node_t *node;
195
        btree_node_t *node;
189
        int i;
196
        int i;
190
       
197
       
191
        node = list_get_instance(cur, btree_node_t, leaf_link);
198
        node = list_get_instance(cur, btree_node_t, leaf_link);
192
        for (i = 0; i < node->keys; i++) {
199
        for (i = 0; i < node->keys; i++) {
Line 196... Line 203...
196
           
203
           
197
            for (j = 0; j < count; j++) {
204
            for (j = 0; j < count; j++) {
198
                pte_t *pte;
205
                pte_t *pte;
199
           
206
           
200
                page_table_lock(area->as, false);
207
                page_table_lock(area->as, false);
201
                pte = page_mapping_find(area->as, base + j*PAGE_SIZE);
208
                pte = page_mapping_find(area->as,
-
 
209
                    base + j * PAGE_SIZE);
202
                ASSERT(pte && PTE_VALID(pte) && PTE_PRESENT(pte));
210
                ASSERT(pte && PTE_VALID(pte) &&
-
 
211
                    PTE_PRESENT(pte));
203
                btree_insert(&area->sh_info->pagemap, (base + j*PAGE_SIZE) - area->base,
212
                btree_insert(&area->sh_info->pagemap,
-
 
213
                    (base + j * PAGE_SIZE) - area->base,
204
                    (void *) PTE_GET_FRAME(pte), NULL);
214
                    (void *) PTE_GET_FRAME(pte), NULL);
205
                page_table_unlock(area->as, false);
215
                page_table_unlock(area->as, false);
-
 
216
 
206
                frame_reference_add(ADDR2PFN(PTE_GET_FRAME(pte)));
217
                pfn_t pfn = ADDR2PFN(PTE_GET_FRAME(pte));
-
 
218
                frame_reference_add(pfn);
207
            }
219
            }
208
               
220
 
209
        }
221
        }
210
    }
222
    }
211
    mutex_unlock(&area->sh_info->lock);
223
    mutex_unlock(&area->sh_info->lock);
212
}
224
}
213
 
225