MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vm_thread_stack_create

Function vm_thread_stack_create

freebsd/vm/vm_glue.c:290–332  ·  view source on GitHub ↗

* Create the kernel stack (including pcb for i386) for a new thread. */

Source from the content-addressed store, hash-verified

288 * Create the kernel stack (including pcb for i386) for a new thread.
289 */
290static vm_offset_t
291vm_thread_stack_create(struct domainset *ds, int pages)
292{
293 vm_page_t ma[KSTACK_MAX_PAGES];
294 vm_offset_t ks;
295 int i;
296
297 /*
298 * Get a kernel virtual address for this thread's kstack.
299 */
300#if defined(__mips__)
301 /*
302 * We need to align the kstack's mapped address to fit within
303 * a single TLB entry.
304 */
305 if (vmem_xalloc(kernel_arena, (pages + KSTACK_GUARD_PAGES) * PAGE_SIZE,
306 PAGE_SIZE * 2, 0, 0, VMEM_ADDR_MIN, VMEM_ADDR_MAX,
307 M_BESTFIT | M_NOWAIT, &ks)) {
308 ks = 0;
309 }
310#else
311 ks = kva_alloc((pages + KSTACK_GUARD_PAGES) * PAGE_SIZE);
312#endif
313 if (ks == 0) {
314 printf("%s: kstack allocation failed\n", __func__);
315 return (0);
316 }
317
318 if (KSTACK_GUARD_PAGES != 0) {
319 pmap_qremove(ks, KSTACK_GUARD_PAGES);
320 ks += KSTACK_GUARD_PAGES * PAGE_SIZE;
321 }
322
323 /*
324 * Allocate physical pages to back the stack.
325 */
326 vm_thread_stack_back(ds, ks, ma, pages, VM_ALLOC_NORMAL);
327 for (i = 0; i < pages; i++)
328 vm_page_valid(ma[i]);
329 pmap_qenter(ks, ma, pages);
330
331 return (ks);
332}
333
334static void
335vm_thread_stack_dispose(vm_offset_t ks, int pages)

Callers 2

vm_thread_newFunction · 0.85
kstack_importFunction · 0.85

Calls 7

vmem_xallocFunction · 0.85
kva_allocFunction · 0.85
vm_thread_stack_backFunction · 0.85
vm_page_validFunction · 0.85
printfFunction · 0.50
pmap_qremoveFunction · 0.50
pmap_qenterFunction · 0.50

Tested by

no test coverage detected