linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: zach@vmware.com
To: akpm@osdl.org, chrisl@vmware.com, chrisw@osdl.org, hpa@zytor.com,
	Keir.Fraser@cl.cam.ac.uk, linux-kernel@vger.kernel.org,
	m+Ian.Pratt@cl.cam.ac.uk, mbligh@mbligh.org, pratap@vmware.com,
	virtualization@lists.osdl.org, zach@vmware.com,
	zwame@arm.linux.org.uk
Subject: [PATCH 6/14] i386 / Add some segment convenience functions
Date: Wed, 10 Aug 2005 21:54:31 -0700	[thread overview]
Message-ID: <200508110454.j7B4sVsL019549@zach-dev.vmware.com> (raw)

Add some convenient segment macros to the kernel.  This makes the
rather obfuscated 'seg & 4' go away.

Patch-keys: i386 segment cleanup
Patch-base: 2.6.13-rc5-mm1
Signed-off-by: Zachary Amsden <zach@vmware.com>
Index: linux-2.6.13/include/asm-i386/segment.h
===================================================================
--- linux-2.6.13.orig/include/asm-i386/segment.h	2005-08-09 19:36:36.000000000 -0700
+++ linux-2.6.13/include/asm-i386/segment.h	2005-08-09 19:43:47.000000000 -0700
@@ -98,4 +98,14 @@
  */
 #define IDT_ENTRIES 256
 
+/*
+ * This bit is set to indicate segment selectors are in the LDT
+ */
+#define LDT_SEGMENT 4
+
+#ifndef __ASSEMBLY__
+#define segment_index(seg) ((seg) >> 3)
+#define segment_from_ldt(seg) ((seg) & LDT_SEGMENT)
+#endif
+
 #endif
Index: linux-2.6.13/arch/i386/kernel/ptrace.c
===================================================================
--- linux-2.6.13.orig/arch/i386/kernel/ptrace.c	2005-08-09 19:36:36.000000000 -0700
+++ linux-2.6.13/arch/i386/kernel/ptrace.c	2005-08-10 20:40:51.000000000 -0700
@@ -146,8 +146,6 @@
 	return retval;
 }
 
-#define LDT_SEGMENT 4
-
 static unsigned long convert_eip_to_linear(struct task_struct *child, struct pt_regs *regs)
 {
 	unsigned long addr, seg;
@@ -165,7 +163,7 @@
 	 * TLS segments are used for data, and the PNPBIOS
 	 * and APM bios ones we just ignore here.
 	 */
-	if (seg & LDT_SEGMENT) {
+	if (segment_from_ldt(seg)) {
 		u32 *desc;
 		unsigned long base;
 
Index: linux-2.6.13/arch/i386/kernel/kprobes.c
===================================================================
--- linux-2.6.13.orig/arch/i386/kernel/kprobes.c	2005-08-09 19:36:36.000000000 -0700
+++ linux-2.6.13/arch/i386/kernel/kprobes.c	2005-08-10 20:42:20.000000000 -0700
@@ -163,8 +163,8 @@
 	/* Check if the application is using LDT entry for its code segment and
 	 * calculate the address by reading the base address from the LDT entry.
 	 */
-	if ((regs->xcs & 4) && (current->mm)) {
-		lp = (unsigned long *) ((unsigned long)((regs->xcs >> 3) * 8)
+	if (segment_from_ldt(regs->xcs) && (current->mm)) {
+		lp = (unsigned long *) ((unsigned long)(segment_index(regs->xcs) * 8)
 					+ (char *) current->mm->context.ldt);
 		addr = (kprobe_opcode_t *) (get_desc_base(lp) + regs->eip -
 						sizeof(kprobe_opcode_t));
Index: linux-2.6.13/arch/i386/kernel/entry.S
===================================================================
--- linux-2.6.13.orig/arch/i386/kernel/entry.S	2005-08-09 19:36:36.000000000 -0700
+++ linux-2.6.13/arch/i386/kernel/entry.S	2005-08-09 19:43:47.000000000 -0700
@@ -268,8 +268,8 @@
 	# See comments in process.c:copy_thread() for details.
 	movb OLDSS(%esp), %ah
 	movb CS(%esp), %al
-	andl $(VM_MASK | (4 << 8) | 3), %eax
-	cmpl $((4 << 8) | 3), %eax
+	andl $(VM_MASK | (LDT_SEGMENT << 8) | 3), %eax
+	cmpl $((LDT_SEGMENT << 8) | 3), %eax
 	je ldt_ss			# returning to user-space with LDT SS
 restore_nocheck:
 	RESTORE_REGS
Index: linux-2.6.13/arch/i386/mm/fault.c
===================================================================
--- linux-2.6.13.orig/arch/i386/mm/fault.c	2005-08-09 19:43:38.000000000 -0700
+++ linux-2.6.13/arch/i386/mm/fault.c	2005-08-10 20:42:20.000000000 -0700
@@ -101,7 +101,7 @@
 	/* Get the GDT/LDT descriptor base. 
 	   When you look for races in this code remember that
 	   LDT and other horrors are only used in user space. */
-	if (seg & (1<<2)) {
+	if (segment_from_ldt(seg)) {
 		/* Must lock the LDT while reading it. */
 		down(&current->mm->context.sem);
 		desc = current->mm->context.ldt;
@@ -115,7 +115,7 @@
 	/* Decode the code segment base from the descriptor */
 	base = get_desc_base((unsigned long *)desc);
 
-	if (seg & (1<<2)) { 
+	if (segment_from_ldt(seg)) { 
 		up(&current->mm->context.sem);
 	} else
 		put_cpu();

             reply	other threads:[~2005-08-11  4:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-11  4:54 zach [this message]
2005-08-16 23:46 ` [PATCH 6/14] i386 / Add some segment convenience functions Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200508110454.j7B4sVsL019549@zach-dev.vmware.com \
    --to=zach@vmware.com \
    --cc=Keir.Fraser@cl.cam.ac.uk \
    --cc=akpm@osdl.org \
    --cc=chrisl@vmware.com \
    --cc=chrisw@osdl.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m+Ian.Pratt@cl.cam.ac.uk \
    --cc=mbligh@mbligh.org \
    --cc=pratap@vmware.com \
    --cc=virtualization@lists.osdl.org \
    --cc=zwame@arm.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).