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