/* -*- 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/. */
int32_t ret = readlink(procPath, aBuf, aBufSize - 1); if (ret > -1) {
aBuf[ret] = '\0';
}
return ret; #endif
}
/** * RAII class for timing the duration of an NSPR I/O call and reporting the * result to the mozilla::IOInterposeObserver API.
*/ class NSPRIOAutoObservation : public mozilla::IOInterposeObserver::Observation { public: explicit NSPRIOAutoObservation(mozilla::IOInterposeObserver::Operation aOp,
PRFileDesc* aFd)
: mozilla::IOInterposeObserver::Observation(aOp, "NSPRIOInterposer") { char filename[MAXPATHLEN]; if (mShouldReport && aFd &&
GetPathFromFd(PR_FileDesc2NativeHandle(aFd), filename, sizeof(filename)) != -1) {
CopyUTF8toUTF16(mozilla::MakeStringSpan(filename), mFilename);
} else {
mFilename.Truncate();
}
}
PRStatus PR_CALLBACK interposedClose(PRFileDesc* aFd) { // If we don't have a valid original function pointer something is very wrong.
NS_ASSERTION(sCloseFn, "NSPR IO Interposing: sCloseFn is NULL");
int32_t PR_CALLBACK interposedRead(PRFileDesc* aFd, void* aBuf, int32_t aAmt) { // If we don't have a valid original function pointer something is very wrong.
NS_ASSERTION(sReadFn, "NSPR IO Interposing: sReadFn is NULL");
int32_t PR_CALLBACK interposedWrite(PRFileDesc* aFd, constvoid* aBuf,
int32_t aAmt) { // If we don't have a valid original function pointer something is very wrong.
NS_ASSERTION(sWriteFn, "NSPR IO Interposing: sWriteFn is NULL");
PRStatus PR_CALLBACK interposedFSync(PRFileDesc* aFd) { // If we don't have a valid original function pointer something is very wrong.
NS_ASSERTION(sFSyncFn, "NSPR IO Interposing: sFSyncFn is NULL");
PRStatus PR_CALLBACK interposedFileInfo(PRFileDesc* aFd, PRFileInfo* aInfo) { // If we don't have a valid original function pointer something is very wrong.
NS_ASSERTION(sFileInfoFn, "NSPR IO Interposing: sFileInfoFn is NULL");
PRStatus PR_CALLBACK interposedFileInfo64(PRFileDesc* aFd,
PRFileInfo64* aInfo) { // If we don't have a valid original function pointer something is very wrong.
NS_ASSERTION(sFileInfo64Fn, "NSPR IO Interposing: sFileInfo64Fn is NULL");
void InitNSPRIOInterposing() { // Check that we have not interposed any of the IO methods before
MOZ_ASSERT(!sCloseFn && !sReadFn && !sWriteFn && !sFSyncFn && !sFileInfoFn &&
!sFileInfo64Fn);
// We can't actually use this assertion because we initialize this code // before XPCOM is initialized, so NS_IsMainThread() always returns false. // MOZ_ASSERT(NS_IsMainThread());
// Get IO methods from NSPR and const cast the structure so we can modify it.
PRIOMethods* methods = const_cast<PRIOMethods*>(PR_GetFileMethods());
// Something is badly wrong if we don't get IO methods... However, we don't // want to crash over that in non-debug builds. This is unlikely to happen // so an assert is enough, no need to report it to the caller.
MOZ_ASSERT(methods); if (!methods) { return;
}
void ClearNSPRIOInterposing() { // If we have already cleared IO interposing, or not initialized it this is // actually bad.
MOZ_ASSERT(sCloseFn && sReadFn && sWriteFn && sFSyncFn && sFileInfoFn &&
sFileInfo64Fn);
// Get IO methods from NSPR and const cast the structure so we can modify it.
PRIOMethods* methods = const_cast<PRIOMethods*>(PR_GetFileMethods());
// Something is badly wrong if we don't get IO methods... However, we don't // want to crash over that in non-debug builds. This is unlikely to happen // so an assert is enough, no need to report it to the caller.
MOZ_ASSERT(methods); if (!methods) { return;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.