From 1e82da8d170066fa8c456a98f0242b8a6d1e6f86 Mon Sep 17 00:00:00 2001 From: Gustavo Frederico Temple Pedrosa Date: Mon, 15 Dec 2014 12:59:55 +0000 Subject: [PATCH] PowerPC64 support in safe_address function Add a ppc64-specific implementation of the safe_address function with overflow checking. --- Zend/zend_multiply.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Zend/zend_multiply.h b/Zend/zend_multiply.h index ab5fd6279d..b0000449af 100644 --- a/Zend/zend_multiply.h +++ b/Zend/zend_multiply.h @@ -224,6 +224,30 @@ static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, si return res; } +#elif defined(__GNUC__) && defined(__powerpc64__) + +static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, size_t offset, int *overflow) +{ + size_t res; + unsigned long m_overflow; + + __asm__ ("mulld %0,%2,%3\n\t" + "mulhdu %1,%2,%3\n\t" + "addc %0,%0,%4\n\t" + "addze %1,%1\n" + : "=&r"(res), "=&r"(m_overflow) + : "r"(nmemb), + "r"(size), + "r"(offset)); + + if (UNEXPECTED(m_overflow)) { + *overflow = 1; + return 0; + } + *overflow = 0; + return res; +} + #elif SIZEOF_SIZE_T == 4 static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, size_t offset, int *overflow) -- 2.40.0