Bug 1640325 - Implement IOInterposeObserver::Observation::FileType() on Windows - r=canaltinova

Use `GetFileType(HANDLE)` on Windows.
Unlike `HandleToFilename`, `GetFileType` is fast enough that we don't need to use a `SmallArrayLRUCache` for it.

The pipe I/Os should not be visible anymore in the startup tests.

Differential Revision: https://phabricator.services.mozilla.com/D82303
This commit is contained in:
Gerald Squelart 2020-07-06 23:43:18 +00:00
Родитель 6447251c76
Коммит 9de7e9a9b5
3 изменённых файлов: 34 добавлений и 18 удалений

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

@ -349,12 +349,6 @@ add_task(async function() {
continue;
}
// Ignore pipe I/Os (probably from IPC) on Windows.
// FIXME: This should be removed when bug 1640325 lands.
if (WIN && filename.startsWith("\\??\\pipe\\")) {
continue;
}
// Shared memory uses temporary files on MacOS <= 10.11 to avoid
// a kernel security bug that will never be patched (see
// https://crbug.com/project-zero/1671 for details). This can

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

@ -798,12 +798,6 @@ add_task(async function() {
continue;
}
// Ignore pipe I/Os (probably from IPC) on Windows.
// FIXME: This should be removed when bug 1640325 lands.
if (WIN && filename.startsWith("\\??\\pipe\\")) {
continue;
}
// Shared memory uses temporary files on MacOS <= 10.11 to avoid
// a kernel security bug that will never be patched (see
// https://crbug.com/project-zero/1671 for details). This can

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

@ -130,6 +130,7 @@ class WinIOAutoObservation : public mozilla::IOInterposeObserver::Observation {
aOp, sReference,
!mozilla::IsDebugFile(reinterpret_cast<intptr_t>(aFileHandle))),
mFileHandle(aFileHandle),
mFileHandleType(GetFileType(aFileHandle)),
mHasQueriedFilename(false) {
if (mShouldReport) {
mOffset.QuadPart = aOffset ? aOffset->QuadPart : 0;
@ -140,6 +141,7 @@ class WinIOAutoObservation : public mozilla::IOInterposeObserver::Observation {
nsAString& aFilename)
: mozilla::IOInterposeObserver::Observation(aOp, sReference),
mFileHandle(nullptr),
mFileHandleType(FILE_TYPE_UNKNOWN),
mHasQueriedFilename(false) {
if (mShouldReport) {
nsAutoString dosPath;
@ -156,21 +158,27 @@ class WinIOAutoObservation : public mozilla::IOInterposeObserver::Observation {
void SetHandle(HANDLE aFileHandle) {
mFileHandle = aFileHandle;
if (aFileHandle && mHasQueriedFilename) {
// `mHasQueriedFilename` indicates we already have a filename, add it to
// the cache with the now-known handle.
sHandleToFilenameCache->Add(aFileHandle, mFilename);
if (aFileHandle) {
// Note: `GetFileType()` is fast enough that we don't need to cache it.
mFileHandleType = GetFileType(aFileHandle);
if (mHasQueriedFilename) {
// `mHasQueriedFilename` indicates we already have a filename, add it to
// the cache with the now-known handle.
sHandleToFilenameCache->Add(aFileHandle, mFilename);
}
}
}
// Custom implementation of
// mozilla::IOInterposeObserver::Observation::Filename
const char* FileType() const override;
void Filename(nsAString& aFilename) override;
~WinIOAutoObservation() { Report(); }
private:
HANDLE mFileHandle;
DWORD mFileHandleType;
LARGE_INTEGER mOffset;
bool mHasQueriedFilename;
nsString mFilename;
@ -204,6 +212,26 @@ void WinIOAutoObservation::Filename(nsAString& aFilename) {
aFilename = mFilename;
}
const char* WinIOAutoObservation::FileType() const {
if (mFileHandle) {
switch (mFileHandleType) {
case FILE_TYPE_CHAR:
return "Char";
case FILE_TYPE_DISK:
return "File";
case FILE_TYPE_PIPE:
return "Pipe";
case FILE_TYPE_REMOTE:
return "Remote";
case FILE_TYPE_UNKNOWN:
default:
break;
}
}
// Fallback to base class default implementation.
return mozilla::IOInterposeObserver::Observation::FileType();
}
/*************************** IO Interposing Methods ***************************/
// Function pointers to original functions