forked from martijnlaan/Ps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ROPS-1045-to-1045a-patch.txt
139 lines (135 loc) · 4.48 KB
/
ROPS-1045-to-1045a-patch.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
This patch adds 'loadwithalteredsearchpath' support to the SVN rev 1045 sources.
diff -ur 1045/Source/uPSC_dll.pas 1045a/Source/uPSC_dll.pas
--- 1045/Source/uPSC_dll.pas Fri Jan 14 10:52:59 2005
+++ 1045a/Source/uPSC_dll.pas Sun Sep 16 01:36:36 2007
@@ -40,12 +40,13 @@
function DllExternalProc(Sender: TPSPascalCompiler; Decl: TPSParametersDecl; const Name, FExternal: string): TPSRegProc;
var
FuncName,
- FuncCC, s: string;
+ FuncCC, s, s2: string;
CC: TDllCallingConvention;
- DelayLoad: Boolean;
+ DelayLoad, LoadWithAlteredSearchPath: Boolean;
begin
DelayLoad := False;
+ LoadWithAlteredSearchPath := False;
FuncCC := FExternal;
if (pos('@', FuncCC) = 0) then
begin
@@ -63,15 +64,28 @@
begin
s := Copy(FuncCC, pos(' ', Funccc)+1, MaxInt);
FuncCC := FastUpperCase(Copy(FuncCC, 1, pos(' ', FuncCC)-1));
- Delete(FuncCC, pos(' ', Funccc), MaxInt);
- if FastUppercase(s) = 'DELAYLOAD' then
- DelayLoad := True
- else
- begin
- Sender.MakeError('', ecCustomError, 'Invalid External');
- Result := nil;
- exit;
- end;
+ repeat
+ if pos(' ', s) > 0 then begin
+ s2 := Copy(s, 1, pos(' ', s)-1);
+ delete(s, 1, pos(' ', s));
+ end else begin
+ s2 := s;
+ s := '';
+ end;
+ if FastUppercase(s2) = 'DELAYLOAD' then
+ DelayLoad := True
+ {$IFNDEF LINUX}
+ else
+ if FastUppercase(s2) = 'LOADWITHALTEREDSEARCHPATH' then
+ LoadWithAlteredSearchPath := True
+ {$ENDIF}
+ else
+ begin
+ Sender.MakeError('', ecCustomError, 'Invalid External');
+ Result := nil;
+ exit;
+ end;
+ until s = '';
end else
FuncCC := FastUpperCase(FuncCC);
if FuncCC = 'STDCALL' then cc := ClStdCall else
@@ -89,7 +103,7 @@
FuncCC := '';
cc := DefaultCC;
end;
- FuncName := 'dll:'+FuncName+char(cc)+char(bytebool(DelayLoad)) + declToBits(Decl);
+ FuncName := 'dll:'+FuncName+char(cc)+char(bytebool(DelayLoad))+char(bytebool(LoadWithAlteredSearchPath)) + declToBits(Decl);
Result := TPSRegProc.Create;
Result.ImportDecl := FuncName;
Result.Decl.Assign(Decl);
diff -ur 1045/Source/uPSR_dll.pas 1045a/Source/uPSR_dll.pas
--- 1045/Source/uPSR_dll.pas Sat Jan 15 17:29:32 2005
+++ 1045a/Source/uPSR_dll.pas Sun Sep 16 01:36:36 2007
@@ -24,7 +24,7 @@
{
p^.Ext1 contains the pointer to the Proc function
p^.ExportDecl:
- 'dll:'+DllName+#0+FunctionName+#0+chr(Cc)+Chr(DelayLoad)+VarParams
+ 'dll:'+DllName+#0+FunctionName+#0+chr(Cc)+Chr(DelayLoad)+Chr(AlternateSearchPath)+VarParams
}
type
@@ -83,7 +83,7 @@
function LoadDll(Caller: TPSExec; P: TPSExternalProcRec): Boolean;
var
- s, s2: string;
+ s, s2, s3: string;
h, i: Longint;
ph: PLoadedDll;
{$IFDEF LINUX}
@@ -91,12 +91,16 @@
{$ELSE}
dllhandle: THandle;
{$ENDIF}
+ loadwithalteredsearchpath: Boolean;
begin
s := p.Decl;
Delete(s, 1, 4);
s2 := copy(s, 1, pos(#0, s)-1);
delete(s, 1, length(s2)+1);
h := makehash(s2);
+ s3 := copy(s, 1, pos(#0, s)-1);
+ delete(s, 1, length(s3)+1);
+ loadwithalteredsearchpath := bytebool(s[3]);
i := 2147483647; // maxint
dllhandle := 0;
repeat
@@ -113,7 +117,10 @@
{$IFDEF LINUX}
dllhandle := dlopen(PChar(s2), RTLD_LAZY);
{$ELSE}
- dllhandle := LoadLibrary(Pchar(s2));
+ if loadwithalteredsearchpath then
+ dllhandle := LoadLibraryEx(Pchar(s2), 0, LOAD_WITH_ALTERED_SEARCH_PATH)
+ else
+ dllhandle := LoadLibrary(Pchar(s2));
{$ENDIF}
if dllhandle = {$IFDEF LINUX}nil{$ELSE}0{$ENDIF}then
begin
@@ -133,9 +140,9 @@
end;
until dllhandle <> {$IFDEF LINUX}nil{$ELSE}0{$ENDIF};
{$IFDEF LINUX}
- p.Ext1 := dlsym(dllhandle, pchar(copy(s, 1, pos(#0, s)-1)));
+ p.Ext1 := dlsym(dllhandle, pchar(s3));
{$ELSE}
- p.Ext1 := GetProcAddress(dllhandle, pchar(copy(s, 1, pos(#0, s)-1)));
+ p.Ext1 := GetProcAddress(dllhandle, pchar(s3));
{$ENDIF}
if p.Ext1 = nil then
begin
@@ -179,7 +186,7 @@
exit;
end;
cc := TPSCallingConvention(s[1]);
- delete(s, 1, 2); // cc + delayload (delayload might also be forced!)
+ delete(s, 1, 3); // cc + delayload + alternatesearchpath (delayload might also be forced!)
CurrStack := Cardinal(Stack.Count) - Cardinal(length(s));
if s[1] = #0 then inc(CurrStack);
MyList := tIfList.Create;