Commit Graph

3151 Commits

Author SHA1 Message Date
Doug Gregor
48aa75d86f [Isolated conformances] Cache resolved global actor for conformances
In the prior implementation of runtime resolution of isolated conformances,
the runtime had to look in both the protocol conformance descriptor and
in all conditional conformance requirements (recursively) to find any
isolated conformances. If it found one, it had to demangle the global
actor type to metadata. Since swift_conformsToProtocol is a hot path through
the runtime, we can't afford this non-constant-time work in the common
case.

Instead, cache the resolved global actor and witness table as part of the
conformance cache, so that we have access to this information every time
we look up a witness table for a conformance. Propagate this up through
various callers (e.g., generic requirement checking) to the point where
we either stash it in the cache or check it at runtime. This gets us down
to a very quick check (basically, NULL-or-not) for nonisolated conformances,
and just one check for isolated conformances.
2025-03-07 23:51:46 -08:00
Doug Gregor
6dd141ad54 Replace dlsym of swift_task_isCurrentGlobalActor with a constructor hook
Following the approach taken with the concurrency-specific type
descriptors, register a hook function for the "is current global actor"
check used for isolated conformances.
2025-03-07 23:51:43 -08:00
Doug Gregor
c266a0965f [Isolated conformances] Check witness tables for conditional requirements
When establishing whether a given conformance is isolated, look through
the witness tables used to satisfy conditional requirements as well. This
is because an otherwise-nonisolated conditional conformance can become
isolated if one of its associated conformance requirements is satisfied
by an isolated conformance.

While here, make sure this code works with variadic generics, too.
2025-03-07 23:51:39 -08:00
Doug Gregor
951b535608 Metadata and runtime support for checking isolated conformances at runtime
Extend the metadata representation of protocol conformance descriptors
to include information about the global actor to which the conformance is
isolated (when there is one), as well as the conformance of that type to
the GlobalActor protocol. Emit this metadata whenever a conformance is
isolated.

When performing a conforms-to-protocol check at runtime, check whether
the conformance that was found is isolated. If so, extract the serial
executor for the global actor and check whether we are running on that
executor. If not, the conformance fails.
2025-03-07 23:51:25 -08:00
Nate Chandler
6581fec9e1 [CoroutineAccessors] PtrAuth. 2025-03-07 11:46:51 -08:00
nate-chandler
30d91d39bf Merge pull request #79625 from nate-chandler/general-coro/20250212/1
[CoroutineAccessors] Use retcon.once variant.
2025-02-27 12:58:49 -08:00
Nate Chandler
dd8cbe3e0a [CoroutineAccessors] Use retcon.once variant.
Allocate a coroutine frame in the caller based on the size in the
corresponding "function pointer" and pass it along with an allocator to
the callee.
2025-02-27 07:53:58 -08:00
Alastair Houghton
b5461aeb22 [Backtracing] Added JSON crash log option.
Also made it so the `sanitize` option causes the crash logs to not
include memory dumps.

Fixes #71057
rdar://121430255
2025-02-26 14:12:17 +00:00
Alastair Houghton
0bc76dae80 [Backtracing] Add warning suppression option, enable it for tests.
The backtracing code will warn you if you attempt to forcibly enable
backtracing for a privileged executable.  This is apparently upsetting
the Driver/filelists.swift test.

Since we want to force it on for tests, so that we will definitely get
backtraces, add an option to suppress warning messages, and turn that
on for tests as well.

rdar://144497613
2025-02-24 12:55:16 +00:00
Saleem Abdulrasool
10c804b0bb runtime: adjust the program name reference
`__progname` is not available on Windows, and is provided by libbsd on
Linux. This provides a replacement for the functional aspect of the
symbol on Windows.
2025-02-22 07:14:26 -08:00
Pavel Yaskevich
1067ead82c [Mangling] Mangle presence of @execution(caller) in a function type
If `@execution(caller)` attribute is present on a function type,
mark its presence in the mangling with `YC` suffix.
2025-02-19 16:48:41 -08:00
Konrad `ktoso` Malawski
d8f89bd948 [Distributed] improved return type metadata test and dont allow partial metadata 2025-02-15 18:15:10 +09:00
Konrad `ktoso` Malawski
62155f380d [Distributed] Improve getting return type metadata for distributed invocations
rdar://141313340
2025-02-15 11:27:06 +09:00
Alastair Houghton
f0050df4c9 Merge pull request #79007 from al45tair/eng/PR-136977833
[Backtracing] Support redirection to a named file.
2025-02-14 16:59:29 +00:00
Rashmi Mudduluru
f60394db46 [SUA][Runtime] Define swift_coroFrameAlloc function that allocates typed memory (#79200)
[SUA][Runtime] Define `swift_coroFrameAlloc` function that allocates typed memory

Define `swift_coroFrameAlloc` that allocates typed memory if SWIFT_STDLIB_HAS_MALLOC_TYPE is defined.
This function will be used by IRGen to emit typed memory allocations for property accessors.

rdar://141235539
2025-02-11 09:57:08 -08:00
Saleem Abdulrasool
db160d5e81 runtime: tweak the environment handling
We would previously enable "environment variables" on Android via global
properties. Re-order the macros a bit to make it more explicit that the
environment handling is required for that and remove it when environment
variables are unsupported.
2025-02-07 09:26:49 -08:00
Konrad `ktoso` Malawski
76f3729644 The SWIFT_DUMP_ACCESSIBLE_FUNCTIONS flag must be a bool, not a string 2025-02-05 10:30:53 +09:00
Saleem Abdulrasool
0174528f81 stdlib: fix the problem swept under the rug in 58a97f1603
The `-Winvalid-offsetof` warning is valid in this case. `offsetof` is
being applied to types with a non-standard layout. The layout of this
type is undefined by the specification. There is no guarantee that the
type layout is uniform across all ABIs. It is not possible to portably
compute the offset statically, especially efficiently.

Sink this check into a unit test to avoid performing this test at
runtime. In order to do this in the standard library, we would need to
do this check through a global constructor.
2025-02-03 09:25:06 -08: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
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
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
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
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
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
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
John McCall
623d063ad7 Fix remangling isolated(any) function types from type metadata. 2025-01-22 21:41:14 -05:00
Allan Shortlidge
58a97f1603 Runtime: Suppress a -Winvalid-offsetof warning. 2025-01-20 20:22:51 -08:00
Saleem Abdulrasool
e9ec50132f runtime: sprinkle some linker pragmas to autolink
This prepares the runtime to be closed with its dependencies when
performing static linking. The pragma ensures that the linker will
automatically pick up the dependent libraries avoiding the need to
explicitly add the dependencies.
2025-01-17 08:58:42 -08:00
Alastair Houghton
760cc57bef [Backtracing] Rename _Backtracing to Runtime.
Move the backtracing code into a new Runtime module.  This means renaming
the Swift Runtime's CMake target because otherwise there will be a name
clash.

rdar://124913332
2025-01-17 10:09:36 +00:00
Saleem Abdulrasool
66921730ee Merge pull request #78251 from andrurogerz/swift-runtime-debugvars-android
[Runtime] load debug env vars from Android system properties
2025-01-13 13:14:04 -08:00
John McCall
11ff5b4348 Merge pull request #78576 from rjmccall/demangle-sending-result-with-function-isolation
Fix the demangling of sending result types when combined with isolation
2025-01-11 12:35:55 -05:00
John McCall
fa932e736c Fix the demangling of sending result types when combined with isolation
Fixes the immediate problem, but the presence of demangling code in the
runtime means that we'll need a follow-up to fix the compiler so that it
doesn't try to use the demangler to materialize metadata for function types
that have both isolation and a sending result.

rdar://142443925
2025-01-10 21:11:45 -05:00
Saleem Abdulrasool
627e79556e runtime: use the preferred spelling on Windows (NFCI)
This changes the windows path to use the preferred `_strdup` over
`strdup` to avoid the deprecation warning.
2025-01-10 09:31:09 -08:00
Andrew Rogers
63dd1997c0 Add comment explaining debug. propname prefix 2024-12-18 10:07:23 -08:00
Andrew Rogers
b2fb2f465c PR feedback: rename propValueString to buffer 2024-12-18 10:02:56 -08:00
Andrew Rogers
feea6aaefe PR feedback 2024-12-17 11:54:02 -08:00
Andrew Rogers
0192aa4728 [android] also load debug env vars from system properties 2024-12-17 10:24:57 -08:00
Egor Zhdan
84ae5fbe8c [cxx-interop] Fix runtime crash when casting from an existential to a foreign reference type
When a C++ foreign reference type is conformed to a Swift protocol via a Swift extension, trying to cast `any MyProtocol` to the foreign reference type crashes the runtime.

This was because `selectCasterForDest` wasn't handling C++ foreign reference types, and we were hitting `swift_unreachable`.

This change makes sure the runtime doesn't crash for such casts.

Notably, Swift doesn't have enough metadata to determine if the conditional cast actually succeeded. This is also a problem for CF types. Casting CF types in a similar fashion triggers a typechecker diagnostic. That diagnostic will be amended in a follow-up patch to also trigger for foreign reference types.

rdar://141227849
2024-12-16 20:23:17 +00:00
Saleem Abdulrasool
bf337a9c63 Merge pull request #78142 from compnerd/variable-environment
runtime: re-order environment variable lookup
2024-12-13 13:40:25 -08:00
Saleem Abdulrasool
6716c0428e runtime: re-order environment variable lookup
Hoist the no environment case over the case with the environment. This
ensures that if no environment configuration is selected, the code still
builds. If no environment configuration is selected, `ENVIRON` may still
be defined and that results in calls to elided functions.
2024-12-12 10:39:01 -08:00
Saleem Abdulrasool
9e413bd3d2 runtime: use _strdup on Windows
Windows prefers the `_strdup` extension over `strdup`. This avoids
unnecessary warnings when building the standard library.
2024-12-12 10:36:36 -08:00
Konrad `ktoso` Malawski
ed5007f6b1 Merge pull request #77584 from ktoso/wip-check-array-calls 2024-12-04 21:01:36 +09:00
Konrad `ktoso` Malawski
7189aded61 [Distributed] minor cleanups, remove dump=always from tests 2024-12-03 14:59:16 +09:00
Konrad `ktoso` Malawski
6e9224cb5d [Distributed] Introduce SWIFT_DUMP_ACCESSIBLE_FUNCTIONS 2024-12-03 14:59:15 +09:00
Kuba Mracek
9c77074cac [Mangling] Establish a new mangling prefix for Embedded Swift: $e 2024-12-02 15:01:24 -08:00
Allan Shortlidge
806c60020c stdlib: Resolve an unused variable warning. 2024-11-13 09:51:29 -08:00
Allan Shortlidge
a549d0144e stdlib: Resolve -Wmissing-designated-field-initializers warnings. 2024-11-13 09:51:29 -08:00
Evan Wilde
af58e6e875 Merge pull request #77566 from etcwilde/ewilde/stdlib-rebuild-all-the-defines
[CMake] Cleaning up macOS symbol list
2024-11-12 22:02:00 -08:00