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