haiku/headers/private/kernel/kernel.h

91 lines
2.3 KiB
C
Raw Normal View History

/*
* Copyright 2002-2005, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
* Distributed under the terms of the NewOS License.
*/
#ifndef _KERNEL_KERNEL_H
#define _KERNEL_KERNEL_H
#include <config/types.h>
#include <arch_kernel.h>
#include <arch_config.h>
2012-07-06 17:34:50 +04:00
#ifndef KERNEL_LOAD_BASE
# define KERNEL_LOAD_BASE KERNEL_BASE
#endif
// macro to check whether an address is in the kernel address space (avoid
// always-true checks)
#if KERNEL_BASE == 0
# define IS_KERNEL_ADDRESS(x) ((addr_t)(x) <= KERNEL_TOP)
#elif KERNEL_TOP == __HAIKU_ADDR_MAX
# define IS_KERNEL_ADDRESS(x) ((addr_t)(x) >= KERNEL_BASE)
#else
# define IS_KERNEL_ADDRESS(x) \
((addr_t)(x) >= KERNEL_BASE && (addr_t)(x) <= KERNEL_TOP)
#endif
// Buffers passed in from user-space shouldn't point into the kernel.
#if USER_BASE == 0
# define IS_USER_ADDRESS(x) ((addr_t)(x) <= USER_TOP)
#elif USER_TOP == __HAIKU_ADDR_MAX
# define IS_USER_ADDRESS(x) ((addr_t)(x) >= USER_BASE)
#else
# define IS_USER_ADDRESS(x) \
((addr_t)(x) >= USER_BASE && (addr_t)(x) <= USER_TOP)
#endif
#define DEBUG_KERNEL_STACKS
// Note, debugging kernel stacks doesn't really work yet. Since the
// interrupt will also try to use the stack on a page fault, all
// you get is a double fault.
// At least, you then know that the stack overflows in this case :)
/** Size of the kernel stack */
#ifdef B_HAIKU_64_BIT
#define KERNEL_STACK_SIZE (B_PAGE_SIZE * 4) // 16 kB
#else
#define KERNEL_STACK_SIZE (B_PAGE_SIZE * 3) // 12 kB
#endif
#ifdef DEBUG_KERNEL_STACKS
# define KERNEL_STACK_GUARD_PAGES 1
#else
# define KERNEL_STACK_GUARD_PAGES 0
#endif
/** Size of the environmental variables space for a process */
#define ENV_SIZE (B_PAGE_SIZE * 8)
* Renamed the ROUNDOWN macro to ROUNDDOWN. Also changed the implementation of ROUNDUP to use '*' and '/' -- the compiler will optimize that for powers of two anyway and this implementation works for other numbers as well. * The thread::fault_handler use in C[++] code was broken with gcc 4. At least when other functions were invoked. Trying to trick the compiler wasn't a particularly good idea anyway, since the next compiler version could break the trick again. So the general policy is to use the fault handlers only in assembly code where we have full control. Changed that for x86 (save for the vm86 mode, which has a similar mechanism), but not for the other architectures. * Introduced fault_handler, fault_handler_stack_pointer, and fault_jump_buffer fields in the cpu_ent structure, which must be used instead of thread::fault_handler in the kernel debugger. Consequently user_memcpy() must not be used in the kernel debugger either. Introduced a debug_memcpy() instead. * Introduced debug_call_with_fault_handler() function which calls a function in a setjmp() and fault handler context. The architecture specific backend arch_debug_call_with_fault_handler() has only been implemented for x86 yet. * Introduced debug_is_kernel_memory_accessible() for use in the kernel debugger. It determines whether a range of memory can be accessed in the way specified. The architecture specific back end arch_vm_translation_map_is_kernel_page_accessible() has only been implemented for x86 yet. * Added arch_debug_unset_current_thread() (only implemented for x86) to unset the current thread pointer in the kernel debugger. When entering the kernel debugger we do some basic sanity checks of the currently set thread structure and unset it, if they fail. This allows certain commands (most importantly the stack trace command) to avoid accessing the thread structure. * x86: When handling a double fault, we do now install a special handler for page faults. This allows us to gracefully catch faulting commands, even if e.g. the thread structure is toast. We are now in much better shape to deal with double faults. Hopefully avoiding the triple faults that some people have been experiencing on their hardware and ideally even allowing to use the kernel debugger normally. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32073 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-08-03 16:39:56 +04:00
#define ROUNDDOWN(a, b) (((a) / (b)) * (b))
#define ROUNDUP(a, b) ROUNDDOWN((a) + (b) - 1, b)
#define CHECK_BIT(a, b) ((a) & (1 << (b)))
#define SET_BIT(a, b) ((a) | (1 << (b)))
#define CLEAR_BIT(a, b) ((a) & (~(1 << (b))))
/* during kernel startup, interrupts are disabled (among other things) */
extern bool gKernelStartup;
extern bool gKernelShutdown;
#ifdef __cplusplus
extern "C" {
#endif
status_t system_shutdown(bool reboot);
status_t _user_shutdown(bool reboot);
#ifdef __cplusplus
}
#endif
#endif /* _KERNEL_KERNEL_H */