Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/sys Deal with architectures defining VM_MIN_A...



details:   https://anonhg.NetBSD.org/src/rev/9061164ed6af
branches:  trunk
changeset: 781467:9061164ed6af
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Sep 07 20:27:12 2012 +0000

description:
Deal with architectures defining VM_MIN_ADDRESS > 0.
Add additional error code tests using a pointer one page past current brk.

diffstat:

 tests/lib/libc/sys/t_mlock.c |  33 +++++++++++++++++++++++++++------
 1 files changed, 27 insertions(+), 6 deletions(-)

diffs (75 lines):

diff -r 6e7f8babd140 -r 9061164ed6af tests/lib/libc/sys/t_mlock.c
--- a/tests/lib/libc/sys/t_mlock.c      Fri Sep 07 18:05:11 2012 +0000
+++ b/tests/lib/libc/sys/t_mlock.c      Fri Sep 07 20:27:12 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mlock.c,v 1.2 2012/04/21 01:15:13 jruoho Exp $ */
+/* $NetBSD: t_mlock.c,v 1.3 2012/09/07 20:27:12 martin Exp $ */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,14 +29,17 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_mlock.c,v 1.2 2012/04/21 01:15:13 jruoho Exp $");
+__RCSID("$NetBSD: t_mlock.c,v 1.3 2012/09/07 20:27:12 martin Exp $");
 
 #include <sys/mman.h>
 #include <sys/resource.h>
 #include <sys/wait.h>
+#define _KMEMUSER
+#include <machine/vmparam.h>
 
 #include <errno.h>
 #include <atf-c.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -77,24 +80,42 @@
 
 ATF_TC_BODY(mlock_err, tc)
 {
+       void *invalid_ptr;
+       int null_errno = ENOMEM;        /* error expected for NULL */
+
+       if ((uintptr_t)VM_MIN_ADDRESS > 0)
+               null_errno = EINVAL;    /* NULL is not inside user VM */
 
        errno = 0;
-       ATF_REQUIRE_ERRNO(ENOMEM, mlock(NULL, page) == -1);
+       ATF_REQUIRE_ERRNO(null_errno, mlock(NULL, page) == -1);
 
        errno = 0;
-       ATF_REQUIRE_ERRNO(ENOMEM, mlock((char *)0, page) == -1);
+       ATF_REQUIRE_ERRNO(null_errno, mlock((char *)0, page) == -1);
 
        errno = 0;
        ATF_REQUIRE_ERRNO(EINVAL, mlock((char *)-1, page) == -1);
 
        errno = 0;
-       ATF_REQUIRE_ERRNO(ENOMEM, munlock(NULL, page) == -1);
+       ATF_REQUIRE_ERRNO(null_errno, munlock(NULL, page) == -1);
 
        errno = 0;
-       ATF_REQUIRE_ERRNO(ENOMEM, munlock((char *)0, page) == -1);
+       ATF_REQUIRE_ERRNO(null_errno, munlock((char *)0, page) == -1);
 
        errno = 0;
        ATF_REQUIRE_ERRNO(EINVAL, munlock((char *)-1, page) == -1);
+
+       /*
+        * Try to create a pointer to an unmapped page - first after current
+        * brk will likely do.
+        */
+       invalid_ptr = (void*)(((uintptr_t)sbrk(0)+page) & ~(page-1));
+       printf("testing with (hopefully) invalid pointer %p\n", invalid_ptr);
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(ENOMEM, mlock(invalid_ptr, page) == -1);
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(ENOMEM, munlock(invalid_ptr, page) == -1);
 }
 
 ATF_TC(mlock_limits);



Home | Main Index | Thread Index | Old Index