Page 1 of 1

What's difference between host_port and task_port??

PostPosted: Sun Aug 11, 2019 2:40 pm
by shakeheart
As we know , we can get the task port via mach_task_self()=>task_self_trap() to get the task port from kernel and also can get the host port via mach_host_self()=>host_self_trap().
They are different syscalls (0x100001C/0x100001D), so I believe there is no need to design two syscalls to get the same port .

But I read the XNU code and find both task_self_trap and host_self_trap return the port that copy send right from task->itk_host.
SO I have this question about this:
- What's difference between host_port and task_port? are they same?

Re: What's difference between host_port and task_port??

PostPosted: Sun Aug 11, 2019 9:45 pm
by darkknight
shakeheart wrote:As we know , we can get the task port via mach_task_self()=>task_self_trap() to get the task port from kernel and also can get the host port via mach_host_self()=>host_self_trap().
They are different syscalls (0x100001C/0x100001D), so I believe there is no need to design two syscalls to get the same port .

But I read the XNU code and find both task_self_trap and host_self_trap return the port that copy send right from task->itk_host.
SO I have this question about this:
- What's difference between host_port and task_port? are they same?


This is covered in Volume I -- Host Port(page 346) and Task Port (pages 350 -354). Per those pages, the Host port provides diagnostic information about the machine and OS as well as access to the processor set etc.

The Task port on the other hand, is like the "handle" to a "process". Recall that in Mach, every BSD process has an associated Mach Task. Obtaining a SEND right to a task via traps -- task_for_pid or pid_for_task means the task is yours to do your bidding -- using mach_vm api's etc....

Re: What's difference between host_port and task_port??

PostPosted: Mon Aug 12, 2019 5:06 am
by shakeheart
darkknight wrote:
shakeheart wrote:As we know , we can get the task port via mach_task_self()=>task_self_trap() to get the task port from kernel and also can get the host port via mach_host_self()=>host_self_trap().
They are different syscalls (0x100001C/0x100001D), so I believe there is no need to design two syscalls to get the same port .

But I read the XNU code and find both task_self_trap and host_self_trap return the port that copy send right from task->itk_host.
SO I have this question about this:
- What's difference between host_port and task_port? are they same?


This is covered in Volume I -- Host Port(page 346) and Task Port (pages 350 -354). Per those pages, the Host port provides diagnostic information about the machine and OS as well as access to the processor set etc.

The Task port on the other hand, is like the "handle" to a "process". Recall that in Mach, every BSD process has an associated Mach Task. Obtaining a SEND right to a task via traps -- task_for_pid or pid_for_task means the task is yours to do your bidding -- using mach_vm api's etc....




But I find the msg can send to host_port also can send to task_port(same layout just the remote port is different, one is host_port and one is task_port)

Re: What's difference between host_port and task_port??

PostPosted: Wed Aug 14, 2019 1:59 am
by morpheus
you can send a message to ANY port. You're confusing a few of the terms here.

task_self returns itk_SELF, not itk_host. host_self returns itk_host. The task port is a SEND right to the task, meaning the kernel (holder of the receive) will act on behalf of the target task . The messages you can send there are for the task, vm_map, mach_vm subsystems. The host port is a send right to the host itself, allowing mach_host and possibly host_priv subsystems.