]> cygwin.com Git - cygwin-apps/setup.git/blob - autoload.c
* net.cc (do_net): Default to direct download.
[cygwin-apps/setup.git] / autoload.c
1 /*
2 * Copyright (c) 2000, Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
13 *
14 */
15
16 static char *cvsid = "\n%%% $Id$\n";
17
18 #include "win32.h"
19
20 typedef struct {
21 char *name;
22 HINSTANCE handle;
23 } DllInfo;
24
25 #define DLL(n) static DllInfo n ## _info __asm__ (#n "_info") = { #n, 0}
26
27 #define Auto(dll, func, size) \
28 __asm__ ("\t.data"); \
29 __asm__ ("\t.global\t_" #func "@" #size); \
30 __asm__ ("_" #func "@" #size ":"); \
31 __asm__ ("\tcall\tautoload_common"); \
32 __asm__ ("\t.long\t" #dll "_info"); \
33 __asm__ ("\t.ascii\t\"" #func "\\0\"")
34
35 DLL (wininet);
36
37 Auto (wininet, InternetAttemptConnect, 4);
38 Auto (wininet, InternetCloseHandle, 4);
39 Auto (wininet, InternetGetLastResponseInfoA, 12);
40 Auto (wininet, InternetOpenA, 20);
41 Auto (wininet, InternetOpenUrlA, 24);
42 Auto (wininet, InternetReadFile, 16);
43 Auto (wininet, InternetSetOptionA, 16);
44 Auto (wininet, InternetQueryOptionA, 16);
45 Auto (wininet, HttpQueryInfoA, 20);
46 Auto (wininet, HttpSendRequestA, 20);
47
48 typedef struct {
49 DllInfo *dll;
50 char name[100];
51 } AutoEntry;
52
53 static void autoload_common () __asm__ ("autoload_common");
54
55 static void
56 autoload_common (int x)
57 {
58 int fp, rel;
59 unsigned char *proc;
60 HINSTANCE h;
61 AutoEntry *a;
62
63 a = *(AutoEntry **)(&x - 1);
64 if (a->dll->handle == 0)
65 {
66 h = LoadLibrary (a->dll->name);
67 a->dll->handle = h;
68 }
69 fp = (int) GetProcAddress (a->dll->handle, a->name);
70 proc = ((unsigned char *)a) - 5;
71 rel = fp - (int)(a); /* now it's a relative call */
72 *proc++ = 0xe9; /* jump near 32-bit relative */
73 *proc++ = rel;
74 *proc++ = rel>>8;
75 *proc++ = rel>>16;
76 *proc++ = rel>>24;
77
78 *(int *)(&x-1) = (int)proc-5;
79 }
This page took 0.038597 seconds and 5 git commands to generate.