ldt.c revision 4b9d6701570cb98fd36e209314239d104ec584d3
/*
* LDT manipulation functions
*
* Copyright 1993 Robert J. Amstadt
* Copyright 1995 Alexandre Julliard
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
* Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
* other than GPL or LGPL is available it will apply instead, Oracle elects to use only
* the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
* a choice of LGPL license versions is made available with the language indicating
* that LGPLv2 or any later version may be used, or where a choice of which version
* of the LGPL is applied is otherwise unspecified.
*/
#include "config.h"
#include <assert.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "windef.h"
#include "winbase.h"
#ifdef __linux__
#ifdef HAVE_SYS_SYSCALL_H
#endif
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;
unsigned int usable : 1;
unsigned int garbage : 25;
};
{
}
{
int res;
"movl %2,%%ebx\n\t"
"int $0x80\n\t"
"popl %%ebx"
: "=a" (res)
: "0" (SYS_modify_ldt),
"r" (func),
"c" (ptr),
"d" (count),
"m" (*ptr) );
return -1;
}
{
int res;
"movl %3,%%ebx\n\t"
"int $0x80\n\t"
"popl %%ebx"
return -1;
}
#endif /* linux */
#ifndef __sun__
#endif
#endif
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
#include <machine/segments.h>
#endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ */
#ifdef __APPLE__
#include <i386/user_ldt.h>
#endif
/* local copy of the LDT */
#ifdef __APPLE__
struct __wine_ldt_copy wine_ldt_copy = { { 0, 0, 0 } };
#else
struct __wine_ldt_copy wine_ldt_copy;
#endif
#define LDT_FIRST_ENTRY 512
#define LDT_SIZE 8192
/* empty function for default locks */
static void nop(void) { }
static void (*unlock_ldt)(void) = nop;
/***********************************************************************
* wine_ldt_init_locking
*
*/
{
}
/***********************************************************************
* wine_ldt_get_entry
*
* Retrieve an LDT entry. Return a null entry if selector is not allocated.
*/
{
if (is_gdt_sel(sel))
{
*entry = null_entry;
return;
}
lock_ldt();
{
}
else *entry = null_entry;
unlock_ldt();
}
/***********************************************************************
* internal_set_entry
*
* Set an LDT entry, without locking. For internal use only.
*/
{
#ifdef linux
{
struct modify_ldt_s ldt_info;
perror( "modify_ldt" );
}
#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
{
/* The kernel will only let us set LDTs with user priority level */
if (ret < 0)
{
perror("i386_set_ldt");
exit(1);
}
}
{
}
perror("i386_set_ldt");
#else
exit(1);
#endif
if (ret >= 0)
{
}
return ret;
}
/***********************************************************************
* wine_ldt_set_entry
*
* Set an LDT entry.
*/
{
int ret;
lock_ldt();
unlock_ldt();
return ret;
}
/***********************************************************************
* wine_ldt_is_system
*
* Check if the selector is a system selector (i.e. not managed by Wine).
*/
int wine_ldt_is_system( unsigned short sel )
{
}
/***********************************************************************
* wine_ldt_get_ptr
*
* Convert a segment:offset pair to a linear pointer.
* Note: we don't lock the LDT since this has to be fast.
*/
{
int index;
return (void *)offset;
return (void *)offset;
}
/***********************************************************************
* wine_ldt_alloc_entries
*
* Allocate a number of consecutive ldt entries, without setting the LDT contents.
* Return a selector for the first entry.
*/
unsigned short wine_ldt_alloc_entries( int count )
{
if (count <= 0) return 0;
lock_ldt();
for (i = LDT_FIRST_ENTRY; i < LDT_SIZE; i++)
{
{
/* mark selectors as allocated */
unlock_ldt();
}
}
unlock_ldt();
return 0;
}
/***********************************************************************
* wine_ldt_realloc_entries
*
* Reallocate a number of consecutive ldt entries, without changing the LDT contents.
* Return a selector for the first entry.
*/
{
int i;
{
lock_ldt();
/* check if the next selectors are free */
else
if (i < newcount) /* they are not free */
{
}
else /* mark the selectors as allocated */
{
}
unlock_ldt();
}
{
}
return sel;
}
/***********************************************************************
* wine_ldt_free_entries
*
* Free a number of consecutive ldt entries and clear their contents.
*/
{
int index;
lock_ldt();
{
}
unlock_ldt();
}
/***********************************************************************
* wine_ldt_alloc_fs
*
* Allocate an LDT entry for a %fs selector, reusing a global
* GDT selector if possible. Return the selector value.
*/
unsigned short wine_ldt_alloc_fs(void)
{
if (global_fs_sel == -1)
{
#ifdef __linux__
struct modify_ldt_s ldt_info;
int ret;
/* the preloader may have allocated it already */
global_fs_sel = wine_get_fs();
{
global_fs_sel = 0; /* don't try it again */
}
#elif defined(__FreeBSD__)
#endif
}
if (global_fs_sel > 0) return global_fs_sel;
return wine_ldt_alloc_entries( 1 );
}
/***********************************************************************
* wine_ldt_init_fs
*
* Initialize the entry for the %fs selector of the current thread, and
* set the thread %fs register.
*
* Note: this runs in the context of the new thread, so cannot acquire locks.
*/
{
{
#ifdef __linux__
struct modify_ldt_s ldt_info;
int ret;
#elif defined(__FreeBSD__)
#endif
}
else /* LDT selector */
{
}
wine_set_fs( sel );
}
/***********************************************************************
* wine_ldt_free_fs
*
* Free a %fs selector returned by wine_ldt_alloc_fs.
*/
void wine_ldt_free_fs( unsigned short sel )
{
{
/* FIXME: if freeing current %fs we cannot acquire locks */
wine_set_fs( 0 );
}
}
/***********************************************************************
* selector access functions
*/
#endif /* __i386__ */