Module Name: src Committed By: christos Date: Wed Jan 19 19:21:30 UTC 2011
Modified Files: src/include: unistd.h src/include/ssp: ssp.h unistd.h Log Message: 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, ...); }. To generate a diff of this commit: cvs rdiff -u -r1.124 -r1.125 src/include/unistd.h cvs rdiff -u -r1.4 -r1.5 src/include/ssp/ssp.h src/include/ssp/unistd.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/include/unistd.h diff -u src/include/unistd.h:1.124 src/include/unistd.h:1.125 --- src/include/unistd.h:1.124 Fri Aug 27 04:40:38 2010 +++ src/include/unistd.h Wed Jan 19 14:21:29 2011 @@ -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_ */ Index: src/include/ssp/ssp.h diff -u src/include/ssp/ssp.h:1.4 src/include/ssp/ssp.h:1.5 --- src/include/ssp/ssp.h:1.4 Wed Dec 22 14:43:33 2010 +++ src/include/ssp/ssp.h Wed Jan 19 14:21:29 2011 @@ -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) \ Index: src/include/ssp/unistd.h diff -u src/include/ssp/unistd.h:1.4 src/include/ssp/unistd.h:1.5 --- src/include/ssp/unistd.h:1.4 Mon Apr 28 16:22:54 2008 +++ src/include/ssp/unistd.h Wed Jan 19 14:21:29 2011 @@ -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_ */