wine/memory/ldt.c
Alexandre Julliard a69b88b2f2 Release 980315
Sun Mar 15 03:46:50 1998  Dimitrie O. Paun  <dimi@mail.cs.toronto.edu>

	* [*/*]
	Fixed some dprintf_ such that there is one and only one
	new line for each dprintf and that new line occurs at the end.
	Transformed some fprintfs into proper debug statements.
	Removed much redundancy from most of the debug statements. The
	redundancy appeared because now the component and function
	name is output automatically. Most debug statements also used to
	output the name of the function.
	All these changes prepared the source to switch completely to
	the new debugging interface.
	For more info, refer to ./documentation/debug-msg

Sat Mar 14 19:45:23 1997  Andreas Mohr <100.30936@germany.net>

	* [misc/shell.c] [if1632/kernel.spec]
	Changed parameters of FUNC004() to fix a crash.
	Not sure if this fix is correct (doc wanted).

	* [windows/user.c] [if1632/user.spec] [include/user.h]
	Implemented UserSeeUserDo.

	* [msdos/int21.c] [include/msdos.h]
	Added "GET LIST OF LISTS" (INT 21/52h).

Sat Mar 14 15:48:02 1998  Douglas Ridgway <ridgway@gmcl.com>

	* [include/windows.h] [relay32/gdi32.spec] [objects/enhmetafile.c]
	Beginnings of enhanced metafile support.

Fri Mar 13 20:53:09 1998  John Richardson <jrichard@zko.dec.com>

	* [win32/console.c]
	Restart interrupted console writes.

Fri Mar 13 18:59:24 1998  Matthew Becker <mbecker@glasscity.net>

	* [*/*.c]
	Updated documentation for API manpages.

	* [windows/dce.c]
	ReleaseDC16: Fixed cast.

	* [include/windows.h] [memory/virtual.c]
	VirtualQuery{Ex} should return DWORD instead of BOOL32.

Fri Mar 13 13:03:06 1998  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>

	* [README][documentation/status/]
	README updated, added lzexpand,version and multimedia
	status notes to new documentation/status directory.

	* [ole/*.c][if1632/typelib.spec]
	Added typelib stubs, several small additions and fixes.

	* [loader/pe_image.c]
	Fixed a small bug (fixup_imports got passed the wrong hModule in a
	remapcase).

	* [loader/signal.c][if1632/signal.c][misc/winsock_dns.c]
	  [loader/module.c]
	Fixed some recursive debugger crashes (caused by invalid FS).

	* [misc/registry.c]
	Two bugs fixed.

Fri Mar 13 04:55:01 1998  David Lee Lambert <lamber45@egr.msu.edu>

	* [include/winnt.h] [include/winnls.h]
	Moved LANG_xxx flags to winnls.h

	* [include/winnls.h]
	Added flags for GetDateFormat(); fixed validity of
	LOCALE_SYSTEM_DEFAULT.

	* [include/windows.h] 
	Added GetTimeFormat() prototypes.

	* [ole/ole2nls.c]
	Implemented ASCII date- and time-functions,  using an
	optimized common core;  added stubs for Unicode versions;  
	started work on a Unicode core.

	* [AUTHORS]
	Added my name.

Mon Mar  9 20:10:15 1998  Eric Kohl <ekohl@abo.rhein-zeitung.de>

	* [relay32/comctl32.spec] [include/imagelist.h]
	  [include/commctrl.h] [misc/imagelist.c] [misc/Makefile.in]
	First attempt at implementing ImageLists.

Sun Mar  8 20:19:49 1998  Uwe Bonnes  <bon@elektron.ikp.physik.tu-darmstadt.de>

	* [files/dos_fs.c] [configure.in]
	Try to get FileTimeToLocalFileTime,FileTimeToSystemTime and
	SystemTimeToFileTime right.
	Use timegm() where available.

	* [misc/lstr.c]
	Fix an off by one error in FormatMessage and handle the case 
	when args = NULL (used by programs to get the length of the 
	string).

	* [win32/console.c]
	Actual display a per-process Title string, better working
	attempt for WriteConsole32W and ReadConsole32W.

Fri Mar  6 20:33:45 1998  Slaven Rezic  <eserte@cs.tu-berlin.de>

	* [include/config.h.in][configure.in][multimedia/audio.c]
	  [multimedia/dsound.c]
	Added check for FreeBSD sound system.

Sun Mar  1 17:40:10 1998  Jason Schonberg <schon@mti.sgi.com>

	* [controls/edit.c] [include/ole.h] [include/shlobj.h]
	Removed final commas in enum types.

Mon Feb 23 07:52:18 1998  Luiz Otavio L. Zorzella  <zorzella@nr.conexware.com>

	* [multimedia/time.c]
	Workaround to avoid infinite recursion inside timeGetTime.

	* [multimedia/audio.c]
	WODM_GETNUMDEVS and WIDM_GETNUMDEVS only return 1 now if the
	SOUND_DEV can be opened, or if it's busy.
1998-03-15 20:29:56 +00:00

297 lines
9.1 KiB
C

/*
* LDT manipulation functions
*
* Copyright 1993 Robert J. Amstadt
* Copyright 1995 Alexandre Julliard
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "ldt.h"
#include "debug.h"
#ifdef __i386__
#ifdef linux
#include <sys/syscall.h>
struct modify_ldt_s
{
unsigned int entry_number;
unsigned long base_addr;
unsigned int limit;
unsigned int seg_32bit : 1;
unsigned int contents : 2;
unsigned int read_exec_only : 1;
unsigned int limit_in_pages : 1;
unsigned int seg_not_present : 1;
};
static __inline__ int modify_ldt( int func, struct modify_ldt_s *ptr,
unsigned long count )
{
int res;
#ifdef __PIC__
__asm__ __volatile__( "pushl %%ebx\n\t"
"movl %2,%%ebx\n\t"
"int $0x80\n\t"
"popl %%ebx"
: "=a" (res)
: "0" (SYS_modify_ldt),
"g" (func),
"c" (ptr),
"d" (count) );
#else
__asm__ __volatile__("int $0x80"
: "=a" (res)
: "0" (SYS_modify_ldt),
"b" (func),
"c" (ptr),
"d" (count) );
#endif /* __PIC__ */
if (res >= 0) return res;
errno = -res;
return -1;
}
#endif /* linux */
#if defined(__svr4__) || defined(_SCO_DS)
#include <sys/sysi86.h>
#ifndef __sun__
#include <sys/seg.h>
#endif
#endif
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include <machine/segments.h>
extern int i386_get_ldt(int, union descriptor *, int);
extern int i386_set_ldt(int, union descriptor *, int);
#endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ */
#endif /* __i386__ */
ldt_copy_entry ldt_copy[LDT_SIZE];
unsigned char ldt_flags_copy[LDT_SIZE];
/***********************************************************************
* LDT_BytesToEntry
*
* Convert the raw bytes of the descriptor to an ldt_entry structure.
*/
void LDT_BytesToEntry( const unsigned long *buffer, ldt_entry *content )
{
content->base = (*buffer >> 16) & 0x0000ffff;
content->limit = *buffer & 0x0000ffff;
buffer++;
content->base |= (*buffer & 0xff000000) | ((*buffer << 16) & 0x00ff0000);
content->limit |= (*buffer & 0x000f0000);
content->type = (*buffer >> 10) & 3;
content->seg_32bit = (*buffer & 0x00400000) != 0;
content->read_only = (*buffer & 0x00000200) == 0;
content->limit_in_pages = (*buffer & 0x00800000) != 0;
}
/***********************************************************************
* LDT_EntryToBytes
*
* Convert an ldt_entry structure to the raw bytes of the descriptor.
*/
void LDT_EntryToBytes( unsigned long *buffer, const ldt_entry *content )
{
*buffer++ = ((content->base & 0x0000ffff) << 16) |
(content->limit & 0x0ffff);
*buffer = (content->base & 0xff000000) |
((content->base & 0x00ff0000)>>16) |
(content->limit & 0xf0000) |
(content->type << 10) |
((content->read_only == 0) << 9) |
((content->seg_32bit != 0) << 22) |
((content->limit_in_pages != 0) << 23) |
0xf000;
}
/***********************************************************************
* LDT_GetEntry
*
* Retrieve an LDT entry.
*/
int LDT_GetEntry( int entry, ldt_entry *content )
{
int ret = 0;
content->base = ldt_copy[entry].base;
content->limit = ldt_copy[entry].limit;
content->type = (ldt_flags_copy[entry] & LDT_FLAGS_TYPE);
content->seg_32bit = (ldt_flags_copy[entry] & LDT_FLAGS_32BIT) != 0;
content->read_only = (ldt_flags_copy[entry] & LDT_FLAGS_READONLY) !=0;
content->limit_in_pages = (ldt_flags_copy[entry] & LDT_FLAGS_BIG) !=0;
if (content->limit_in_pages) content->limit >>= 12;
return ret;
}
/***********************************************************************
* LDT_SetEntry
*
* Set an LDT entry.
*/
int LDT_SetEntry( int entry, const ldt_entry *content )
{
int ret = 0;
TRACE(ldt, "entry=%04x base=%08lx limit=%05lx %s %d-bit "
"flags=%c%c%c\n", entry, content->base, content->limit,
content->limit_in_pages ? "pages" : "bytes",
content->seg_32bit ? 32 : 16,
content->read_only && (content->type & SEGMENT_CODE) ? '-' : 'r',
content->read_only || (content->type & SEGMENT_CODE) ? '-' : 'w',
(content->type & SEGMENT_CODE) ? 'x' : '-' );
/* Entry 0 must not be modified; its base and limit are always 0 */
if (!entry) return 0;
#ifdef __i386__
#ifdef linux
{
struct modify_ldt_s ldt_info;
ldt_info.entry_number = entry;
ldt_info.base_addr = content->base;
ldt_info.limit = content->limit;
ldt_info.seg_32bit = content->seg_32bit != 0;
ldt_info.contents = content->type;
ldt_info.read_exec_only = content->read_only != 0;
ldt_info.limit_in_pages = content->limit_in_pages != 0;
ldt_info.seg_not_present = 0;
/* Make sure the info will be accepted by the kernel */
/* This is ugly, but what can I do? */
if (content->type == SEGMENT_STACK)
{
/* FIXME */
}
else
{
if (ldt_info.base_addr >= 0xc0000000)
{
fprintf( stderr, "LDT_SetEntry: invalid base addr %08lx\n",
ldt_info.base_addr );
return -1;
}
if (content->limit_in_pages)
{
if ((ldt_info.limit << 12) + 0xfff >
0xc0000000 - ldt_info.base_addr)
ldt_info.limit = (0xc0000000 - 0xfff - ldt_info.base_addr) >> 12;
}
else
{
if (ldt_info.limit > 0xc0000000 - ldt_info.base_addr)
ldt_info.limit = 0xc0000000 - ldt_info.base_addr;
}
}
if ((ret = modify_ldt(1, &ldt_info, sizeof(ldt_info))) < 0)
perror( "modify_ldt" );
}
#endif /* linux */
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
{
long d[2];
LDT_EntryToBytes( d, content );
ret = i386_set_ldt(entry, (union descriptor *)d, 1);
if (ret < 0)
{
perror("i386_set_ldt");
fprintf(stderr,
"Did you reconfigure the kernel with \"options USER_LDT\"?\n");
exit(1);
}
}
#endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ */
#if defined(__svr4__) || defined(_SCO_DS)
{
struct ssd ldt_mod;
int i;
ldt_mod.sel = ENTRY_TO_SELECTOR(entry) | 4;
ldt_mod.bo = content->base;
ldt_mod.ls = content->limit;
i = ((content->limit & 0xf0000) |
(content->type << 10) |
(((content->read_only != 0) ^ 1) << 9) |
((content->seg_32bit != 0) << 22) |
((content->limit_in_pages != 0)<< 23) |
(1<<15) |
0x7000);
ldt_mod.acc1 = (i & 0xff00) >> 8;
ldt_mod.acc2 = (i & 0xf00000) >> 20;
if (content->base == 0)
{
ldt_mod.acc1 = 0;
ldt_mod.acc2 = 0;
}
if ((ret = sysi86(SI86DSCR, &ldt_mod)) == -1) perror("sysi86");
}
#endif
#endif /* __i386__ */
if (ret < 0) return ret;
ldt_copy[entry].base = content->base;
if (!content->limit_in_pages) ldt_copy[entry].limit = content->limit;
else ldt_copy[entry].limit = (content->limit << 12) | 0x0fff;
ldt_flags_copy[entry] = (content->type & LDT_FLAGS_TYPE) |
(content->read_only ? LDT_FLAGS_READONLY : 0) |
(content->seg_32bit ? LDT_FLAGS_32BIT : 0) |
(content->limit_in_pages ? LDT_FLAGS_BIG : 0) |
(ldt_flags_copy[entry] & LDT_FLAGS_ALLOCATED);
return ret;
}
/***********************************************************************
* LDT_Print
*
* Print the content of the LDT on stdout.
*/
void LDT_Print( int start, int length )
{
int i;
char flags[3];
if (length == -1) length = LDT_SIZE - start;
for (i = start; i < start + length; i++)
{
if (!ldt_copy[i].base && !ldt_copy[i].limit) continue; /* Free entry */
if ((ldt_flags_copy[i] & LDT_FLAGS_TYPE) == SEGMENT_CODE)
{
flags[0] = (ldt_flags_copy[i] & LDT_FLAGS_EXECONLY) ? '-' : 'r';
flags[1] = '-';
flags[2] = 'x';
}
else
{
flags[0] = 'r';
flags[1] = (ldt_flags_copy[i] & LDT_FLAGS_READONLY) ? '-' : 'w';
flags[2] = '-';
}
fprintf(stderr,"%04x: sel=%04x base=%08lx limit=%08lx %d-bit %c%c%c\n",
i, ENTRY_TO_SELECTOR(i),
ldt_copy[i].base, ldt_copy[i].limit,
ldt_flags_copy[i] & LDT_FLAGS_32BIT ? 32 : 16,
flags[0], flags[1], flags[2] );
}
}