Commit Graph

89 Commits

Author SHA1 Message Date
Ariel Abreu
be203fd569
Allow threads to perform S2C calls at any time
This is possible now because we can signal threads with a real-time
signal that libsystem_kernel handles.
2022-04-01 02:11:17 -04:00
Ariel Abreu
b4fccbd6dd
Thread: Add mapFile call 2022-04-01 02:04:55 -04:00
Ariel Abreu
fe6df7af56
Add mprotect S2C call 2022-04-01 01:56:35 -04:00
Ariel Abreu
5b0bf0ff13
dtape: Safely stub thread_abort_safely 2022-04-01 01:51:31 -04:00
Ariel Abreu
e46c682d50
Add some dyld info debug messages and fix a typo in TASK_DYLD_INFO
I had forgotten to add `return KERN_SUCCESS`, so it was continuing into
TASK_VM_INFO and presumably failing with KERN_INVALID_ARGUMENT.
2022-03-28 14:19:14 -04:00
Ariel Abreu
f099fe3390
Fix mach_vm_region{,_recurse} to use the target task
They were using the current task, but that's not always the case.
LLDB, for example, calls mach_vm_region_recurse with the map of the task
it's debugging.
2022-03-28 14:17:48 -04:00
Ariel Abreu
8a28cb0dde
Fix Process::memoryRegionInfo and change how it returns info
std::stoul is base 10 by default, so we were trying to process hex
values as decimal values(producing incorrect values, as expected).

Also, memoryRegionInfo now returns a structure with the info rather than
having everything passed in as a reference, just like memoryInfo was
recently changed to do as well. This should make easier to add more info
fields later.
2022-03-28 14:16:00 -04:00
Ariel Abreu
71a247e51e
Add support for nested interrupts 2022-03-27 14:50:23 -04:00
Ariel Abreu
f5b97b9192
Implement mach_vm_region_recurse
This is only a subset of its actual behavior, but this is all that the
LKM supported and everything (read: LLDB) seemed to run fine with that,
so that should be enough for us as well.
2022-03-25 01:09:37 -04:00
Ariel Abreu
fd71ed2bfa
Implement task and thread suspension and resumption
These should be the final missing bits for sigexc from the LKM
2022-03-24 14:04:56 -04:00
Ariel Abreu
d5aa92fb5c
Add a thread_suspended call 2022-03-24 14:03:35 -04:00
Ariel Abreu
94c0528f72
Add a ptrace_thupdate call 2022-03-24 14:02:37 -04:00
Ariel Abreu
337935e64c
Add a ptrace_sigexc call 2022-03-24 14:02:08 -04:00
Ariel Abreu
be9afe1fa5
Add a tid_for_thread call 2022-03-24 13:58:45 -04:00
Ariel Abreu
a4364df97b
Add a stop_after_exec call 2022-03-24 13:58:18 -04:00
Ariel Abreu
f1ba799ba9
Add a set_dyld_info call 2022-03-24 13:57:07 -04:00
Ariel Abreu
8bb81313a0
Add a set_tracer call (and implement get_tracer) 2022-03-24 13:47:32 -04:00
Ariel Abreu
2b0ae0e30b
Turn DSERVER_SINGLE_THREADED on by default
This is just until I can work out the bugs specific to multi-threaded darlingserver.
2022-03-24 13:44:20 -04:00
Ariel Abreu
ffcd17e5a7
Implement TASK_VM_INFO 2022-03-24 13:42:04 -04:00
Ariel Abreu
69c5a1d7ed
Add a method and a hook to send a signal to a thread 2022-03-24 13:40:27 -04:00
Ariel Abreu
be6e1921d2
dtape: Add a basic condition variable implementation 2022-03-24 13:35:06 -04:00
Ariel Abreu
df94cff467
psynch: Log to the server log file rather than stdout 2022-03-24 13:06:37 -04:00
Ariel Abreu
11fc38e931
thread_block_parameter: Handle continuation when not waiting
This is actually a valid state for `thread_block_parameter` to enter.
If the caller gave us a continuation but we were unable to wait, we
should simply invoke the continuation with the wait result, much like
we would if we were returning the result.
2022-03-24 13:05:50 -04:00
Ariel Abreu
a82cff6069
RPC changes for better interrupt/signal handling 2022-03-21 00:29:29 -04:00
Ariel Abreu
aee29954e2
Minor fixes for interrupt/signal handling 2022-03-21 00:27:28 -04:00
Ariel Abreu
bf2dce949a
Mount procfs in child
procfs can only be mounted once we're in the container's PID namespace;
otherwise, it shows the old PID namespace.
2022-03-21 00:23:46 -04:00
Ariel Abreu
42f778c9d0
thread_policy and thread_policy_set are actually safe to stub 2022-03-21 00:20:34 -04:00
Ariel Abreu
e450df2d9d
dtape: Stub vm_stats in a less crash-y way 2022-03-21 00:20:09 -04:00
Ariel Abreu
127442f146
dtape: host_info: Fix how RAM size is reported
`basic_info->memory_size` is 32-bit; using it for `basic_info->max_mem`
truncates the actual value.
2022-03-21 00:19:24 -04:00
Ariel Abreu
878918aa18
dtape: Implement a few duct-taped functions for neofetch
`mach_vm_region`, `thread_info`, and `TASK_THREAD_TIMES_INFO`
2022-03-15 01:59:46 -04:00
Ariel Abreu
0c08310cc5
dtape: Fix mach_vm_remap
It was using the byte size as the page count, which resulted in mapping many more fixed pages than necessary, overwriting existing memory.
2022-03-10 10:50:49 -05:00
Ariel Abreu
10e4d99c93
Remove constexpr from Call::callNumberToString
Some older compilers can't detect that this is actually constexpr.
2022-03-09 18:41:59 -05:00
Ariel Abreu
2cf1226395
Turn build options into proper CMake options 2022-03-09 17:44:54 -05:00
Ariel Abreu
cb4353fcd2
dtape: Implement a few more duct-taped XNU calls
Also, make sure to terminate the IPC space when destroying a task;
this is what actually terminates ports and turns them into dead names.
2022-03-09 17:35:29 -05:00
Ariel Abreu
db67387fcd
Allow calls to be unmanaged
Unmanaged calls are those that can come from unmanaged processes,
i.e. processes that the server does not control. They can also come from
managed processes, but they don't have to.

This commit does not introduce any unmanaged calls, however.
During local development, I created one and later decided to discard it.
However, this does seem like a useful feature, so it's being added with
this commit.
2022-03-09 17:33:33 -05:00
Ariel Abreu
d33faaa3d8
Treat ECONNREFUSED like EPIPE when sending messages 2022-03-09 17:29:30 -05:00
Ariel Abreu
ddac152b11
Add some code useful for debugging
The main debugging code added is for keeping track of port names and
their associated IPC objects, as well as keeping track of the members of
port sets.

Additionally, when extended debugging is enabled, the server can now
wait for a debugger with the new env var `DSERVER_WAIT4DEBUGGER`.

The AsyncWriter class was originally written for some additional
debugging code I wrote but later decided wouldn't really be useful.
I kept the AsyncWriter class, however, as it seems it might be useful
for future code (it's basically fire-and-forget asynchronous writing).
Note that it has not been tested at all.
2022-03-09 17:28:37 -05:00
Ariel Abreu
1be73cf3ae
Remove threads from ksyn queues upon death 2022-03-04 14:24:44 -05:00
Ariel Abreu
bce5f3049b
Re-work sigexc handling code
We now handle the sigexc calls as normal calls, with the exception that
it's okay for them to become active while another call was active.

We also set the thread's wait result to THREAD_INTERRUPTED and handle
syscall returns in interrupted continuations by jumping back to the
sigexc_enter code.
2022-03-04 12:51:57 -05:00
Ariel Abreu
99da1d77c9
dtape: Partially implement mach_vm_remap
It doesn't support memory sharing or copying to a map other than the
current task yet. However, the LKM didn't support the latter case either,
so the only thing we're really missing is the ability to create a shared
region from a previously private one.
2022-03-04 12:49:17 -05:00
Ariel Abreu
06f9612fa2
Fix race for call destruction when sleeping a microthread
When a microthread went to sleep with a continuation, we discarded its
call. This would lead to the call being disposed before we had a chance
to reply to it. Instead, now we keep a reference to it in the thread
until we send a reply for it.
2022-03-04 00:29:21 -05:00
Ariel Abreu
65cee94d6c
dtape: Initialize host statistics properly 2022-03-03 00:13:03 -05:00
Ariel Abreu
d2fa20cdd1
dtape: Safely stub HOST_VM_INFO in host_statistics 2022-03-03 00:12:31 -05:00
Ariel Abreu
2179e01ebf
dtape: Allow locks to be locked from non-microthread contexts 2022-03-03 00:12:02 -05:00
Ariel Abreu
fa7257ddfd
kqchan: Re-enable ipc_mqueue_override_send
This function works properly now.

Additionally, add some more debug code to Mach port kqchannels,
but remove some debug code from `misc.c` (it causes issues with ASAN).
2022-03-03 00:11:21 -05:00
Ariel Abreu
342245fa21
dtape getters: Return NULL if input is NULL
Found via UBSAN
2022-03-03 00:09:29 -05:00
Ariel Abreu
a7e054c57e
Properly handle task and thread death
It was mainly thread death that needed fixing; we need to remove
duct-taped threads from their task's thread list.
2022-03-03 00:08:38 -05:00
Ariel Abreu
ba7ef096a2
Fix for systems without the "index" option in overlayfs 2022-03-03 00:05:47 -05:00
Ariel Abreu
8c2fc2e364
Inform ASAN about our microthreading business
If we don't tell ASAN about what we're doing with microthreads, it gets
majorly confused about what's going on and generates lots of false
positives.

This is mainly because it poisons the stack, which we re-use when we
start a microthread from a new point (e.g. from a continuation or a new
call). The solution is simple: just tell ASAN that that memory for the
stack is OK when we do this.

Informing ASAN about our microthreads (which it calls "fibers") is just
a neat bonus to have it recognize our microthread stacks as actual stacks
and not just random memory.
2022-03-03 00:04:49 -05:00
Ariel Abreu
3c8765b284
Prevent threads from being doubly impersonated
This means that it should now be impossible for microthread to be running
on two different threads simultaneously, impersonated or not.
2022-03-02 23:56:00 -05:00