public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: libc-alpha@sourceware.org
Cc: Florian Weimer <fweimer@redhat.com>,
	Adhemerval Zanella <adhemerval.zanella@linaro.org>
Subject: [PATCH v5 0/5] Add an internal wrapper for clone, clone2 and clone3
Date: Sat, 15 May 2021 05:34:37 -0700	[thread overview]
Message-ID: <20210515123442.1432385-1-hjl.tools@gmail.com> (raw)

The clone3 system call provides a superset of the functionality of clone
and clone2.  It also provides a number of API improve ments, including
the ability to specify the size of the child's stack area which can be
used by kernel to compute the shadow stack size when allocating the
shadow stack.  Add:

extern int __clone_internal (struct clone_args *__cl_args,
			     int (*__func) (void *__arg), void *__arg);

to provide an abstract interface for clone, clone2 and clone3.

1. Add cast_to_pointer to cast an integer to void * pointer.
2. Simplify stack management for thread creation by passing both stack
base and size to create_thread.
3. Consolidate clone vs clone2 differences into a single file.
4. Use only __clone_internal to clone a thread.
5. Call __clone3 if HAVE_CLONE3_WAPPER is defined.  If __clone3 returns
-1 with ENOSYS, fall back to clone or clone2.
6. Enable the public clone3 wrapper in the future after it has been
added to all targets.

Tested with build-many-glibcs.py.

H.J. Lu (5):
  Add an internal wrapper for clone, clone2 and clone3
  nptl: Always pass stack size to create_thread
  GLIBC_PRIVATE: Export __clone_internal
  x86-64: Add the clone3 wrapper
  Add tests for __clone_internal

 include/clone_internal.h                      |  14 ++
 include/libc-pointer-arith.h                  |   3 +
 nptl/allocatestack.c                          |  59 +-------
 nptl/createthread.c                           |   3 +-
 nptl/pthread_create.c                         |  17 ++-
 sysdeps/unix/sysv/linux/Makefile              |  11 +-
 sysdeps/unix/sysv/linux/Versions              |   1 +
 sysdeps/unix/sysv/linux/clone-internal.c      |  97 ++++++++++++
 sysdeps/unix/sysv/linux/clone-offsets.sym     |   5 +
 sysdeps/unix/sysv/linux/clone3.c              |   1 +
 sysdeps/unix/sysv/linux/clone3.h              |  55 +++++++
 sysdeps/unix/sysv/linux/createthread.c        |  25 +--
 sysdeps/unix/sysv/linux/spawni.c              |  26 ++--
 .../sysv/linux/tst-align-clone-internal.c     |  91 +++++++++++
 sysdeps/unix/sysv/linux/tst-clone-internal.c  |  51 +++++++
 sysdeps/unix/sysv/linux/tst-clone2-internal.c | 142 ++++++++++++++++++
 sysdeps/unix/sysv/linux/tst-clone3-internal.c | 101 +++++++++++++
 .../unix/sysv/linux/tst-getpid1-internal.c    | 137 +++++++++++++++++
 sysdeps/unix/sysv/linux/x86_64/clone3.S       |  92 ++++++++++++
 sysdeps/unix/sysv/linux/x86_64/sysdep.h       |   2 +
 20 files changed, 841 insertions(+), 92 deletions(-)
 create mode 100644 include/clone_internal.h
 create mode 100644 sysdeps/unix/sysv/linux/clone-internal.c
 create mode 100644 sysdeps/unix/sysv/linux/clone-offsets.sym
 create mode 100644 sysdeps/unix/sysv/linux/clone3.c
 create mode 100644 sysdeps/unix/sysv/linux/clone3.h
 create mode 100644 sysdeps/unix/sysv/linux/tst-align-clone-internal.c
 create mode 100644 sysdeps/unix/sysv/linux/tst-clone-internal.c
 create mode 100644 sysdeps/unix/sysv/linux/tst-clone2-internal.c
 create mode 100644 sysdeps/unix/sysv/linux/tst-clone3-internal.c
 create mode 100644 sysdeps/unix/sysv/linux/tst-getpid1-internal.c
 create mode 100644 sysdeps/unix/sysv/linux/x86_64/clone3.S

-- 
2.31.1


             reply	other threads:[~2021-05-15 12:34 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-15 12:34 H.J. Lu [this message]
2021-05-15 12:34 ` [PATCH v5 1/5] " H.J. Lu
2021-05-20 14:46   ` Florian Weimer
2021-05-22  1:14     ` H.J. Lu
2021-05-15 12:34 ` [PATCH v5 2/5] nptl: Always pass stack size to create_thread H.J. Lu
2021-05-20 14:26   ` Florian Weimer
2021-05-15 12:34 ` [PATCH v5 3/5] GLIBC_PRIVATE: Export __clone_internal H.J. Lu
2021-05-17 13:54   ` Andreas Schwab
2021-05-20 14:24   ` Florian Weimer
2021-05-22  1:55     ` H.J. Lu
2021-05-15 12:34 ` [PATCH v5 4/5] x86-64: Add the clone3 wrapper H.J. Lu
2021-05-20 14:53   ` Florian Weimer
2021-05-22  1:38     ` H.J. Lu
2021-05-20 18:35   ` Noah Goldstein
2021-05-20 18:39     ` Noah Goldstein
2021-05-22  1:52       ` H.J. Lu
2021-05-15 12:34 ` [PATCH v5 5/5] Add tests for __clone_internal H.J. Lu
2021-05-20 15:08   ` Florian Weimer
2021-05-22  1:54     ` H.J. Lu
2021-05-22  3:50 [PATCH v5 0/5] Add an internal wrapper for clone, clone2 and clone3 H.J. Lu

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=20210515123442.1432385-1-hjl.tools@gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /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 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).