]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - nptl/tst-cancel17.c
Add per-thread cache to malloc
[thirdparty/glibc.git] / nptl / tst-cancel17.c
index 9fb089ac839020530925d2fa1311d411f84c960a..33204978e512d235597afcad10322917c77f51f6 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2003-2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
 
@@ -13,9 +13,8 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include <aio.h>
 #include <errno.h>
@@ -228,7 +227,7 @@ do_test (void)
 
   size_t len2 = fpathconf (fds[1], _PC_PIPE_BUF);
   size_t page_size = sysconf (_SC_PAGESIZE);
-  len2 = (len2 < page_size ? page_size : len2) + sizeof (mem) + 1;
+  len2 = 20 * (len2 < page_size ? page_size : len2) + sizeof (mem) + 1;
   char *mem2 = malloc (len2);
   if (mem2 == NULL)
     {
@@ -334,6 +333,22 @@ do_test (void)
 
   puts ("early cancellation succeeded");
 
+  if (ap == &a2)
+    {
+      /* The aio_read(&a) was not canceled because the read request was
+        already in progress. In the meanwhile aio_write(ap) wrote something
+        to the pipe and the read request either has already been finished or
+        is able to read the requested byte.
+        Wait for the read request before returning from this function because
+        the return value and error code from the read syscall will be written
+        to the struct aiocb a, which lies on the stack of this function.
+        Otherwise the stack from subsequent function calls - e.g. _dl_fini -
+        will be corrupted, which can lead to undefined behaviour like a
+        segmentation fault.  */
+      const struct aiocb *l[1] = { &a };
+      TEMP_FAILURE_RETRY (aio_suspend(l, 1, NULL));
+    }
+
   return 0;
 }