summaryrefslogtreecommitdiffstats
path: root/toolkit/xre/dllservices/mozglue/WindowsFallbackLoaderAPI.cpp
blob: bda309d4990110fdc9feedb0788d7881e9d22351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* -*- 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 https://mozilla.org/MPL/2.0/. */

#include "WindowsFallbackLoaderAPI.h"

namespace mozilla {

ModuleLoadInfo FallbackLoaderAPI::ConstructAndNotifyBeginDllLoad(
    void** aContext, PCUNICODE_STRING aRequestedDllName) {
  ModuleLoadInfo loadInfo(aRequestedDllName);

  MOZ_ASSERT(mLoaderObserver);
  if (mLoaderObserver) {
    mLoaderObserver->OnBeginDllLoad(aContext, aRequestedDllName);
  }

  return loadInfo;
}

bool FallbackLoaderAPI::SubstituteForLSP(PCUNICODE_STRING aLSPLeafName,
                                         PHANDLE aOutHandle) {
  MOZ_ASSERT(mLoaderObserver);
  if (!mLoaderObserver) {
    return false;
  }

  return mLoaderObserver->SubstituteForLSP(aLSPLeafName, aOutHandle);
}

void FallbackLoaderAPI::NotifyEndDllLoad(void* aContext, NTSTATUS aLoadNtStatus,
                                         ModuleLoadInfo&& aModuleLoadInfo) {
  aModuleLoadInfo.SetEndLoadTimeStamp();

  if (NT_SUCCESS(aLoadNtStatus)) {
    aModuleLoadInfo.CaptureBacktrace();
  }

  MOZ_ASSERT(mLoaderObserver);
  if (mLoaderObserver) {
    mLoaderObserver->OnEndDllLoad(aContext, aLoadNtStatus,
                                  std::move(aModuleLoadInfo));
  }
}

nt::AllocatedUnicodeString FallbackLoaderAPI::GetSectionName(
    void* aSectionAddr) {
  static const StaticDynamicallyLinkedFunctionPtr<
      decltype(&::NtQueryVirtualMemory)>
      pNtQueryVirtualMemory(L"ntdll.dll", "NtQueryVirtualMemory");
  MOZ_ASSERT(pNtQueryVirtualMemory);

  if (!pNtQueryVirtualMemory) {
    return nt::AllocatedUnicodeString();
  }

  nt::MemorySectionNameBuf buf;
  NTSTATUS ntStatus =
      pNtQueryVirtualMemory(::GetCurrentProcess(), aSectionAddr,
                            MemorySectionName, &buf, sizeof(buf), nullptr);
  if (!NT_SUCCESS(ntStatus)) {
    return nt::AllocatedUnicodeString();
  }

  return nt::AllocatedUnicodeString(&buf.mSectionFileName);
}

nt::LoaderAPI::InitDllBlocklistOOPFnPtr
FallbackLoaderAPI::GetDllBlocklistInitFn() {
  MOZ_ASSERT_UNREACHABLE("This should not be called so soon!");
  return nullptr;
}

nt::LoaderAPI::HandleLauncherErrorFnPtr
FallbackLoaderAPI::GetHandleLauncherErrorFn() {
  MOZ_ASSERT_UNREACHABLE("This should not be called so soon!");
  return nullptr;
}

nt::SharedSection* FallbackLoaderAPI::GetSharedSection() {
  MOZ_ASSERT_UNREACHABLE("This should not be called so soon!");
  return nullptr;
}

void FallbackLoaderAPI::SetObserver(nt::LoaderObserver* aLoaderObserver) {
  mLoaderObserver = aLoaderObserver;
}

}  // namespace mozilla