public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v3 1/4] support: Add xclone
@ 2020-12-23 16:36 Adhemerval Zanella
  2020-12-23 16:36 ` [PATCH v3 2/4] Linux: Add close_range Adhemerval Zanella
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Adhemerval Zanella @ 2020-12-23 16:36 UTC (permalink / raw)
  To: libc-alpha; +Cc: Florian Weimer

Changes from previous version:

  - Fixed typos and corrected one line file description.

--

It is a wrapper for Linux clone syscall, to simplify the call to the
use only the most common arguments and remove architecture specific
handling (such as ia64 different name and signature).
---
 support/Makefile |  1 +
 support/xclone.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
 support/xsched.h | 38 ++++++++++++++++++++++++++++++++++++
 3 files changed, 89 insertions(+)
 create mode 100644 support/xclone.c
 create mode 100644 support/xsched.h

diff --git a/support/Makefile b/support/Makefile
index 3198eb5022..aecd27316e 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -89,6 +89,7 @@ libsupport-routines = \
   xcalloc \
   xchroot \
   xclock_gettime \
+  xclone \
   xclose \
   xconnect \
   xcopy_file_range \
diff --git a/support/xclone.c b/support/xclone.c
new file mode 100644
index 0000000000..027b367ba1
--- /dev/null
+++ b/support/xclone.c
@@ -0,0 +1,50 @@
+/* Auxiliary functions to issue the clone syscall.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   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, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifdef __linux__
+# include <support/check.h>
+# include <stackinfo.h>  /* For _STACK_GROWS_{UP,DOWN}.  */
+# include <xsched.h>
+
+pid_t
+xclone (int (*fn) (void *arg), void *arg, void *stack, size_t stack_size,
+	int flags)
+{
+  pid_t r = -1;
+
+# ifdef __ia64__
+  extern int __clone2 (int (*fn) (void *arg), void *stack, size_t stack_size,
+		       int flags, void *arg, ...);
+  r = __clone2 (f, stack, stack_size, flags, arg, /* ptid */ NULL,
+		/* tls */ NULL, /* ctid  */ ctid);
+# else
+#  if _STACK_GROWS_DOWN
+  r = clone (fn, stack + stack_size, flags, arg, /* ptid */ NULL,
+	     /* tls */ NULL, /* ctid */  NULL);
+#  elif _STACK_GROWS_UP
+  r = clone (fn, stack, flags, arg, /* ptid */ NULL, /* tls */ NULL,
+	     &ctid);
+#  endif
+# endif
+
+  if (r < 0)
+    FAIL_EXIT1 ("clone: %m");
+
+  return r;
+}
+#endif
diff --git a/support/xsched.h b/support/xsched.h
new file mode 100644
index 0000000000..1b7ce7286f
--- /dev/null
+++ b/support/xsched.h
@@ -0,0 +1,38 @@
+/* Wrapper for sched.h functions.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   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, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef SUPPORT_XSCHED_H
+#define SUPPORT_XSCHED_H
+
+__BEGIN_DECLS
+
+#include <sched.h>
+#include <sys/types.h>
+
+#ifdef __linux__
+# define DEFINE_STACK(name, size) \
+  char name[size] __attribute__ ((aligned))
+
+pid_t
+xclone (int (*fn) (void *arg), void *arg, void *stack, size_t stack_size,
+	int flags);
+#endif
+
+__END_DECLS
+
+#endif
-- 
2.25.1


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

end of thread, other threads:[~2021-03-09 20:04 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-23 16:36 [PATCH v3 1/4] support: Add xclone Adhemerval Zanella
2020-12-23 16:36 ` [PATCH v3 2/4] Linux: Add close_range Adhemerval Zanella
2021-03-09  9:47   ` Florian Weimer
2021-03-09 10:02     ` Christian Brauner
2021-03-09 17:53     ` Adhemerval Zanella
2021-03-09 18:30       ` Florian Weimer
2020-12-23 16:36 ` [PATCH v3 3/4] io: Add closefrom [BZ #10353] Adhemerval Zanella
2021-03-09 10:23   ` Florian Weimer
2021-03-09 19:07     ` Adhemerval Zanella
2020-12-23 16:36 ` [PATCH v3 4/4] posix: Add posix_spawn_file_actions_closefrom Adhemerval Zanella
2021-03-09 10:45   ` Florian Weimer
2021-03-09 19:48     ` Adhemerval Zanella
2021-03-09 20:00       ` Florian Weimer
2021-03-09 20:04         ` Adhemerval Zanella
2021-03-09  9:19 ` [PATCH v3 1/4] support: Add xclone Florian Weimer
2021-03-09 16:17   ` Adhemerval Zanella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).