mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
- Add RuntimeTarget template This will allow for converting between metadata structures for native host and remote target architectures. - Create InProcess and External templates for stored pointers Add a few more types to abstract pointer access in the runtime structures but keep native in-process pointer access the same as that with a plain old pointer type. There is now a notion of a "stored pointer", which is just the raw value of the pointer, and the actual pointer type, which is used for loads. Decoupling these allows us to fork the behavior when looking at metadata in an external process, but keep things the same for the in-process case. There are two basic "runtime targets" that you can use to work with metadata: InProcess: Defines the pointer to be trivially a T* and stored as a uintptr_t. A Metadata * is exactly as it was before, but defined via AbstractMetadata<InProcess>. External: A template that requires a target to specify its pointer size. ExternalPointer: An opaque pointer in another address space that can't (and shouldn't) be indirected with operator* or operator->. The memory reader will fetch the data explicitly.
67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
//===--- HeapObject.h -------------------------------------------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
#ifndef SWIFT_STDLIB_SHIMS_HEAPOBJECT_H
|
|
#define SWIFT_STDLIB_SHIMS_HEAPOBJECT_H
|
|
|
|
#include "RefCount.h"
|
|
|
|
#ifdef __cplusplus
|
|
#include <type_traits>
|
|
#include "swift/Basic/type_traits.h"
|
|
|
|
namespace swift {
|
|
|
|
struct InProcess;
|
|
|
|
template <typename Target> struct TargetHeapMetadata;
|
|
using HeapMetadata = TargetHeapMetadata<InProcess>;
|
|
#else
|
|
typedef struct HeapMetadata HeapMetadata;
|
|
#endif
|
|
|
|
// The members of the HeapObject header that are not shared by a
|
|
// standard Objective-C instance
|
|
#define SWIFT_HEAPOBJECT_NON_OBJC_MEMBERS \
|
|
StrongRefCount refCount; \
|
|
WeakRefCount weakRefCount
|
|
|
|
/// The Swift heap-object header.
|
|
struct HeapObject {
|
|
/// This is always a valid pointer to a metadata object.
|
|
HeapMetadata const *metadata;
|
|
|
|
SWIFT_HEAPOBJECT_NON_OBJC_MEMBERS;
|
|
// FIXME: allocate two words of metadata on 32-bit platforms
|
|
|
|
#ifdef __cplusplus
|
|
HeapObject() = default;
|
|
|
|
// Initialize a HeapObject header as appropriate for a newly-allocated object.
|
|
constexpr HeapObject(HeapMetadata const *newMetadata)
|
|
: metadata(newMetadata)
|
|
, refCount(StrongRefCount::Initialized)
|
|
, weakRefCount(WeakRefCount::Initialized)
|
|
{ }
|
|
#endif
|
|
};
|
|
|
|
#ifdef __cplusplus
|
|
static_assert(swift::IsTriviallyConstructible<HeapObject>::value,
|
|
"HeapObject must be trivially initializable");
|
|
static_assert(std::is_trivially_destructible<HeapObject>::value,
|
|
"HeapObject must be trivially destructible");
|
|
|
|
}
|
|
#endif
|
|
|
|
#endif
|