sys: Use __is_aligned and __align_down for some kstack alignment operations
Reviewed by: kib, jhibbits Effort: CHERI upstreaming Sponsored by: AFRL, DARPA Differential Revision: https://reviews.freebsd.org/D54840
This commit is contained in:
@@ -93,8 +93,7 @@ set_top_of_stack_td(struct thread *td)
|
||||
struct savefpu *
|
||||
get_pcb_user_save_td(struct thread *td)
|
||||
{
|
||||
KASSERT(((vm_offset_t)td->td_md.md_usr_fpu_save %
|
||||
XSAVE_AREA_ALIGN) == 0,
|
||||
KASSERT(__is_aligned(td->td_md.md_usr_fpu_save, XSAVE_AREA_ALIGN),
|
||||
("Unaligned pcb_user_save area ptr %p td %p",
|
||||
td->td_md.md_usr_fpu_save, td));
|
||||
return (td->td_md.md_usr_fpu_save);
|
||||
|
||||
@@ -91,7 +91,8 @@ get_pcb_user_save_td(struct thread *td)
|
||||
|
||||
p = td->td_kstack + td->td_kstack_pages * PAGE_SIZE -
|
||||
roundup2(cpu_max_ext_state_size, XSAVE_AREA_ALIGN);
|
||||
KASSERT((p % XSAVE_AREA_ALIGN) == 0, ("Unaligned pcb_user_save area"));
|
||||
KASSERT(__is_aligned(p, XSAVE_AREA_ALIGN),
|
||||
("Unaligned pcb_user_save area"));
|
||||
return ((union savefpu *)p);
|
||||
}
|
||||
|
||||
|
||||
@@ -1082,8 +1082,8 @@ cpu_thread_alloc(struct thread *td)
|
||||
{
|
||||
struct pcb *pcb;
|
||||
|
||||
pcb = (struct pcb *)((td->td_kstack + td->td_kstack_pages * PAGE_SIZE -
|
||||
sizeof(struct pcb)) & ~0x3fUL);
|
||||
pcb = (struct pcb *)__align_down(td->td_kstack + td->td_kstack_pages *
|
||||
PAGE_SIZE - sizeof(struct pcb), 0x40);
|
||||
td->td_pcb = pcb;
|
||||
td->td_frame = (struct trapframe *)pcb - 1;
|
||||
}
|
||||
|
||||
@@ -488,9 +488,8 @@ powerpc_init(vm_offset_t fdt, vm_offset_t toc, vm_offset_t ofentry, void *mdp,
|
||||
/*
|
||||
* Finish setting up thread0.
|
||||
*/
|
||||
thread0.td_pcb = (struct pcb *)
|
||||
((thread0.td_kstack + thread0.td_kstack_pages * PAGE_SIZE -
|
||||
sizeof(struct pcb)) & ~15UL);
|
||||
thread0.td_pcb = (struct pcb *)__align_down(thread0.td_kstack +
|
||||
thread0.td_kstack_pages * PAGE_SIZE - sizeof(struct pcb), 16);
|
||||
bzero((void *)thread0.td_pcb, sizeof(struct pcb));
|
||||
pc->pc_curpcb = thread0.td_pcb;
|
||||
|
||||
|
||||
@@ -123,8 +123,8 @@ cpu_fork(struct thread *td1, struct proc *p2, struct thread *td2, int flags)
|
||||
if (td1 == curthread)
|
||||
cpu_update_pcb(td1);
|
||||
|
||||
pcb = (struct pcb *)((td2->td_kstack +
|
||||
td2->td_kstack_pages * PAGE_SIZE - sizeof(struct pcb)) & ~0x3fUL);
|
||||
pcb = (struct pcb *)__align_down(td2->td_kstack +
|
||||
td2->td_kstack_pages * PAGE_SIZE - sizeof(struct pcb), 0x40);
|
||||
td2->td_pcb = pcb;
|
||||
|
||||
/* Copy the pcb */
|
||||
|
||||
Reference in New Issue
Block a user