fpu_lazy_eflags.vgtest \
fucomip.stderr.exp fucomip.vgtest \
gxx304.stderr.exp gxx304.vgtest \
+ map_unmap.stdout.exp map_unmap.vgtest \
munmap_exe.stderr.exp munmap_exe.vgtest \
pth_blockedsig.stderr.exp \
pth_blockedsig.stdout.exp pth_blockedsig.vgtest \
check_PROGRAMS = \
args bitfield1 bt_everything bt_literal coolo_strlen \
cpuid dastest discard floored fork fpu_lazy_eflags \
- fucomip munmap_exe rcl_assert \
+ fucomip munmap_exe map_unmap rcl_assert \
rcrl readline1 resolv seg_override sha1_test shortpush shorts smc1 \
pth_blockedsig \
coolo_sigaction gxx304 yield
floored_LDADD = -lm
fpu_lazy_eflags_SOURCES = fpu_lazy_eflags.c
fucomip_SOURCES = fucomip.c
+map_unmap_SOURCES = map_unmap.c
munmap_exe_SOURCES = munmap_exe.c
rcl_assert_SOURCES = rcl_assert.S
rcrl_SOURCES = rcrl.c
--- /dev/null
+#include <stdio.h>
+#include <sys/mman.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static unsigned int pagesize;
+
+#define PAGES 1024u
+#define LEN (PAGES*pagesize)
+
+static void *domap(void)
+{
+ void *ret = mmap(0, LEN, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+
+ if (ret == (void *)-1) {
+ perror("mmap");
+ exit(1);
+ }
+
+ return ret;
+}
+
+/* unmap in pieces to exercise munmap more */
+static void nibblemap(void *p)
+{
+ int off;
+ int i;
+
+ off = (random() & ~0x1fff) % LEN;
+
+ for(i = 0; i < PAGES; i++) {
+ munmap((char *)p + off, pagesize);
+ off += 619*pagesize;
+ off %= LEN;
+ }
+}
+
+int main()
+{
+ int i;
+ void *expect1, *expect2;
+
+ pagesize = getpagesize();
+
+ expect1 = domap();
+ expect2 = domap();
+ munmap(expect1, LEN);
+ munmap(expect2, LEN);
+ for(i = 0; i < 1000; i++) {
+ void *m1, *m2;
+
+ m1 = domap();
+ if (m1 != expect1) {
+ printf("FAIL: m=%p expect=%p\n",
+ m1, expect1);
+ return 1;
+ }
+ m2 = domap();
+ if (m2 != expect2) {
+ printf("FAIL: m=%p expect=%p\n",
+ m2, expect2);
+ return 1;
+ }
+ nibblemap(m2);
+ munmap(m1, LEN);
+ }
+
+ printf("PASS\n");
+ return 0;
+}