Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Zend/zend_multiply.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, si

static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, size_t offset, bool *overflow)
{
size_t res = nmemb;
size_t res;
zend_ulong m_overflow = 0;

#ifdef __ILP32__ /* x32 */
Expand All @@ -186,12 +186,21 @@ static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, si
#endif

if (ZEND_CONST_COND(offset == 0, 0)) {
res = nmemb;
__asm__ ("mul" LP_SUFF " %3\n\t"
"adc $0,%1"
: "=&a"(res), "=&d" (m_overflow)
: "%0"(res),
"rm"(size));
} else if (ZEND_CONST_COND(nmemb == 1, 0)) {
res = size;
__asm__ ("add %2, %0\n\t"
"adc $0,%1"
: "+r"(res), "+r" (m_overflow)
: "rm"(offset)
: "cc");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not need this clobber hint for the other branches?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also surprised me, I think we actually do need it. I don't know why it isn't there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to backport that part.

} else {
res = nmemb;
__asm__ ("mul" LP_SUFF " %3\n\t"
"add %4,%0\n\t"
"adc $0,%1"
Expand Down