What's difference between host_port and task_port??

Questions and Answers about all things *OS (macOS, iOS, tvOS, watchOS)

What's difference between host_port and task_port??

Postby shakeheart » Sun Aug 11, 2019 2:40 pm

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?
shakeheart
 
Posts: 3
Joined: Sun Aug 11, 2019 1:45 pm

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

Postby darkknight » Sun Aug 11, 2019 9:45 pm

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....
darkknight
 
Posts: 102
Joined: Mon Apr 18, 2016 10:49 pm

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

Postby shakeheart » Mon Aug 12, 2019 5:06 am

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)
shakeheart
 
Posts: 3
Joined: Sun Aug 11, 2019 1:45 pm

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

Postby morpheus » Wed Aug 14, 2019 1:59 am

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.
morpheus
Site Admin
 
Posts: 731
Joined: Thu Apr 11, 2013 6:24 pm


Return to Questions and Answers

Who is online

Users browsing this forum: No registered users and 2 guests