1 static char RCSId[] = "$Id: relay.c,v 1.2 1993/07/04 04:04:21 root Exp root $";
2 static char Copyright[] = "Copyright Robert J. Amstadt, 1993";
12 #include <linux/unistd.h>
13 #include <linux/head.h>
14 #include <linux/ldt.h>
15 #include <linux/segment.h>
21 #include "prototypes.h"
25 #define DEBUG_RELAY /* */
27 struct dll_name_table_entry_s dll_builtin_table[N_BUILTINS] =
29 { "KERNEL", KERNEL_table, 410, 1 },
30 { "USER", USER_table, 540, 2 },
31 { "GDI", GDI_table, 490, 3 },
32 { "UNIXLIB", UNIXLIB_table, 10, 4 },
33 { "WIN87EM", WIN87EM_table, 10, 5 },
34 { "SHELL", SHELL_table, 256, 6 },
35 { "SOUND", SOUND_table, 20, 7 },
36 { "KEYBOARD",KEYBOARD_table,137, 8 },
37 { "WINSOCK", WINSOCK_table, 155, 9 },
38 { "STRESS", STRESS_table, 15, 10},
39 { "MMSYSTEM",MMSYSTEM_table,1226,11},
40 { "SYSTEM", SYSTEM_table, 20 ,12},
41 { "TOOLHELP",TOOLHELP_table, 83, 13},
43 /* don't forget to increase N_BUILTINS in dll.h if you add a dll */
45 unsigned short *Stack16Frame;
47 extern unsigned long IF1632_Saved16_esp;
48 extern unsigned long IF1632_Saved16_ebp;
49 extern unsigned short IF1632_Saved16_ss;
51 /**********************************************************************
54 * We get a stack frame pointer to data that looks like this:
58 * +00 previous saved_16ss
59 * +02 previous saved_16ebp
60 * +06 previous saved_16esp
64 * +12 length of 16-bit arguments
70 DLLRelay(unsigned int func_num, unsigned int seg_off)
72 struct dll_table_entry_s *dll_p;
73 unsigned short *saved_Stack16Frame;
78 int arg_table[DLL_MAX_ARGS];
85 * Determine address of arguments.
87 saved_Stack16Frame = Stack16Frame;
88 Stack16Frame = (unsigned short *) seg_off;
89 arg_ptr = (void *) (seg_off + 0x18);
92 * Extract the DLL number and ordinal number.
94 dll_id = ((func_num >> 16) & 0xffff) - 1;
95 ordinal = func_num & 0xffff;
96 dll_p = &dll_builtin_table[dll_id].dll_table[ordinal];
99 if (Options.relay_debug)
101 unsigned int *ret_addr;
102 unsigned short *stack_p;
104 ret_addr = (unsigned int *) ((char *) seg_off + 0x14);
105 printf("Calling %s (%s.%d), 16-bit stack at %04x:%04x, ",
107 dll_builtin_table[dll_id].dll_name, ordinal,
108 seg_off >> 16, seg_off & 0xffff);
109 printf("return to %08x\n", *ret_addr);
110 printf(" ESP %08x, EBP %08x, SS %04x\n",
111 IF1632_Saved16_esp, IF1632_Saved16_ebp,
115 stack_p = (unsigned short *) seg_off;
116 for (i = 0; i < 24; i++, stack_p++)
118 printf("%04x ", *stack_p);
123 #endif /* DEBUG_STACK */
125 #endif /* DEBUG_RELAY */
128 * Make sure we have a handler defined for this call.
130 if (dll_p->handler == NULL)
134 sprintf(buffer, "No handler for routine %s.%d",
135 dll_builtin_table[dll_id].dll_name, ordinal);
138 func_ptr = dll_p->handler;
141 * OK, special case. If the handler is define as taking no arguments
142 * then pass the address of the arguments on the 16-bit stack to the
143 * handler. It will just ignore the pointer if it really takes no
144 * arguments. This allows us to write slightly faster library routines
147 if (dll_p->n_args == 0)
149 ret_val = (*func_ptr)(arg_ptr);
150 Stack16Frame = saved_Stack16Frame;
155 * Getting this far means we need to convert the 16-bit argument stack.
157 for (i = 0; i < dll_p->n_args; i++)
162 offset = dll_p->args[i].dst_arg;
164 switch (dll_p->args[i].src_type)
166 case DLL_ARGTYPE_SIGNEDWORD:
167 sp = (short *) ((char *) arg_ptr + offset);
171 case DLL_ARGTYPE_WORD:
172 sp = (short *) ((char *) arg_ptr + offset);
173 arg_table[i] = (int) *sp & 0xffff;
176 case DLL_ARGTYPE_LONG:
177 ip = (int *) ((char *) arg_ptr + offset);
181 case DLL_ARGTYPE_FARPTR:
182 ip = (int *) ((char *) arg_ptr + offset);
183 if (*ip & 0xffff0000)
184 arg_table[i] = FIXPTR(*ip);
194 ret_val = (*func_ptr)(arg_table[0], arg_table[1], arg_table[2],
195 arg_table[3], arg_table[4], arg_table[5],
196 arg_table[6], arg_table[7], arg_table[8],
197 arg_table[9], arg_table[10], arg_table[11],
198 arg_table[12], arg_table[13], arg_table[14],
202 if (Options.relay_debug)
204 printf("Returning %08.8x from %s (%s.%d)\n",
207 dll_builtin_table[dll_id].dll_name, ordinal);
211 Stack16Frame = saved_Stack16Frame;
215 /**********************************************************************
218 struct dll_table_entry_s *
219 FindDLLTable(char *dll_name)
223 for (i = 0; i < N_BUILTINS; i++)
224 if (strcasecmp(dll_builtin_table[i].dll_name, dll_name) == 0)
225 return dll_builtin_table[i].dll_table;
230 /**********************************************************************
231 * FindOrdinalFromName
234 FindOrdinalFromName(struct dll_table_entry_s *dll_table, char *func_name)
238 for (i = 0; i < N_BUILTINS; i++)
239 if (dll_table == dll_builtin_table[i].dll_table)
245 limit = dll_builtin_table[i].dll_table_length;
246 for (i = 0; i < limit; i++)
247 if (strcasecmp(dll_table[i].export_name, func_name) == 0)
252 /**********************************************************************
265 int used, implemented;
266 int tused, timplemented;
267 struct dll_table_entry_s *table;
271 for (i = 0; i < N_BUILTINS; i++) {
272 table = dll_builtin_table[i].dll_table;
275 for(j=0; j < dll_builtin_table[i].dll_table_length; j++) {
278 if (table[j].handler) implemented++;
281 dll_builtin_table[i].dll_name,
286 timplemented += implemented;
288 perc = implemented * 100.00 / used;
291 printf("%s: %d %d %3.1f\n", dll_builtin_table[i].dll_name, implemented, used, perc);
293 perc = timplemented * 100.00 / tused;
294 printf("TOTAL: %d %d %3.1f\n",timplemented, tused, perc);
296 #endif /* WINESTAT */