Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/include Re-do ssp hijacking by defining inline functions and...



details:   https://anonhg.NetBSD.org/src/rev/85393be20e06
branches:  trunk
changeset: 761056:85393be20e06
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jan 19 19:21:29 2011 +0000

description:
Re-do ssp hijacking by defining inline functions and using the weak libc
symbols to do the indirection for unistd.h instead of #define tricks.
Fixes compilation for things that define struct { ssize_t read(int fd, ...); }.

diffstat:

 include/ssp/ssp.h    |  18 ++++++++----------
 include/ssp/unistd.h |   5 +----
 include/unistd.h     |  15 ++++++++++-----
 3 files changed, 19 insertions(+), 19 deletions(-)

diffs (114 lines):

diff -r 9ba95db889f4 -r 85393be20e06 include/ssp/ssp.h
--- a/include/ssp/ssp.h Wed Jan 19 18:29:28 2011 +0000
+++ b/include/ssp/ssp.h Wed Jan 19 19:21:29 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ssp.h,v 1.4 2010/12/22 19:43:33 jruoho Exp $   */
+/*     $NetBSD: ssp.h,v 1.5 2011/01/19 19:21:29 christos Exp $ */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -43,21 +43,19 @@
 # endif
 #endif
 
-#define __ssp_alias_name(fun) __ ## fun ## _alias
-#ifdef _NAMESPACE_H_
-#define __ssp_alias_func(fun, args) ___ ## fun ## _alias args
-#else
-#define __ssp_alias_func(fun, args) __ssp_alias_name(fun) args
-#endif
+#define __ssp_weak_name(fun) _ ## fun
 #define __ssp_inline static __inline __attribute__((__always_inline__))
+
 #define __ssp_bos(ptr) __builtin_object_size(ptr, __SSP_FORTIFY_LEVEL > 1)
 #define __ssp_bos0(ptr) __builtin_object_size(ptr, 0)
+
 #define __ssp_redirect_raw(rtype, fun, args, call, bos) \
-__ssp_inline rtype __ssp_alias_name(fun) args; \
-__ssp_inline rtype __ssp_alias_name(fun) args { \
+rtype __ssp_weak_name(fun) args; \
+__ssp_inline rtype fun args; \
+__ssp_inline rtype fun args { \
        if (bos(__buf) != (size_t)-1 && __len > bos(__buf)) \
                __chk_fail(); \
-       return fun call; \
+       return __ssp_weak_name(fun) call; \
 }
 
 #define __ssp_redirect(rtype, fun, args, call) \
diff -r 9ba95db889f4 -r 85393be20e06 include/ssp/unistd.h
--- a/include/ssp/unistd.h      Wed Jan 19 18:29:28 2011 +0000
+++ b/include/ssp/unistd.h      Wed Jan 19 19:21:29 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: unistd.h,v 1.4 2008/04/28 20:22:54 martin Exp $        */
+/*     $NetBSD: unistd.h,v 1.5 2011/01/19 19:21:29 christos Exp $      */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -46,8 +46,5 @@
 
 __END_DECLS
 
-#define read(fd, buf, len)             __ssp_alias_func(read, (fd, buf, len))
-#define readlink(path, buf, len)       __ssp_alias_func(readlink, (path, buf, len))
-#define getcwd(buf, len)               __ssp_alias_func(getcwd, (buf, len))
 #endif /* __SSP_FORTIFY_LEVEL > 0 */
 #endif /* _SSP_UNISTD_H_ */
diff -r 9ba95db889f4 -r 85393be20e06 include/unistd.h
--- a/include/unistd.h  Wed Jan 19 18:29:28 2011 +0000
+++ b/include/unistd.h  Wed Jan 19 19:21:29 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: unistd.h,v 1.124 2010/08/27 08:40:38 christos Exp $    */
+/*     $NetBSD: unistd.h,v 1.125 2011/01/19 19:21:29 christos Exp $    */
 
 /*-
  * Copyright (c) 1998, 1999, 2008 The NetBSD Foundation, Inc.
@@ -70,6 +70,9 @@
 #include <sys/types.h>
 #include <sys/unistd.h>
 
+#if _FORTIFY_SOURCE > 0
+#include <ssp/unistd.h>
+#endif
 
 /*
  * IEEE Std 1003.1-90
@@ -107,7 +110,9 @@
 int     execvp(const char *, char * const *);
 pid_t   fork(void);
 long    fpathconf(int, int);
+#if __SSP_FORTIFY_LEVEL == 0
 char   *getcwd(char *, size_t);
+#endif
 gid_t   getegid(void);
 uid_t   geteuid(void);
 gid_t   getgid(void);
@@ -123,7 +128,9 @@
 long    pathconf(const char *, int);
 int     pause(void);
 int     pipe(int *);
+#if __SSP_FORTIFY_LEVEL == 0
 ssize_t         read(int, void *, size_t);
+#endif
 int     rmdir(const char *);
 int     setgid(gid_t);
 int     setpgid(pid_t, pid_t);
@@ -253,7 +260,9 @@
 int     lchown(const char *, uid_t, gid_t);
 #endif
 int     lockf(int, int, off_t);
+#if __SSP_FORTIFY_LEVEL == 0
 ssize_t         readlink(const char * __restrict, char * __restrict, size_t);
+#endif
 void   *sbrk(intptr_t);
 /* XXX prototype wrong! */
 int     setpgrp(pid_t, pid_t);                 /* obsoleted by setpgid() */
@@ -355,8 +364,4 @@
 #endif
 
 __END_DECLS
-
-#if _FORTIFY_SOURCE > 0
-#include <ssp/unistd.h>
-#endif
 #endif /* !_UNISTD_H_ */



Home | Main Index | Thread Index | Old Index