[PATCH 4/5] Provide facility to catch unhandled page faults in user mode.
Jan Klötzke <[email protected]> Fri, 16 May 2008 20:13:44 +0200
| Newsgroups | gmane.os.openbeos.kernel.devel |
|---|---|
| Message-ID | <[email protected]> |
Add a "fault_callback" to the thread structure which is called when a unhandled
page fault happens in user space. A SIGSEGV will only be sent if the callback
returns "true".
---
headers/private/kernel/thread_types.h | 8 +++++++-
src/system/kernel/vm/vm.cpp | 8 ++++++--
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/headers/private/kernel/thread_types.h b/headers/private/kernel/thread_types.h
index 2088f8c..61227c3 100644
--- a/headers/private/kernel/thread_types.h
+++ b/headers/private/kernel/thread_types.h
@@ -224,6 +224,9 @@ struct team {
typedef int32 (*thread_entry_func)(thread_func, void *);
+typedef bool (*page_fault_callback)(addr_t address, addr_t faultAddress,
+ bool isWrite);
+
struct thread {
int32 flags; // summary of events relevant in interrupt
// handlers (signals pending, user debugging
@@ -275,7 +278,10 @@ struct thread {
cbuf *buffer;
} msg;
- addr_t fault_handler;
+ union {
+ addr_t fault_handler;
+ page_fault_callback fault_callback;
+ };
int32 page_faults_allowed;
/* this field may only stay in debug builds in the future */
diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp
index b6e8a5f..73df1d7 100644
--- a/src/system/kernel/vm/vm.cpp
+++ b/src/system/kernel/vm/vm.cpp
@@ -3864,8 +3864,12 @@ vm_page_fault(addr_t address, addr_t faultAddress, bool isWrite, bool isUser,
release_sem_etc(addressSpace->sem, READ_COUNT, 0);
vm_put_address_space(addressSpace);
#endif
- if (user_debug_exception_occurred(B_SEGMENT_VIOLATION, SIGSEGV))
- send_signal(team_get_current_team_id(), SIGSEGV);
+ struct thread *thread = thread_get_current_thread();
+ if (thread->fault_callback == NULL || thread->fault_callback(
+ address, faultAddress, isWrite)) {
+ if (user_debug_exception_occurred(B_SEGMENT_VIOLATION, SIGSEGV))
+ send_signal(team_get_current_team_id(), SIGSEGV);
+ }
}
}
--
1.5.4.2
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/