emacs/lib/pthread_sigmask.c

93 lines
2.7 KiB
C
Raw Normal View History

/* POSIX compatible signal blocking for threads.
2024-01-02 01:47:10 +00:00
Copyright (C) 2011-2024 Free Software Foundation, Inc.
This file 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.
This file 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 this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#include <signal.h>
#include <errno.h>
Merge from gnulib, using build-aux to remove clutter. * m4/largefile.m4: New file, so that Emacs does not mess up when accessing files with large inode numbers in MacOS X 10.5 and later. * m4/nocrash.m4: New file, to avoid triggering background debugger and/or create core dumps during 'configure'. * build-aux/move-if-change: Renamed from move-if-change. * build-aux/snippet/arg-nonnull.h: Renamed from arg-nonnull.h. * build-aux/snippet/c++defs.h: Renamed from c++defs.h. * build-aux/snippet/warn-on-use.h: Renamed from warn-on-use.h. * build-aux/snippet/_Noreturn.h: New file, for draft C1X _Noreturn. * .bzrignore: The autogenerated files compile, config.guess, config.sub, depcomp, install-sh, and missing are now in build-aux. * Makefile.in (epaths-force, sync-from-gnulib): move-if-change is now in build-aux. (GNULIB_TOOL_FLAGS): Avoid threadlib; this is now a prerequisite of gnulib's pthread_sigmask module, but Emacs doesn't need it. (mkdir): install-sh is now in build-aux. * config.bat: c++defs.h is now in build-aux/snippets. * configure.in: Specify AC_CONFIG_AUX_DIR with build-aux (the usual parameter). * lib/gnulib.mk, m4/gl-comp.m4: Regenerate. * lib/makefile.w32-in (ARG_NONNULL_H): arg-nonnull.h moved to build-aux/snippet. * lib/pthread_sigmask.c, lib/stdlib.in.h, m4/extensions.m4: * m4/getopt.m4, m4/gnulib-common.m4, m4/pthread_sigmask.m4: Merge from gnuilib. This fixes porting bugs on Cygwin, Irix, and Solaris, enables MacOS extensions, and enables nocrash during 'configure'. * make-dist: Adjust to new build-aux and build-aux/snippit dirs. * admin/notes/copyright: The files compile, config.guess, config.sub, depcomp, install-sh, missing, and move-if-change are now in the new build-aux subdirectory. The files arg-nonnull.h, c++defs.h, and warn-on-use.h are now in build-aux/snippets. New file build-aux/snippets/_Noreturn.h. * leim/Makefile.in (install): install-sh is now in build-aux. * lib-src/Makefile.in ($(DESTDIR)${archlibdir}): install-sh moved to build-aux. * msdos/sedlibmk.inp (CONFIG_CLEAN_VPATH_FILES): Adjust to snippet moves from top level to build-aux/snippet. * src/Makefile.in (gl-stamp): move-if-change is now in build-aux.
2011-07-24 22:15:47 +00:00
#include <stddef.h>
#if PTHREAD_SIGMASK_INEFFECTIVE
# include <string.h>
#endif
Merge from gnulib, using build-aux to remove clutter. * m4/largefile.m4: New file, so that Emacs does not mess up when accessing files with large inode numbers in MacOS X 10.5 and later. * m4/nocrash.m4: New file, to avoid triggering background debugger and/or create core dumps during 'configure'. * build-aux/move-if-change: Renamed from move-if-change. * build-aux/snippet/arg-nonnull.h: Renamed from arg-nonnull.h. * build-aux/snippet/c++defs.h: Renamed from c++defs.h. * build-aux/snippet/warn-on-use.h: Renamed from warn-on-use.h. * build-aux/snippet/_Noreturn.h: New file, for draft C1X _Noreturn. * .bzrignore: The autogenerated files compile, config.guess, config.sub, depcomp, install-sh, and missing are now in build-aux. * Makefile.in (epaths-force, sync-from-gnulib): move-if-change is now in build-aux. (GNULIB_TOOL_FLAGS): Avoid threadlib; this is now a prerequisite of gnulib's pthread_sigmask module, but Emacs doesn't need it. (mkdir): install-sh is now in build-aux. * config.bat: c++defs.h is now in build-aux/snippets. * configure.in: Specify AC_CONFIG_AUX_DIR with build-aux (the usual parameter). * lib/gnulib.mk, m4/gl-comp.m4: Regenerate. * lib/makefile.w32-in (ARG_NONNULL_H): arg-nonnull.h moved to build-aux/snippet. * lib/pthread_sigmask.c, lib/stdlib.in.h, m4/extensions.m4: * m4/getopt.m4, m4/gnulib-common.m4, m4/pthread_sigmask.m4: Merge from gnuilib. This fixes porting bugs on Cygwin, Irix, and Solaris, enables MacOS extensions, and enables nocrash during 'configure'. * make-dist: Adjust to new build-aux and build-aux/snippit dirs. * admin/notes/copyright: The files compile, config.guess, config.sub, depcomp, install-sh, missing, and move-if-change are now in the new build-aux subdirectory. The files arg-nonnull.h, c++defs.h, and warn-on-use.h are now in build-aux/snippets. New file build-aux/snippets/_Noreturn.h. * leim/Makefile.in (install): install-sh is now in build-aux. * lib-src/Makefile.in ($(DESTDIR)${archlibdir}): install-sh moved to build-aux. * msdos/sedlibmk.inp (CONFIG_CLEAN_VPATH_FILES): Adjust to snippet moves from top level to build-aux/snippet. * src/Makefile.in (gl-stamp): move-if-change is now in build-aux.
2011-07-24 22:15:47 +00:00
#if PTHREAD_SIGMASK_UNBLOCK_BUG
# include <unistd.h>
#endif
int
pthread_sigmask (int how, const sigset_t *new_mask, sigset_t *old_mask)
Merge from gnulib, using build-aux to remove clutter. * m4/largefile.m4: New file, so that Emacs does not mess up when accessing files with large inode numbers in MacOS X 10.5 and later. * m4/nocrash.m4: New file, to avoid triggering background debugger and/or create core dumps during 'configure'. * build-aux/move-if-change: Renamed from move-if-change. * build-aux/snippet/arg-nonnull.h: Renamed from arg-nonnull.h. * build-aux/snippet/c++defs.h: Renamed from c++defs.h. * build-aux/snippet/warn-on-use.h: Renamed from warn-on-use.h. * build-aux/snippet/_Noreturn.h: New file, for draft C1X _Noreturn. * .bzrignore: The autogenerated files compile, config.guess, config.sub, depcomp, install-sh, and missing are now in build-aux. * Makefile.in (epaths-force, sync-from-gnulib): move-if-change is now in build-aux. (GNULIB_TOOL_FLAGS): Avoid threadlib; this is now a prerequisite of gnulib's pthread_sigmask module, but Emacs doesn't need it. (mkdir): install-sh is now in build-aux. * config.bat: c++defs.h is now in build-aux/snippets. * configure.in: Specify AC_CONFIG_AUX_DIR with build-aux (the usual parameter). * lib/gnulib.mk, m4/gl-comp.m4: Regenerate. * lib/makefile.w32-in (ARG_NONNULL_H): arg-nonnull.h moved to build-aux/snippet. * lib/pthread_sigmask.c, lib/stdlib.in.h, m4/extensions.m4: * m4/getopt.m4, m4/gnulib-common.m4, m4/pthread_sigmask.m4: Merge from gnuilib. This fixes porting bugs on Cygwin, Irix, and Solaris, enables MacOS extensions, and enables nocrash during 'configure'. * make-dist: Adjust to new build-aux and build-aux/snippit dirs. * admin/notes/copyright: The files compile, config.guess, config.sub, depcomp, install-sh, missing, and move-if-change are now in the new build-aux subdirectory. The files arg-nonnull.h, c++defs.h, and warn-on-use.h are now in build-aux/snippets. New file build-aux/snippets/_Noreturn.h. * leim/Makefile.in (install): install-sh is now in build-aux. * lib-src/Makefile.in ($(DESTDIR)${archlibdir}): install-sh moved to build-aux. * msdos/sedlibmk.inp (CONFIG_CLEAN_VPATH_FILES): Adjust to snippet moves from top level to build-aux/snippet. * src/Makefile.in (gl-stamp): move-if-change is now in build-aux.
2011-07-24 22:15:47 +00:00
#undef pthread_sigmask
{
Merge from gnulib, using build-aux to remove clutter. * m4/largefile.m4: New file, so that Emacs does not mess up when accessing files with large inode numbers in MacOS X 10.5 and later. * m4/nocrash.m4: New file, to avoid triggering background debugger and/or create core dumps during 'configure'. * build-aux/move-if-change: Renamed from move-if-change. * build-aux/snippet/arg-nonnull.h: Renamed from arg-nonnull.h. * build-aux/snippet/c++defs.h: Renamed from c++defs.h. * build-aux/snippet/warn-on-use.h: Renamed from warn-on-use.h. * build-aux/snippet/_Noreturn.h: New file, for draft C1X _Noreturn. * .bzrignore: The autogenerated files compile, config.guess, config.sub, depcomp, install-sh, and missing are now in build-aux. * Makefile.in (epaths-force, sync-from-gnulib): move-if-change is now in build-aux. (GNULIB_TOOL_FLAGS): Avoid threadlib; this is now a prerequisite of gnulib's pthread_sigmask module, but Emacs doesn't need it. (mkdir): install-sh is now in build-aux. * config.bat: c++defs.h is now in build-aux/snippets. * configure.in: Specify AC_CONFIG_AUX_DIR with build-aux (the usual parameter). * lib/gnulib.mk, m4/gl-comp.m4: Regenerate. * lib/makefile.w32-in (ARG_NONNULL_H): arg-nonnull.h moved to build-aux/snippet. * lib/pthread_sigmask.c, lib/stdlib.in.h, m4/extensions.m4: * m4/getopt.m4, m4/gnulib-common.m4, m4/pthread_sigmask.m4: Merge from gnuilib. This fixes porting bugs on Cygwin, Irix, and Solaris, enables MacOS extensions, and enables nocrash during 'configure'. * make-dist: Adjust to new build-aux and build-aux/snippit dirs. * admin/notes/copyright: The files compile, config.guess, config.sub, depcomp, install-sh, missing, and move-if-change are now in the new build-aux subdirectory. The files arg-nonnull.h, c++defs.h, and warn-on-use.h are now in build-aux/snippets. New file build-aux/snippets/_Noreturn.h. * leim/Makefile.in (install): install-sh is now in build-aux. * lib-src/Makefile.in ($(DESTDIR)${archlibdir}): install-sh moved to build-aux. * msdos/sedlibmk.inp (CONFIG_CLEAN_VPATH_FILES): Adjust to snippet moves from top level to build-aux/snippet. * src/Makefile.in (gl-stamp): move-if-change is now in build-aux.
2011-07-24 22:15:47 +00:00
#if HAVE_PTHREAD_SIGMASK
int ret;
# if PTHREAD_SIGMASK_INEFFECTIVE
sigset_t omask, omask_copy;
sigset_t *old_mask_ptr = &omask;
sigemptyset (&omask);
/* Add a signal unlikely to be blocked, so that OMASK_COPY
is unlikely to match the actual mask. */
sigaddset (&omask, SIGILL);
memcpy (&omask_copy, &omask, sizeof omask);
# else
sigset_t *old_mask_ptr = old_mask;
# endif
ret = pthread_sigmask (how, new_mask, old_mask_ptr);
Merge from gnulib, using build-aux to remove clutter. * m4/largefile.m4: New file, so that Emacs does not mess up when accessing files with large inode numbers in MacOS X 10.5 and later. * m4/nocrash.m4: New file, to avoid triggering background debugger and/or create core dumps during 'configure'. * build-aux/move-if-change: Renamed from move-if-change. * build-aux/snippet/arg-nonnull.h: Renamed from arg-nonnull.h. * build-aux/snippet/c++defs.h: Renamed from c++defs.h. * build-aux/snippet/warn-on-use.h: Renamed from warn-on-use.h. * build-aux/snippet/_Noreturn.h: New file, for draft C1X _Noreturn. * .bzrignore: The autogenerated files compile, config.guess, config.sub, depcomp, install-sh, and missing are now in build-aux. * Makefile.in (epaths-force, sync-from-gnulib): move-if-change is now in build-aux. (GNULIB_TOOL_FLAGS): Avoid threadlib; this is now a prerequisite of gnulib's pthread_sigmask module, but Emacs doesn't need it. (mkdir): install-sh is now in build-aux. * config.bat: c++defs.h is now in build-aux/snippets. * configure.in: Specify AC_CONFIG_AUX_DIR with build-aux (the usual parameter). * lib/gnulib.mk, m4/gl-comp.m4: Regenerate. * lib/makefile.w32-in (ARG_NONNULL_H): arg-nonnull.h moved to build-aux/snippet. * lib/pthread_sigmask.c, lib/stdlib.in.h, m4/extensions.m4: * m4/getopt.m4, m4/gnulib-common.m4, m4/pthread_sigmask.m4: Merge from gnuilib. This fixes porting bugs on Cygwin, Irix, and Solaris, enables MacOS extensions, and enables nocrash during 'configure'. * make-dist: Adjust to new build-aux and build-aux/snippit dirs. * admin/notes/copyright: The files compile, config.guess, config.sub, depcomp, install-sh, missing, and move-if-change are now in the new build-aux subdirectory. The files arg-nonnull.h, c++defs.h, and warn-on-use.h are now in build-aux/snippets. New file build-aux/snippets/_Noreturn.h. * leim/Makefile.in (install): install-sh is now in build-aux. * lib-src/Makefile.in ($(DESTDIR)${archlibdir}): install-sh moved to build-aux. * msdos/sedlibmk.inp (CONFIG_CLEAN_VPATH_FILES): Adjust to snippet moves from top level to build-aux/snippet. * src/Makefile.in (gl-stamp): move-if-change is now in build-aux.
2011-07-24 22:15:47 +00:00
# if PTHREAD_SIGMASK_INEFFECTIVE
if (ret == 0)
{
/* Detect whether pthread_sigmask is currently ineffective.
Don't cache the information: libpthread.so could be dynamically
loaded after the program started and after pthread_sigmask was
called for the first time. */
if (memcmp (&omask_copy, &omask, sizeof omask) == 0
&& pthread_sigmask (1729, &omask_copy, NULL) == 0)
Merge from gnulib, using build-aux to remove clutter. * m4/largefile.m4: New file, so that Emacs does not mess up when accessing files with large inode numbers in MacOS X 10.5 and later. * m4/nocrash.m4: New file, to avoid triggering background debugger and/or create core dumps during 'configure'. * build-aux/move-if-change: Renamed from move-if-change. * build-aux/snippet/arg-nonnull.h: Renamed from arg-nonnull.h. * build-aux/snippet/c++defs.h: Renamed from c++defs.h. * build-aux/snippet/warn-on-use.h: Renamed from warn-on-use.h. * build-aux/snippet/_Noreturn.h: New file, for draft C1X _Noreturn. * .bzrignore: The autogenerated files compile, config.guess, config.sub, depcomp, install-sh, and missing are now in build-aux. * Makefile.in (epaths-force, sync-from-gnulib): move-if-change is now in build-aux. (GNULIB_TOOL_FLAGS): Avoid threadlib; this is now a prerequisite of gnulib's pthread_sigmask module, but Emacs doesn't need it. (mkdir): install-sh is now in build-aux. * config.bat: c++defs.h is now in build-aux/snippets. * configure.in: Specify AC_CONFIG_AUX_DIR with build-aux (the usual parameter). * lib/gnulib.mk, m4/gl-comp.m4: Regenerate. * lib/makefile.w32-in (ARG_NONNULL_H): arg-nonnull.h moved to build-aux/snippet. * lib/pthread_sigmask.c, lib/stdlib.in.h, m4/extensions.m4: * m4/getopt.m4, m4/gnulib-common.m4, m4/pthread_sigmask.m4: Merge from gnuilib. This fixes porting bugs on Cygwin, Irix, and Solaris, enables MacOS extensions, and enables nocrash during 'configure'. * make-dist: Adjust to new build-aux and build-aux/snippit dirs. * admin/notes/copyright: The files compile, config.guess, config.sub, depcomp, install-sh, missing, and move-if-change are now in the new build-aux subdirectory. The files arg-nonnull.h, c++defs.h, and warn-on-use.h are now in build-aux/snippets. New file build-aux/snippets/_Noreturn.h. * leim/Makefile.in (install): install-sh is now in build-aux. * lib-src/Makefile.in ($(DESTDIR)${archlibdir}): install-sh moved to build-aux. * msdos/sedlibmk.inp (CONFIG_CLEAN_VPATH_FILES): Adjust to snippet moves from top level to build-aux/snippet. * src/Makefile.in (gl-stamp): move-if-change is now in build-aux.
2011-07-24 22:15:47 +00:00
{
/* pthread_sigmask is currently ineffective. The program is not
linked to -lpthread. So use sigprocmask instead. */
return (sigprocmask (how, new_mask, old_mask) < 0 ? errno : 0);
}
if (old_mask)
memcpy (old_mask, &omask, sizeof omask);
Merge from gnulib, using build-aux to remove clutter. * m4/largefile.m4: New file, so that Emacs does not mess up when accessing files with large inode numbers in MacOS X 10.5 and later. * m4/nocrash.m4: New file, to avoid triggering background debugger and/or create core dumps during 'configure'. * build-aux/move-if-change: Renamed from move-if-change. * build-aux/snippet/arg-nonnull.h: Renamed from arg-nonnull.h. * build-aux/snippet/c++defs.h: Renamed from c++defs.h. * build-aux/snippet/warn-on-use.h: Renamed from warn-on-use.h. * build-aux/snippet/_Noreturn.h: New file, for draft C1X _Noreturn. * .bzrignore: The autogenerated files compile, config.guess, config.sub, depcomp, install-sh, and missing are now in build-aux. * Makefile.in (epaths-force, sync-from-gnulib): move-if-change is now in build-aux. (GNULIB_TOOL_FLAGS): Avoid threadlib; this is now a prerequisite of gnulib's pthread_sigmask module, but Emacs doesn't need it. (mkdir): install-sh is now in build-aux. * config.bat: c++defs.h is now in build-aux/snippets. * configure.in: Specify AC_CONFIG_AUX_DIR with build-aux (the usual parameter). * lib/gnulib.mk, m4/gl-comp.m4: Regenerate. * lib/makefile.w32-in (ARG_NONNULL_H): arg-nonnull.h moved to build-aux/snippet. * lib/pthread_sigmask.c, lib/stdlib.in.h, m4/extensions.m4: * m4/getopt.m4, m4/gnulib-common.m4, m4/pthread_sigmask.m4: Merge from gnuilib. This fixes porting bugs on Cygwin, Irix, and Solaris, enables MacOS extensions, and enables nocrash during 'configure'. * make-dist: Adjust to new build-aux and build-aux/snippit dirs. * admin/notes/copyright: The files compile, config.guess, config.sub, depcomp, install-sh, missing, and move-if-change are now in the new build-aux subdirectory. The files arg-nonnull.h, c++defs.h, and warn-on-use.h are now in build-aux/snippets. New file build-aux/snippets/_Noreturn.h. * leim/Makefile.in (install): install-sh is now in build-aux. * lib-src/Makefile.in ($(DESTDIR)${archlibdir}): install-sh moved to build-aux. * msdos/sedlibmk.inp (CONFIG_CLEAN_VPATH_FILES): Adjust to snippet moves from top level to build-aux/snippet. * src/Makefile.in (gl-stamp): move-if-change is now in build-aux.
2011-07-24 22:15:47 +00:00
}
# endif
# if PTHREAD_SIGMASK_FAILS_WITH_ERRNO
if (ret == -1)
return errno;
# endif
# if PTHREAD_SIGMASK_UNBLOCK_BUG
if (ret == 0
&& new_mask != NULL
&& (how == SIG_UNBLOCK || how == SIG_SETMASK))
{
/* Give the OS the opportunity to raise signals that were pending before
the pthread_sigmask call and have now been unblocked. */
usleep (1);
}
# endif
return ret;
#else
int ret = sigprocmask (how, new_mask, old_mask);
return (ret < 0 ? errno : 0);
Merge from gnulib, using build-aux to remove clutter. * m4/largefile.m4: New file, so that Emacs does not mess up when accessing files with large inode numbers in MacOS X 10.5 and later. * m4/nocrash.m4: New file, to avoid triggering background debugger and/or create core dumps during 'configure'. * build-aux/move-if-change: Renamed from move-if-change. * build-aux/snippet/arg-nonnull.h: Renamed from arg-nonnull.h. * build-aux/snippet/c++defs.h: Renamed from c++defs.h. * build-aux/snippet/warn-on-use.h: Renamed from warn-on-use.h. * build-aux/snippet/_Noreturn.h: New file, for draft C1X _Noreturn. * .bzrignore: The autogenerated files compile, config.guess, config.sub, depcomp, install-sh, and missing are now in build-aux. * Makefile.in (epaths-force, sync-from-gnulib): move-if-change is now in build-aux. (GNULIB_TOOL_FLAGS): Avoid threadlib; this is now a prerequisite of gnulib's pthread_sigmask module, but Emacs doesn't need it. (mkdir): install-sh is now in build-aux. * config.bat: c++defs.h is now in build-aux/snippets. * configure.in: Specify AC_CONFIG_AUX_DIR with build-aux (the usual parameter). * lib/gnulib.mk, m4/gl-comp.m4: Regenerate. * lib/makefile.w32-in (ARG_NONNULL_H): arg-nonnull.h moved to build-aux/snippet. * lib/pthread_sigmask.c, lib/stdlib.in.h, m4/extensions.m4: * m4/getopt.m4, m4/gnulib-common.m4, m4/pthread_sigmask.m4: Merge from gnuilib. This fixes porting bugs on Cygwin, Irix, and Solaris, enables MacOS extensions, and enables nocrash during 'configure'. * make-dist: Adjust to new build-aux and build-aux/snippit dirs. * admin/notes/copyright: The files compile, config.guess, config.sub, depcomp, install-sh, missing, and move-if-change are now in the new build-aux subdirectory. The files arg-nonnull.h, c++defs.h, and warn-on-use.h are now in build-aux/snippets. New file build-aux/snippets/_Noreturn.h. * leim/Makefile.in (install): install-sh is now in build-aux. * lib-src/Makefile.in ($(DESTDIR)${archlibdir}): install-sh moved to build-aux. * msdos/sedlibmk.inp (CONFIG_CLEAN_VPATH_FILES): Adjust to snippet moves from top level to build-aux/snippet. * src/Makefile.in (gl-stamp): move-if-change is now in build-aux.
2011-07-24 22:15:47 +00:00
#endif
}