Commit d6333678 authored by Bob Owen's avatar Bob Owen
Browse files

Bug 1682520 p1: Move GeckoProcessType and implementation of get and set into mozglue. r=glandium

This means we can set and use the process type earlier in process startup.

Differential Revision: https://phabricator.services.mozilla.com/D152198
parent 2f55a1a8
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#include "XREShellData.h"
#include "application.ini.h"
#include "mozilla/Bootstrap.h"
#include "mozilla/ProcessType.h"
#if defined(XP_WIN)
#  include <windows.h>
#  include <stdlib.h>
@@ -28,6 +29,7 @@
#  include "freestanding/SharedSection.h"
#  include "LauncherProcessWin.h"
#  include "mozilla/GeckoArgs.h"
#  include "mozilla/mscom/ProcessRuntime.h"
#  include "mozilla/WindowsDllBlocklist.h"
#  include "mozilla/WindowsDpiInitialization.h"
#  include "mozilla/WindowsProcessMitigations.h"
@@ -295,6 +297,9 @@ int main(int argc, char* argv[], char* envp[]) {
  // We are launching as a content process, delegate to the appropriate
  // main
  if (argc > 1 && IsArg(argv[1], "contentproc")) {
    // Set the process type. We don't remove the arg here as that will be done
    // later in common code.
    SetGeckoProcessType(argv[argc - 1]);
#  ifdef HAS_DLL_BLOCKLIST
    uint32_t initFlags =
        gBlocklistInitFlags | eDllBlocklistInitFlagIsChildProcess;
+3 −0
Original line number Diff line number Diff line
@@ -66,6 +66,9 @@ int main(int argc, char* argv[]) {
  if (UseForkServer(argc, argv)) {
    ret = RunForkServer(std::move(bootstrap), argc, argv);
  } else {
    // Set the process type. We don't remove the arg here as that will be done
    // later in common code.
    SetGeckoProcessType(argv[argc - 1]);
#ifdef HAS_DLL_BLOCKLIST
    uint32_t initFlags = eDllBlocklistInitFlagIsChildProcess;
#  if defined(MOZ_SANDBOX)
+58 −0
Original line number Diff line number Diff line
/* -*- 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 "ProcessType.h"

#include <cstring>

#include "mozilla/Assertions.h"

using namespace mozilla::startup;

namespace mozilla {
namespace startup {
GeckoProcessType sChildProcessType = GeckoProcessType_Default;
}  // namespace startup

void SetGeckoProcessType(const char* aProcessTypeString) {
#if !defined(DEBUG)
  // If not a DEBUG build then just return if sChildProcessType has already been
  // set and is not fork server. In DEBUG builds we will check that process type
  // matches the one already set if it is not fork server.
  if (sChildProcessType != GeckoProcessType_Default &&
      sChildProcessType != GeckoProcessType_ForkServer) {
    return;
  }
#endif

#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \
                           process_bin_type, procinfo_typename,               \
                           webidl_typename, allcaps_name)                     \
  if (std::strcmp(aProcessTypeString, string_name) == 0) {                    \
    MOZ_ASSERT_IF(                                                            \
        sChildProcessType != GeckoProcessType_Default &&                      \
            sChildProcessType != GeckoProcessType_ForkServer,                 \
        sChildProcessType == GeckoProcessType::GeckoProcessType_##enum_name); \
    sChildProcessType = GeckoProcessType::GeckoProcessType_##enum_name;       \
    return;                                                                   \
  }
#define SKIP_PROCESS_TYPE_DEFAULT
#if !defined(MOZ_ENABLE_FORKSERVER)
#  define SKIP_PROCESS_TYPE_FORKSERVER
#endif
#if !defined(ENABLE_TESTS)
#  define SKIP_PROCESS_TYPE_IPDLUNITTEST
#endif
#include "mozilla/GeckoProcessTypes.h"
#undef SKIP_PROCESS_TYPE_IPDLUNITTEST
#undef SKIP_PROCESS_TYPE_FORKSERVER
#undef SKIP_PROCESS_TYPE_DEFAULT
#undef GECKO_PROCESS_TYPE

  MOZ_CRASH("aProcessTypeString is not valid.");
}

}  // namespace mozilla
+44 −0
Original line number Diff line number Diff line
/* -*- 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/. */

#ifndef IPC_PROCESSTYPE_H_
#define IPC_PROCESSTYPE_H_

#include "mozilla/Attributes.h"
#include "mozilla/Types.h"

// This enum is not dense.  See GeckoProcessTypes.h for details.
enum GeckoProcessType {
#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \
                           process_bin_type, procinfo_typename,               \
                           webidl_typename, allcaps_name)                     \
  GeckoProcessType_##enum_name = (enum_value),
#include "mozilla/GeckoProcessTypes.h"
#undef GECKO_PROCESS_TYPE
  GeckoProcessType_End,
  GeckoProcessType_Invalid = GeckoProcessType_End
};

namespace mozilla {
namespace startup {
extern MFBT_DATA GeckoProcessType sChildProcessType;
}  // namespace startup

/**
 * @return the GeckoProcessType of the current process.
 */
MOZ_ALWAYS_INLINE GeckoProcessType GetGeckoProcessType() {
  return startup::sChildProcessType;
}

/**
 * Set the gecko process type based on a null-terminated byte string.
 */
MFBT_API void SetGeckoProcessType(const char* aProcessTypeString);

}  // namespace mozilla

#endif  // IPC_PROCESSTYPE_H_
+9 −0
Original line number Diff line number Diff line
@@ -58,6 +58,15 @@ if CONFIG["CPU_ARCH"].startswith("x86"):
    ]
    SOURCES["SIMD_avx2.cpp"].flags += ["-mavx2"]

if not CONFIG["JS_STANDALONE"]:
    EXPORTS.mozilla += [
        "ProcessType.h",
    ]

    SOURCES += [
        "ProcessType.cpp",
    ]

OS_LIBS += CONFIG["REALTIME_LIBS"]

if CONFIG["OS_ARCH"] == "WINNT":
Loading