Mask the non-native bridgeobject bits rather than all spare bits. This prevents us from trying to retain pointers that aren't valid native object pointers.
Rather than attempt to use standard C++ type names, create a namespace specifically for environment variable types and require vars to use a type from that namespace. This avoids the annoying collision between this `string` and `std::string`, and makes everything a bit more consistent. Rename the types a bit to be more appropriate for this context: boolean, uint8, and uint32, instead of bool, uint8_t, and uint32_t.
Fix several early returns which didn't free the string copy made earlier in the function. Fix most of them by doing the string copy only at the very end where it's needed. When we race to insert into the cache and we lose that race, then free the copies before returning the other thread's cached entry.
rdar://170736413
Rather than always calling malloc/free, parameterize the StackAllocator
on the underlying global allocator. The default uses malloc/free, so
most uses of StackAllocator are unchanged by this refactoring.
In the embedded concurrency library, swap in an global allocator that
uses swift_slowAllloc/swift_slowDealloc instead, eliminating the
remaining malloc/free references so everything goes through the
platform abstraction layer. For now, don't change the non-embedded
concurrency library in the same manner.
The shapes this function sees can include both things like
```
kind=Type
kind=ConstrainedExistential
...
```
as well as
```
kind=Type
kind=ExistentialMetatype
kind=Type
kind=ConstrainedExistential
...
```
As such, we need to eat any `Type` or `ExistentialMetatype` nodes
when searching for the `ConstrainedExistential` node.
rdar://169035241
We were crashing when using this hook function because the hook points
at a Swift function, which expects `self` to be set, but we weren't
telling the C compiler and so when we called through the function pointer
from C++ code, the relevant register wasn't set and we'd crash.
Fixes#85134
rdar://163401438
2026-04-27 17:29:34 +01:00
Joe Groff󠄱󠄾󠅄󠄸󠅂󠄿󠅀󠄹󠄳󠅏󠄽󠄱󠄷󠄹󠄳󠅏󠅃󠅄󠅂󠄹󠄾󠄷󠅏󠅄󠅂󠄹󠄷󠄷󠄵󠅂󠅏󠅂󠄵󠄶󠅅󠅃󠄱󠄼󠅏󠄡󠄶󠄱󠄵󠄶󠄲󠄦󠄡󠄧󠄧󠄲󠄤󠄦󠄧󠄢󠄴󠄵󠄵󠄠󠄧󠄶󠄩󠄴󠄣󠄱󠄶󠄳󠄦󠄢󠄥󠄨󠄨󠄳󠄳󠄴󠄢󠄦󠄣󠄡󠄵󠄴󠄳󠄶󠄢󠄢󠄵󠄨󠄳󠄳󠄳󠄡󠄶󠄲󠄣󠄥󠄲󠄥󠄠󠄡󠄳󠄩󠄳󠄨󠄦
In an oversight, I neglected to update this function while updating the other
runtime metadata paths. This function isn't actually used yet, but we want it
to be ready if we do start using it in the future.
rdar://174974129
`DebugActiveProcess()` can fail under certain circumstances, which results
in us not seeing the crashing thread, hence you don't get a backtrace (in
fact, the backtracer used to crash, since we never expected to be in that
situation).
Instead, use `NtQuerySystemInformation()` to get the thread list, then
`OpenProcess()` and `OpenThread()` to get process/thread handles. This
should be more robust.
rdar://171438432
* Have job_run include the actor, executor, and task name.
* Make task_status_changed only trace if one of the tracked values actually changed.
* Add a job_enqueue_executor that covers enqueueing jobs on serial executors (default actors, custom executors, main actor, etc.).
* Actually end the actor lifetime signpost interval.
* Include the actor metadata and context descriptor pointers in actor enqueue/dequeue so the type can be identified.
* Add the task pointer to all task-related signpost messages.
* Emit job_enqueue_main_executor from the swift_task_enqueueImpl path so main actor enqueues appear in traces.
* Add TracingExecutorKind enum and log executorKind in job_enqueue_executor and job_run to distinguish global, default actor, main actor, custom serial executor, and task executor contexts.
While we're here, finally add a test for Concurrency signposts. This is difficult because the signposts are disabled by default and there isn't a good way to turn them on in an automated fashion. Resolve this by adding an environment variable, SWIFT_CONCURRENCY_TRACING_SUBSYSTEM, which overrides the subsystem used by the Concurrency signpost code. The test can use this to set a subsystem that isn't disabled by default, which then allows `log stream` to capture the signposts.
POSIX says the `si_addr` field is valid for `SIGILL`, `SIGFPE`,
`SIGSEGV`, `SIGBUS` and `SIGTRAP`; it doesn't say it's invalid
otherwise, but in practice Linux doesn't always fill it out in
other cases.
For `SIGABRT` and `SIGQUIT` it makes sense to use the program
counter value instead.
rdar://149007223
On older versions of Linux (e.g. Amazon) needs a fix.
The close_range system call doesn't exist on CrashHandlerLinux.cpp uses
SYS_close_range which is not defined in Amazon Linux 2 kernel headers
(pre-Linux 5.9). Introduced by commit e7adede064 "[Backtracing] Add an
option to close all file handles (#87382)" (Carl Peto).
rdar://172151192
---------
Co-authored-by: Carl Peto <carlpeto@Carls-MacBook-Pro.local>
Add an option so that when the backtracer starts in a crashing process
it will close all unnecessary file descriptors before it tries to start
gathering the backtrace as that may take time.
rdar://144402533
If the backtracer crashes, at present we get no clues as to what
went wrong. This makes it very hard to debug. Part of the reason
for this is that we were worried about it entering a recursive
backtracing loop, however not having any messages at all when
something goes awry is a bit of a problem.
To address this, have the backtracing code set an environment
variable to indicate that we're backtracing, then if we crash with
that variable set, disable the backtracer for the subsequent run
of the backtracer. This means that if the initial backtracer
instance crashes, we will try to run at most one more instance to
backtrace *that*.
rdar://170801141
In an effort to disentangle the three sets of llvm headers the targets
in stlib uses (real llvm headers, RuntimeHeaders/llvm,
stdlib/include/llvm), this patch completely removes the includes from
the runtime to RemoteInspection.
This is the first patch to eventually completely remove
RuntimeHeaders/llvm headers.
`flattenWindowsCommandLine` is only used when backtracing on crashes is
enabled. Hoist this into that preprocessor condition to allow it to
reference the command line buffer without an error.
The only way to get a pointer to an artificial subclass is by using ObjC runtime calls to retrieve the class pointer. If someone does this, they probably want the name of that class, rather than the Swift superclass.
rdar://165919756
Improve sporadic inability to capture some thread backtraces on linux.
Occasionally (especially under stress test conditions) crashing programs on Linux were occasionally failing to capture threads with message "swift-runtime: failed to suspend thread". Root cause analysis suggested the issue was libraries such as glibc masking all signals for the process, e.g. during pthread_create. This patch adds a suitable pause and retry semantic for this case.
rdar://169803867
Also, Linux on arm64 (e.g. on Raspberry Pi or running in Docker containers on Apple Silicon Macs) was only capturing the main thread and the crashing thread, this was due to a missing SA_SIGINFO flag when registering a signal handler.
rdar://165040681
This renames the source file to accomodate static linking of the
runtime. When `libswiftCore.lib` is linked against, we would encounter
a linker warning due to the replicated filename:
```
libswiftCore.lib(Win32.cpp.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
```
This just renames two `Errors.cpp` to different names to accomodate the
compaction of `libDemangling` into `swiftCoreRuntime`. This is important
as when statically linked we end up with two members with the same name
which produces a linker issue:
```
libswiftCore.lib(Errors.cpp.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
```
Sometimes crashing programs on Linux were failing to capture threads with message "swift-runtime: failed to suspend thread."
RCA suggested the issue may be libraries such as glibc masking all signals for the process during pthread_create and similar circumstances.
This patch just tries a few times to find a suitable signal.
The patch does not have unit tests, however there is good coverage of the issue in the multi threaded crash unit tests of the soon to be released swift-symbolicate program.
rdar://169803867
On the compiler side, `Borrow` ought to use extra inhabitants from its value
representation, or at least the null pointer for the pointer representation.
On the runtime side, the choice of representation needs to take size into
account.
Tweaked the comment in `Runtime/Config.h`.
Fixed a couple of incorrect ARM64 instruction mnemonics. This still needs
testing on ARM64 Windows.
Fixed an out-of-date comment in `swift-backtrace`.
Use a macro in `Backtrace.cpp` to guarantee we don't overrun the buffer,
and in the process simplify the code slightly.
rdar://101623384
`swift_slowAlloc()` and related functions assume that `malloc(0)` and `aligned_alloc(0)` return non-`NULL` pointers. The C standards allow implementations to return `NULL` when the allocation size is `0`.
This PR implements a check for `0` that instead allocates `1`. The cost of the check is negligible next to the cost of actually allocating, but we'll mark it `SWIFT_UNLIKELY` just in case.
Resolves rdar://169304909.
Hitting `D` when in the backtracer should do the same on Windows
that it does on macOS, namely launching `lldb` and attaching it to
the crashed program.
rdar://101623384