~vcs-imports/qemu/git

« back to all changes in this revision

Viewing changes to linux-user/mmap.c

  • Committer: pbrook
  • Date: 2006-10-22 00:18:54 UTC
  • Revision ID: git-v1:e6e5906b6e0a81718066ca43aef57515026c6624
ColdFire target.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2196 c046a42c-6fe2-441c-8c8c-71466251a162

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  mmap support for qemu
3
 
 *
 
3
 * 
4
4
 *  Copyright (c) 2003 Fabrice Bellard
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
29
29
 
30
30
//#define DEBUG_MMAP
31
31
 
32
 
#if defined(USE_NPTL)
33
 
pthread_mutex_t mmap_mutex;
34
 
static int __thread mmap_lock_count;
35
 
 
36
 
void mmap_lock(void)
37
 
{
38
 
    if (mmap_lock_count++ == 0) {
39
 
        pthread_mutex_lock(&mmap_mutex);
40
 
    }
41
 
}
42
 
 
43
 
void mmap_unlock(void)
44
 
{
45
 
    if (--mmap_lock_count == 0) {
46
 
        pthread_mutex_unlock(&mmap_mutex);
47
 
    }
48
 
}
49
 
#else
50
 
/* We aren't threadsafe to start with, so no need to worry about locking.  */
51
 
void mmap_lock(void)
52
 
{
53
 
}
54
 
 
55
 
void mmap_unlock(void)
56
 
{
57
 
}
58
 
#endif
59
 
 
60
32
/* NOTE: all the constants are the HOST ones, but addresses are target. */
61
 
int target_mprotect(abi_ulong start, abi_ulong len, int prot)
 
33
int target_mprotect(target_ulong start, target_ulong len, int prot)
62
34
{
63
 
    abi_ulong end, host_start, host_end, addr;
 
35
    target_ulong end, host_start, host_end, addr;
64
36
    int prot1, ret;
65
37
 
66
38
#ifdef DEBUG_MMAP
67
 
    printf("mprotect: start=0x" TARGET_FMT_lx
68
 
           "len=0x" TARGET_FMT_lx " prot=%c%c%c\n", start, len,
 
39
    printf("mprotect: start=0x%lx len=0x%lx prot=%c%c%c\n", start, len,
69
40
           prot & PROT_READ ? 'r' : '-',
70
41
           prot & PROT_WRITE ? 'w' : '-',
71
42
           prot & PROT_EXEC ? 'x' : '-');
77
48
    end = start + len;
78
49
    if (end < start)
79
50
        return -EINVAL;
80
 
    prot &= PROT_READ | PROT_WRITE | PROT_EXEC;
 
51
    if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
 
52
        return -EINVAL;
81
53
    if (len == 0)
82
54
        return 0;
83
 
 
84
 
    mmap_lock();
 
55
    
85
56
    host_start = start & qemu_host_page_mask;
86
57
    host_end = HOST_PAGE_ALIGN(end);
87
58
    if (start > host_start) {
98
69
        }
99
70
        ret = mprotect(g2h(host_start), qemu_host_page_size, prot1 & PAGE_BITS);
100
71
        if (ret != 0)
101
 
            goto error;
 
72
            return ret;
102
73
        host_start += qemu_host_page_size;
103
74
    }
104
75
    if (end < host_end) {
106
77
        for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
107
78
            prot1 |= page_get_flags(addr);
108
79
        }
109
 
        ret = mprotect(g2h(host_end - qemu_host_page_size), qemu_host_page_size,
 
80
        ret = mprotect(g2h(host_end - qemu_host_page_size), qemu_host_page_size, 
110
81
                       prot1 & PAGE_BITS);
111
82
        if (ret != 0)
112
 
            goto error;
 
83
            return ret;
113
84
        host_end -= qemu_host_page_size;
114
85
    }
115
 
 
 
86
    
116
87
    /* handle the pages in the middle */
117
88
    if (host_start < host_end) {
118
89
        ret = mprotect(g2h(host_start), host_end - host_start, prot);
119
90
        if (ret != 0)
120
 
            goto error;
 
91
            return ret;
121
92
    }
122
93
    page_set_flags(start, start + len, prot | PAGE_VALID);
123
 
    mmap_unlock();
124
94
    return 0;
125
 
error:
126
 
    mmap_unlock();
127
 
    return ret;
128
95
}
129
96
 
130
97
/* map an incomplete host page */
131
 
static int mmap_frag(abi_ulong real_start,
132
 
                     abi_ulong start, abi_ulong end,
133
 
                     int prot, int flags, int fd, abi_ulong offset)
 
98
static int mmap_frag(target_ulong real_start, 
 
99
                     target_ulong start, target_ulong end, 
 
100
                     int prot, int flags, int fd, target_ulong offset)
134
101
{
135
 
    abi_ulong real_end, addr;
 
102
    target_ulong real_end, ret, addr;
136
103
    void *host_start;
137
104
    int prot1, prot_new;
138
105
 
145
112
        if (addr < start || addr >= end)
146
113
            prot1 |= page_get_flags(addr);
147
114
    }
148
 
 
 
115
    
149
116
    if (prot1 == 0) {
150
117
        /* no page was there, so we allocate one */
151
 
        void *p = mmap(host_start, qemu_host_page_size, prot,
152
 
                       flags | MAP_ANONYMOUS, -1, 0);
153
 
        if (p == MAP_FAILED)
154
 
            return -1;
 
118
        ret = (long)mmap(host_start, qemu_host_page_size, prot, 
 
119
                         flags | MAP_ANONYMOUS, -1, 0);
 
120
        if (ret == -1)
 
121
            return ret;
155
122
        prot1 = prot;
156
123
    }
157
124
    prot1 &= PAGE_BITS;
167
134
        /* adjust protection to be able to read */
168
135
        if (!(prot1 & PROT_WRITE))
169
136
            mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE);
170
 
 
 
137
        
171
138
        /* read the corresponding file data */
172
139
        pread(fd, g2h(start), end - start, offset);
173
 
 
 
140
        
174
141
        /* put final protection */
175
142
        if (prot_new != (prot1 | PROT_WRITE))
176
143
            mprotect(host_start, qemu_host_page_size, prot_new);
183
150
    return 0;
184
151
}
185
152
 
186
 
#if defined(__CYGWIN__)
187
 
/* Cygwin doesn't have a whole lot of address space.  */
188
 
static abi_ulong mmap_next_start = 0x18000000;
189
 
#else
190
 
static abi_ulong mmap_next_start = 0x40000000;
191
 
#endif
192
 
 
193
 
unsigned long last_brk;
194
 
 
195
 
/* find a free memory area of size 'size'. The search starts at
196
 
   'start'. If 'start' == 0, then a default start address is used.
197
 
   Return -1 if error.
198
 
*/
199
 
/* page_init() marks pages used by the host as reserved to be sure not
200
 
   to use them. */
201
 
static abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size)
202
 
{
203
 
    abi_ulong addr, addr1, addr_start;
204
 
    int prot;
205
 
    unsigned long new_brk;
206
 
 
207
 
    new_brk = (unsigned long)sbrk(0);
208
 
    if (last_brk && last_brk < new_brk && last_brk == (target_ulong)last_brk) {
209
 
        /* This is a hack to catch the host allocating memory with brk().
210
 
           If it uses mmap then we loose.
211
 
           FIXME: We really want to avoid the host allocating memory in
212
 
           the first place, and maybe leave some slack to avoid switching
213
 
           to mmap.  */
214
 
        page_set_flags(last_brk & TARGET_PAGE_MASK,
215
 
                       TARGET_PAGE_ALIGN(new_brk),
216
 
                       PAGE_RESERVED); 
217
 
    }
218
 
    last_brk = new_brk;
219
 
 
220
 
    size = HOST_PAGE_ALIGN(size);
221
 
    start = start & qemu_host_page_mask;
222
 
    addr = start;
223
 
    if (addr == 0)
224
 
        addr = mmap_next_start;
225
 
    addr_start = addr;
226
 
    for(;;) {
227
 
        prot = 0;
228
 
        for(addr1 = addr; addr1 < (addr + size); addr1 += TARGET_PAGE_SIZE) {
229
 
            prot |= page_get_flags(addr1);
230
 
        }
231
 
        if (prot == 0)
232
 
            break;
233
 
        addr += qemu_host_page_size;
234
 
        /* we found nothing */
235
 
        if (addr == addr_start)
236
 
            return (abi_ulong)-1;
237
 
    }
238
 
    if (start == 0)
239
 
        mmap_next_start = addr + size;
240
 
    return addr;
241
 
}
242
 
 
243
153
/* NOTE: all the constants are the HOST ones */
244
 
abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
245
 
                     int flags, int fd, abi_ulong offset)
 
154
long target_mmap(target_ulong start, target_ulong len, int prot, 
 
155
                 int flags, int fd, target_ulong offset)
246
156
{
247
 
    abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len;
248
 
    unsigned long host_start;
 
157
    target_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len;
 
158
    long host_start;
 
159
#if defined(__alpha__) || defined(__sparc__) || defined(__x86_64__) || \
 
160
    defined(__ia64)
 
161
    static target_ulong last_start = 0x40000000;
 
162
#elif defined(__CYGWIN__)
 
163
    /* Cygwin doesn't have a whole lot of address space.  */
 
164
    static target_ulong last_start = 0x18000000;
 
165
#endif
249
166
 
250
 
    mmap_lock();
251
167
#ifdef DEBUG_MMAP
252
168
    {
253
 
        printf("mmap: start=0x" TARGET_FMT_lx
254
 
               " len=0x" TARGET_FMT_lx " prot=%c%c%c flags=",
255
 
               start, len,
 
169
        printf("mmap: start=0x%lx len=0x%lx prot=%c%c%c flags=",
 
170
               start, len, 
256
171
               prot & PROT_READ ? 'r' : '-',
257
172
               prot & PROT_WRITE ? 'w' : '-',
258
173
               prot & PROT_EXEC ? 'x' : '-');
271
186
            printf("[MAP_TYPE=0x%x] ", flags & MAP_TYPE);
272
187
            break;
273
188
        }
274
 
        printf("fd=%d offset=" TARGET_FMT_lx "\n", fd, offset);
 
189
        printf("fd=%d offset=%lx\n", fd, offset);
275
190
    }
276
191
#endif
277
192
 
278
193
    if (offset & ~TARGET_PAGE_MASK) {
279
194
        errno = EINVAL;
280
 
        goto fail;
 
195
        return -1;
281
196
    }
282
197
 
283
198
    len = TARGET_PAGE_ALIGN(len);
284
199
    if (len == 0)
285
 
        goto the_end;
 
200
        return start;
286
201
    real_start = start & qemu_host_page_mask;
287
202
 
288
203
    if (!(flags & MAP_FIXED)) {
289
 
        abi_ulong mmap_start;
290
 
        void *p;
291
 
        host_offset = offset & qemu_host_page_mask;
292
 
        host_len = len + offset - host_offset;
293
 
        host_len = HOST_PAGE_ALIGN(host_len);
294
 
        mmap_start = mmap_find_vma(real_start, host_len);
295
 
        if (mmap_start == (abi_ulong)-1) {
296
 
            errno = ENOMEM;
297
 
            goto fail;
298
 
        }
299
 
        /* Note: we prefer to control the mapping address. It is
300
 
           especially important if qemu_host_page_size >
301
 
           qemu_real_host_page_size */
302
 
        p = mmap(g2h(mmap_start),
303
 
                 host_len, prot, flags | MAP_FIXED, fd, host_offset);
304
 
        if (p == MAP_FAILED)
305
 
            goto fail;
306
 
        /* update start so that it points to the file position at 'offset' */
307
 
        host_start = (unsigned long)p;
308
 
        if (!(flags & MAP_ANONYMOUS))
309
 
            host_start += offset - host_offset;
310
 
        start = h2g(host_start);
311
 
    } else {
312
 
        int flg;
313
 
        target_ulong addr;
 
204
#if defined(__alpha__) || defined(__sparc__) || defined(__x86_64__) || \
 
205
    defined(__ia64) || defined(__CYGWIN__)
 
206
        /* tell the kenel to search at the same place as i386 */
 
207
        if (real_start == 0) {
 
208
            real_start = last_start;
 
209
            last_start += HOST_PAGE_ALIGN(len);
 
210
        }
 
211
#endif
 
212
        if (0 && qemu_host_page_size != qemu_real_host_page_size) {
 
213
            /* NOTE: this code is only for debugging with '-p' option */
 
214
            /* ??? Can also occur when TARGET_PAGE_SIZE > host page size.  */
 
215
            /* reserve a memory area */
 
216
            /* ??? This needs fixing for remapping.  */
 
217
abort();
 
218
            host_len = HOST_PAGE_ALIGN(len) + qemu_host_page_size - TARGET_PAGE_SIZE;
 
219
            real_start = (long)mmap(g2h(real_start), host_len, PROT_NONE, 
 
220
                                    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
221
            if (real_start == -1)
 
222
                return real_start;
 
223
            real_end = real_start + host_len;
 
224
            start = HOST_PAGE_ALIGN(real_start);
 
225
            end = start + HOST_PAGE_ALIGN(len);
 
226
            if (start > real_start)
 
227
                munmap((void *)real_start, start - real_start);
 
228
            if (end < real_end)
 
229
                munmap((void *)end, real_end - end);
 
230
            /* use it as a fixed mapping */
 
231
            flags |= MAP_FIXED;
 
232
        } else {
 
233
            /* if not fixed, no need to do anything */
 
234
            host_offset = offset & qemu_host_page_mask;
 
235
            host_len = len + offset - host_offset;
 
236
            host_start = (long)mmap(real_start ? g2h(real_start) : NULL,
 
237
                                    host_len, prot, flags, fd, host_offset);
 
238
            if (host_start == -1)
 
239
                return host_start;
 
240
            /* update start so that it points to the file position at 'offset' */
 
241
            if (!(flags & MAP_ANONYMOUS)) 
 
242
                host_start += offset - host_offset;
 
243
            start = h2g(host_start);
 
244
            goto the_end1;
 
245
        }
 
246
    }
 
247
    
 
248
    if (start & ~TARGET_PAGE_MASK) {
 
249
        errno = EINVAL;
 
250
        return -1;
 
251
    }
 
252
    end = start + len;
 
253
    real_end = HOST_PAGE_ALIGN(end);
314
254
 
315
 
        if (start & ~TARGET_PAGE_MASK) {
 
255
    /* worst case: we cannot map the file because the offset is not
 
256
       aligned, so we read it */
 
257
    if (!(flags & MAP_ANONYMOUS) &&
 
258
        (offset & ~qemu_host_page_mask) != (start & ~qemu_host_page_mask)) {
 
259
        /* msync() won't work here, so we return an error if write is
 
260
           possible while it is a shared mapping */
 
261
        if ((flags & MAP_TYPE) == MAP_SHARED &&
 
262
            (prot & PROT_WRITE)) {
316
263
            errno = EINVAL;
317
 
            goto fail;
318
 
        }
319
 
        end = start + len;
320
 
        real_end = HOST_PAGE_ALIGN(end);
321
 
 
322
 
        for(addr = real_start; addr < real_end; addr += TARGET_PAGE_SIZE) {
323
 
            flg = page_get_flags(addr);
324
 
            if (flg & PAGE_RESERVED) {
325
 
                errno = ENXIO;
326
 
                goto fail;
327
 
            }
328
 
        }
329
 
 
330
 
        /* worst case: we cannot map the file because the offset is not
331
 
           aligned, so we read it */
332
 
        if (!(flags & MAP_ANONYMOUS) &&
333
 
            (offset & ~qemu_host_page_mask) != (start & ~qemu_host_page_mask)) {
334
 
            /* msync() won't work here, so we return an error if write is
335
 
               possible while it is a shared mapping */
336
 
            if ((flags & MAP_TYPE) == MAP_SHARED &&
337
 
                (prot & PROT_WRITE)) {
338
 
                errno = EINVAL;
339
 
                goto fail;
340
 
            }
341
 
            retaddr = target_mmap(start, len, prot | PROT_WRITE,
342
 
                                  MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS,
343
 
                                  -1, 0);
344
 
            if (retaddr == -1)
345
 
                goto fail;
346
 
            pread(fd, g2h(start), len, offset);
347
 
            if (!(prot & PROT_WRITE)) {
348
 
                ret = target_mprotect(start, len, prot);
349
 
                if (ret != 0) {
350
 
                    start = ret;
351
 
                    goto the_end;
352
 
                }
353
 
            }
354
 
            goto the_end;
355
 
        }
356
 
        
357
 
        /* handle the start of the mapping */
358
 
        if (start > real_start) {
359
 
            if (real_end == real_start + qemu_host_page_size) {
360
 
                /* one single host page */
361
 
                ret = mmap_frag(real_start, start, end,
362
 
                                prot, flags, fd, offset);
363
 
                if (ret == -1)
364
 
                    goto fail;
365
 
                goto the_end1;
366
 
            }
367
 
            ret = mmap_frag(real_start, start, real_start + qemu_host_page_size,
 
264
            return -1;
 
265
        }
 
266
        retaddr = target_mmap(start, len, prot | PROT_WRITE, 
 
267
                              MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, 
 
268
                              -1, 0);
 
269
        if (retaddr == -1)
 
270
            return retaddr;
 
271
        pread(fd, g2h(start), len, offset);
 
272
        if (!(prot & PROT_WRITE)) {
 
273
            ret = target_mprotect(start, len, prot);
 
274
            if (ret != 0)
 
275
                return ret;
 
276
        }
 
277
        goto the_end;
 
278
    }
 
279
 
 
280
    /* handle the start of the mapping */
 
281
    if (start > real_start) {
 
282
        if (real_end == real_start + qemu_host_page_size) {
 
283
            /* one single host page */
 
284
            ret = mmap_frag(real_start, start, end,
368
285
                            prot, flags, fd, offset);
369
286
            if (ret == -1)
370
 
                goto fail;
371
 
            real_start += qemu_host_page_size;
372
 
        }
373
 
        /* handle the end of the mapping */
374
 
        if (end < real_end) {
375
 
            ret = mmap_frag(real_end - qemu_host_page_size,
376
 
                            real_end - qemu_host_page_size, real_end,
377
 
                            prot, flags, fd,
378
 
                            offset + real_end - qemu_host_page_size - start);
379
 
            if (ret == -1)
380
 
                goto fail;
381
 
            real_end -= qemu_host_page_size;
382
 
        }
383
 
 
384
 
        /* map the middle (easier) */
385
 
        if (real_start < real_end) {
386
 
            void *p;
387
 
            unsigned long offset1;
388
 
            if (flags & MAP_ANONYMOUS)
389
 
                offset1 = 0;
390
 
            else
391
 
                offset1 = offset + real_start - start;
392
 
            p = mmap(g2h(real_start), real_end - real_start,
393
 
                     prot, flags, fd, offset1);
394
 
            if (p == MAP_FAILED)
395
 
                goto fail;
396
 
        }
 
287
                return ret;
 
288
            goto the_end1;
 
289
        }
 
290
        ret = mmap_frag(real_start, start, real_start + qemu_host_page_size,
 
291
                        prot, flags, fd, offset);
 
292
        if (ret == -1)
 
293
            return ret;
 
294
        real_start += qemu_host_page_size;
 
295
    }
 
296
    /* handle the end of the mapping */
 
297
    if (end < real_end) {
 
298
        ret = mmap_frag(real_end - qemu_host_page_size, 
 
299
                        real_end - qemu_host_page_size, real_end,
 
300
                        prot, flags, fd, 
 
301
                        offset + real_end - qemu_host_page_size - start);
 
302
        if (ret == -1)
 
303
            return ret;
 
304
        real_end -= qemu_host_page_size;
 
305
    }
 
306
    
 
307
    /* map the middle (easier) */
 
308
    if (real_start < real_end) {
 
309
        unsigned long offset1;
 
310
        if (flags & MAP_ANONYMOUS)
 
311
          offset1 = 0;
 
312
        else
 
313
          offset1 = offset + real_start - start;
 
314
        ret = (long)mmap(g2h(real_start), real_end - real_start, 
 
315
                         prot, flags, fd, offset1);
 
316
        if (ret == -1)
 
317
            return ret;
397
318
    }
398
319
 the_end1:
399
320
    page_set_flags(start, start + len, prot | PAGE_VALID);
400
321
 the_end:
401
322
#ifdef DEBUG_MMAP
402
 
    printf("ret=0x" TARGET_FMT_lx "\n", start);
 
323
    printf("ret=0x%lx\n", (long)start);
403
324
    page_dump(stdout);
404
325
    printf("\n");
405
326
#endif
406
 
    mmap_unlock();
407
327
    return start;
408
 
fail:
409
 
    mmap_unlock();
410
 
    return -1;
411
328
}
412
329
 
413
 
int target_munmap(abi_ulong start, abi_ulong len)
 
330
int target_munmap(target_ulong start, target_ulong len)
414
331
{
415
 
    abi_ulong end, real_start, real_end, addr;
 
332
    target_ulong end, real_start, real_end, addr;
416
333
    int prot, ret;
417
334
 
418
335
#ifdef DEBUG_MMAP
423
340
    len = TARGET_PAGE_ALIGN(len);
424
341
    if (len == 0)
425
342
        return -EINVAL;
426
 
    mmap_lock();
427
343
    end = start + len;
428
344
    real_start = start & qemu_host_page_mask;
429
345
    real_end = HOST_PAGE_ALIGN(end);
451
367
        if (prot != 0)
452
368
            real_end -= qemu_host_page_size;
453
369
    }
454
 
 
455
 
    ret = 0;
 
370
    
456
371
    /* unmap what we can */
457
372
    if (real_start < real_end) {
458
 
        ret = munmap(g2h(real_start), real_end - real_start);
 
373
        ret = munmap((void *)real_start, real_end - real_start);
 
374
        if (ret != 0)
 
375
            return ret;
459
376
    }
460
377
 
461
 
    if (ret == 0)
462
 
        page_set_flags(start, start + len, 0);
463
 
    mmap_unlock();
464
 
    return ret;
 
378
    page_set_flags(start, start + len, 0);
 
379
    return 0;
465
380
}
466
381
 
467
382
/* XXX: currently, we only handle MAP_ANONYMOUS and not MAP_FIXED
468
383
   blocks which have been allocated starting on a host page */
469
 
abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
470
 
                       abi_ulong new_size, unsigned long flags,
471
 
                       abi_ulong new_addr)
 
384
long target_mremap(target_ulong old_addr, target_ulong old_size, 
 
385
                   target_ulong new_size, unsigned long flags,
 
386
                   target_ulong new_addr)
472
387
{
473
388
    int prot;
474
 
    unsigned long host_addr;
475
389
 
476
 
    mmap_lock();
477
390
    /* XXX: use 5 args syscall */
478
 
    host_addr = (long)mremap(g2h(old_addr), old_size, new_size, flags);
479
 
    if (host_addr == -1) {
480
 
        new_addr = -1;
481
 
    } else {
482
 
        new_addr = h2g(host_addr);
483
 
        prot = page_get_flags(old_addr);
484
 
        page_set_flags(old_addr, old_addr + old_size, 0);
485
 
        page_set_flags(new_addr, new_addr + new_size, prot | PAGE_VALID);
486
 
    }
487
 
    mmap_unlock();
 
391
    new_addr = (long)mremap(g2h(old_addr), old_size, new_size, flags);
 
392
    if (new_addr == -1)
 
393
        return new_addr;
 
394
    new_addr = h2g(new_addr);
 
395
    prot = page_get_flags(old_addr);
 
396
    page_set_flags(old_addr, old_addr + old_size, 0);
 
397
    page_set_flags(new_addr, new_addr + new_size, prot | PAGE_VALID);
488
398
    return new_addr;
489
399
}
490
400
 
491
 
int target_msync(abi_ulong start, abi_ulong len, int flags)
 
401
int target_msync(target_ulong start, target_ulong len, int flags)
492
402
{
493
 
    abi_ulong end;
 
403
    target_ulong end;
494
404
 
495
405
    if (start & ~TARGET_PAGE_MASK)
496
406
        return -EINVAL;
500
410
        return -EINVAL;
501
411
    if (end == start)
502
412
        return 0;
503
 
 
 
413
    
504
414
    start &= qemu_host_page_mask;
505
415
    return msync(g2h(start), end - start, flags);
506
416
}
 
417