All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Stancek <jstancek@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 1/3] lib: add ltp_alloc_stack()
Date: Thu, 13 Jun 2019 09:23:59 +0200	[thread overview]
Message-ID: <adca7c08dbf20805da9b99a7fa03d498de70235d.1560410182.git.jstancek@redhat.com> (raw)

Meant to allocate stack with sufficient alignment for all arches.
Use it in lib/cloner.c instead of malloc().

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 include/tst_clone.h |  1 +
 lib/cloner.c        | 23 ++++++++++++++++++++---
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/include/tst_clone.h b/include/tst_clone.h
index 72145fabe7cd..786cee5d1209 100644
--- a/include/tst_clone.h
+++ b/include/tst_clone.h
@@ -33,6 +33,7 @@ int ltp_clone_malloc(unsigned long clone_flags, int (*fn)(void *arg),
 		void *arg, size_t stacksize);
 int ltp_clone_quick(unsigned long clone_flags, int (*fn)(void *arg),
 		void *arg);
+void *ltp_alloc_stack(size_t size);
 
 #define clone(...) (use_the_ltp_clone_functions__do_not_use_clone)
 
diff --git a/lib/cloner.c b/lib/cloner.c
index 63f223d2a150..cf37184aa22a 100644
--- a/lib/cloner.c
+++ b/lib/cloner.c
@@ -28,8 +28,7 @@
 #include <stdlib.h>
 #include <sched.h>
 #include <stdarg.h>
-#include "test.h"
-#include "config.h"
+#include "tst_clone.h"
 
 #undef clone			/* we want to use clone() */
 
@@ -118,6 +117,24 @@ int ltp_clone7(unsigned long flags, int (*fn)(void *arg), void *arg,
 }
 
 /*
+ * ltp_alloc_stack: allocate stack of size 'size', that is sufficiently
+ * aligned for all arches. User is responsible for freeing allocated
+ * memory.
+ * Returns pointer to new stack. On error, returns NULL with errno set.
+ */
+void *ltp_alloc_stack(size_t size)
+{
+	void *ret = NULL;
+	int err;
+
+	err = posix_memalign(&ret, 64, size);
+	if (err)
+		errno = err;
+
+	return ret;
+}
+
+/*
  * ltp_clone_malloc: also does the memory allocation for clone with a
  * caller-specified size.
  */
@@ -129,7 +146,7 @@ ltp_clone_malloc(unsigned long clone_flags, int (*fn) (void *arg), void *arg,
 	int ret;
 	int saved_errno;
 
-	stack = malloc(stack_size);
+	stack = ltp_alloc_stack(stack_size);
 	if (stack == NULL)
 		return -1;
 
-- 
1.8.3.1


             reply	other threads:[~2019-06-13  7:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-13  7:23 Jan Stancek [this message]
2019-06-13  7:24 ` [LTP] [PATCH v3 2/3] lib: rename ltp_clone_malloc to ltp_clone_alloc Jan Stancek
2019-06-13  8:55   ` Li Wang
2019-06-13 13:57     ` Cyril Hrubis
2019-06-14  2:46       ` Li Wang
2019-06-14 15:24         ` Cyril Hrubis
2019-06-13  7:24 ` [LTP] [PATCH v3 3/3] syscalls/ioctl_ns0[156]: align stack and wait for child Jan Stancek
2019-06-13  8:25   ` Li Wang
2019-06-13 10:16     ` Jan Stancek
2019-06-13 11:26       ` Li Wang
2019-06-13 14:17       ` Cyril Hrubis
2019-06-13 14:57         ` Jan Stancek
2019-06-13 15:14           ` Cyril Hrubis
2019-06-16  7:34             ` Jan Stancek
2019-06-17  8:50               ` Cyril Hrubis
2019-06-17 14:38                 ` Jan Stancek
2019-06-18 16:00                   ` Amir Goldstein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=adca7c08dbf20805da9b99a7fa03d498de70235d.1560410182.git.jstancek@redhat.com \
    --to=jstancek@redhat.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.