summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2016-05-07 19:05:21 +0000
committerguenther <guenther@openbsd.org>2016-05-07 19:05:21 +0000
commitfe38b55cb0aae270de3f844146814682e8cd345c (patch)
tree9825cc8aa96314e8e79ea1802ccbc9349772680b /lib/libc/stdio
parentImplement ACPI 5.0 GeneralPurposeIo OpRegion support. This basically allows (diff)
downloadwireguard-openbsd-fe38b55cb0aae270de3f844146814682e8cd345c.tar.xz
wireguard-openbsd-fe38b55cb0aae270de3f844146814682e8cd345c.zip
Use a Thread Information Block in both single and multi-threaded programs.
This stores errno, the cancelation flags, and related bits for each thread and is allocated by ld.so or libc.a. This is an ABI break from 5.9-stable! Make libpthread dlopen'able by moving the cancelation wrappers into libc and doing locking and fork/errno handling via callbacks that libpthread registers when it first initializes. 'errno' *must* be declared via <errno.h> now! Clean up libpthread's symbol exports like libc. On powerpc, offset the TIB/TCB/TLS data from the register per the ELF spec. Testing by various, particularly sthen@ and patrick@ ok kettenis@
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r--lib/libc/stdio/flockfile.c36
-rw-r--r--lib/libc/stdio/local.h15
2 files changed, 24 insertions, 27 deletions
diff --git a/lib/libc/stdio/flockfile.c b/lib/libc/stdio/flockfile.c
index 5ffcae57609..88d90b8e4b1 100644
--- a/lib/libc/stdio/flockfile.c
+++ b/lib/libc/stdio/flockfile.c
@@ -1,41 +1,29 @@
-/* $OpenBSD: flockfile.c,v 1.8 2012/09/01 01:08:16 fgsch Exp $ */
+/* $OpenBSD: flockfile.c,v 1.9 2016/05/07 19:05:22 guenther Exp $ */
-#include <sys/time.h>
#include <stdio.h>
-#include "thread_private.h"
-
-/*
- * Subroutine versions of the macros in <stdio.h>
- * Note that these are all no-ops because libc does not do threads.
- * Strong implementation of file locking in librthread/rthread_file.c
- */
-
-#undef flockfile
-#undef ftrylockfile
-#undef funlockfile
-
-WEAK_PROTOTYPE(flockfile);
-WEAK_PROTOTYPE(ftrylockfile);
-WEAK_PROTOTYPE(funlockfile);
-
-WEAK_ALIAS(flockfile);
-WEAK_ALIAS(ftrylockfile);
-WEAK_ALIAS(funlockfile);
+#include "local.h"
void
-WEAK_NAME(flockfile)(FILE * fp)
+flockfile(FILE *fp)
{
+ FLOCKFILE(fp);
}
+DEF_WEAK(flockfile);
int
-WEAK_NAME(ftrylockfile)(FILE *fp)
+ftrylockfile(FILE *fp)
{
+ if (_thread_cb.tc_ftrylockfile != NULL)
+ return (_thread_cb.tc_ftrylockfile(fp));
return 0;
}
+DEF_WEAK(ftrylockfile);
void
-WEAK_NAME(funlockfile)(FILE * fp)
+funlockfile(FILE *fp)
{
+ FUNLOCKFILE(fp);
}
+DEF_WEAK(funlockfile);
diff --git a/lib/libc/stdio/local.h b/lib/libc/stdio/local.h
index 94b2804ff18..ad888b0fd50 100644
--- a/lib/libc/stdio/local.h
+++ b/lib/libc/stdio/local.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: local.h,v 1.23 2015/10/25 18:01:24 guenther Exp $ */
+/* $OpenBSD: local.h,v 1.24 2016/05/07 19:05:22 guenther Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -40,6 +40,7 @@
#include <wchar.h>
#include "wcio.h"
#include "fileext.h"
+#include "thread_private.h"
void _cleanup(void);
int _fwalk(int (*)(FILE *));
@@ -96,5 +97,13 @@ __END_HIDDEN_DECLS
(fp)->_lb._base = NULL; \
}
-#define FLOCKFILE(fp) do { if (__isthreaded) flockfile(fp); } while (0)
-#define FUNLOCKFILE(fp) do { if (__isthreaded) funlockfile(fp); } while (0)
+#define FLOCKFILE(fp) \
+ do { \
+ if (_thread_cb.tc_flockfile != NULL) \
+ _thread_cb.tc_flockfile(fp); \
+ } while (0)
+#define FUNLOCKFILE(fp) \
+ do { \
+ if (_thread_cb.tc_funlockfile != NULL) \
+ _thread_cb.tc_funlockfile(fp); \
+ } while (0)