Closed Bug 1704684 Opened 3 years ago Closed 3 years ago

Improve stability and performance of SharedLibraryInfo::GetInfoForSelf

Categories

(Core :: Gecko Profiler, defect, P2)

defect

Tracking

()

RESOLVED DUPLICATE of bug 1702086

People

(Reporter: toshi, Assigned: toshi)

Details

Crash Data

Attachments

(2 obsolete files)

Bug 1702086 reduced the number of crashes in SharedLibraryInfo::GetInfoForSelf, but the crash still happens because there is a slim timing window where the module could be unloaded.

Severity: -- → S3
Crash Signature: [@ SharedLibraryInfo::GetInfoForSelf] [@ strlen | SharedLibraryInfo::GetInfoForSelf] [@ strlen | NS_ConvertUTF8toUTF16::NS_ConvertUTF8toUTF16 | SharedLibraryInfo::GetInfoForSelf]
Priority: -- → P2

Bug 1702086 had LoadLibraryEx run before GetModuleInformation so that if the module
was already unloaded, we could detect it by checking the return value from GetModuleInformation.

With that patch, however, the same crash still happens and the minidumps indicate LoadLibraryEx
loaded a module onto an address different from hMods[i]. One possible situation which can cause
it is the module was unloaded between GetModuleFileNameEx and LoadLibraryEx, and it was loaded
again between LoadLibraryEx and GetModuleInformation.

This patch detects the situation where the module was unloaded by checking HMODULE returned from
LoadLibraryEx. If LoadLibraryEx returned the same value as hMods[i], it's clear that we
successfully incremented the module's refcount i.e. locked the loaded module.

Because SharedLibraryInfo::GetInfoForSelf() only needs the start/end address of
a module's mapped region in the local process, we can use nt::PEHeaders instead of
GetModuleInformation. It's roughly 100x faster because GetModuleInformation uses
two system calls NtQueryInformationProcess and NtReadVirtualMemory
while nt::PEHeaders does not.

Depends on D111767

Bug 1702086 was reopened due to a regression. Resolving this as a dup.

Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → DUPLICATE
See Also: 1702086
Attachment #9215331 - Attachment is obsolete: true
Attachment #9215330 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: