Subversion Repositories HelenOS-historic

Rev

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

Rev 1760 Rev 1780
Line 49... Line 49...
49
#include <arch/types.h>
49
#include <arch/types.h>
50
#include <typedefs.h>
50
#include <typedefs.h>
51
#include <align.h>
51
#include <align.h>
52
#include <arch.h>
52
#include <arch.h>
53
 
53
 
54
static int anon_page_fault(as_area_t *area, __address addr, pf_access_t access);
54
static int anon_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access);
55
static void anon_frame_free(as_area_t *area, __address page, __address frame);
55
static void anon_frame_free(as_area_t *area, uintptr_t page, uintptr_t frame);
56
static void anon_share(as_area_t *area);
56
static void anon_share(as_area_t *area);
57
 
57
 
58
mem_backend_t anon_backend = {
58
mem_backend_t anon_backend = {
59
    .page_fault = anon_page_fault,
59
    .page_fault = anon_page_fault,
60
    .frame_free = anon_frame_free,
60
    .frame_free = anon_frame_free,
Line 69... Line 69...
69
 * @param addr Faulting virtual address.
69
 * @param addr Faulting virtual address.
70
 * @param access Access mode that caused the fault (i.e. read/write/exec).
70
 * @param access Access mode that caused the fault (i.e. read/write/exec).
71
 *
71
 *
72
 * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e. serviced).
72
 * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e. serviced).
73
 */
73
 */
74
int anon_page_fault(as_area_t *area, __address addr, pf_access_t access)
74
int anon_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access)
75
{
75
{
76
    __address frame;
76
    uintptr_t frame;
77
 
77
 
78
    if (!as_area_check_access(area, access))
78
    if (!as_area_check_access(area, access))
79
        return AS_PF_FAULT;
79
        return AS_PF_FAULT;
80
 
80
 
81
    if (area->sh_info) {
81
    if (area->sh_info) {
Line 86... Line 86...
86
         * in the pagemap of the address space area share info structure.
86
         * in the pagemap of the address space area share info structure.
87
         * In the case that the pagemap does not contain the respective
87
         * In the case that the pagemap does not contain the respective
88
         * mapping, a new frame is allocated and the mapping is created.
88
         * mapping, a new frame is allocated and the mapping is created.
89
         */
89
         */
90
        mutex_lock(&area->sh_info->lock);
90
        mutex_lock(&area->sh_info->lock);
91
        frame = (__address) btree_search(&area->sh_info->pagemap,
91
        frame = (uintptr_t) btree_search(&area->sh_info->pagemap,
92
            ALIGN_DOWN(addr, PAGE_SIZE) - area->base, &leaf);
92
            ALIGN_DOWN(addr, PAGE_SIZE) - area->base, &leaf);
93
        if (!frame) {
93
        if (!frame) {
94
            bool allocate = true;
94
            bool allocate = true;
95
            int i;
95
            int i;
96
           
96
           
Line 103... Line 103...
103
                    allocate = false;
103
                    allocate = false;
104
                    break;
104
                    break;
105
                }
105
                }
106
            }
106
            }
107
            if (allocate) {
107
            if (allocate) {
108
                frame = (__address) frame_alloc(ONE_FRAME, 0);
108
                frame = (uintptr_t) frame_alloc(ONE_FRAME, 0);
109
                memsetb(PA2KA(frame), FRAME_SIZE, 0);
109
                memsetb(PA2KA(frame), FRAME_SIZE, 0);
110
               
110
               
111
                /*
111
                /*
112
                 * Insert the address of the newly allocated frame to the pagemap.
112
                 * Insert the address of the newly allocated frame to the pagemap.
113
                 */
113
                 */
Line 130... Line 130...
130
         *   currently not implemented, would be frame
130
         *   currently not implemented, would be frame
131
         *   reuse; when this becomes a possibility,
131
         *   reuse; when this becomes a possibility,
132
         *   do not forget to distinguish between
132
         *   do not forget to distinguish between
133
         *   the different causes
133
         *   the different causes
134
         */
134
         */
135
        frame = (__address)frame_alloc(ONE_FRAME, 0);
135
        frame = (uintptr_t)frame_alloc(ONE_FRAME, 0);
136
        memsetb(PA2KA(frame), FRAME_SIZE, 0);
136
        memsetb(PA2KA(frame), FRAME_SIZE, 0);
137
    }
137
    }
138
   
138
   
139
    /*
139
    /*
140
     * Map 'page' to 'frame'.
140
     * Map 'page' to 'frame'.
Line 154... Line 154...
154
 *
154
 *
155
 * @param area Ignored.
155
 * @param area Ignored.
156
 * @param page Ignored.
156
 * @param page Ignored.
157
 * @param frame Frame to be released.
157
 * @param frame Frame to be released.
158
 */
158
 */
159
void anon_frame_free(as_area_t *area, __address page, __address frame)
159
void anon_frame_free(as_area_t *area, uintptr_t page, uintptr_t frame)
160
{
160
{
161
    frame_free(frame);
161
    frame_free(frame);
162
}
162
}
163
 
163
 
164
/** Share the anonymous address space area.
164
/** Share the anonymous address space area.
Line 182... Line 182...
182
        btree_node_t *node;
182
        btree_node_t *node;
183
        int i;
183
        int i;
184
       
184
       
185
        node = list_get_instance(cur, btree_node_t, leaf_link);
185
        node = list_get_instance(cur, btree_node_t, leaf_link);
186
        for (i = 0; i < node->keys; i++) {
186
        for (i = 0; i < node->keys; i++) {
187
            __address base = node->key[i];
187
            uintptr_t base = node->key[i];
188
            count_t count = (count_t) node->value[i];
188
            count_t count = (count_t) node->value[i];
189
            int j;
189
            int j;
190
           
190
           
191
            for (j = 0; j < count; j++) {
191
            for (j = 0; j < count; j++) {
192
                pte_t *pte;
192
                pte_t *pte;