Commit Graph

17573 Commits

Author SHA1 Message Date
Alastair Houghton
884cf75fb2 [Backtracing] Add missing CxxStdlib dependency.
To do this we also need to fix AddSwiftStdlib because if you set the
`INSTALL_WITH_SHARED` flag, the CMake scripts don't make a target
with the `-static` suffix, but AddSwiftStdlib also assumes that it
should dad `-static` to any module dependencies when building a
static library.
2025-01-31 14:52:48 +00:00
Alastair Houghton
6c7eda887e [Backtracing] Harden output path setting.
We should harden the output path setting so that it can't be used
as part of an exploit to get a crashing process to overwrite a
file at an attacker-controller path, or to divert the crash report
to `/dev/null` to hide their tracks or other such undesirable
activity.

Take a copy of the setting at start-up and write-protect it to
prevent attackers overwriting it.

Note that we already protect against attempts to trigger the
backtracer from privileged programs (both on Darwin and Linux);
this is really a belt and braces measure to make life harder for
attackers.

rdar://136977833
2025-01-31 14:36:56 +00:00
Alastair Houghton
5d9def94ad [Backtracing] Uncached(Local|Remote)MemoryReader only exists on macOS and Linux.
There's no support for this type on anything other than macOS and Linux
right now.

rdar://143865183
2025-01-31 14:22:31 +00:00
Alastair Houghton
857c96300f [Backtracing] Bump minimum deployment targets.
We need a minimum deployment target of 10.15 now, because of the use
of `some Sequence<T>` in the Runtime module interface.

rdar://143869185
2025-01-31 14:16:07 +00:00
Meghana Gupta
681a6c814a Merge pull request #78939 from meg-gupta/ossamoduleson
Enable serialization in OSSA
2025-01-30 23:25:19 -08:00
Dario Rexin
21c4850f6d Merge pull request #79031 from drexin/wip-143852239
[Runtime] Add specialized CVW entry points for multi payload enums
2025-01-30 21:45:09 -08:00
Kuba (Brecka) Mracek
38c0ce58aa Merge pull request #79055 from kubamracek/embedded-concurrency-libcxx
[embedded] Prepare the Embedded Concurrency library for building on armv7m/armv7em
2025-01-30 18:37:59 -08:00
Kuba (Brecka) Mracek
55d5a57963 Merge pull request #79054 from kubamracek/embedded-custom-triples
[embedded] Add a CMake setting for building Embedded Swift stdlib for custom target triples
2025-01-30 18:37:47 -08:00
Erik Eckstein
20db2a488b stdlib: add a missing fixLifetime in withVaList
If this function is inlined, the optimizer can shrink the lifetime of the `args` parameter. This would deallocate the passed arguments (e.g. `NSString`s) before the are used in the closure.
2025-01-30 17:30:22 -08:00
Dario Rexin
923cccf1ea [Runtime] Add specialized CVW entry points for multi payload enums
rdar://143852239

Adding these specialized entry points reduces the overhead of the witness functions by removing the first indirection.
2025-01-30 14:44:49 -08:00
Kuba Mracek
aea2bb563c [embedded] Prepare the Embedded Concurrency library for building on armv7m/armv7em 2025-01-30 10:48:09 -08:00
Kuba Mracek
0a678670cd [embedded] Add a CMake setting for building Embedded Swift stdlib for custom target triples 2025-01-30 10:43:59 -08:00
Saleem Abdulrasool
35cbb211c1 Distributed: silence some -Wcast-function-type-mismatch
This silences some of the newer warnings about the casting of function
pointers which is technically not permitted by the standard (function
and data pointers are not guaranteed to be the same).
2025-01-29 17:46:37 -08:00
Alejandro Alonso
0572eb9ef0 Merge pull request #78857 from Azoy/wordpair-comparable
[stdlib] Add Comparable conformance to WordPair
2025-01-29 11:20:56 -08:00
Saleem Abdulrasool
0e73015f96 Merge pull request #78985 from compnerd/central-dispatch
Concurrency: centralise the definition for `std::bit_cast`
2025-01-29 08:38:11 -08:00
Alastair Houghton
255a39573f [Backtracing] Handle EINTR while trying to create a crash log.
Mike rightly points out that it's possible for `open()` to fail
with `EINTR`, which we should handle here.

rdar://136977833
2025-01-29 16:15:38 +00:00
Alastair Houghton
9bdd9e73dc [Backtracing] Support redirection to a named file.
Add the ability to specify a filename or directory name as the output-to
setting in `SWIFT_BACKTRACE`.  If the option is set to a directory name,
generate a unique filename in that directory using the process name,
process ID and timestamp.

rdar://136977833
2025-01-29 10:20:15 +00:00
Gábor Horváth
8462105e29 Merge pull request #78947 from swiftlang/gaborh/lifetimebound-this 2025-01-29 09:09:53 +00:00
Kuba Mracek
642a8f9762 [embedded] #ifdef the Dictionary.init(uniqueKeysWithValues:) changes only to Embedded Swift 2025-01-28 16:22:46 -08:00
Alejandro Alonso
d2309d264d Fix tests 2025-01-28 12:50:51 -08:00
Kuba (Brecka) Mracek
53921e4c8c Merge pull request #78920 from kubamracek/embedded-wae
[embedded] Support withoutActuallyEscaping in Embedded Swift
2025-01-28 12:32:48 -08:00
Saleem Abdulrasool
f1b859c9a5 Concurrency: centralise the definition for std::bit_cast
Remove the multiple definitions of `std::bit_cast` into a header. While
this is still not great, it does reduce the duplication. This also
silently works towards reducing a bit of the UB introduced here by
adding an inline namespace for `std` which you are not technically
allowed to use. However, by doing this, we have a clear migration path
away from this once we adopt C++20.
2025-01-28 11:14:15 -08:00
Saleem Abdulrasool
21841fc3a3 Merge pull request #78911 from compnerd/bitcasting
Concurrency: silence some `-Wcast-function-type-mismatch` warnings
2025-01-28 10:53:10 -08:00
Dario Rexin
0587075839 Merge pull request #78890 from drexin/wip-143429827
[Runtime] Add compatibility override support for CVW runtime functions
2025-01-28 10:33:52 -08:00
Gabor Horvath
06e5ead8da [cxx-interop] Support borrowing from self in SwiftifyImport
Support adding safe wrappers for APIs returning std::span depending on
the this object. This also fixes an issue for APIs with 0 parameters.

rdar://139074571
2025-01-28 13:54:10 +00:00
Alastair Houghton
ab8e561583 Merge pull request #78516 from al45tair/eng/PR-124913332
[Backtracing] Implement API per SE-0419
2025-01-28 10:48:33 +00:00
Dario Rexin
e15bdc132c [Runtime] Rename CVW entry points for compatibility 2025-01-27 15:43:01 -08:00
Kuba Mracek
f4c69e1ca0 [embedded] Also allow nil in swift_isEscapingClosureAtFileLocation to match the C++ runtime 2025-01-27 10:20:23 -08:00
Alastair Houghton
26d0e49764 [Backtracing] Updates following review.
Added some explanatory text to the Compact Backtrace Format
documentation, and also to the `CMakeLists.txt` for the runtime.

Tweaked the conversions for `Backtrace.Address` to truncate, which
should result in reasonable behaviour for negative fixed-width
integers.

Use a constant for the ASCII values for `/` and `\` in the Compact
Image Format encoder/decoder.

Make the TSD key for `ElfImageCache` non-optional, and call
`fatalError()` if we don't get one.

rdar://124913332
2025-01-27 17:22:39 +00:00
Alastair Houghton
c9c5dc0de1 [Backtracing] Add platform and architecture information.
It's useful to capture the platform and platform version with the image map.
Also, display both the platform and architecture information when generating
a crash log.

rdar://124913332
2025-01-27 15:44:28 +00:00
Kuba Mracek
8e3ee38324 [embedded] Support withoutActuallyEscaping in Embedded Swift 2025-01-25 15:24:20 -08:00
Kuba Mracek
c99e9e4922 [embedded] Support Dictionary.init(uniqueKeysWithValues:) in Embedded Swift 2025-01-25 14:55:19 -08:00
Saleem Abdulrasool
c9df7c57a9 Concurrency: silence some -Wcast-function-type-mismatch warnings
The C++ standard does not guarantee that the code and data pointers are
interchangeable. Recent enhancements to clang now properly identify the
improper `reinterpret_cast` between function types. Silence the warning
by switching to `std::bit_cast`. Unfortunately, this is a C++20 feature
and we are still on C++17. In the case that the compiler doesn't have a
`bit_cast` implementation, fallback with some UB to a local definition.
2025-01-25 10:37:01 -08:00
Saleem Abdulrasool
0dc31a8469 Merge pull request #78900 from compnerd/typechecked
runtime: restore some typechecking for keypath functions
2025-01-25 08:07:41 -08:00
Tim Kientzle
674c76274e Merge pull request #77062 from tbkka/tbkka-remotemirror-133890406
Let indirect enum cases export spare bits
2025-01-24 19:52:59 -08:00
Saleem Abdulrasool
70b7c5446b runtime: restore some typechecking for keypath functions
This addresses some feedback on #78141 as per @rjmccall. Ensure that the
runtime functions match the expected signature.
2025-01-24 16:52:28 -08:00
Dario Rexin
92bebee121 [Runtime] Add compatibility override support for CVW runtime functions
rdar://143429827
2025-01-24 15:11:52 -08:00
Dario Rexin
82d7260ee1 Merge pull request #78818 from drexin/wip-143401725
[Runtime] Improve performance and memory footprint of compatibility o…
2025-01-24 15:11:19 -08:00
Alejandro Alonso
9af4a76b52 Use tuple comparison 2025-01-23 15:55:19 -08:00
Alejandro Alonso
8500d0cba1 Less than is a static function.. 2025-01-23 13:09:47 -08:00
Dario Rexin
96d5ed22db [Runtime] Improve performance and memory footprint of compatibility overrides
rdar://143401725

Replacing the (non-inlined) call to `swift_once` with a relaxed atomic significantly improves the generated code and reduces the memory footprint. The mechanism itself now does not cause a stack frame to be generated and the expected case (no override) should be perfectly predicted and executed in straight line code. The override case should also be well predicted, with only two branches on the same value.
2025-01-23 13:06:40 -08:00
Alejandro Alonso
22d5acd207 Fix logic around comparison 2025-01-23 11:55:21 -08:00
Alejandro Alonso
d5b131a436 Add Comparable conformance to WordPair 2025-01-23 10:08:52 -08:00
John McCall
623d063ad7 Fix remangling isolated(any) function types from type metadata. 2025-01-22 21:41:14 -05:00
Mike Ash
29efab6ccc [Concurrency] Fix Task.sleep on values greater than Int64.max.
In the Dispatch implementation, clamp the delay to INT64_MAX. Swift's nanoseconds value is unsigned, but we ultimately use it with dispatch_time, which takes a signed int64_t. Extremely large values get interpreted as negative, which results in not sleeping.

INT64_MAX nanoseconds is about 292 years, so it should be difficult to notice a practical effect from sleeping for less time than requested due to the clamping.

rdar://143278824
2025-01-22 12:28:18 -05:00
Tony Allevato
400b21fc82 Merge pull request #78808 from allevato/strictness-fixes
[NFC] Include `<cstdlib>` and `<cstdint>` where necessary.
2025-01-22 11:54:45 -05:00
Alastair Houghton
12aee901c2 [Backtracing] Fix compact image map decoding bug.
If we ended up with a `/` at the beginning of a string segment, we
were erroneously not adding to the expansion dictionary when we
should have been.

rdar://124913332
2025-01-22 16:35:44 +00:00
Gábor Horváth
4d24b7d888 Merge pull request #78709 from swiftlang/gaborh/span-lifetimebound-overload
[cxx-interop] Support transforming lifetimebound spans
2025-01-22 14:21:57 +00:00
Tony Allevato
3bd71c9d62 [NFC] Include <cstdlib> and <cstdint> where necessary.
Our Bazel builds have become more strict about libc++
dependencies recently, so these are required to pick up
declarations of `malloc` and `uint32_t`, respectively.
2025-01-22 07:47:16 -05:00
Alastair Houghton
2300577b56 [Backtracing] Fix symbol lookup on Linux.
Also removed a spurious `print()` that got left in by accident,
and disabled the `CodableBacktrace.swift` test on Linux since we
need Foundation and we don't have it there.

rdar://124913332
2025-01-21 19:05:08 +00:00