[Xenomai-git] Gilles Chanteperdrix : lib/cobalt: allow compiling applications with _FORTIFY_SOURCE

2013-06-21 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 2793e2ee4767966406eead401d984595d1ebb17d
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=2793e2ee4767966406eead401d984595d1ebb17d

Author: Gilles Chanteperdrix 
Date:   Tue Apr 16 01:12:27 2013 +0200

lib/cobalt: allow compiling applications with _FORTIFY_SOURCE

When _FORTIFY_SOURCE is set, some services are replaced at compilation
time with versions performing additional checks on their
arguments. This is a problem if the same services need to be wrapped
by Xenomai: the checked versions are not wrapped, causing switches to
secondary mode.

This commit provides wrappers for the checked services.

The wrappers simply call the non checked version wrapper: calling
glibc checked services directly would break compilation with libcs
without this option, meaning old glibcs and alternative libcs.

In order to enable the checks provided by _FORTIFY_SOURCE, the Xenomai
binaries should be compiled with this option.

We attempt to auto-detect whether the underlying *libc supports
_FORTIFY_SOURCE at configuration time. --enable-fortify is introduced
to enable or disable the corresponding support in Xenomai libs.

If the support is enabled, checked versions of the Cobalt services are
redirected to checked versions of the *libc services. Otherwise, if a
checked version of a Cobalt service ends up being called, a fatal
error is raised.

---

 configure.in   |   19 +
 include/cobalt/stdio.h |6 ++
 include/cobalt/syslog.h|7 ++
 include/rtdk.h |5 ++
 lib/cobalt/cobalt.wrappers |6 ++
 lib/cobalt/printf.c|  170 +---
 lib/cobalt/wrappers.c  |   18 +
 7 files changed, 205 insertions(+), 26 deletions(-)

diff --git a/configure.in b/configure.in
index 10cf78d..0786039 100644
--- a/configure.in
+++ b/configure.in
@@ -745,6 +745,25 @@ dnl in-tree executables which require POSIX symbol 
wrapping.
AC_CONFIG_LINKS([lib/include/$base/xenomai:$srcdir/include/$base])
 fi
 
+unset want_fortify
+AC_MSG_CHECKING(for fortify support)
+AC_ARG_ENABLE([fortify], 
+ AC_HELP_STRING([--enable-fortify],
+[Enable support for applications compiled
+with _FORTIFY_SOURCE]),
+ [case "$enableval" in
+  y | yes) want_fortify=yes;;
+ *) want_fortify=no;;
+ esac])
+AC_MSG_RESULT(${want_fortify:-autodetect})
+if test x"$want_fortify" != xno; then
+   AC_CHECK_FUNC(__vfprintf_chk,
+ [AC_DEFINE(CONFIG_XENO_FORTIFY, 1 ,[config])],
+ [if test x"$want_fortify" = "xyes"; then
+ AC_MSG_ERROR([Fortify support enabled but not available in *libc])
+  fi])
+fi
+
 dnl
 dnl Build the Makefiles
 dnl
diff --git a/include/cobalt/stdio.h b/include/cobalt/stdio.h
index 4a88778..9f3fd4d 100644
--- a/include/cobalt/stdio.h
+++ b/include/cobalt/stdio.h
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 #ifdef __cplusplus
@@ -15,6 +16,11 @@ extern "C" {
 
 COBALT_DECL(int, vfprintf(FILE *stream, const char *fmt, va_list args));
 
+#ifdef CONFIG_XENO_FORTIFY
+COBALT_DECL(int, __vfprintf_chk(FILE *stream, int level,
+   const char *fmt, va_list ap));
+#endif
+
 COBALT_DECL(int, vprintf(const char *fmt, va_list args));
 
 COBALT_DECL(int, fprintf(FILE *stream, const char *fmt, ...));
diff --git a/include/cobalt/syslog.h b/include/cobalt/syslog.h
index d446f45..701ec22 100644
--- a/include/cobalt/syslog.h
+++ b/include/cobalt/syslog.h
@@ -3,6 +3,7 @@
 
 #include 
 #include_next 
+#include 
 #include 
 
 #ifdef __cplusplus
@@ -13,6 +14,12 @@ COBALT_DECL(void, syslog(int priority, const char *fmt, 
...));
 
 COBALT_DECL(void, vsyslog(int priority,
  const char *fmt, va_list ap));
+
+#ifdef CONFIG_XENO_FORTIFY
+COBALT_DECL(void, __vsyslog_chk(int priority, int level,
+   const char *fmt, va_list ap));
+#endif
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/include/rtdk.h b/include/rtdk.h
index 1b5f218..ecebbff 100644
--- a/include/rtdk.h
+++ b/include/rtdk.h
@@ -43,6 +43,7 @@ static inline const char *rt_print_buffer_name(void)
 
 #include 
 #include 
+#include 
 
 #ifdef __cplusplus
 extern "C" {
@@ -65,6 +66,10 @@ void rt_print_cleanup(void);
 void rt_print_auto_init(int enable);
 const char *rt_print_buffer_name(void);
 void rt_print_flush_buffers(void);
+#ifdef CONFIG_XENO_FORTIFY
+int __rt_vfprintf_chk(FILE *stream, int level, const char *fmt, va_list args);
+void __rt_vsyslog_chk(int priority, int level, const char *fmt, va_list args);
+#endif
 
 void assert_nrt(void);
 
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index 4ed9188..3d5d16b 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -98,3 +98,9 @@
 --wrap malloc
 --wrap free
 --wrap gettimeofday
+--wrap __vfprintf_chk
+--wrap __vprintf_chk

[Xenomai-git] Gilles Chanteperdrix : lib/cobalt: allow compiling applications with _FORTIFY_SOURCE

2013-06-21 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 2793e2ee4767966406eead401d984595d1ebb17d
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=2793e2ee4767966406eead401d984595d1ebb17d

Author: Gilles Chanteperdrix 
Date:   Tue Apr 16 01:12:27 2013 +0200

lib/cobalt: allow compiling applications with _FORTIFY_SOURCE

When _FORTIFY_SOURCE is set, some services are replaced at compilation
time with versions performing additional checks on their
arguments. This is a problem if the same services need to be wrapped
by Xenomai: the checked versions are not wrapped, causing switches to
secondary mode.

This commit provides wrappers for the checked services.

The wrappers simply call the non checked version wrapper: calling
glibc checked services directly would break compilation with libcs
without this option, meaning old glibcs and alternative libcs.

In order to enable the checks provided by _FORTIFY_SOURCE, the Xenomai
binaries should be compiled with this option.

We attempt to auto-detect whether the underlying *libc supports
_FORTIFY_SOURCE at configuration time. --enable-fortify is introduced
to enable or disable the corresponding support in Xenomai libs.

If the support is enabled, checked versions of the Cobalt services are
redirected to checked versions of the *libc services. Otherwise, if a
checked version of a Cobalt service ends up being called, a fatal
error is raised.

---

 configure.in   |   19 +
 include/cobalt/stdio.h |6 ++
 include/cobalt/syslog.h|7 ++
 include/rtdk.h |5 ++
 lib/cobalt/cobalt.wrappers |6 ++
 lib/cobalt/printf.c|  170 +---
 lib/cobalt/wrappers.c  |   18 +
 7 files changed, 205 insertions(+), 26 deletions(-)

diff --git a/configure.in b/configure.in
index 10cf78d..0786039 100644
--- a/configure.in
+++ b/configure.in
@@ -745,6 +745,25 @@ dnl in-tree executables which require POSIX symbol 
wrapping.
AC_CONFIG_LINKS([lib/include/$base/xenomai:$srcdir/include/$base])
 fi
 
+unset want_fortify
+AC_MSG_CHECKING(for fortify support)
+AC_ARG_ENABLE([fortify], 
+ AC_HELP_STRING([--enable-fortify],
+[Enable support for applications compiled
+with _FORTIFY_SOURCE]),
+ [case "$enableval" in
+  y | yes) want_fortify=yes;;
+ *) want_fortify=no;;
+ esac])
+AC_MSG_RESULT(${want_fortify:-autodetect})
+if test x"$want_fortify" != xno; then
+   AC_CHECK_FUNC(__vfprintf_chk,
+ [AC_DEFINE(CONFIG_XENO_FORTIFY, 1 ,[config])],
+ [if test x"$want_fortify" = "xyes"; then
+ AC_MSG_ERROR([Fortify support enabled but not available in *libc])
+  fi])
+fi
+
 dnl
 dnl Build the Makefiles
 dnl
diff --git a/include/cobalt/stdio.h b/include/cobalt/stdio.h
index 4a88778..9f3fd4d 100644
--- a/include/cobalt/stdio.h
+++ b/include/cobalt/stdio.h
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 #ifdef __cplusplus
@@ -15,6 +16,11 @@ extern "C" {
 
 COBALT_DECL(int, vfprintf(FILE *stream, const char *fmt, va_list args));
 
+#ifdef CONFIG_XENO_FORTIFY
+COBALT_DECL(int, __vfprintf_chk(FILE *stream, int level,
+   const char *fmt, va_list ap));
+#endif
+
 COBALT_DECL(int, vprintf(const char *fmt, va_list args));
 
 COBALT_DECL(int, fprintf(FILE *stream, const char *fmt, ...));
diff --git a/include/cobalt/syslog.h b/include/cobalt/syslog.h
index d446f45..701ec22 100644
--- a/include/cobalt/syslog.h
+++ b/include/cobalt/syslog.h
@@ -3,6 +3,7 @@
 
 #include 
 #include_next 
+#include 
 #include 
 
 #ifdef __cplusplus
@@ -13,6 +14,12 @@ COBALT_DECL(void, syslog(int priority, const char *fmt, 
...));
 
 COBALT_DECL(void, vsyslog(int priority,
  const char *fmt, va_list ap));
+
+#ifdef CONFIG_XENO_FORTIFY
+COBALT_DECL(void, __vsyslog_chk(int priority, int level,
+   const char *fmt, va_list ap));
+#endif
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/include/rtdk.h b/include/rtdk.h
index 1b5f218..ecebbff 100644
--- a/include/rtdk.h
+++ b/include/rtdk.h
@@ -43,6 +43,7 @@ static inline const char *rt_print_buffer_name(void)
 
 #include 
 #include 
+#include 
 
 #ifdef __cplusplus
 extern "C" {
@@ -65,6 +66,10 @@ void rt_print_cleanup(void);
 void rt_print_auto_init(int enable);
 const char *rt_print_buffer_name(void);
 void rt_print_flush_buffers(void);
+#ifdef CONFIG_XENO_FORTIFY
+int __rt_vfprintf_chk(FILE *stream, int level, const char *fmt, va_list args);
+void __rt_vsyslog_chk(int priority, int level, const char *fmt, va_list args);
+#endif
 
 void assert_nrt(void);
 
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index 4ed9188..3d5d16b 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -98,3 +98,9 @@
 --wrap malloc
 --wrap free
 --wrap gettimeofday
+--wrap __vfprintf_chk
+--wrap __vprintf_chk
+

[Xenomai-git] Gilles Chanteperdrix : lib/cobalt: allow compiling applications with _FORTIFY_SOURCE

2013-06-14 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 777bfeecbb3befc3da87b10408c06c501749fc59
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=777bfeecbb3befc3da87b10408c06c501749fc59

Author: Gilles Chanteperdrix 
Date:   Tue Apr 16 01:12:27 2013 +0200

lib/cobalt: allow compiling applications with _FORTIFY_SOURCE

When _FORTIFY_SOURCE is set, some services are replaced at compilation
time with versions performing additional checks on their
arguments. This is a problem if the same services need to be wrapped
by Xenomai: the checked versions are not wrapped, causing switches to
secondary mode.

This commit provides wrappers for the checked services.

The wrappers simply call the non checked version wrapper: calling
glibc checked services directly would break compilation with libcs
without this option, meaning old glibcs and alternative libcs.

In order to enable the checks provided by _FORTIFY_SOURCE, the Xenomai
binaries should be compiled with this option.

We attempt to auto-detect whether the underlying *libc supports
_FORTIFY_SOURCE at configuration time. --enable-fortify is introduced
to enable or disable the corresponding support in Xenomai libs.

If the support is enabled, checked versions of the Cobalt services are
redirected to checked versions of the *libc services. Otherwise, if a
checked version of a Cobalt service ends up being called, a fatal
error is raised.

---

 configure.in   |   19 +
 include/cobalt/stdio.h |6 ++
 include/cobalt/syslog.h|7 ++
 include/rtdk.h |5 ++
 lib/cobalt/cobalt.wrappers |6 ++
 lib/cobalt/printf.c|  170 +---
 lib/cobalt/wrappers.c  |   18 +
 7 files changed, 205 insertions(+), 26 deletions(-)

diff --git a/configure.in b/configure.in
index 10cf78d..0786039 100644
--- a/configure.in
+++ b/configure.in
@@ -745,6 +745,25 @@ dnl in-tree executables which require POSIX symbol 
wrapping.
AC_CONFIG_LINKS([lib/include/$base/xenomai:$srcdir/include/$base])
 fi
 
+unset want_fortify
+AC_MSG_CHECKING(for fortify support)
+AC_ARG_ENABLE([fortify], 
+ AC_HELP_STRING([--enable-fortify],
+[Enable support for applications compiled
+with _FORTIFY_SOURCE]),
+ [case "$enableval" in
+  y | yes) want_fortify=yes;;
+ *) want_fortify=no;;
+ esac])
+AC_MSG_RESULT(${want_fortify:-autodetect})
+if test x"$want_fortify" != xno; then
+   AC_CHECK_FUNC(__vfprintf_chk,
+ [AC_DEFINE(CONFIG_XENO_FORTIFY, 1 ,[config])],
+ [if test x"$want_fortify" = "xyes"; then
+ AC_MSG_ERROR([Fortify support enabled but not available in *libc])
+  fi])
+fi
+
 dnl
 dnl Build the Makefiles
 dnl
diff --git a/include/cobalt/stdio.h b/include/cobalt/stdio.h
index 4a88778..9f3fd4d 100644
--- a/include/cobalt/stdio.h
+++ b/include/cobalt/stdio.h
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 #ifdef __cplusplus
@@ -15,6 +16,11 @@ extern "C" {
 
 COBALT_DECL(int, vfprintf(FILE *stream, const char *fmt, va_list args));
 
+#ifdef CONFIG_XENO_FORTIFY
+COBALT_DECL(int, __vfprintf_chk(FILE *stream, int level,
+   const char *fmt, va_list ap));
+#endif
+
 COBALT_DECL(int, vprintf(const char *fmt, va_list args));
 
 COBALT_DECL(int, fprintf(FILE *stream, const char *fmt, ...));
diff --git a/include/cobalt/syslog.h b/include/cobalt/syslog.h
index d446f45..701ec22 100644
--- a/include/cobalt/syslog.h
+++ b/include/cobalt/syslog.h
@@ -3,6 +3,7 @@
 
 #include 
 #include_next 
+#include 
 #include 
 
 #ifdef __cplusplus
@@ -13,6 +14,12 @@ COBALT_DECL(void, syslog(int priority, const char *fmt, 
...));
 
 COBALT_DECL(void, vsyslog(int priority,
  const char *fmt, va_list ap));
+
+#ifdef CONFIG_XENO_FORTIFY
+COBALT_DECL(void, __vsyslog_chk(int priority, int level,
+   const char *fmt, va_list ap));
+#endif
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/include/rtdk.h b/include/rtdk.h
index 1b5f218..ecebbff 100644
--- a/include/rtdk.h
+++ b/include/rtdk.h
@@ -43,6 +43,7 @@ static inline const char *rt_print_buffer_name(void)
 
 #include 
 #include 
+#include 
 
 #ifdef __cplusplus
 extern "C" {
@@ -65,6 +66,10 @@ void rt_print_cleanup(void);
 void rt_print_auto_init(int enable);
 const char *rt_print_buffer_name(void);
 void rt_print_flush_buffers(void);
+#ifdef CONFIG_XENO_FORTIFY
+int __rt_vfprintf_chk(FILE *stream, int level, const char *fmt, va_list args);
+void __rt_vsyslog_chk(int priority, int level, const char *fmt, va_list args);
+#endif
 
 void assert_nrt(void);
 
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index 4ed9188..3d5d16b 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -98,3 +98,9 @@
 --wrap malloc
 --wrap free
 --wrap gettimeofday
+--wrap __vfprintf_chk
+--wrap __vprintf_chk
+