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 /* */
29 struct dll_name_table_entry_s dll_builtin_table[N_BUILTINS] =
31 { "KERNEL", KERNEL_table, 410, 1 },
32 { "USER", USER_table, 540, 2 },
33 { "GDI", GDI_table, 490, 3 },
34 { "UNIXLIB", UNIXLIB_table, 10, 4 },
35 { "WIN87EM", WIN87EM_table, 10, 5 },
36 { "SHELL", SHELL_table, 256, 6 },
37 { "SOUND", SOUND_table, 20, 7 },
38 { "KEYBOARD",KEYBOARD_table,137, 8 },
39 { "WINSOCK", WINSOCK_table, 155, 9 },
40 { "STRESS", STRESS_table, 15, 10},
41 { "MMSYSTEM",MMSYSTEM_table,1023,11},
44 unsigned short *Stack16Frame;
46 extern unsigned long IF1632_Saved16_esp;
47 extern unsigned long IF1632_Saved16_ebp;
48 extern unsigned short IF1632_Saved16_ss;
50 /**********************************************************************
53 * We get a stack frame pointer to data that looks like this:
57 * +00 previous saved_16ss
58 * +02 previous saved_16ebp
59 * +06 previous saved_16esp
63 * +12 length of 16-bit arguments
69 DLLRelay(unsigned int func_num, unsigned int seg_off)
71 struct dll_table_entry_s *dll_p;
72 unsigned short *saved_Stack16Frame;
77 int arg_table[DLL_MAX_ARGS];
84 * Determine address of arguments.
86 saved_Stack16Frame = Stack16Frame;
87 Stack16Frame = (unsigned short *) seg_off;
88 arg_ptr = (void *) (seg_off + 0x18);
91 * Extract the DLL number and ordinal number.
93 dll_id = ((func_num >> 16) & 0xffff) - 1;
94 ordinal = func_num & 0xffff;
95 dll_p = &dll_builtin_table[dll_id].dll_table[ordinal];
98 if (Options.relay_debug)
100 unsigned int *ret_addr;
101 unsigned short *stack_p;
103 ret_addr = (unsigned int *) ((char *) seg_off + 0x14);
104 printf("Calling %s (%s.%d), 16-bit stack at %04x:%04x, ",
106 dll_builtin_table[dll_id].dll_name, ordinal,
107 seg_off >> 16, seg_off & 0xffff);
108 printf("return to %08x\n", *ret_addr);
109 printf(" ESP %08x, EBP %08x, SS %04x\n",
110 IF1632_Saved16_esp, IF1632_Saved16_ebp,
114 stack_p = (unsigned short *) seg_off;
115 for (i = 0; i < 24; i++, stack_p++)
117 printf("%04x ", *stack_p);
122 #endif /* DEBUG_STACK */
124 #endif /* DEBUG_RELAY */
127 * Make sure we have a handler defined for this call.
129 if (dll_p->handler == NULL)
133 sprintf(buffer, "No handler for routine %s.%d",
134 dll_builtin_table[dll_id].dll_name, ordinal);
137 func_ptr = dll_p->handler;
140 * OK, special case. If the handler is define as taking no arguments
141 * then pass the address of the arguments on the 16-bit stack to the
142 * handler. It will just ignore the pointer if it really takes no
143 * arguments. This allows us to write slightly faster library routines
146 if (dll_p->n_args == 0)
148 ret_val = (*func_ptr)(arg_ptr);
149 Stack16Frame = saved_Stack16Frame;
154 * Getting this far means we need to convert the 16-bit argument stack.
156 for (i = 0; i < dll_p->n_args; i++)
161 offset = dll_p->args[i].dst_arg;
163 switch (dll_p->args[i].src_type)
165 case DLL_ARGTYPE_SIGNEDWORD:
166 sp = (short *) ((char *) arg_ptr + offset);
170 case DLL_ARGTYPE_WORD:
171 sp = (short *) ((char *) arg_ptr + offset);
172 arg_table[i] = (int) *sp & 0xffff;
175 case DLL_ARGTYPE_LONG:
176 ip = (int *) ((char *) arg_ptr + offset);
180 case DLL_ARGTYPE_FARPTR:
181 ip = (int *) ((char *) arg_ptr + offset);
182 if (*ip & 0xffff0000)
183 arg_table[i] = FIXPTR(*ip);
193 ret_val = (*func_ptr)(arg_table[0], arg_table[1], arg_table[2],
194 arg_table[3], arg_table[4], arg_table[5],
195 arg_table[6], arg_table[7], arg_table[8],
196 arg_table[9], arg_table[10], arg_table[11],
197 arg_table[12], arg_table[13], arg_table[14],
201 if (Options.relay_debug)
203 printf("Returning %08.8x from %s (%s.%d)\n",
206 dll_builtin_table[dll_id].dll_name, ordinal);
210 Stack16Frame = saved_Stack16Frame;
214 /**********************************************************************
217 struct dll_table_entry_s *
218 FindDLLTable(char *dll_name)
222 for (i = 0; i < N_BUILTINS; i++)
223 if (strcmp(dll_builtin_table[i].dll_name, dll_name) == 0)
224 return dll_builtin_table[i].dll_table;
229 /**********************************************************************
230 * FindOrdinalFromName
233 FindOrdinalFromName(struct dll_table_entry_s *dll_table, char *func_name)
237 for (i = 0; i < N_BUILTINS; i++)
238 if (dll_table == dll_builtin_table[i].dll_table)
244 limit = dll_builtin_table[i].dll_table_length;
245 for (i = 0; i < limit; i++)
246 if (strcasecmp(dll_table[i].export_name, func_name) == 0)
251 /**********************************************************************
264 int used, implemented;
265 int tused, timplemented;
266 struct dll_table_entry_s *table;
270 for (i = 0; i < N_BUILTINS; i++) {
271 table = dll_builtin_table[i].dll_table;
274 for(j=0; j < dll_builtin_table[i].dll_table_length; j++) {
277 if (table[j].handler) implemented++;
280 dll_builtin_table[i].dll_name,
285 timplemented += implemented;
287 perc = implemented * 100.00 / used;
290 printf("%s: %d %d %3.1f\n", dll_builtin_table[i].dll_name, implemented, used, perc);
292 perc = timplemented * 100.00 / tused;
293 printf("TOTAL: %d %d %3.1f\n",timplemented, tused, perc);
295 #endif /* WINESTAT */