Bug 1551562 - Use CopyMemory instead of memcpy on Windows inside try/catch blocks r=necko-reviewers,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D112343
This commit is contained in:
Valentin Gosu 2021-04-16 12:58:28 +00:00
Родитель 6b07b736ec
Коммит 3477d25274
1 изменённых файлов: 12 добавлений и 2 удалений

Просмотреть файл

@ -20,6 +20,16 @@
# include <windows.h>
#endif
// When accessing data inside the MMAP_FAULT_HANDLER_{BEGIN_HANDLE}/{CATCH}
// we can't use the C memcpy because that's guaranteed not to throw
// any exceptions, so the exception handling gets optimized out.
// We use the Windows specific CopyMemory which doesn't have this problem.
#if defined(HAVE_SEH_EXCEPTIONS)
# define CatchableMemcpy CopyMemory
#else
# define CatchableMemcpy memcpy
#endif
/*---------------------------------------------
* nsISupports implementation
*--------------------------------------------*/
@ -224,7 +234,7 @@ nsJARInputStream::Read(char* aBuffer, uint32_t aCount, uint32_t* aBytesRead) {
"Did we read more than expected?");
uint32_t count = std::min(aCount, mOutSize - uint32_t(mZs.total_out));
if (count) {
memcpy(aBuffer, mZs.next_in + mZs.total_out, count);
CatchableMemcpy(aBuffer, mZs.next_in + mZs.total_out, count);
mZs.total_out += count;
}
*aBytesRead = count;
@ -400,7 +410,7 @@ uint32_t nsJARInputStream::CopyDataToBuffer(char*& aBuffer, uint32_t& aCount) {
const uint32_t writeLength = std::min(aCount, mBuffer.Length() - mCurPos);
if (writeLength > 0) {
memcpy(aBuffer, mBuffer.get() + mCurPos, writeLength);
CatchableMemcpy(aBuffer, mBuffer.get() + mCurPos, writeLength);
mCurPos += writeLength;
aCount -= writeLength;
aBuffer += writeLength;