This is a follow-up to commit 36acdc59f895 ("Override glibc's printf for
vcore context").Using a #define for printf turned into a mess. This approach accomplishes the same goals (printf can be safely called from vcore context), but without preprocessor magic. Rebuild glibc. Signed-off-by: Barret Rhoden <[email protected]> --- .../glibc-2.19-akaros/sysdeps/akaros/Versions | 2 + .../sysdeps/akaros/parlib-compat.c | 24 ++++++++--- .../glibc-2.19-akaros/sysdeps/akaros/printf.c | 46 ++++++++++++++++++++++ user/parlib/include/stdio.h | 10 ++--- 4 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/printf.c diff --git a/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/Versions b/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/Versions index e9912691eddc..d2b3cc386de7 100644 --- a/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/Versions +++ b/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/Versions @@ -56,7 +56,9 @@ libc { eventfd_write; # Weak symbols in parlib-compat.c + __vcore_context; akaros_printf; + akaros_vprintf; print_user_context; _assert_failed; } diff --git a/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/parlib-compat.c b/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/parlib-compat.c index 881e6e2c8b66..b84efa7aea3d 100644 --- a/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/parlib-compat.c +++ b/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/parlib-compat.c @@ -6,13 +6,18 @@ #include <libc-symbols.h> #include <parlib/stdio.h> #include <parlib/assert.h> +#include <stdbool.h> -/* Here we define functions that are really defined in parlib, but we need - * them in libc in order to link it. We weak alias them here so that the - * parlib definitions will override them later. Unfortunately, this trick - * only works so long as we leave parlib as a static library. If we ever - * decide to make parlib a .so, then we will have to revisit this and use - * function pointers at runtime or something similar. */ +/* Here we define functions and variables that are really defined in parlib, but + * we need them in libc in order to link it. We weak alias them here so that the + * parlib definitions will override them later. + * + * Unfortunately, this trick only works so long as we leave parlib as a static + * library. If we ever decide to make parlib a .so, then we will have to revisit + * this and use function pointers at runtime or something similar. */ + +__thread bool __weak_vcore_context = FALSE; +weak_alias(__weak_vcore_context, __vcore_context); int __akaros_printf(const char *format, ...) { @@ -21,6 +26,13 @@ int __akaros_printf(const char *format, ...) } weak_alias(__akaros_printf, akaros_printf) +int __akaros_vprintf(const char *fmt, va_list ap) +{ + assert(0); + return -1; +} +weak_alias(__akaros_vprintf, akaros_vprintf) + void __print_user_context(struct user_context *ctx) { assert(0); diff --git a/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/printf.c b/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/printf.c new file mode 100644 index 000000000000..20598c639067 --- /dev/null +++ b/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/printf.c @@ -0,0 +1,46 @@ +/* Copyright (C) 1991-2014 Free Software Foundation, Inc. + * This file is part of the GNU C Library. + * + * The GNU C Library 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. + + * The GNU C Library 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 the GNU C Library; if not, see + * <http://www.gnu.org/licenses/>. */ + +#include <libioP.h> +#include <stdarg.h> +#include <stdio.h> + +#include <parlib/stdio.h> +#include <parlib/vcore.h> + +#undef printf + +/* Write formatted output to stdout from the format string FORMAT. */ +/* VARARGS1 */ +int __printf(const char *format, ...) +{ + va_list ap; + int ret; + + va_start(ap, format); + if (in_vcore_context()) + ret = akaros_vprintf(format, ap); + else + ret = vfprintf(stdout, format, ap); + va_end(ap); + return ret; +} + +#undef _IO_printf +ldbl_strong_alias(__printf, printf); +/* This is for libg++. */ +ldbl_strong_alias(__printf, _IO_printf); diff --git a/user/parlib/include/stdio.h b/user/parlib/include/stdio.h index e752bc247fd0..0c5ddabdab14 100644 --- a/user/parlib/include/stdio.h +++ b/user/parlib/include/stdio.h @@ -18,6 +18,10 @@ __BEGIN_DECLS void akaros_vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt, va_list); int akaros_vprintf(const char *fmt, va_list); +/* This is the same as our sysdep for glibc's printf. We use this to print in + * a few places in glibc that can't link directly against printf. (the + * 'multiple libcs' problem). */ +int akaros_printf(const char *format, ...); #ifdef PRINTD_DEBUG #define printd(args...) printf(args) @@ -25,10 +29,4 @@ int akaros_vprintf(const char *fmt, va_list); #define printd(args...) {} #endif -/* Override glibc's printf; ours will be safe from VC context, and uses glibc's - * otherwise. */ -int akaros_printf(const char *format, ...); -#undef printf -#define printf(args...) akaros_printf(args) - __END_DECLS -- 2.6.0.rc2.230.g3dd15c0 -- You received this message because you are subscribed to the Google Groups "Akaros" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/d/optout.
