summaryrefslogtreecommitdiff
path: root/src/posix-lock.c
Commit message (Collapse)AuthorAgeFilesLines
* core: Fix support of posix-lock for FreeBSD.NIIBE Yutaka2022-03-281-1/+35
| | | | | | | | | | | | | | | * src/posix-lock.c [__FreeBSD__] (use_pthread_p): Use pthread_key_create to determine if it's linked to lpthread or not. -- This is from glthread_in_use in gnulib/lib/glthread/threadlib.c. On FreeBSD, pthread_key_create in there in libc (stub function) as well as -lpthread (real one), while pthread_create is not available in libc. Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
* posix-lock: Support GNU C library 2.34 or later.NIIBE Yutaka2021-08-061-2/+5
| | | | | | | | | | | * configure.ac: Add check for sys/single_threaded.h. * src/posix-lock.c [USE_POSIX_THREADS_FROM_LIBC]: Use __libc_single_threaded to detect if it's single threaded. -- GnuPG-bug-id: 5547 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
* core: New functions gpgrt_abort and gpgrt_add_emergency_cleanup.Werner Koch2019-01-041-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | * src/init.c (emergency_cleanup_list): New gloabl var. (_gpgrt_add_emergency_cleanup): New. (_gpgrt_abort): New. Repalce all calls to abort by this. Also replace all assert by either log_assert or a stderr output followed by a _gpgrt_abort. (run_emergency_cleanup): New. * src/visibility.c (gpgrt_add_emergency_cleanup): New public API. (gpgrt_abort): New public API. -- Libgcrypt uses its own assert function which makes sure to terminate the secure memory. This is safe as log as an assert is triggered internally in Libgcrypt. GnuPG runs emergency cleanup handlers right before log_fatal etc to tell Libgcrypt to terminate the secure memory. With the move of the logging function to gpgrt in gnupg 2.3 this did not anymore. Thus we now provide a mechanism in gpgrt to do right that. Eventually Libgcrypt can also make use of this. What this does not handle are calls to abort or failed asserts in external libraries or in libc. We can't do anything about it in a library because a library may not setup signal handlers. Signed-off-by: Werner Koch <wk@gnupg.org>
* core: Unify syscall_clamp functions.Werner Koch2017-11-291-29/+8
| | | | | | | | | | | | | | | * src/estream.c (_gpgrt_set_syscall_clamp) (_gpgrt_get_syscall_clamp): Move to ... * src/syscall-clamp.c: new file. (_gpgrt_pre_syscall, _gpgrt_post_syscall): New. * src/Makefile.am (libgpg_error_la_SOURCES): Add that file. * src/estream.c: Replace the syscall wrapper with the new functions. * src/posix-lock.c: Ditto. * src/w32-lock.c: Ditto. * src/posix-thread.c: Ditto. * src/w32-thread.c: Ditto. Signed-off-by: Werner Koch <wk@gnupg.org>
* Use the syscall clamp functions also for lock functionsWerner Koch2016-11-111-0/+22
| | | | | | | | | | | | | | | | | | | | * src/posix-lock.c (pre_lock_func, post_lock_func): New. (_gpgrt_lock_set_lock_clamp): New. (_gpgrt_lock_lock): Use clamp functions. * src/w32-lock.c (pre_lock_func, post_lock_func): New. (_gpgrt_lock_set_lock_clamp): New. (_gpgrt_lock_lock): Use clamp functions. * src/posix-lock.c (pre_syscall_func, post_syscall_func): New. (_gpgrt_thread_set_syscall_clamp): New. (_gpgrt_yield): Use clamp functions. * src/w32-lock.c (pre_syscall_func, post_syscall_func): New. (_gpgrt_thread_set_syscall_clamp): New. (_gpgrt_yield): Use clamp functions. * src/estream.c: Include lock.h and thread.h. (do_deinit): Call _gpgrt_lock_set_lock_clamp. (_gpgrt_set_syscall_clamp): Ditto. Signed-off-by: Werner Koch <wk@gnupg.org>
* Convert http links to https where possible in the source.Daniel Kahn Gillmor2016-02-081-1/+1
| | | | | | | | | | | | | | | | -- * use https for bug reporting * in comments and docs, use https to refer to: - www.gnu.org - creativecommons.org - translationproject.org - mail.gnome.org - www.perl.org - www.ctan.org - www.cl.cam.ac.uk - www.ntg.nl - cygwin.com - www.ethnologue.com
* Allow building with --disable-threads.Werner Koch2015-06-151-5/+5
| | | | | | | | | | | | | | | | | | | | * src/posix-lock-obj.h (LOCK_ABI_NOT_AVAILABLE): New. (LOCK_ABI_VERSION): Define depending on USE_POSIX_THREADS. (_gpgrt_lock_t) [!USE_POSIX_THREADS]: Do not define the union. * src/gen-posix-lock-obj.c: Take care of USE_POSIX_THREADS. * src/posix-lock.c (_gpgrt_lock_init, _gpgrt_lock_lock) (_gpgrt_lock_trylock, _gpgrt_lock_unlock) (_gpgrt_lock_destroy): Return success for a no-threads version. * tests/t-lock.c: Disable tests if threads are not available. * src/mkheader.c (main): Add NO-THREADS to the printed comment. * configure.ac: Show NO-TRHEADS in the final summary. -- Warning: Using --disable-threads creates a different ABI which we can't encode in the the cpu-vendor-os triplet. The run time checks should detect this and abort the process. Signed-off-by: Werner Koch <wk@gnupg.org>
* Use assert to print diagnosicts before calling abort.Werner Koch2015-03-241-4/+17
| | | | | | * src/posix-lock.c: Add assert calls. Signed-off-by: Werner Koch <wk@gnupg.org>
* Replace locking code in estream functions.Werner Koch2014-08-251-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | * src/posix-lock.c: Add weak program for pthread_mutex_trylock. (_gpgrt_lock_trylock): New. * src/w32-lock.c (_gpgrt_lock_init): Add missing return statement. (_gpgrt_lock_trylock): New. * src/visibility.c (gpgrt_set_syscall_clamp): New. (gpgrt_lock_trylock): New. (gpgrt_vsnprintf): Fix symbol name. * src/init.c (DllMain): Mark unused arg. * src/estream.c: Replace npth mutexes by our own locks. Replace yeild macro by _gpgrt_yield. (pre_syscall_func, post_syscall_func): New. (do_deinit): Clear both new vars. (es_func_fd_read, es_func_fd_write): Call pre and post syscall functions instead of the former SYSCALL macros. (es_func_w32_read, es_func_w32_write): Ditto. (es_func_fd_seek, es_func_w32_seek, es_func_fp_read) (es_func_fp_write, es_func_fp_seek, es_func_fp_destroy): Bracket syscalls with the pre- and post-syscall fucntions. (do_npth_read, do_npth_write): Remove. (_gpgrt_es_init): Remove call to mutex init. It is now statically initialized. (_gpgrt_set_syscall_clamp): New. (es_create): Destroy stream lock on error. (do_close): Destroy stream lock.
* Implement symbol visibility.Werner Koch2014-08-251-4/+4
| | | | | | | | | | | | | * configure.ac: New option --enable-ld-version-script. (GPGRT_USE_VISIBILITY): New ac_define. (HAVE_LD_VERSION_SCRIPT): New am_conditional. * src/gpg-error.vers: New. * src/gpgrt-int.h: New. * src/visibility.c, src/visibility.h: New. Lot of changes to symbold names. -- This is only doe for the old API. The estream API needs to be added.
* Allow using gpgrt_lock_init on an unitialized variable.Werner Koch2014-01-241-2/+14
| | | | | | | | | | | | | | | | | | | | | * src/posix-lock.c (gpgrt_lock_init): Detect unitialized lock var. * src/w32-lock.c (gpgrt_lock_init): Ditto. -- gpgrt_lock_init may be used for dynamically allocated locks. For example gpgrt_lock_t *lock = xcalloc (1, sizeof *lock); gpgrt_lock_init (lock); gpgrt_lock_lock (lock); foo (); gpgrt_lock_unlock (lock); gpgrt_lock_destroy (lock); free (lock); This patch actually allows for this. Signed-off-by: Werner Koch <wk@gnupg.org>
* Move version number first in the Posix lock-obj.Werner Koch2014-01-171-4/+4
| | | | | | | | | * src/posix-lock-obj.h (_gpgrt_lock_t): Swap VERS and MTX and put MTX into a union. * src/posix-lock.c (gpgrt_lock_lock): Adjust for this change. * src/gen-posix-lock-obj.c (main): Change output accordingly. Signed-off-by: Werner Koch <wk@gnupg.org>
* Add gpgrt_lock_ functions.Werner Koch2014-01-161-0/+213
* src/gpg-error.h.in (GPGRT_LOCK_DEFINE): New. (gpgrt_lock_init): New. (gpgrt_lock_lock): New. (gpgrt_lock_unlock): New. (gpgrt_lock_destroy): New. (gpgrt_yield): New. * src/gpg-error.def.in: Add new functions. * m4/lock.m4, m4/threadlib.m4: New. Taken from current gnulib. * configure.ac: Call gl_LOCK. Check size of pthread_mutex_t. Add LIBTHREAD to GPG_ERROR_CONFIG_LIBS. * src/err-codes.h.in (GPG_ERR_INV_LOCK_OBJ): New. * src/gen-posix-lock-obj.c: New. * src/gen-w32-lock-obj.c: New. * src/lock.h, src/thread.h: New. * src/posix-lock-obj.h, src/w32-lock-obj.h: New. * src/posix-lock.c, src/w32-lock.c: New. * src/posix-thread.c, src/w32-thread.c: * src/w32-lock-obj-pub.in: New. * src/mkheader.c (include_file): Support build time include files. (write_special): Add keyword "include:lock-obj". * src/Makefile.am: (posix-lock-obj-pub.in): New rule. (noinst_PROGRAMS): Add gen-*-lock-obj helpers. * tests/t-common.h: New. * tests/t-lock.c: New. * tests/Makefile.am (t_lock_LDADD): Add new test. -- This patch introduces the gpgrt_ functions which will be extended over time to provide a library of commonly used code in GnuPG and Libgcrypt. Having them in a library named libgpg-error is a misnomer but this way we can achieve a smooth upgrade path. In contrasts to other GnuPG libraries, the gpgrt_ functions return a simple gpg_err_code_t and not gpg_error_t. The rationale for this is that a source of error identifier does not make sense here; it is better to use the source of error identifier of the caller. This can easily be achieved in a component by wrapping these function in a gpg_error macro/inline. There is no cross-compiling support for Posix platforms; the gen-posix-lock-obj tool must be run on the target system. Note that the gen-w32-lock-obj tool is not needed at build time but was used to figure out ABI definitions for Windows. Signed-off-by: Werner Koch <wk@gnupg.org>