All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v3 1/3] lib: add ltp_alloc_stack()
@ 2019-06-13  7:23 Jan Stancek
  2019-06-13  7:24 ` [LTP] [PATCH v3 2/3] lib: rename ltp_clone_malloc to ltp_clone_alloc Jan Stancek
  2019-06-13  7:24 ` [LTP] [PATCH v3 3/3] syscalls/ioctl_ns0[156]: align stack and wait for child Jan Stancek
  0 siblings, 2 replies; 17+ messages in thread
From: Jan Stancek @ 2019-06-13  7:23 UTC (permalink / raw)
  To: ltp

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


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2019-06-18 16:00 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-13  7:23 [LTP] [PATCH v3 1/3] lib: add ltp_alloc_stack() Jan Stancek
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

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.