Commit Graph

37 Commits

Author SHA1 Message Date
Kuba (Brecka) Mracek
84e71b8d7a Change the RemoteMirror API to have extensible data layout callback (#15291)
* Change the RemoteMirror API to have extensible data layout callback

* Use DLQ_Get prefix on DataLayoutQueryType enum values

* Simplify MemoryReaderImpl and synthesize minimalDataLayoutQueryFunction
2018-03-16 14:54:04 -07:00
Mike Ash
6c59410943 [ReflectionMirror] Change swift-reflection-test.c to use addReflectionInfo on non-Macho platforms. 2018-03-02 17:36:33 -05:00
Mike Ash
6468322615 [RemoteMirrors] Remove unused PipeMemoryReader_getSizeSize function. 2018-02-27 12:51:21 -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
bf58357e54 [Reflection] Change ReadBytesFunction to return a pointer rather than copying data, and adjust its users accordingly.
rdar://problem/37538580
2018-02-21 12:17:28 -05:00
Mike Ash
1dcdd939ca [Reflection] Implement swift_reflection_addImage which takes care of looking up reflection info on behalf of the client.
rdar://problem/37538580
2018-02-20 16:47:07 -05:00
Saleem Abdulrasool
df54b2af11 reflection: handle LMA != VMA for ELF
ELF is segment mapped, where the segment which contains a particular
section may be mapped to an address which does not correspond to the
address on disk.  Since the reflection dumper does not use the loader to
load the image into memory, we must manually account for any section
offsets.  Calculate this value when we query the mmap'ed image and wire
it through to the relative direct pointer accesses.

When switching to the linker table approach for the ELF metadata
introspection, this was uncovered as the segment containing the orphaned
sections was coalesced into a separate PT_LOAD header which had a non-0
offset for the mapping.
2017-11-29 17:56:15 -08:00
Erik Eckstein
5e80555c9b demangler: put the demangler into a separate library
Previously it was part of swiftBasic.

The demangler library does not depend on llvm (except some header-only utilities like StringRef). Putting it into its own library makes sure that no llvm stuff will be linked into clients which use the demangler library.

This change also contains other refactoring, like moving demangler code into different files. This makes it easier to remove the old demangler from the runtime library when we switch to the new symbol mangling.

Also in this commit: remove some unused API functions from the demangler Context.

fixes rdar://problem/30503344
2017-03-09 13:42:43 -08:00
Erik Eckstein
7d7dc5aaac Demangler: Use a bump-pointer allocator for node allocation.
This makes the demangler about 10 times faster.
It also changes the lifetimes of nodes. Previously nodes were reference-counted.
Now the returned demangle  node-tree is owned by the Demangler class and it’s lifetime ends with the lifetime of the Demangler.

Therefore the old (and already deprecated) global functions demangleSymbolAsNode and demangleTypeAsNode are no longer available.

Another change is that the demangling for reflection now only supports the new mangling (which should be no problem because
we are generating only new mangled names for reflection).
2017-02-24 19:04:13 -08:00
Greg Parker
b71f2fd871 [test] Fix error handling in swift-reflection-test.
* Fix handling of EINTR return from read().
* Don't print errno after errors that do not set errno.
2017-01-20 17:51:23 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Joe
d82ad0357f Fixed buffer overflow in demangler
Changing the name of ErrorProtocol to Error broke this runtime test —
causing a buffer overflow.

The mangled name changed from _TtPs13ErrorProtocol_->_TtPs5Error_  but
the strlen didn’t change from 21 to 12; I update the callers to use
static string length instead of a literal string & length.

Error reported is:
=================================================================
==88865==ERROR: AddressSanitizer: global-buffer-overflow on address
0x0001028ba40d at pc 0x000103291a1f bp 0x7fff5d3492c0 sp 0x7fff5d348a80
READ of size 9 at 0x0001028ba40d thread T0
(libclang_rt.asan_osx_dynamic.dylib+0x42a1e)
std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char
const*, unsigned long) (libc++.1.dylib+0x3f224)
swift::Demangle::NodeFactory::create(swift::Demangle::Node::Kind,
llvm::StringRef) string:2044
namespace)::Demangler::demangleTopLevel() Demangle.cpp:358
unsigned long, swift::Demangle::DemangleOptions const&)
Demangle.cpp:2288
MetadataReader.h:772

0x0001028ba40d is located 51 bytes to the left of global variable
'<string literal>' defined in
'/Users/buildslave/jenkins/workspace/swift-incremental-asan-RDA/swift/to
ols/swift-reflection-test/swift-reflection-test.c:458:19' (0x1028ba440)
of size 41
'<string literal>' is ascii string 'swift-reflection-test <binary
filename>
'
0x0001028ba40d is located 0 bytes to the right of global variable
'<string literal>' defined in
'/Users/buildslave/jenkins/workspace/swift-incremental-asan-RDA/swift/to
ols/swift-reflection-test/swift-reflection-test.c:435:15' (0x1028ba400)
of size 13
'<string literal>' is ascii string '_TtPs5Error_'

SUMMARY: AddressSanitizer: global-buffer-overflow
(libclang_rt.asan_osx_dynamic.dylib+0x42a1e) in wrap_memmove
2016-07-20 18:54:23 +01:00
David Farler
787b0dcc3f Merge pull request #3419 from bitjammer/remote-mirror-metadata-version
SwiftRemoteMirror: Add reflection metadata version query API
2016-07-14 08:30:18 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
David Farler
941ec1e043 SwiftRemoteMirror: Add reflection metadata version query API
rdar://problem/27251582
2016-07-08 14:12:59 -07:00
Slava Pestov
da40b5e566 Merge pull request #2285 from tinysun212/pr-portability-1
[SwiftRemoteMirror] Renamed addr_t to swift_addr_t
2016-06-02 10:59:46 -07:00
David Farler
9dddc6492b SwiftRemoteMirror: Project error existentials
Error existentials have a kind of special heap layout and can also
be compatible as NSError instances, too.
2016-05-10 12:50:31 -07:00
Han Sangjin
675de4048d [SwiftRemoteMirror] Renamed addr_t to swift_addr_t
They would think the type 'addr_t' is defined in the standard library
because it has the same name format with the types in <cstdint>. In
addition, the definition conflicts in Cygwin which defines it differently
in the system library.
2016-05-11 04:02:11 +09:00
David Farler
2fd0b39751 SwiftRemoteMirror: move dump APIs to print to stdout instead of stderr
Rather than move file descriptors around in the tools, just tell the
underlying ::dump methods to print to stdout instead.
2016-05-09 14:29:33 -07:00
Slava Pestov
06dc666b49 Reflection: Small cleanups for swift-reflection-test 2016-05-09 13:40:57 -07:00
Slava Pestov
5cc4ce1760 Reflection: Looking up CaptureDescriptors by remote address
Remote metadata for closure contexts points to a capture descriptor.
We have a local copy of all capture descriptors. Translate the
address by recording the local and remote start address of
reflection metadata.
2016-05-09 13:40:57 -07:00
David Farler
8a005e6335 swift-reflection-test: Funnel all test output to stdout
Some test harnesses may print stdout/stderr in batches, which can
complicate FileCheck. Just funnel everything through stdout.
2016-05-09 13:39:39 -07:00
David Farler
86f2886f17 swift-reflection-test: Send target-specific sizes
There were some unconditional 64-bit values getting sent which
was hanging up on the 32-bit iOS simulator.
2016-05-03 21:04:31 -07:00
David Farler
5f5ce39a1d SwiftRemoteMirror: Wire up existential projection API
Implement the ReflectionContext's implementation of:
swift_reflection_projectExistential.

First, we get the type info of the existential typeref - it should be a
record type info. If it's a class existential, it has trivial layout:
the first word is a pointer to the class instance. Otherwise, if the
value fits in the 3-word buffer of the existential container, it
trivially is also at the start of the container. Otherwise, the value is
off in a heap box somewhere, but the first word of the container is a
pointer to that box.
2016-05-03 21:04:31 -07:00
David Farler
b8cb128a17 swift-reflection-test: Make it possible to call reflect multiple times
This allows you to test multiple class instances in the same file.
2016-05-03 21:04:31 -07:00
Slava Pestov
71d28691ef Reflection: Plumb through capture descriptor section 2016-05-02 01:16:25 -07:00
Slava Pestov
ddc81e1b68 Reflection: Some more refactoring for swift-reflection-test, NFC 2016-05-02 01:16:24 -07:00
practicalswift
8e3ba900b0 [gardening] Fix recently introduced headers. 2016-05-01 12:59:13 +02:00
Slava Pestov
faecfda594 Reflection: Consolidate some code for passing around reflection sections
I'm about to add a new section, and I'd like to update as few
places as possible.
2016-04-30 15:12:38 -07:00
Slava Pestov
1d5b9b09ac Reflection: Add instance-specific layout entry point, and do some refactoring
Closure context layout will depend on the instance itself as well
as the isa pointer, because instead of instantiating metadata for
closures that capture generic parameters, we store the substitutions
inside the context itself.

For classes, this entry point just reads the isa pointer, applies
the isa mask and proceeds down the metadata path.

For now, the only the latter is hooked up.
2016-04-29 15:39:49 -07:00
David Farler
11faafe65e swift-reflection-test: Spread out the printing a little 2016-04-29 12:10:52 -07:00
Slava Pestov
ce1c30b1bc Reflection: Support reading the remote process's isaMask
Also, use the instance layout entry point in swift-reflection-test,
so that we can dump the layout of a class instance and not the
lowering of the reference value.
2016-04-28 22:56:15 -07:00
David Farler
bd9fd053ed swift-reflection-test: Remove stray debug print 2016-04-28 19:38:06 -07:00
David Farler
d769eb328f swift-reflection-test: Reference sizeof pointer/size types statically
These tools are always architecture-specific and always match the
architecture of the built Swift binary that links against
SwiftReflectionTest, so they can statically reference the size of their
pointer types.
2016-04-28 19:38:06 -07:00
David Farler
210f8dfe63 swift-reflection-test: Target SwiftRemoteMirror C API
This tool should test the usage from SwiftRemoteMirror dylib and
the C API, since that is the public interface from which we're
vending the remote reflection functionality.
2016-04-28 19:38:03 -07:00