1 // Copyright 2018 The Fuchsia Authors 2 // 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file or at 5 // https://opensource.org/licenses/MIT 6 #pragma once 7 8 #include <err.h> 9 #include <sys/types.h> 10 11 __BEGIN_CDECLS 12 13 // kstack encapsulates a kernel stack. 14 // 15 // kstack must be a C struct because it is embedded in thread_t. 16 typedef struct kstack { 17 vaddr_t base; 18 size_t size; 19 vaddr_t top; 20 21 // When non-null, |vmar| (and, if safe-stack is enabled, |unsafe_vmar|) points to a ref-counted 22 // VmAddressRegion that must be freed via |vm_free_kstack|. 23 // 24 // Note, the type is void* rather than |fbl::RefPtr| because this struct is used by C code. 25 void* vmar; 26 #if __has_feature(safe_stack) 27 vaddr_t unsafe_base; 28 // See comment for |vmar|. 29 void* unsafe_vmar; 30 #endif 31 } kstack_t; 32 33 // Allocates a kernel stack with appropriate overrun padding. 34 // 35 // Assumes stack has been zero-initialized. 36 zx_status_t vm_allocate_kstack(kstack_t* stack); 37 38 // Frees a stack allocated by |vm_allocate_kstack|. 39 zx_status_t vm_free_kstack(kstack_t* stack); 40 41 __END_CDECLS 42