Files
palemoon27/memory/replace/logalloc/FdPrintf.cpp
T
roytam1 60a7b63caa import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1202965 (part 1) - Add MOZ_UNUSED. r=froydnj. (457960f48)
- Bug 1200097 - Fix warnings in logalloc. r=glandium. (3f115e470)
- Bug 1200623 - Fix FdPrintf.o link error in --disable-optimize builds. r=glandium. (4f07a36e2)
- Bug 1202965 (part 2) - Use MOZ_UNUSED in FdPrintf.c. r=glandium. (2dd55aaa7)
- Bug 1203314 - Make operator<< a method on unused_t. r=froydnj This prevents operator overload resolution from failing when this file is included in a file that uses Chromium IPC logging. (80f5cf4c5)
- Bug 1014691 - Move APZ mochitests to gfx/layers/apz/test/mochitest. r=kats (b3e811b10)
- Bug 1014691 - Move TestAsyncPanZoomController.cpp to gfx/layers/apz/test/gtest. r=kats,glandium (7c7598033)
- Bug 1083101 - Add a memory arena to Moz2D. r=jrmuizel (986b49392)
- Bug 1083101 - Add a task scheduler to Moz2D. r=jrmuizel (58002f967)
- partial of Bug 1140675 - Disable failing tests on windows opt. r=me (8d4b5b761)
- Bug 1170081 - Add a tag to run only mochitests that use HTMLMediaElement::MozCaptureStream. r=cpearce. (fc9e19146)
- Bug 1189744 - Fix crash after GetOwnPropertyDescriptor failed to populate all fields of desc. r=jandem, a=abillings. (464905f1b)
- Bug 1184414 - X.[[SetPrototypeOf]](Y) should succeed if X.[[Prototype]] is already Y. r=jorendorff. (3c3b9767c)
- Bug 1240792 - Test that assignment to primitives throws in strict mode. r=jorendorff (5fe30b7d1)
- Bug 1172609 - Part 5: Add js::ResetTimeZone() function. r=waldo, r=ted (2f8021714)
- Bug 1172609 - Part 6: Add nsJSUtils::ResetTimeZone() function. r=ehsan (35c1bbeb2)
- Bug 1172609 - Part 7: Hal calls nsJSUtils::ResetTimeZone() when timezone changes. r=dhylands (fe55a0830)
- Bug 1150534 - Synchronously decode favicons before calling GetFrame. r=tn (4f1acc810)
- Bug 1168495 - Restrict updated region to fall within GTK window. r=jrmuizel (d92a71a5c)
- Bug 1180971 - Fix X11 SHM invalidation regions on HiDPI with GTK3. r=karlt (98cce94d0)
- Bug 1156182 - Prevent widgets from creating a LayerManager during shutdown. r=sotaro (4af6914c9)
- Bug 1194397 - Force gdk_window_ensure_native on gdk window creation. r=acomminos (06a6eb2d8)
- Bug 1190935 - Fix race condition in gtk window EndRemoteDrawingInRegion. r=nical (cc7468e81)
- Bug 1182972 - Fallback to GTK monitor scale factor when mGdkWindow is null. r=karlt (69326bcfd)
- Bug 1168843 - use thread-safe refcounting for shared memory surfaces to avoid shutdown crashes. r=jmuizelaar (1d9b0914e)
- Bug 1167786. Restrict bounds of drawn region to the nsShmImage bounds to avoid X errors. r=karlt (005464f91)
- Bug 1205045 - remove GTK calls from compositor thread. r=jmuizelaar (ce5753137)
- Bug 1120851 - Set candidate window position for prediction even if no composition. r=masayuki (5814e776e)
- Bug 1176843 - Don't query caret rect on layout change. r=masayuki (4673f14ff)
- Bug 1177171 - Round widget coordinates on GTK3. r=karlt (3cd3af1c1)
- Bug 1186017 part.1 Rename nsGtkIMModule to mozilla::widget::IMContextWrapper r=m_kato+kerlt (f2b60dcd2)
- Bug 1186017 part.2 Rename GetBoolName() in IMContextWrapper.cpp to ToChar() r=kerlt (dade4fd9d)
- bug 1182972 remove unused aRepaint parameter from NativeResize methods r=acomminos (ae76c8f99)
- bug 1182972 remove mNeedsMove/mNeedsResize logic; instead process changes immediately r=acomminos (9417b03dc)
- bug 1182972 no need to pass member variable bounds to NativeResize r=acomminos (422e57acc)
- Bug 1181000 - Use logical pixel to set IME candidate window. r=karlt (d6f78610a)
- Bug 1191213 nsBaseWidget::NotifyWindowMoved() shouldn't notify IME when native IME handler doesn't have focus r=m_kato (59ee4fc9c)
- Bug 1198861 - Improve aliasing information and type barrier handling for unboxed arrays, r=jandem. (9ea8fd1cd)
- Bug 1198861 - Improve type barrier logic to avoid unnecessary tests on primitive types, and fix redundant baseline stubs for SETELEM property adds, r=jandem. (f1f2252c0)
- Bug 1083101 - Win32 implementation of the JobScheduler. r=jrmuizel (https://github.com/mozilla/newtab-dev/commit/120cce1d)
- Bug 1083101 - rename gfx::Mutex into gfx::CriticalSection and move it to its own file. r=jrmuizel (https://github.com/mozilla/newtab-dev/commit/6198b794)
- Bug 1083101 - Make SyncObject's waiting jobs list lock-free. r=jrmuizel (https://github.com/mozilla/newtab-dev/commit/e27060d8)
2021-11-15 14:53:00 +08:00

133 lines
3.0 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <cstdarg>
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
#include <cstring>
#include "mozilla/Assertions.h"
#include "mozilla/unused.h"
/* Template class allowing a limited number of increments on a value */
template <typename T>
class CheckedIncrement
{
public:
CheckedIncrement(T aValue, size_t aMaxIncrement)
: mValue(aValue), mMaxIncrement(aMaxIncrement)
{}
T operator ++(int)
{
if (!mMaxIncrement) {
MOZ_CRASH("overflow detected");
}
mMaxIncrement--;
return mValue++;
}
T& operator ++()
{
(*this)++;
return mValue;
}
operator T() { return mValue; }
private:
T mValue;
size_t mMaxIncrement;
};
void
FdPrintf(intptr_t aFd, const char* aFormat, ...)
{
if (aFd == 0) {
return;
}
char buf[256];
CheckedIncrement<char*> b(buf, sizeof(buf));
CheckedIncrement<const char*> f(aFormat, strlen(aFormat) + 1);
va_list ap;
va_start(ap, aFormat);
while (true) {
switch (*f) {
case '\0':
goto out;
case '%':
switch (*++f) {
case 'z': {
if (*(++f) == 'u') {
size_t i = va_arg(ap, size_t);
size_t x = 1;
// Compute the number of digits.
while (x <= i / 10) {
x *= 10;
}
// Write the digits into the buffer.
do {
*(b++) = "0123456789"[(i / x) % 10];
x /= 10;
} while (x > 0);
} else {
// Write out the format specifier if it's unknown.
*(b++) = '%';
*(b++) = 'z';
*(b++) = *f;
}
break;
}
case 'p': {
intptr_t ptr = va_arg(ap, intptr_t);
*(b++) = '0';
*(b++) = 'x';
int x = sizeof(intptr_t) * 8;
bool wrote_msb = false;
do {
x -= 4;
size_t hex_digit = ptr >> x & 0xf;
if (hex_digit || wrote_msb) {
*(b++) = "0123456789abcdef"[hex_digit];
wrote_msb = true;
}
} while (x > 0);
if (!wrote_msb) {
*(b++) = '0';
}
break;
}
default:
// Write out the format specifier if it's unknown.
*(b++) = '%';
*(b++) = *f;
break;
}
break;
default:
*(b++) = *f;
break;
}
f++;
}
out:
#ifdef _WIN32
// See comment in FdPrintf.h as to why WriteFile is used.
DWORD written;
WriteFile(reinterpret_cast<HANDLE>(aFd), buf, b - buf, &written, nullptr);
#else
MOZ_UNUSED(write(aFd, buf, b - buf));
#endif
va_end(ap);
}