Move the FORTIFY_SOURCE helpers over to .cpp.
Change-Id: Ib5067d51b983cac7760c975becce7fe2408ead04
diff --git a/libc/bionic/__fgets_chk.c b/libc/bionic/__fgets_chk.cpp
similarity index 96%
rename from libc/bionic/__fgets_chk.c
rename to libc/bionic/__fgets_chk.cpp
index 19123b9..780cf16 100644
--- a/libc/bionic/__fgets_chk.c
+++ b/libc/bionic/__fgets_chk.cpp
@@ -41,7 +41,7 @@
* This fgets check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-char *__fgets_chk(char *dest, int supplied_size,
+extern "C" char *__fgets_chk(char *dest, int supplied_size,
FILE *stream, size_t dest_len_from_compiler)
{
if (supplied_size < 0) {
diff --git a/libc/bionic/__memcpy_chk.c b/libc/bionic/__memcpy_chk.cpp
similarity index 96%
rename from libc/bionic/__memcpy_chk.c
rename to libc/bionic/__memcpy_chk.cpp
index 10334ba..991ff02 100644
--- a/libc/bionic/__memcpy_chk.c
+++ b/libc/bionic/__memcpy_chk.cpp
@@ -42,7 +42,7 @@
* This memcpy check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-void *__memcpy_chk(void *dest, const void *src,
+extern "C" void *__memcpy_chk(void *dest, const void *src,
size_t copy_amount, size_t dest_len)
{
if (__builtin_expect(copy_amount > dest_len, 0)) {
diff --git a/libc/bionic/__memmove_chk.c b/libc/bionic/__memmove_chk.cpp
similarity index 96%
rename from libc/bionic/__memmove_chk.c
rename to libc/bionic/__memmove_chk.cpp
index 529eb8f..1867d71 100644
--- a/libc/bionic/__memmove_chk.c
+++ b/libc/bionic/__memmove_chk.cpp
@@ -41,7 +41,7 @@
* This memmove check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-void *__memmove_chk (void *dest, const void *src,
+extern "C" void *__memmove_chk (void *dest, const void *src,
size_t len, size_t dest_len)
{
if (len > dest_len) {
diff --git a/libc/bionic/__memset_chk.c b/libc/bionic/__memset_chk.cpp
similarity index 95%
rename from libc/bionic/__memset_chk.c
rename to libc/bionic/__memset_chk.cpp
index 0904c03..97c5c38 100644
--- a/libc/bionic/__memset_chk.c
+++ b/libc/bionic/__memset_chk.cpp
@@ -41,8 +41,7 @@
* This memset check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-void *__memset_chk (void *dest, int c, size_t n, size_t dest_len)
-{
+extern "C" void *__memset_chk (void *dest, int c, size_t n, size_t dest_len) {
if (n > dest_len) {
__libc_android_log_print(ANDROID_LOG_FATAL, "libc",
"*** memset buffer overflow detected ***\n");
diff --git a/libc/bionic/__snprintf_chk.c b/libc/bionic/__snprintf_chk.c
deleted file mode 100644
index dbda3db..0000000
--- a/libc/bionic/__snprintf_chk.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdarg.h>
-
-/*
- * Runtime implementation of __builtin____snprintf_chk.
- *
- * See
- * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This snprintf check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-int __snprintf_chk(
- char *dest,
- size_t supplied_size,
- int flags,
- size_t dest_len_from_compiler,
- const char *format, ...)
-{
- va_list va;
- int retval;
-
- va_start(va, format);
- retval = __vsnprintf_chk(dest, supplied_size, flags,
- dest_len_from_compiler, format, va);
- va_end(va);
-
- return retval;
-}
diff --git a/libc/bionic/__sprintf_chk.c b/libc/bionic/__sprintf_chk.c
deleted file mode 100644
index 67acbe1..0000000
--- a/libc/bionic/__sprintf_chk.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdarg.h>
-
-/*
- * Runtime implementation of __builtin____sprintf_chk.
- *
- * See
- * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This sprintf check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-int __sprintf_chk(
- char *dest,
- int flags,
- size_t dest_len_from_compiler,
- const char *format, ...)
-{
- va_list va;
- int retval;
-
- va_start(va, format);
- retval = __vsprintf_chk(dest, flags,
- dest_len_from_compiler, format, va);
- va_end(va);
-
- return retval;
-}
diff --git a/libc/bionic/__strcat_chk.c b/libc/bionic/__strcat_chk.cpp
similarity index 96%
rename from libc/bionic/__strcat_chk.c
rename to libc/bionic/__strcat_chk.cpp
index 4665d66..ec194fc 100644
--- a/libc/bionic/__strcat_chk.c
+++ b/libc/bionic/__strcat_chk.cpp
@@ -42,8 +42,7 @@
* This strcat check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-char *__strcat_chk (char *dest, const char *src, size_t dest_buf_size)
-{
+extern "C" char *__strcat_chk (char *dest, const char *src, size_t dest_buf_size) {
// TODO: optimize so we don't scan src/dest twice.
size_t src_len = strlen(src);
size_t dest_len = strlen(dest);
diff --git a/libc/bionic/__strcpy_chk.c b/libc/bionic/__strcpy_chk.cpp
similarity index 95%
rename from libc/bionic/__strcpy_chk.c
rename to libc/bionic/__strcpy_chk.cpp
index 79486b4..1d45ea2 100644
--- a/libc/bionic/__strcpy_chk.c
+++ b/libc/bionic/__strcpy_chk.cpp
@@ -41,8 +41,7 @@
* This strcpy check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-char *__strcpy_chk (char *dest, const char *src, size_t dest_len)
-{
+extern "C" char *__strcpy_chk (char *dest, const char *src, size_t dest_len) {
// TODO: optimize so we don't scan src twice.
size_t src_len = strlen(src) + 1;
if (src_len > dest_len) {
diff --git a/libc/bionic/__strlcat_chk.c b/libc/bionic/__strlcat_chk.cpp
similarity index 96%
rename from libc/bionic/__strlcat_chk.c
rename to libc/bionic/__strlcat_chk.cpp
index b895fb8..05b7d7d 100644
--- a/libc/bionic/__strlcat_chk.c
+++ b/libc/bionic/__strlcat_chk.cpp
@@ -42,7 +42,7 @@
* This strlcat check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-size_t __strlcat_chk(char *dest, const char *src,
+extern "C" size_t __strlcat_chk(char *dest, const char *src,
size_t supplied_size, size_t dest_len_from_compiler)
{
if (supplied_size > dest_len_from_compiler) {
diff --git a/libc/bionic/__strlcpy_chk.c b/libc/bionic/__strlcpy_chk.cpp
similarity index 96%
rename from libc/bionic/__strlcpy_chk.c
rename to libc/bionic/__strlcpy_chk.cpp
index 752c86c..bf98037 100644
--- a/libc/bionic/__strlcpy_chk.c
+++ b/libc/bionic/__strlcpy_chk.cpp
@@ -42,7 +42,7 @@
* This strlcpy check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-size_t __strlcpy_chk(char *dest, const char *src,
+extern "C" size_t __strlcpy_chk(char *dest, const char *src,
size_t supplied_size, size_t dest_len_from_compiler)
{
if (supplied_size > dest_len_from_compiler) {
diff --git a/libc/bionic/__strlen_chk.c b/libc/bionic/__strlen_chk.cpp
similarity index 96%
rename from libc/bionic/__strlen_chk.c
rename to libc/bionic/__strlen_chk.cpp
index 43e7e80..67410d4 100644
--- a/libc/bionic/__strlen_chk.c
+++ b/libc/bionic/__strlen_chk.cpp
@@ -53,8 +53,7 @@
*
* or anytime strlen reads beyond an object boundary.
*/
-size_t __strlen_chk(const char *s, size_t s_len)
-{
+extern "C" size_t __strlen_chk(const char *s, size_t s_len) {
size_t ret = strlen(s);
if (__builtin_expect(ret >= s_len, 0)) {
diff --git a/libc/bionic/__strncat_chk.c b/libc/bionic/__strncat_chk.cpp
similarity index 97%
rename from libc/bionic/__strncat_chk.c
rename to libc/bionic/__strncat_chk.cpp
index 2036c9f..2ba8550 100644
--- a/libc/bionic/__strncat_chk.c
+++ b/libc/bionic/__strncat_chk.cpp
@@ -42,7 +42,7 @@
* This strncat check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-char *__strncat_chk (char *dest, const char *src,
+extern "C" char *__strncat_chk (char *dest, const char *src,
size_t len, size_t dest_buf_size)
{
// TODO: optimize so we don't scan src/dest twice.
diff --git a/libc/bionic/__strncpy_chk.c b/libc/bionic/__strncpy_chk.cpp
similarity index 96%
rename from libc/bionic/__strncpy_chk.c
rename to libc/bionic/__strncpy_chk.cpp
index 3f9e9fb..875d092 100644
--- a/libc/bionic/__strncpy_chk.c
+++ b/libc/bionic/__strncpy_chk.cpp
@@ -41,7 +41,7 @@
* This strncpy check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-char *__strncpy_chk (char *dest, const char *src,
+extern "C" char *__strncpy_chk (char *dest, const char *src,
size_t len, size_t dest_len)
{
if (len > dest_len) {
diff --git a/libc/bionic/__umask_chk.c b/libc/bionic/__umask_chk.cpp
similarity index 97%
rename from libc/bionic/__umask_chk.c
rename to libc/bionic/__umask_chk.cpp
index 5bb6a3b..df066b2 100644
--- a/libc/bionic/__umask_chk.c
+++ b/libc/bionic/__umask_chk.cpp
@@ -41,8 +41,7 @@
* This umask check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-mode_t __umask_chk(mode_t mode)
-{
+extern "C" mode_t __umask_chk(mode_t mode) {
if ((mode & 0777) != mode) {
__libc_android_log_print(ANDROID_LOG_FATAL, "libc",
"*** FORTIFY_SOURCE: umask called with invalid mask ***\n");
diff --git a/libc/bionic/__vsnprintf_chk.c b/libc/bionic/__vsnprintf_chk.cpp
similarity index 74%
rename from libc/bionic/__vsnprintf_chk.c
rename to libc/bionic/__vsnprintf_chk.cpp
index a1a1039..b4f534b 100644
--- a/libc/bionic/__vsnprintf_chk.c
+++ b/libc/bionic/__vsnprintf_chk.cpp
@@ -42,10 +42,10 @@
* This vsnprintf check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-int __vsnprintf_chk(
+extern "C" int __vsnprintf_chk(
char *dest,
size_t supplied_size,
- int flags,
+ int /*flags*/,
size_t dest_len_from_compiler,
const char *format,
va_list va)
@@ -58,3 +58,32 @@
return vsnprintf(dest, supplied_size, format, va);
}
+
+/*
+ * Runtime implementation of __builtin____snprintf_chk.
+ *
+ * See
+ * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
+ * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
+ * for details.
+ *
+ * This snprintf check is called if _FORTIFY_SOURCE is defined and
+ * greater than 0.
+ */
+extern "C" int __snprintf_chk(
+ char *dest,
+ size_t supplied_size,
+ int flags,
+ size_t dest_len_from_compiler,
+ const char *format, ...)
+{
+ va_list va;
+ int retval;
+
+ va_start(va, format);
+ retval = __vsnprintf_chk(dest, supplied_size, flags,
+ dest_len_from_compiler, format, va);
+ va_end(va);
+
+ return retval;
+}
diff --git a/libc/bionic/__vsprintf_chk.c b/libc/bionic/__vsprintf_chk.cpp
similarity index 75%
rename from libc/bionic/__vsprintf_chk.c
rename to libc/bionic/__vsprintf_chk.cpp
index 8a809fc..00010cf 100644
--- a/libc/bionic/__vsprintf_chk.c
+++ b/libc/bionic/__vsprintf_chk.cpp
@@ -42,9 +42,9 @@
* This vsprintf check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
-int __vsprintf_chk(
+extern "C" int __vsprintf_chk(
char *dest,
- int flags,
+ int /*flags*/,
size_t dest_len_from_compiler,
const char *format,
va_list va)
@@ -59,3 +59,31 @@
return ret;
}
+
+/*
+ * Runtime implementation of __builtin____sprintf_chk.
+ *
+ * See
+ * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
+ * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
+ * for details.
+ *
+ * This sprintf check is called if _FORTIFY_SOURCE is defined and
+ * greater than 0.
+ */
+extern "C" int __sprintf_chk(
+ char *dest,
+ int flags,
+ size_t dest_len_from_compiler,
+ const char *format, ...)
+{
+ va_list va;
+ int retval;
+
+ va_start(va, format);
+ retval = __vsprintf_chk(dest, flags,
+ dest_len_from_compiler, format, va);
+ va_end(va);
+
+ return retval;
+}