Commit Graph

29 Commits

Author SHA1 Message Date
Mike Ash
15468ee70a [RemoteMirror] Remove C++isms from interop header and clean up.
* Change nullptr to NULL.
* Change bool to int.
* Fix missing DataLayout parameter in createReflectionContext.
* Silence unused parameter warnings in the minimalDataLayoutQueryFunctions.

rdar://problem/59909982
2020-03-23 13:53:35 -04:00
Mike Ash
308695b7f3 [RemoteMirror] Add copyDemangledNameForTypeRef to interop header.
rdar://problem/59909982
2020-03-23 13:53:35 -04:00
tbkka
0d361bd3ea Teach RemoteMirror how to project enum values (#30161)
Teach RemoteMirror how to project enum values

This adds two new functions to the SwiftRemoteMirror
facility that support inspecting enum values.

Currently, these support non-payload enums and
single-payload enums, including nested enums and
payloads with struct, tuple, and reference payloads.
In particular, it handles nested `Optional` types.

TODO: Multi-payload enums use different strategies for
encoding the cases that aren't yet supported by this
code.

Note: This relies on information from dataLayoutQuery
to correctly decode invalid pointer values that are used
to encode enums.  Existing clients will need to augment
their DLQ functions before using these new APIs.

Resolves rdar://59961527

```
/// Projects the value of an enum.
///
/// Takes the address and typeref for an enum and determines the
/// index of the currently-selected case within the enum.
///
/// Returns true iff the enum case could be successfully determined.
/// In particular, note that this code may fail for valid in-memory data
/// if the compiler is using a strategy we do not yet understand.
SWIFT_REMOTE_MIRROR_LINKAGE
int swift_reflection_projectEnumValue(SwiftReflectionContextRef ContextRef,
                                      swift_addr_t EnumAddress,
                                      swift_typeref_t EnumTypeRef,
                                      uint64_t *CaseIndex);

/// Finds information about a particular enum case.
///
/// Given an enum typeref and index of a case, returns:
/// * Typeref of the associated payload or zero if there is no payload
/// * Name of the case if known.
///
/// The Name points to a freshly-allocated C string on the heap.  You
/// are responsible for freeing the string (via `free()`) when you are finished.
SWIFT_REMOTE_MIRROR_LINKAGE
int swift_reflection_getEnumCaseTypeRef(SwiftReflectionContextRef ContextRef,
                                        swift_typeref_t EnumTypeRef,
                                        unsigned CaseIndex,
                                        char **CaseName,
                                        swift_typeref_t *PayloadTypeRef);
```


Co-authored-by: Mike Ash <mikeash@apple.com>
2020-03-06 13:17:40 -08:00
Daniel Duan
ff4ecd2e5b [include] Use nullptr instead of NULL (#28509)
NFC, gardening.
2019-12-01 23:20:10 -08:00
Mike Ash
eb830231ba [RemoteMirror] Add support for QueryDataLayoutFunction to the interop header.
Remote Mirror added a new callback, QueryDataLayoutFunction, which provides a nicer and more extensible way to provide things like the target pointer size. Add support for that in the interop header. Search for and call the new creation function when it exists, and shim in support for older libraries that don't have it.

rdar://problem/52849572
2019-07-09 16:25:20 -04:00
Mike Ash
2b89074944 [RemoteMirror] Add a call to the interop header to set the upcoming classIsSwiftMask value. 2019-02-13 14:59:05 -05:00
Mike Ash
7c9388127a [RemoteMirror] Fix various interop warnings in the headers. 2018-11-26 11:12:16 -05:00
Mike Ash
47be50cccc [RemoteMirror] Update interop to handle 4.2 libraries.
The Remote Mirror interop header now accepts an arbitrary number of remote mirror libraries so that it can have 4.1, 4.2, and 5.0 loaded side by side.

rdar://problem/45808282
2018-11-26 11:12:16 -05:00
Mike Ash
ef863ab00a [RemoteMirrors] Have interop header cache address->library lookups.
rdar://problem/37538580
2018-03-16 16:24:54 -04:00
Mike Ash
cdf890b8be [RemoteMirrors] Document lookupMetadata.
rdar://problem/37538580
2018-03-08 13:31:50 -05:00
Mike Ash
da2649a433 [RemoteMirrors] Fix the declaration of lookupMetadata.
rdar://problem/37538580
2018-03-08 13:29:51 -05:00
Mike Ash
ac026128d1 [RemoteMirrors] Provide interop function for converting a raw metadata pointer into a swift_metadata_interop_t.
rdar://problem/37538580
2018-03-08 13:25:09 -05:00
Mike Ash
0e3044bd3a [RemoteMirrors] Provide interop types for typeinfo and childinfo.
rdar://problem/37538580
2018-03-08 10:28:11 -05:00
Mike Ash
c01b9e05ca [RemoteMirrors] Fix a bunch of missing static inlines from SwiftRemoteMirrorLegacyInterop.h. 2018-03-05 10:26:36 -05:00
Mike Ash
acb4142b1a [RemoteMirrors] Move the interop typedefs into a separate header for API clients that just want to pass the types around. 2018-03-05 09:36:44 -05:00
Mike Ash
1434fce417 [RemoteMirrors] Switch #ifdef __APPLE__ to #if defined(__APPLE__) && defined(__MACH__) to be more specific about the fact that this code is for MachO. 2018-03-02 11:03:45 -05:00
Mike Ash
83837ccd12 [RemoteMirrors] Clean up some documentation, comments and macros. Add an assert for pointer sizes that don't match what SwiftRemoteMirror.cpp was built with. 2018-03-01 15:39:14 -05:00
Mike Ash
b3522fa139 [RemoteMirrors] Read the TEXT segment into local memory when getting legacy reflection sections. Test that this works when memory is read into a dynamic buffer. 2018-03-01 13:56:29 -05:00
Mike Ash
09181712d4 [RemoteMirrors] Move up the typedef for SwiftReflectionInteropContextRef so things compile again. 2018-03-01 13:55:20 -05:00
Mike Ash
4424b2757f [RemoteMirrors] Add some header documentation and add prototypes for the "public" interop functions. 2018-02-28 16:36:17 -05:00
Mike Ash
c059ff2a5c [RemoteMirrors] Fix the ownership check for legacy libraries. The working implementation requires a non-legacy library to be present. Fall back to always saying "yes" otherwise. 2018-02-27 17:06:37 -05:00
Mike Ash
0b5876607e [RemoteMirrors] Implement object ownership interop for the legacy library. This avoids crashing when inspecting newer metadata with only the legacy library loaded. 2018-02-27 15:16:16 -05:00
Mike Ash
d775f72d19 [RemoteMirrors] Support passing NULL for the FreeBytesFunction. 2018-02-27 15:16:15 -05:00
Mike Ash
71f1c391ab [RemoteMirrors] Move FreeBytesFunction from an out-parameter on ReadBytesFunction to a function pointer passed in when creating a reflection context. 2018-02-27 12:51:04 -05:00
Mike Ash
6f887475a3 [Reflection] Lots of smaller fixes and API changes due to testing the interop code.
* Remove getPointerSize and getSizeSize functions, replace with a single PointerSize value.
* Remove imageLength parameter from addImage, calculate it internally instead.
* Check remote mirrors libraries' metadata version and reject them if it's too old.
* Shim GetStringLength and GetSymbolAddress for the legacy library since we don't pass the caller's context pointer through directly.
* Actually set the IsLegacy flag in the Library struct.
* Implement ownsObject by tracking each added image's data segment and checking metadata pointers against them. The previous approach didn't work.
2018-02-26 16:56:54 -05:00
Mike Ash
1ad9729bb5 [Reflection] Add the last of the interop APIs.
rdar://problem/37538580
2018-02-23 13:57:13 -05:00
Mike Ash
4ae7740c28 [Reflection] Fill out more remote mirror interop APIs.
rdar://problem/37538580
2018-02-23 13:20:18 -05:00
Mike Ash
4c7d203574 [Reflection] Implement more interop API calls.
rdar://problem/37538580
2018-02-23 11:47:24 -05:00
Mike Ash
89d9f2ba82 [Reflection] Start work on a header to help clients that want to use both old and new remote mirrors libraries at the same time.
rdar://problem/37538580
2018-02-22 12:07:39 -05:00