Copying in the iovecs requires acquiring mm.mappingRWMutex, which is above
task.mu in the lock ordering.
Instead of copying with task.CopyContext, we perform the copy with
MemoryManager.Copy{In,Out}. The MemoryManagers are 'pinned' with IncUser()
for the duration of the copy operations.
PiperOrigin-RevId: 725325325
Also allow it to target exiting threads, which is consistently observable via
e.g. PTRACE_EVENT_EXIT; check remoteTask.MemoryManager() with remoteTask.mu
locked instead, which is consistent with Linux's
mm/process_vm_access.c:process_vm_rw_core() => kernel/fork.c:mm_access() and
avoids racing with remote task exit.
PiperOrigin-RevId: 599943619
First, it avoids allocating a large buffer that can be costly.
Second, it allows to interrupt a system call in case of any signals.
PiperOrigin-RevId: 580721720
We were using t.ThreadGroup.Leader() as the local task, which led to data races
reading fields that are owned by the task goroutine. But there's no need to use
the Leader, so we just use the calling task everywhere.
PiperOrigin-RevId: 570826256
Some fixes:
* First argument of Task.CopyContext should always be the context.Context
derived from the currently running task, because it is used to get a
CopyScratchBuffer, which must be from the current task. This solved a bunch
of data races.
* Fix logic around which process is remote and which is local. These were
getting mixed up.
* Always read iovec structs (local and remote) from the local process's address
space, since they are syscall arguments. Only use the remote process address
space to read the memory pointed to by the remote iovecs.
* Added ptrace permissions check, per linux.
* Delete unused code from kernel/task_usermem.go
* Rewrote tests so that we read to (write from) a subprocess, rather than the
other way around. So we don't need CAP_PTRACE to run the tests.
* Also make tests async-signal-safe after call to fork(). I think this was the
source of the flakyness on linux previously.
PiperOrigin-RevId: 570506366
This will be used to plumb the syscall number through to a counter metric that
exports the number of times an unimplemented syscall has been called.
Plenty of syscall implementations call `EmitUnimplementedEvent` for flags and
settings that are not implemented. With `sysno` available, they will be able
to plumb that bit of information through.
PiperOrigin-RevId: 518635831
If we use the remote process's scratch buffer in process_vm_readv|writev
calls, we will get data races. Use the local task's scratch buffer always.
PiperOrigin-RevId: 491468904