public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Convenience function for allocating (alternate signal) stacks
@ 2021-05-20 12:11 Florian Weimer
  2021-05-20 12:13 ` [PATCH 1/3] elf: Initialize GLRO (dl_minsigstacksize) after static dlopen Florian Weimer
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Florian Weimer @ 2021-05-20 12:11 UTC (permalink / raw)
  To: libc-alpha

This complements the _SC_MINSIGSTKSZ changes by wrapping the stack
allocation with its size computation in a helper function.  Guard pages
are also allocated.

If this is acceptable, I'll figure out a way to integrate this with
threads, so that applications can request an alternate signal stack on
thread creation that is automatically deallocated once the thread exits.

Thanks,
Florian

Florian Weimer (3):
  elf: Initialize GLRO (dl_minsigstacksize) after static dlopen
  Hurd: Define ARCH_MIN_GUARD_SIZE in internal <pthread.h>
  Misc: Add <sys/cstack.h> and the cstack_* family of functions

 NEWS                                          |   4 +
 elf/rtld_static_init.c                        |   2 +
 include/sys/cstack.h                          |  39 ++++++
 manual/memory.texi                            |  99 ++++++++++++++
 manual/signal.texi                            |   3 +
 misc/Makefile                                 |   8 +-
 misc/Versions                                 |   5 +
 misc/cstack_allocate.c                        | 125 ++++++++++++++++++
 misc/cstack_free.c                            |  30 +++++
 misc/cstack_get.c                             |  27 ++++
 misc/sys/cstack.h                             |  53 ++++++++
 misc/tst-cstack.c                             | 118 +++++++++++++++++
 sysdeps/htl/include/pthread.h                 |   3 +
 sysdeps/mach/hurd/i386/libc.abilist           |   3 +
 sysdeps/unix/sysv/linux/aarch64/libc.abilist  |   3 +
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |   3 +
 sysdeps/unix/sysv/linux/arc/libc.abilist      |   3 +
 sysdeps/unix/sysv/linux/arm/be/libc.abilist   |   3 +
 sysdeps/unix/sysv/linux/arm/le/libc.abilist   |   3 +
 sysdeps/unix/sysv/linux/csky/libc.abilist     |   3 +
 sysdeps/unix/sysv/linux/hppa/libc.abilist     |   3 +
 sysdeps/unix/sysv/linux/i386/libc.abilist     |   3 +
 sysdeps/unix/sysv/linux/ia64/libc.abilist     |   3 +
 .../sysv/linux/m68k/coldfire/libc.abilist     |   3 +
 .../unix/sysv/linux/m68k/m680x0/libc.abilist  |   3 +
 .../sysv/linux/microblaze/be/libc.abilist     |   3 +
 .../sysv/linux/microblaze/le/libc.abilist     |   3 +
 .../sysv/linux/mips/mips32/fpu/libc.abilist   |   3 +
 .../sysv/linux/mips/mips32/nofpu/libc.abilist |   3 +
 .../sysv/linux/mips/mips64/n32/libc.abilist   |   3 +
 .../sysv/linux/mips/mips64/n64/libc.abilist   |   3 +
 sysdeps/unix/sysv/linux/nios2/libc.abilist    |   3 +
 .../linux/powerpc/powerpc32/fpu/libc.abilist  |   3 +
 .../powerpc/powerpc32/nofpu/libc.abilist      |   3 +
 .../linux/powerpc/powerpc64/be/libc.abilist   |   3 +
 .../linux/powerpc/powerpc64/le/libc.abilist   |   3 +
 .../unix/sysv/linux/riscv/rv32/libc.abilist   |   3 +
 .../unix/sysv/linux/riscv/rv64/libc.abilist   |   3 +
 .../unix/sysv/linux/s390/s390-32/libc.abilist |   3 +
 .../unix/sysv/linux/s390/s390-64/libc.abilist |   3 +
 sysdeps/unix/sysv/linux/sh/be/libc.abilist    |   3 +
 sysdeps/unix/sysv/linux/sh/le/libc.abilist    |   3 +
 .../sysv/linux/sparc/sparc32/libc.abilist     |   3 +
 .../sysv/linux/sparc/sparc64/libc.abilist     |   3 +
 .../unix/sysv/linux/x86_64/64/libc.abilist    |   3 +
 .../unix/sysv/linux/x86_64/x32/libc.abilist   |   3 +
 46 files changed, 612 insertions(+), 3 deletions(-)
 create mode 100644 include/sys/cstack.h
 create mode 100644 misc/cstack_allocate.c
 create mode 100644 misc/cstack_free.c
 create mode 100644 misc/cstack_get.c
 create mode 100644 misc/sys/cstack.h
 create mode 100644 misc/tst-cstack.c

-- 
2.31.1


^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: [PATCH 3/3] Misc: Add <sys/cstack.h> and the cstack_* family of functions
@ 2021-05-24 14:58 Bruno Haible
  2021-05-24 15:28 ` Bruno Haible
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Bruno Haible @ 2021-05-24 14:58 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha

[-- Attachment #1: Type: text/plain, Size: 2182 bytes --]

In reply to <https://sourceware.org/pipermail/libc-alpha/2021-May/126608.html>:

> These functions are expected to be used with sigaltstack and
> coroutines.

What is the added value of these functions, compared to what existing
programs already do?

I did a small survey of how a couple of single-threaded programs allocate
their alternate stack:
  - The majority allocate it statically.
  - Some use malloc().
  - Some use mmap().
  - Some use alloca(), i.e. a portion of the already-allocated stack in
    the program's main() function.
The size that these programs use are:
  - some use SIGSTKSZ,
  - some use 16 KiB,
  - some use 64 KiB.

We know that 16 KiB is too small on some platforms, and that a static
allocation of SIGSTKSZ bytes leads to a compilation error now.

Therefore the implemented added value is:

  * The ability to use SIGSTKSZ without a compilation error.

Other added value that would be useful in some cases are:

  * The ability to have a guard page at the stack top.
    This is half implemented. IMO an mprotect (.., top_guard_size, PROT_NONE)
    is missing after the __mmap call.

  * The ability to have a guard page at the stack bottom.
    This too is half implemented. IMO an mprotect (.., bottom_guard_size, PROT_NONE)
    is missing after the __mmap call.

  * A verification that the allocated size is not larger than
    getrlimit(RLIMIT_STACK). If the system or the user has set a maximum
    stack size of, say, 8 MB, should the program be able to allocate a
    stack of 1 GB size, in this way?

  * Support for GCC nested functions, when they need an executable stack.
    GCC, binutils, and glibc/nptl/allocatestack.c go to great lengths to
    support this, even from dynamically loaded shared libraries. (See the
    attached test cases.) It is poor if this facility does not support it.

  * Automatic deallocation when the current thread exits.
    In those cases where a thread allocated a cstack_t for its own use,
    it is welcome if it can say "clean it up automatically when the thread
    exits". Otherwise some programmers will still prefer the "use alloca()"
    approach, which has this automatic cleanup property.

Bruno

[-- Attachment #2: nested-functions.tar.gz --]
[-- Type: application/x-compressed-tar, Size: 1302 bytes --]

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

end of thread, other threads:[~2021-05-25 12:29 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20 12:11 [PATCH 0/3] Convenience function for allocating (alternate signal) stacks Florian Weimer
2021-05-20 12:13 ` [PATCH 1/3] elf: Initialize GLRO (dl_minsigstacksize) after static dlopen Florian Weimer
2021-05-20 14:40   ` H.J. Lu
2021-05-20 12:13 ` [PATCH 2/3] Hurd: Define ARCH_MIN_GUARD_SIZE in internal <pthread.h> Florian Weimer
2021-05-20 14:41   ` H.J. Lu
2021-05-20 12:13 ` [PATCH 3/3] Misc: Add <sys/cstack.h> and the cstack_* family of functions Florian Weimer
2021-05-20 12:21   ` Florian Weimer
2021-05-20 12:50   ` Andreas Schwab
2021-05-20 13:14     ` Florian Weimer
2021-05-24 14:58 Bruno Haible
2021-05-24 15:28 ` Bruno Haible
2021-05-25  7:42   ` Florian Weimer
2021-05-24 19:11 ` Adhemerval Zanella
2021-05-24 23:41   ` Paul Eggert
2021-05-25  7:40     ` Florian Weimer
2021-05-25 12:17       ` Adhemerval Zanella
2021-05-25 12:23         ` Florian Weimer
2021-05-25 12:25           ` Adhemerval Zanella
2021-05-25 12:29     ` Adhemerval Zanella
2021-05-25  8:41 ` Florian Weimer

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).