Revision 7cb69cae exec.c

b/exec.c
89 89
/* any access to the tbs or the page table must use this lock */
90 90
spinlock_t tb_lock = SPIN_LOCK_UNLOCKED;
91 91

  
92
uint8_t code_gen_prologue[1024] __attribute__((aligned (32)));
92 93
uint8_t code_gen_buffer[CODE_GEN_BUFFER_SIZE] __attribute__((aligned (32)));
93 94
uint8_t *code_gen_ptr;
94 95

  
......
173 174
    void *opaque[TARGET_PAGE_SIZE][2][4];
174 175
} subpage_t;
175 176

  
177
#ifdef _WIN32
178
static void map_exec(void *addr, long size)
179
{
180
    DWORD old_protect;
181
    VirtualProtect(addr, size,
182
                   PAGE_EXECUTE_READWRITE, &old_protect);
183
    
184
}
185
#else
186
static void map_exec(void *addr, long size)
187
{
188
    unsigned long start, end;
189
    
190
    start = (unsigned long)addr;
191
    start &= ~(qemu_real_host_page_size - 1);
192
    
193
    end = (unsigned long)addr + size;
194
    end += qemu_real_host_page_size - 1;
195
    end &= ~(qemu_real_host_page_size - 1);
196
    
197
    mprotect((void *)start, end - start,
198
             PROT_READ | PROT_WRITE | PROT_EXEC);
199
}
200
#endif
201

  
176 202
static void page_init(void)
177 203
{
178 204
    /* NOTE: we can always suppose that qemu_host_page_size >=
......
184 210

  
185 211
        GetSystemInfo(&system_info);
186 212
        qemu_real_host_page_size = system_info.dwPageSize;
187

  
188
        VirtualProtect(code_gen_buffer, sizeof(code_gen_buffer),
189
                       PAGE_EXECUTE_READWRITE, &old_protect);
190 213
    }
191 214
#else
192 215
    qemu_real_host_page_size = getpagesize();
193
    {
194
        unsigned long start, end;
195

  
196
        start = (unsigned long)code_gen_buffer;
197
        start &= ~(qemu_real_host_page_size - 1);
198

  
199
        end = (unsigned long)code_gen_buffer + sizeof(code_gen_buffer);
200
        end += qemu_real_host_page_size - 1;
201
        end &= ~(qemu_real_host_page_size - 1);
202

  
203
        mprotect((void *)start, end - start,
204
                 PROT_READ | PROT_WRITE | PROT_EXEC);
205
    }
206 216
#endif
217
    map_exec(code_gen_buffer, sizeof(code_gen_buffer));
218
    map_exec(code_gen_prologue, sizeof(code_gen_prologue));
207 219

  
208 220
    if (qemu_host_page_size == 0)
209 221
        qemu_host_page_size = qemu_real_host_page_size;

Also available in: Unified diff