a2cf7d
commit 70ba28f7ab2923d4e36ffc9d5d2e32357353b25c
a2cf7d
Author: Lucas A. M. Magalhaes <lamm@linux.ibm.com>
a2cf7d
Date:   Thu Jan 16 10:39:12 2020 -0300
a2cf7d
a2cf7d
    Fix tst-pkey.c pkey_alloc return checks and manual
a2cf7d
    
a2cf7d
    This test was failing in some powerpc systems as it was not checking
a2cf7d
    for ENOSPC return.
a2cf7d
    
a2cf7d
    As said on the Linux man-pages and can be observed by the implementation
a2cf7d
    at mm/mprotect.c in the Linux Kernel source.  The syscall pkey_alloc can
a2cf7d
    return EINVAL or ENOSPC.  ENOSPC will indicate either that all keys are
a2cf7d
    in use or that the kernel does not support pkeys.
a2cf7d
    
a2cf7d
    Reviewed-by: Gabriel F. T. Gomes <gabriel@inconstante.net.br>
a2cf7d
a2cf7d
diff --git a/manual/memory.texi b/manual/memory.texi
a2cf7d
index a1435aad1acd3239..4731a38bcc5701e0 100644
a2cf7d
--- a/manual/memory.texi
a2cf7d
+++ b/manual/memory.texi
a2cf7d
@@ -3289,6 +3289,10 @@ in which memory protection keys are disabled.
a2cf7d
 
a2cf7d
 @item ENOSPC
a2cf7d
 All available protection keys already have been allocated.
a2cf7d
+
a2cf7d
+The system does not implement memory protection keys or runs in a mode
a2cf7d
+in which memory protection keys are disabled.
a2cf7d
+
a2cf7d
 @end table
a2cf7d
 @end deftypefun
a2cf7d
 
a2cf7d
diff --git a/sysdeps/unix/sysv/linux/tst-pkey.c b/sysdeps/unix/sysv/linux/tst-pkey.c
a2cf7d
index 600b6f0098def773..40d7e9f24dec3e57 100644
a2cf7d
--- a/sysdeps/unix/sysv/linux/tst-pkey.c
a2cf7d
+++ b/sysdeps/unix/sysv/linux/tst-pkey.c
a2cf7d
@@ -199,6 +199,10 @@ do_test (void)
a2cf7d
       if (errno == EINVAL)
a2cf7d
         FAIL_UNSUPPORTED
a2cf7d
           ("CPU does not support memory protection keys: %m");
a2cf7d
+      if (errno == ENOSPC)
a2cf7d
+        FAIL_UNSUPPORTED
a2cf7d
+          ("no keys available or kernel does not support memory"
a2cf7d
+           " protection keys");
a2cf7d
       FAIL_EXIT1 ("pkey_alloc: %m");
a2cf7d
     }
a2cf7d
   TEST_COMPARE (pkey_get (keys[0]), 0);