This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
additional cleanups for cygwin32 port
[perl5.git] / ext / DynaLoader / dl_cygwin32.xs
CommitLineData
5aabfad6 1/* dl_cygwin32.xs
2 *
3 * Platform: Win32 (Windows NT/Windows 95)
4 * Author: Wei-Yuen Tan (wyt@hip.com)
5 * Created: A warm day in June, 1995
6 *
7 * Modified:
8 * August 23rd 1995 - rewritten after losing everything when I
9 * wiped off my NT partition (eek!)
10 */
11/* Modified from the original dl_win32.xs to work with cygwin32
12 -John Cerney 3/26/97
13*/
14/* Porting notes:
15
16I merely took Paul's dl_dlopen.xs, took out extraneous stuff and
17replaced the appropriate SunOS calls with the corresponding Win32
18calls.
19
20*/
21
22#define WIN32_LEAN_AND_MEAN
23// Defines from windows needed for this function only. Can't include full
24// Cygwin32 windows headers because of problems with CONTEXT redefinition
25// Removed logic to tell not dynamically load static modules. It is assumed that all
26// modules are dynamically built. This should be similar to the behavoir on sunOS.
27// Leaving in the logic would have required changes to the standard perlmain.c code
28//
5aabfad6 29#include <stdio.h>
5aabfad6 30
31//#include <windows.h>
32#define LOAD_WITH_ALTERED_SEARCH_PATH (8)
33typedef void *HANDLE;
34typedef HANDLE HINSTANCE;
35#define STDCALL __attribute__ ((stdcall))
36typedef int STDCALL (*FARPROC)();
f89d6eaa 37#define MAX_PATH 260
5aabfad6 38
39HINSTANCE
40STDCALL
41LoadLibraryExA(
42 char* lpLibFileName,
43 HANDLE hFile,
44 unsigned int dwFlags
45 );
46unsigned int
47STDCALL
48GetLastError(
49 void
50 );
51FARPROC
52STDCALL
53GetProcAddress(
54 HINSTANCE hModule,
55 char* lpProcName
56 );
57
58#include <string.h>
59
60#include "EXTERN.h"
61#include "perl.h"
62#include "XSUB.h"
63
64#include "dlutils.c" /* SaveError() etc */
65
66static void
67dl_private_init()
68{
69 (void)dl_generic_private_init();
70}
71
72
73MODULE = DynaLoader PACKAGE = DynaLoader
74
75BOOT:
76 (void)dl_private_init();
77
78void *
79dl_load_file(filename,flags=0)
80 char * filename
81 int flags
82 PREINIT:
83 CODE:
f89d6eaa
EF
84 {
85 char win32_path[MAX_PATH];
86 cygwin_conv_to_full_win32_path(filename, win32_path);
87 filename = win32_path;
88
c78749f2 89 DLDEBUG(1,PerlIO_printf(PerlIO_stderr(),"dl_load_file(%s):\n", filename));
5aabfad6 90
91 RETVAL = (void*) LoadLibraryExA(filename, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) ;
92
c78749f2 93 DLDEBUG(2,PerlIO_printf(PerlIO_stderr()," libref=%x\n", RETVAL));
5aabfad6 94 ST(0) = sv_newmortal() ;
95 if (RETVAL == NULL){
96 SaveError("%d",GetLastError()) ;
f89d6eaa
EF
97 } else {
98 sv_setiv( ST(0), (IV)RETVAL);
5aabfad6 99 }
5aabfad6 100 }
101
102
103
104void *
105dl_find_symbol(libhandle, symbolname)
106 void * libhandle
107 char * symbolname
108 CODE:
c78749f2 109 DLDEBUG(2,PerlIO_printf(PerlIO_stderr(),"dl_find_symbol(handle=%x, symbol=%s)\n",
5aabfad6 110 libhandle, symbolname));
111 RETVAL = (void*) GetProcAddress((HINSTANCE) libhandle, symbolname);
c78749f2 112 DLDEBUG(2,PerlIO_printf(PerlIO_stderr()," symbolref = %x\n", RETVAL));
5aabfad6 113 ST(0) = sv_newmortal() ;
114 if (RETVAL == NULL)
115 SaveError("%d",GetLastError()) ;
116 else
117 sv_setiv( ST(0), (IV)RETVAL);
118
119
120void
121dl_undef_symbols()
122 PPCODE:
123
124
125
126# These functions should not need changing on any platform:
127
128void
129dl_install_xsub(perl_name, symref, filename="$Package")
130 char * perl_name
131 void * symref
132 char * filename
133 CODE:
c78749f2 134 DLDEBUG(2,PerlIO_printf(PerlIO_stderr(),"dl_install_xsub(name=%s, symref=%x)\n",
5aabfad6 135 perl_name, symref));
136 ST(0)=sv_2mortal(newRV((SV*)newXS(perl_name, (void(*)())symref, filename)));
137
138
139char *
140dl_error()
141 CODE:
142 RETVAL = LastError ;
143 OUTPUT:
144 RETVAL
145
146# end.