setting LDTs under FreeBSD

Pierre Beyssac pb at fasterix.freenix.org
Wed Aug 1 15:04:34 CDT 2001


Hi all,

It seems the BSD part of ldt.c directly copies the LDT descriptor
provided by the Windows application, including the priority level.

The problem is that the application sometimes requests LDTs with a
priority of 2, whereas i386_set_ldt() will only let us set level 3
(user) LDTs, and will otherwise fail with EACCESS.

The equivalent Linux code seems to ignore priority, so I wrote the
following patch which fixes the problem by forcing user level on
all requested LDTs.

Pierre

--- ldt.c.orig	Thu Nov 23 16:16:52 2000
+++ ldt.c	Wed Aug  1 21:54:19 2001
@@ -133,7 +133,12 @@
 
 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
     {
-        ret = i386_set_ldt(index, (union descriptor *)entry, 1);
+	LDT_ENTRY entry_copy = *entry;
+	/* The kernel will only let us set LDTs with user priority level */
+	if (entry_copy.HighWord.Bits.Pres
+	    && entry_copy.HighWord.Bits.Dpl != 3)
+		entry_copy.HighWord.Bits.Dpl = 3;
+        ret = i386_set_ldt(index, (union descriptor *)&entry_copy, 1);
         if (ret < 0)
         {
             perror("i386_set_ldt");




More information about the wine-patches mailing list