OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [test0/] [src/] [mmaptest.c.orig] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Test mmap/munmap posix calls.
3
 *
4
 * Copyright (C) 2007 - 2008 Bahadir Balban
5
 */
6
#include 
7
#include 
8
#include 
9
#include 
10
#include 
11
#include 
12
#include 
13
#include 
14
#include 
15
#include 
16
 
17
#define PAGE_SIZE               0x1000
18
 
19
int mmaptest(void)
20
{
21
        int fd;
22
        void *base;
23
        int x = 0x1000;
24
 
25
        if ((fd = open("./newfile.txt", O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) < 0)
26
                perror("open:");
27
        else
28
                printf("open: Success.\n");
29
 
30
        /* Extend the file */
31
        if ((int)lseek(fd, PAGE_SIZE*16, SEEK_SET) < 0)
32
                perror("lseek");
33
        else
34
                printf("lseek: Success.\n");
35
 
36
        if (write(fd, &x, sizeof(x)) < 0)
37
                perror("write");
38
        else
39
                printf("write: Success.\n");
40
 
41
        if ((int)(base = mmap(0, PAGE_SIZE*16, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) < 0)
42
                perror("mmap");
43
        else
44
                printf("mmap: Success: %p\n", base);
45
 
46
        *(unsigned int *)(base + PAGE_SIZE*2) = 0x1000;
47
        if (msync(base + PAGE_SIZE*2, PAGE_SIZE, MS_SYNC) < 0)
48
                perror("msync");
49
        else
50
                printf("msync: Success: %p\n", base);
51
 
52
        if (munmap(base + PAGE_SIZE*2, PAGE_SIZE) < 0)
53
                perror("munmap");
54
        else
55
                printf("munmap: Success: %p\n", base);
56
        *(unsigned int *)(base + PAGE_SIZE*3) = 0x1000;
57
        *(unsigned int *)(base + PAGE_SIZE*1) = 0x1000;
58
 
59
        return 0;
60
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.