OSDN Git Service

Inline helpers need to be exported unmangled.
authorDan Albert <danalbert@google.com>
Tue, 7 Oct 2014 18:10:36 +0000 (11:10 -0700)
committerElliott Hughes <enh@google.com>
Wed, 8 Oct 2014 01:51:24 +0000 (18:51 -0700)
__open_2() is used by the fortify implementation of open(2) in
fcntl.h, and as such needs an unmangled C name. For some reason
(inlining?), this doesn't cause problems at the default optimization
level, but does for -O0.

The rest of these didn't cause build failures, but they look suspect
and probably will, we just haven't caught them yet.

(cherry-pick of 658727e111ed6dee7be5239494f0764f7b1b02f8 with conflicts
in stdio.h and string.h.)

Bug: 17784968
Change-Id: I7391a7a8999ee204eaf6abd14a3d5373ea419d5b

libc/bionic/__fgets_chk.cpp
libc/bionic/__recvfrom_chk.cpp
libc/include/fcntl.h
libc/include/stdio.h
libc/include/string.h
libc/include/sys/select.h
libc/include/sys/socket.h
libc/include/sys/stat.h
libc/include/unistd.h

index c09f6c5..75e4ca0 100644 (file)
@@ -43,8 +43,8 @@
  * This fgets check is called if _FORTIFY_SOURCE is defined and
  * greater than 0.
  */
-extern "C" char* __fgets_chk(char* dest, int supplied_size,
-                             FILE* stream, size_t dest_len_from_compiler) {
+char* __fgets_chk(char* dest, int supplied_size, FILE* stream,
+                  size_t dest_len_from_compiler) {
   if (supplied_size < 0) {
     __fortify_chk_fail("fgets: buffer size < 0", 0);
   }
index 48baa8e..9c894b0 100644 (file)
@@ -32,9 +32,9 @@
 #include <sys/socket.h>
 #include "private/libc_logging.h"
 
-extern "C"
-ssize_t __recvfrom_chk(int socket, void* buf, size_t len, size_t buflen, unsigned int flags,
-                       const struct sockaddr* src_addr, socklen_t* addrlen) {
+ssize_t __recvfrom_chk(int socket, void* buf, size_t len, size_t buflen,
+                       int flags, const struct sockaddr* src_addr,
+                       socklen_t* addrlen) {
   if (__predict_false(len > buflen)) {
     __fortify_chk_fail("recvfrom: prevented write past end of buffer", 0);
   }
index 87c8481..794e62c 100644 (file)
@@ -81,8 +81,6 @@ extern ssize_t tee(int, int, size_t, unsigned int);
 extern int unlinkat(int, const char*, int);
 extern ssize_t vmsplice(int, const struct iovec*, size_t, unsigned int);
 
-#if defined(__BIONIC_FORTIFY)
-
 extern int __open_2(const char*, int);
 extern int __open_real(const char*, int, ...) __RENAME(open);
 extern int __openat_2(int, const char*, int);
@@ -90,6 +88,8 @@ extern int __openat_real(int, const char*, int, ...) __RENAME(openat);
 __errordecl(__creat_missing_mode, "called with O_CREAT, but missing mode");
 __errordecl(__creat_too_many_args, "too many arguments");
 
+#if defined(__BIONIC_FORTIFY)
+
 #if !defined(__clang__)
 
 __BIONIC_FORTIFY_INLINE
index 38a2677..a0161de 100644 (file)
@@ -47,6 +47,8 @@
 #define __need_NULL
 #include <stddef.h>
 
+__BEGIN_DECLS
+
 #define        _FSTDIO                 /* Define for new stdio with functions. */
 
 typedef off_t fpos_t;          /* stdio file position type */
@@ -136,9 +138,7 @@ typedef     struct __sFILE {
        fpos_t  _offset;        /* current lseek offset */
 } FILE;
 
-__BEGIN_DECLS
 extern FILE __sF[];
-__END_DECLS
 
 #define        __SLBF  0x0001          /* line buffered */
 #define        __SNBF  0x0002          /* unbuffered */
@@ -208,7 +208,6 @@ __END_DECLS
 /*
  * Functions defined in ANSI C standard.
  */
-__BEGIN_DECLS
 void    clearerr(FILE *);
 int     fclose(FILE *);
 int     feof(FILE *);
@@ -296,16 +295,12 @@ int        vsscanf(const char * __restrict, const char * __restrict, __va_list)
                __scanflike(2, 0);
 #endif /* __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE */
 
-__END_DECLS
-
-
 /*
  * Functions defined in POSIX 1003.1.
  */
 #if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
 #define        L_ctermid       1024    /* size for ctermid(); PATH_MAX */
 
-__BEGIN_DECLS
 FILE   *fdopen(int, const char *);
 int     fileno(FILE *);
 
@@ -329,15 +324,12 @@ int        putc_unlocked(int, FILE *);
 int     putchar_unlocked(int);
 #endif /* __POSIX_VISIBLE >= 199506 */
 
-__END_DECLS
-
 #endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */
 
 /*
  * Routines that are purely local.
  */
 #if __BSD_VISIBLE
-__BEGIN_DECLS
 int     asprintf(char ** __restrict, const char * __restrict, ...)
                __printflike(2, 3);
 char   *fgetln(FILE * __restrict, size_t * __restrict);
@@ -347,25 +339,26 @@ int        setlinebuf(FILE *);
 int     vasprintf(char ** __restrict, const char * __restrict,
     __va_list)
                __printflike(2, 0);
-__END_DECLS
 
 /*
  * Stdio function-access interface.
  */
-__BEGIN_DECLS
 FILE   *funopen(const void *,
                int (*)(void *, char *, int),
                int (*)(void *, const char *, int),
                fpos_t (*)(void *, fpos_t, int),
                int (*)(void *));
-__END_DECLS
+
 #define        fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
 #define        fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
 #endif /* __BSD_VISIBLE */
 
-#if defined(__BIONIC_FORTIFY)
+extern char* __fgets_chk(char*, int, FILE*, size_t);
+extern char* __fgets_real(char*, int, FILE*) __RENAME(fgets);
+__errordecl(__fgets_too_big_error, "fgets called with size bigger than buffer");
+__errordecl(__fgets_too_small_error, "fgets called with size less than zero");
 
-__BEGIN_DECLS
+#if defined(__BIONIC_FORTIFY)
 
 __BIONIC_FORTIFY_INLINE
 __printflike(3, 0)
@@ -411,11 +404,6 @@ int sprintf(char *dest, const char *format, ...)
 }
 #endif
 
-extern char* __fgets_chk(char*, int, FILE*, size_t);
-extern char* __fgets_real(char*, int, FILE*) __RENAME(fgets);
-__errordecl(__fgets_too_big_error, "fgets called with size bigger than buffer");
-__errordecl(__fgets_too_small_error, "fgets called with size less than zero");
-
 #if !defined(__clang__)
 
 __BIONIC_FORTIFY_INLINE
@@ -450,8 +438,8 @@ char *fgets(char* dest, int size, FILE* stream) {
 
 #endif /* !defined(__clang__) */
 
-__END_DECLS
-
 #endif /* defined(__BIONIC_FORTIFY) */
 
+__END_DECLS
+
 #endif /* _STDIO_H_ */
index 2971760..f2f6dd2 100644 (file)
@@ -92,6 +92,13 @@ extern size_t strxfrm(char* __restrict, const char* __restrict, size_t);
 extern int    strcoll_l(const char *, const char *, locale_t) __purefunc;
 extern size_t strxfrm_l(char* __restrict, const char* __restrict, size_t, locale_t);
 
+extern char* __stpncpy_chk2(char* __restrict, const char* __restrict, size_t, size_t, size_t);
+extern char* __strncpy_chk2(char* __restrict, const char* __restrict, size_t, size_t, size_t);
+extern size_t __strlcpy_real(char* __restrict, const char* __restrict, size_t) __RENAME(strlcpy);
+extern size_t __strlcpy_chk(char *, const char *, size_t, size_t);
+extern size_t __strlcat_real(char* __restrict, const char* __restrict, size_t) __RENAME(strlcat);
+extern size_t __strlcat_chk(char* __restrict, const char* __restrict, size_t, size_t);
+
 #if defined(__BIONIC_FORTIFY)
 
 __BIONIC_FORTIFY_INLINE
@@ -114,8 +121,6 @@ char* strcpy(char* __restrict dest, const char* __restrict src) {
     return __builtin___strcpy_chk(dest, src, __bos(dest));
 }
 
-extern char* __stpncpy_chk2(char* __restrict, const char* __restrict, size_t, size_t, size_t);
-
 __BIONIC_FORTIFY_INLINE
 char* stpncpy(char* __restrict dest, const char* __restrict src, size_t n) {
     size_t bos_dest = __bos(dest);
@@ -137,8 +142,6 @@ char* stpncpy(char* __restrict dest, const char* __restrict src, size_t n) {
     return __stpncpy_chk2(dest, src, n, bos_dest, bos_src);
 }
 
-extern char* __strncpy_chk2(char* __restrict, const char* __restrict, size_t, size_t, size_t);
-
 __BIONIC_FORTIFY_INLINE
 char* strncpy(char* __restrict dest, const char* __restrict src, size_t n) {
     size_t bos_dest = __bos(dest);
@@ -175,9 +178,6 @@ void* memset(void *s, int c, size_t n) {
     return __builtin___memset_chk(s, c, n, __bos0(s));
 }
 
-extern size_t __strlcpy_real(char* __restrict, const char* __restrict, size_t) __RENAME(strlcpy);
-extern size_t __strlcpy_chk(char *, const char *, size_t, size_t);
-
 __BIONIC_FORTIFY_INLINE
 size_t strlcpy(char* __restrict dest, const char* __restrict src, size_t size) {
     size_t bos = __bos(dest);
@@ -198,9 +198,6 @@ size_t strlcpy(char* __restrict dest, const char* __restrict src, size_t size) {
     return __strlcpy_chk(dest, src, size, bos);
 }
 
-extern size_t __strlcat_real(char* __restrict, const char* __restrict, size_t) __RENAME(strlcat);
-extern size_t __strlcat_chk(char* __restrict, const char* __restrict, size_t, size_t);
-
 
 __BIONIC_FORTIFY_INLINE
 size_t strlcat(char* __restrict dest, const char* __restrict src, size_t size) {
index 4ddcb6a..32c1206 100644 (file)
@@ -51,10 +51,11 @@ typedef struct {
 
 #define FD_ZERO(set) (memset(set, 0, sizeof(*(fd_set*)(set))))
 
-#if defined(__BIONIC_FORTIFY)
 extern void __FD_CLR_chk(int, fd_set*, size_t);
 extern void __FD_SET_chk(int, fd_set*, size_t);
 extern int  __FD_ISSET_chk(int, fd_set*, size_t);
+
+#if defined(__BIONIC_FORTIFY)
 #define FD_CLR(fd, set) __FD_CLR_chk(fd, set, __bos(set))
 #define FD_SET(fd, set) __FD_SET_chk(fd, set, __bos(set))
 #define FD_ISSET(fd, set) __FD_ISSET_chk(fd, set, __bos(set))
index a8840ff..43d1586 100644 (file)
@@ -291,11 +291,12 @@ extern ssize_t recv(int, void*, size_t, int);
 __socketcall ssize_t sendto(int, const void*, size_t, int, const struct sockaddr*, socklen_t);
 __socketcall ssize_t recvfrom(int, void*, size_t, int, const struct sockaddr*, socklen_t*);
 
-#if defined(__BIONIC_FORTIFY)
 __errordecl(__recvfrom_error, "recvfrom called with size bigger than buffer");
 extern ssize_t __recvfrom_chk(int, void*, size_t, size_t, int, const struct sockaddr*, socklen_t*);
 extern ssize_t __recvfrom_real(int, void*, size_t, int, const struct sockaddr*, socklen_t*) __RENAME(recvfrom);
 
+#if defined(__BIONIC_FORTIFY)
+
 __BIONIC_FORTIFY_INLINE
 ssize_t recvfrom(int fd, void* buf, size_t len, int flags, const struct sockaddr* src_addr, socklen_t* addr_len) {
   size_t bos = __bos0(buf);
index a6cc368..9c7373a 100644 (file)
@@ -159,12 +159,12 @@ extern int stat64(const char*, struct stat64*);
 extern int mknod(const char*, mode_t, dev_t);
 extern mode_t umask(mode_t);
 
-#if defined(__BIONIC_FORTIFY)
-
 extern mode_t __umask_chk(mode_t);
 extern mode_t __umask_real(mode_t) __RENAME(umask);
 __errordecl(__umask_invalid_mode, "umask called with invalid mode");
 
+#if defined(__BIONIC_FORTIFY)
+
 __BIONIC_FORTIFY_INLINE
 mode_t umask(mode_t mode) {
 #if !defined(__clang__)
index 781fc44..9b9adce 100644 (file)
@@ -197,12 +197,13 @@ extern int   tcsetpgrp(int fd, pid_t _pid);
     } while (_rc == -1 && errno == EINTR); \
     _rc; })
 
-#if defined(__BIONIC_FORTIFY)
 extern ssize_t __read_chk(int, void*, size_t, size_t);
 __errordecl(__read_dest_size_error, "read called with size bigger than destination");
 __errordecl(__read_count_toobig_error, "read called with count > SSIZE_MAX");
 extern ssize_t __read_real(int, void*, size_t) __RENAME(read);
 
+#if defined(__BIONIC_FORTIFY)
+
 __BIONIC_FORTIFY_INLINE
 ssize_t read(int fd, void* buf, size_t count) {
     size_t bos = __bos0(buf);