2 * SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
3 unsigned long, prot, unsigned long, flags,
4 unsigned long, fd, unsigned long, offset)
6 * sys_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, long pgoff)
17 #include "utils.h" //ARRAY_SIZE
26 // need this to actually get MAP_UNINITIALIZED defined
27 #define CONFIG_MMAP_ALLOW_UNINITIALIZED
29 static void do_anon(int childno
)
31 /* no fd if anonymous mapping. */
32 shm
->syscall
[childno
].a5
= -1;
33 shm
->syscall
[childno
].a6
= 0;
36 static void sanitise_mmap(int childno
)
39 unsigned int flagvals
[NUM_FLAGS
] = { MAP_FIXED
, MAP_ANONYMOUS
,
40 MAP_GROWSDOWN
, MAP_DENYWRITE
, MAP_EXECUTABLE
, MAP_LOCKED
,
41 MAP_NORESERVE
, MAP_POPULATE
, MAP_NONBLOCK
, MAP_STACK
,
42 MAP_HUGETLB
, MAP_UNINITIALIZED
,
47 unsigned int numflags
= rand() % NUM_FLAGS
;
48 unsigned long sizes
[] = {
49 -1, /* over-written with page_size below */
50 1 * MB
, 2 * MB
, 4 * MB
, 10 * MB
,
56 /* Don't actually set a hint right now. */
57 shm
->syscall
[childno
].a1
= 0;
59 // set additional flags
60 for (i
= 0; i
< numflags
; i
++)
61 shm
->syscall
[childno
].a4
|= flagvals
[rand() % NUM_FLAGS
];
63 if (shm
->syscall
[childno
].a4
& MAP_ANONYMOUS
) {
64 shm
->syscall
[childno
].a2
= sizes
[rand() % ARRAY_SIZE(sizes
)];
67 if (this_syscallname("mmap2", childno
) == TRUE
) {
68 /* mmap2 counts in 4K units */
69 shm
->syscall
[childno
].a6
/= 4096;
71 /* page align non-anonymous mappings. */
72 shm
->syscall
[childno
].a6
&= PAGE_MASK
;
75 shm
->syscall
[childno
].a2
= page_size
;
79 static void post_mmap(int childno
)
82 struct list_head
*list
;
85 p
= (void *) shm
->syscall
[childno
].retval
;
89 new = zmalloc(sizeof(struct map
));
90 new->name
= strdup("misc");
91 new->size
= shm
->syscall
[childno
].a2
;
92 new->prot
= shm
->syscall
[childno
].a3
;
93 //TODO: store fd if !anon
95 new->type
= MAP_LOCAL
;
97 // Add this to a list for use by subsequent syscalls.
98 list
= &shm
->mappings
[childno
]->list
;
99 list_add_tail(&new->list
, list
);
100 shm
->num_mappings
[childno
]++;
102 /* Sometimes dirty the mapping. */
107 static char * decode_mmap(int argnum
, int childno
)
112 int flags
= shm
->syscall
[childno
].a3
;
115 p
= buf
= zmalloc(80);
116 p
+= sprintf(buf
, "[");
119 p
+= sprintf(p
, "PROT_NONE]");
122 if (flags
& PROT_READ
)
123 p
+= sprintf(p
, "PROT_READ|");
124 if (flags
& PROT_WRITE
)
125 p
+= sprintf(p
, "PROT_WRITE|");
126 if (flags
& PROT_EXEC
)
127 p
+= sprintf(p
, "PROT_EXEC|");
128 if (flags
& PROT_SEM
)
129 p
+= sprintf(p
, "PROT_SEM ");
138 struct syscallentry syscall_mmap
= {
142 .sanitise
= sanitise_mmap
,
144 .decode
= decode_mmap
,
150 .arg3type
= ARG_LIST
,
153 .values
= { PROT_READ
, PROT_WRITE
, PROT_EXEC
, PROT_SEM
},
159 .values
= { MAP_SHARED
, MAP_PRIVATE
},
170 struct syscallentry syscall_mmap2
= {
174 .sanitise
= sanitise_mmap
,
176 .decode
= decode_mmap
,
182 .arg3type
= ARG_LIST
,
185 .values
= { PROT_READ
, PROT_WRITE
, PROT_EXEC
, PROT_SEM
},
191 .values
= { MAP_SHARED
, MAP_PRIVATE
},