AsInject
| Number | 0x38 |
|---|---|
| Signature | (args*) -> 0 or -err |
| Group | memory |
| Since | 1.0 |
Fill a frozen process’s address space from parsed ELF data. Second step of the three-step process spawn sequence:
PSpawncreates a new FROZEN process and returns its handle.AsInjectfills the new process’s address space with parsed ELF data.Kickstartmarks the process as schedulable. This is the privileged step betweenPSpawnandKickstart. The asinject struct isAsInjectArgs, defined inspawn_args.h:
typedef struct
{
uint32_t size; /* sizeof(AsInjectArgs); wrapper sets it */
Handle taskHandle; // handle of the target task
VirtAddr DestVAddr; // destination virtual address in the target task's address space
const void *src_buf; // pointer to the source buffer in the current task's address space
size_t len; // length of the source buffer in bytes
MemProt prot; // memory protection flags for the destination mapping (e.g., PROT_READ | PROT_WRITE)
uint32_t flags; // ASINJECT_FLAG_* bits; 0 for the original copy-in behavior
} AsInjectArgs;
flags accepts ASINJECT_FLAG_RESERVE: instead of copying len bytes from src_buf, it
reserves [DestVAddr, DestVAddr + len) as demand-zero anonymous memory in the target address
space. src_buf must be NULL when this flag is set, since no bytes are copied up front.
Pitfalls
Only the init process may call this. Ordinary processes spawn children by messaging init, not by calling AsInject directly. The init process is granted the permission via the PROC_FLAG_INIT flag in the PCB.
Arguments
| Register | Name | Description |
|---|---|---|
r0 | args | Pointer to the injection struct; its first field is a caller-set size |
Returns
0 on success.
Errors
| Code | Condition |
|---|---|
ERR_NOPERM | For a non-privileged caller |
ERR_BADPTR / ERR_BADARG | For a bad struct |