[RFC 2/6] Replace all checks to USER_CODE_SEG by IFRAME_IS_USER macro.
Jan Klötzke <[email protected]> Tue, 29 Apr 2008 00:45:55 +0200
| Newsgroups | gmane.os.openbeos.kernel.devel |
|---|---|
| Message-ID | <[email protected]> |
In vm86 mode CS will have arbitrary values so we check for both USER_CODE_SEG
and the VM flag in EFLAGS. This is also done when entering interrupt gates.
---
headers/private/kernel/arch/x86/arch_cpu.h | 4 ++++
src/system/kernel/arch/x86/arch_int.c | 2 +-
src/system/kernel/arch/x86/arch_interrupts.S | 2 ++
src/system/kernel/arch/x86/arch_thread.cpp | 2 +-
src/system/kernel/arch/x86/arch_user_debugger.cpp | 4 ++--
5 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/headers/private/kernel/arch/x86/arch_cpu.h b/headers/private/kernel/arch/x86/arch_cpu.h
index 803edc6..11e412f 100644
--- a/headers/private/kernel/arch/x86/arch_cpu.h
+++ b/headers/private/kernel/arch/x86/arch_cpu.h
@@ -157,6 +157,10 @@ struct iframe {
uint32 user_ss;
};
+#define IFRAME_IS_USER(f) ( ((f)->cs == USER_CODE_SEG) \
+ || (((f)->flags & 0x20000) != 0 ))
+#define IFRAME_IS_VM86(f) ( ((f)->flags & 0x20000) != 0 )
+
// features
enum x86_feature_type {
FEATURE_COMMON = 0, // cpuid eax=1, ecx register
diff --git a/src/system/kernel/arch/x86/arch_int.c b/src/system/kernel/arch/x86/arch_int.c
index c612ec6..4d2b472 100644
--- a/src/system/kernel/arch/x86/arch_int.c
+++ b/src/system/kernel/arch/x86/arch_int.c
@@ -401,7 +401,7 @@ unexpected_exception(struct iframe* frame)
return;
}
- if (frame->cs == USER_CODE_SEG) {
+ if (IFRAME_IS_USER(frame)) {
enable_interrupts();
if (user_debug_exception_occurred(type, signal))
diff --git a/src/system/kernel/arch/x86/arch_interrupts.S b/src/system/kernel/arch/x86/arch_interrupts.S
index ace4dd5..1f00a63 100644
--- a/src/system/kernel/arch/x86/arch_interrupts.S
+++ b/src/system/kernel/arch/x86/arch_interrupts.S
@@ -248,6 +248,8 @@ int_bottom:
cmp $USER_CODE_SEG, IFRAME_cs(%ebp)
je int_bottom_user
+ testl $0x20000, IFRAME_flags(%ebp) // VM86 mode
+ jnz int_bottom_user
// disable interrupts -- the handler will enable them, if necessary
cli
diff --git a/src/system/kernel/arch/x86/arch_thread.cpp b/src/system/kernel/arch/x86/arch_thread.cpp
index 3b4f5c0..d9ad8ff 100644
--- a/src/system/kernel/arch/x86/arch_thread.cpp
+++ b/src/system/kernel/arch/x86/arch_thread.cpp
@@ -143,7 +143,7 @@ i386_get_user_iframe(void)
struct iframe* frame = get_current_iframe();
while (frame != NULL) {
- if (frame->cs == USER_CODE_SEG)
+ if (IFRAME_IS_USER(frame))
return frame;
frame = get_previous_iframe(frame);
}
diff --git a/src/system/kernel/arch/x86/arch_user_debugger.cpp b/src/system/kernel/arch/x86/arch_user_debugger.cpp
index 66ec93a..7d9b70f 100644
--- a/src/system/kernel/arch/x86/arch_user_debugger.cpp
+++ b/src/system/kernel/arch/x86/arch_user_debugger.cpp
@@ -778,7 +778,7 @@ x86_handle_debug_exception(struct iframe *frame)
TRACE(("i386_handle_debug_exception(): DR6: %lx, DR7: %lx\n", dr6, dr7));
- if (frame->cs != USER_CODE_SEG) {
+ if (!IFRAME_IS_USER(frame)) {
panic("debug exception in kernel mode: dr6: 0x%lx, dr7: 0x%lx", dr6,
dr7);
return;
@@ -850,7 +850,7 @@ x86_handle_breakpoint_exception(struct iframe *frame)
{
TRACE(("i386_handle_breakpoint_exception()\n"));
- if (frame->cs != USER_CODE_SEG) {
+ if (!IFRAME_IS_USER(frame)) {
panic("breakpoint exception in kernel mode");
return;
}
--
1.5.4.2
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone