~ubuntu-branches/debian/sid/trinity/sid

« back to all changes in this revision

Viewing changes to syscalls/mmap.c

  • Committer: Package Import Robot
  • Author(s): gustavo panizzo
  • Date: 2014-01-17 21:10:15 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140117211015-k2qbnpu0osa5mlil
Tags: 1.3-1
* New upstream version 1.3.
* Removed wrong dependency on linux-headers. (Closes: #733771).

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
        unsigned long, fd, unsigned long, off)
5
5
 */
6
6
#include <stdlib.h>
7
 
#include <asm/mman.h>
8
 
#include "trinity.h"    // page_size
 
7
#include <string.h>
 
8
#include <sys/mman.h>
 
9
#include "maps.h"
9
10
#include "sanitise.h"
10
11
#include "shm.h"
11
12
#include "arch.h"
12
13
#include "compat.h"
 
14
#include "random.h"
 
15
#include "utils.h"      //ARRAY_SIZE
 
16
#include "utils.h"
13
17
 
 
18
#ifdef __x86_64__
 
19
#define NUM_FLAGS 13
 
20
#else
14
21
#define NUM_FLAGS 12
 
22
#endif
15
23
 
16
24
// need this to actually get MAP_UNINITIALIZED defined
17
25
#define CONFIG_MMAP_ALLOW_UNINITIALIZED
18
26
 
 
27
static void do_anon(int childno)
 
28
{
 
29
        /* no fd if anonymous mapping. */
 
30
        shm->a5[childno] = -1;
 
31
        shm->a6[childno] = 0;
 
32
}
 
33
 
19
34
void sanitise_mmap(int childno)
20
35
{
21
36
        unsigned int i;
22
37
        unsigned int flagvals[NUM_FLAGS] = { MAP_FIXED, MAP_ANONYMOUS,
23
 
                            MAP_GROWSDOWN, MAP_DENYWRITE, MAP_EXECUTABLE, MAP_LOCKED,
24
 
                            MAP_NORESERVE, MAP_POPULATE, MAP_NONBLOCK, MAP_STACK,
25
 
                            MAP_HUGETLB, MAP_UNINITIALIZED };
 
38
                        MAP_GROWSDOWN, MAP_DENYWRITE, MAP_EXECUTABLE, MAP_LOCKED,
 
39
                        MAP_NORESERVE, MAP_POPULATE, MAP_NONBLOCK, MAP_STACK,
 
40
                        MAP_HUGETLB, MAP_UNINITIALIZED,
 
41
#ifdef __x86_64__
 
42
                        MAP_32BIT,
 
43
#endif
 
44
        };
26
45
        unsigned int numflags = rand() % NUM_FLAGS;
27
 
 
28
 
        /* Don't actually set a hint right now, in case we give out
29
 
           something that we don't want changed.  One day, we'll recycle
30
 
           mappings from mmap results and the like here instead.
31
 
           Right now, ARG_ADDRESS is a bad choice, as it causes page_rand()
32
 
           to be remapped as unwritable/unreadable, and then we segfault */
 
46
        unsigned long sizes[] = {
 
47
                -1,     /* over-written with page_size below */
 
48
                1 * MB, 2 * MB, 4 * MB, 10 * MB,
 
49
                1 * GB,
 
50
        };
 
51
 
 
52
        sizes[0] = page_size;
 
53
 
 
54
        /* Don't actually set a hint right now. */
33
55
        shm->a1[childno] = 0;
34
56
 
35
 
        shm->a2[childno] = page_size;
36
 
        if (shm->a2[childno] == 0)
37
 
                shm->a2[childno] = page_size;
38
 
 
 
57
        shm->a2[childno] = sizes[rand() % ARRAY_SIZE(sizes)];
39
58
 
40
59
        // set additional flags
41
60
        for (i = 0; i < numflags; i++)
42
61
                shm->a4[childno] |= flagvals[rand() % NUM_FLAGS];
43
62
 
44
 
        /* no fd if anonymous mapping. */
45
 
        if (shm->a4[childno] & MAP_ANONYMOUS)
46
 
                shm->a5[childno] = -1;
47
 
 
48
 
        /* page align non-anonymous mappings. */
49
 
        if (shm->a4[childno] & MAP_ANONYMOUS)
 
63
        if (shm->a4[childno] & MAP_ANONYMOUS) {
 
64
                do_anon(childno);
 
65
        } else {
 
66
                /* page align non-anonymous mappings. */
50
67
                shm->a6[childno] &= PAGE_MASK;
51
 
        else
52
 
                shm->a6[childno] = 0;
53
 
 
 
68
        }
 
69
}
 
70
 
 
71
static void post_mmap(int childno)
 
72
{
 
73
        char *p;
 
74
        struct list_head *list;
 
75
        struct map *new;
 
76
 
 
77
        p = (void *) shm->retval[childno];
 
78
        if (p == MAP_FAILED)
 
79
                return;
 
80
 
 
81
        new = zmalloc(sizeof(struct map));
 
82
        new->name = strdup("misc");
 
83
        new->size = shm->a2[childno];
 
84
        new->prot = shm->a3[childno];
 
85
        new->ptr = p;
 
86
        new->type = MAP_LOCAL;
 
87
 
 
88
        // Add this to a list for use by subsequent syscalls.
 
89
        list = &shm->mappings[childno]->list;
 
90
        list_add_tail(&new->list, list);
 
91
        shm->num_mappings[childno]++;
 
92
 
 
93
        /* Sometimes dirty the mapping. */
 
94
        if (rand_bool())
 
95
                dirty_mapping(new);
54
96
}
55
97
 
56
98
struct syscall syscall_mmap = {
58
100
        .num_args = 6,
59
101
        .sanitise = sanitise_mmap,
60
102
        .arg1name = "addr",
61
 
        .arg1type = ARG_ADDRESS,
 
103
        .arg1type = ARG_MMAP,
62
104
        .arg2name = "len",
63
105
        .arg2type = ARG_LEN,
64
106
        .arg3name = "prot",
79
121
        .arg6type = ARG_LEN,
80
122
        .group = GROUP_VM,
81
123
        .flags = NEED_ALARM,
 
124
        .post = post_mmap,
82
125
};