2 * Selector manipulation functions
4 * Copyright 1993 Robert J. Amstadt
5 * Copyright 1995 Alexandre Julliard
11 #include <sys/types.h>
20 #include <linux/unistd.h>
21 #include <linux/head.h>
22 #include <linux/mman.h>
23 #include <linux/a.out.h>
24 #include <linux/ldt.h>
26 #if defined(__NetBSD__) || defined(__FreeBSD__)
28 #include <machine/segments.h>
38 #include "prototypes.h"
41 /* #define DEBUG_SELECTORS */
45 #define MAX_ENV_SIZE 16384 /* Max. environment size (ought to be dynamic) */
47 static HANDLE EnvironmentHandle
= 0;
50 extern char WindowsPath
[256];
54 extern char **environ
;
57 /**********************************************************************
58 * Check whether pseudo-functions like __0040H for direct memory
59 * access are referenced and return 1 if so.
60 * FIXME: Reading and writing to the returned selectors has no effect
61 * (e.g. reading from the Bios data segment (esp. clock!) )
64 unsigned int GetMemoryReference( char *dll_name
, char *function
,
65 WORD
*sel
, WORD
*offset
)
67 static HANDLE memory_handles
[ 10 ] = { 0,0,0,0,0,0,0,0,0,0 };
68 static char *memory_names
[ 10 ] = { "segment 0xA000",
77 "Bios data segment" };
80 if( strcasecmp( dll_name
, "KERNEL" ) )
83 if( HIWORD( function
) ) {
84 if( ( *function
!= '_' ) || ( *(function
+1) != '_' ) )
86 if( !strcasecmp( function
, "__A000H" ) ) nr
= 0;
87 else if( !strcasecmp( function
, "__B000H" ) ) nr
= 1;
88 else if( !strcasecmp( function
, "__B800H" ) ) nr
= 2;
89 else if( !strcasecmp( function
, "__ROMBIOS" ) ) nr
= 3;
90 else if( !strcasecmp( function
, "__D000H" ) ) nr
= 4;
91 else if( !strcasecmp( function
, "__0000H" ) ) nr
= 5;
92 else if( !strcasecmp( function
, "__E000H" ) ) nr
= 6;
93 else if( !strcasecmp( function
, "__F000H" ) ) nr
= 7;
94 else if( !strcasecmp( function
, "__C000H" ) ) nr
= 8;
95 else if( !strcasecmp( function
, "__0040H" ) ) nr
= 9;
100 switch( LOWORD( function
) ) {
101 case 174: nr
= 0; break;
102 case 181: nr
= 1; break;
103 case 182: nr
= 2; break;
104 case 173: nr
= 3; break;
105 case 179: nr
= 4; break;
106 case 183: nr
= 5; break;
107 case 190: nr
= 6; break;
108 case 194: nr
= 7; break;
109 case 195: nr
= 8; break;
110 case 193: nr
= 9; break;
115 if( !memory_handles
[ nr
] ) {
116 fprintf( stderr
, "Warning: Direct access to %s!\n", memory_names
[ nr
] );
117 memory_handles
[ nr
] = GlobalAlloc( GMEM_FIXED
, 65535 );
119 *sel
= *offset
= memory_handles
[ nr
];
125 unsigned int GetEntryDLLName( char * dll_name
, char * function
,
126 WORD
* sel
, WORD
*offset
)
129 struct dll_table_s
*dll_table
;
132 if( GetMemoryReference( dll_name
, function
, sel
, offset
) )
135 hModule
= GetModuleHandle( dll_name
);
136 ordinal
= MODULE_GetOrdinal( hModule
, function
);
137 if (!ordinal
) return 1;
138 addr
= MODULE_GetEntryPoint( hModule
, ordinal
);
141 if ((dll_table
= FindDLLTable(dll_name
)) != NULL
)
143 dll_table
->dll_table
[ordinal
].used
++;
146 *offset
= LOWORD(addr
);
152 unsigned int GetEntryDLLOrdinal( char * dll_name
, int ordinal
,
153 WORD
*sel
, WORD
*offset
)
156 struct dll_table_s
*dll_table
;
159 if( GetMemoryReference( dll_name
, (char*)ordinal
, sel
, offset
) )
162 hModule
= GetModuleHandle( dll_name
);
163 addr
= MODULE_GetEntryPoint( hModule
, ordinal
);
166 if ((dll_table
= FindDLLTable(dll_name
)) != NULL
)
167 dll_table
->dll_table
[ordinal
].used
++;
169 *offset
= LOWORD(addr
);
175 WNDPROC
GetWndProcEntry16( char *name
)
179 GetEntryDLLName( "WINPROCS", name
, &sel
, &offset
);
180 return (WNDPROC
) MAKELONG( offset
, sel
);
184 /***********************************************************************
185 * GetDOSEnvironment (KERNEL.131)
187 SEGPTR
GetDOSEnvironment(void)
189 return WIN16_GlobalLock( EnvironmentHandle
);
193 /**********************************************************************
196 static HANDLE
CreateEnvironment(void)
202 handle
= GlobalAlloc( GMEM_MOVEABLE
, MAX_ENV_SIZE
);
203 if (!handle
) return 0;
204 p
= (char *) GlobalLock( handle
);
207 * Fill environment with Windows path, the Unix environment,
211 strcat(p
, WindowsPath
);
214 for (e
= environ
; *e
; e
++)
216 if (strncasecmp(*e
, "path", 4))
226 * Display environment
228 p
= (char *) GlobalLock( handle
);
229 dprintf_selectors(stddeb
, "Environment at %p\n", p
);
230 for (; *p
; p
+= strlen(p
) + 1) dprintf_selectors(stddeb
, " %s\n", p
);
237 /**********************************************************************
240 void CreateSelectors(void)
242 if(!EnvironmentHandle
) EnvironmentHandle
= CreateEnvironment();
246 #endif /* ifndef WINELIB */