mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Read a list of disabled process names from the prespecializations library, and turn the feature off if the current process matches. Also allow passing process names in environment variables. Processes can be disabled by name using SWIFT_DEBUG_LIB_PRESPECIALIZED_DISABLED_PROCESSES, and a disable can be overridden with SWIFT_DEBUG_LIB_PRESPECIALIZED_ENABLED_PROCESSES. rdar://126216786
77 lines
2.8 KiB
C++
77 lines
2.8 KiB
C++
//===--- LibPrespecialized.h - Interface for prespecializations -*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Interface for interacting with prespecialized metadata library.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_LIB_PRESPECIALIZED_H
|
|
#define SWIFT_LIB_PRESPECIALIZED_H
|
|
|
|
#include "PrebuiltStringMap.h"
|
|
#include "swift/ABI/Metadata.h"
|
|
#include "swift/ABI/TargetLayout.h"
|
|
|
|
#define LIB_PRESPECIALIZED_TOP_LEVEL_SYMBOL_NAME "_swift_prespecializationsData"
|
|
|
|
namespace swift {
|
|
|
|
template <typename Runtime>
|
|
struct LibPrespecializedData {
|
|
uint32_t majorVersion;
|
|
uint32_t minorVersion;
|
|
|
|
TargetPointer<Runtime, const void> metadataMap;
|
|
TargetPointer<Runtime, const void> disabledProcessesTable;
|
|
|
|
static constexpr uint32_t currentMajorVersion = 1;
|
|
static constexpr uint32_t currentMinorVersion = 2;
|
|
|
|
static constexpr uint32_t minorVersionWithDisabledProcessesTable = 2;
|
|
|
|
// Helpers for retrieving the metadata map in-process.
|
|
static bool stringIsNull(const char *str) { return str == nullptr; }
|
|
|
|
using MetadataMap = PrebuiltStringMap<const char *, Metadata *, stringIsNull>;
|
|
|
|
const MetadataMap *getMetadataMap() const {
|
|
return reinterpret_cast<const MetadataMap *>(metadataMap);
|
|
}
|
|
|
|
const char *const *getDisabledProcessesTable() const {
|
|
if (minorVersion < minorVersionWithDisabledProcessesTable)
|
|
return nullptr;
|
|
return reinterpret_cast<const char *const *>(disabledProcessesTable);
|
|
}
|
|
};
|
|
|
|
const LibPrespecializedData<InProcess> *getLibPrespecializedData();
|
|
Metadata *getLibPrespecializedMetadata(const TypeContextDescriptor *description,
|
|
const void *const *arguments);
|
|
void libPrespecializedImageLoaded();
|
|
|
|
} // namespace swift
|
|
|
|
// Validate the prespecialized metadata map by building each entry dynamically
|
|
// and comparing. This should be called before any metadata is built for other
|
|
// purposes, as any prespecialized entries that have already been cached will
|
|
// not be rebuilt, so the validation will be comparing the prespecialized
|
|
// metadata with itself.
|
|
//
|
|
// On return, outValidated is set to the total number of metadata records that
|
|
// were validated (which is the total number in the table), and outFailed is set
|
|
// to the number that failed validation.
|
|
SWIFT_RUNTIME_EXPORT
|
|
void _swift_validatePrespecializedMetadata();
|
|
|
|
#endif // SWIFT_LIB_PRESPECIALIZED_H
|