source: trunk/src/win32k/ldr/mytkExecPgm.asm@ 2832

Last change on this file since 2832 was 2827, checked in by bird, 26 years ago

g_tkExecPgm is overloaded, so we may change paramerters for a process later.

File size: 7.2 KB
Line 
1; $Id: mytkExecPgm.asm,v 1.3 2000-02-19 08:40:31 bird Exp $
2;
3; mytkExecPgm - tkExecPgm overload
4;
5; Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
6;
7; Project Odin Software License can be found in LICENSE.TXT
8;
9 .386p
10
11;
12; Include files
13;
14 include devsegdf.inc
15
16;
17; Imported Functions
18;
19DATA32 SEGMENT
20 extrn g_tkExecPgm:PROC
21DATA32 ENDS
22 extrn AcquireBuffer:PROC
23 extrn ReleaseBuffer:PROC
24 extrn QueryBufferSegmentOffset:PROC
25
26;
27; Exported symbols
28;
29 public mytkExecPgm
30 public pszFilename
31 public pszArguments
32
33
34DATA32 SEGMENT
35pszFilename dd 0 ; Pointer to the filename (in the buffer)
36pszArguments dd 0 ; Pointer to the arguments (int the buffer)
37DATA32 ENDS
38
39
40CODE32 SEGMENT
41
42;;
43;
44; @returns same as tkExecPgm: eax, edx and carry flag
45; @param ax Exec flag
46; ds:dx Filename address. (String)
47; es:bx Environment address. (String)
48; di:si Argument address. (String)
49; @uses all - bp
50; @status
51; @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
52; @remark Current implemententation assumes that there is one buffer,
53; this serializes the usage of the two pointers.
54;
55; The buffer we are using is a C struct as follows.
56; struct Buffer
57; {
58; char szFilename[261]; /* offset 0 */
59; char achArg[1536-261]; /* offset 261 */
60; };
61;
62mytkExecPgm PROC FAR
63pBuffer = dword ptr -04h
64;SegBuffer = word ptr (dword ptr -08h)
65SegBuffer = -08h
66;OffBuffer = word ptr (dword ptr -0Ch)
67OffBuffer = -0Ch
68cchFilename = dword ptr -10h
69cchArgs = dword ptr -14h
70 ASSUME CS:CODE32, DS:NOTHING, SS:NOTHING
71 push ebp
72 mov ebp, esp
73 lea esp, [ebp + cchArgs]
74
75 push eax
76 push ecx
77 push ds
78 push es
79 push edi
80
81IF 0
82; ; Check if this overloading has anything too say, after all it is using some stack space!
83; jmp mytkExecPgm_CalltkExecPgm_X1
84ENDIF
85
86 ; parameter validations
87 mov ax, ds ; pointer to filename
88 cmp ax, 4
89 jb mytkExecPgm_CalltkExecPgm_X1
90
91 ; This test is currently disabled. We'll pass on an empty string if the argument pointer is NULL.
92 ; Hopefully an empty string is treated equally to an NULL pointer.
93; cmp di, 4
94; jl mytkExecPgm_CalltkExecPgm_X1
95
96 ; filename length
97 mov ax, ds
98 mov es, ax
99 xor eax, eax
100 movzx edi, dx ; es:di is now filename address (ds:dx).
101 mov ecx, 0ffffffffh
102 cld
103 repne scasb
104 not ecx
105
106 ;
107 ; if filename length is more that CCHMAXPATH then we don't do anything!.
108 ;
109 cmp ecx, 260
110 jae mytkExecPgm_CalltkExecPgm_X1; length >= 260
111 mov [ebp+cchFilename], ecx
112
113 ;
114 ; args length
115 ; Note: the arguments are a series of ASCIIZs ended by an empty string (ie. '\0').
116 ;
117 pop edi
118 push edi
119 xor ecx, ecx
120 cmp di, 4 ; The argument might me a invalid pointer...
121 jb mytkExecPgm_CalltkExecPgm_1
122 mov es, di
123 movzx edi, si ; es:edi is now args address (di:si), eax is still 0
124 dec ecx
125 cld
126mytkExecPgm_CalltkExecPgm_loop: ; loop true all ASCIIZ strings
127 repne scasb ; scans forwards until '\0' is read. es:edi is pointing at the char after the '\0'.
128 cmp byte ptr es:[edi], 0 ; is this char '\0' ? stop looping : loop once more;
129 jnz mytkExecPgm_CalltkExecPgm_loop
130 dec ecx ; update count - count terminating zero too
131 not ecx
132
133mytkExecPgm_CalltkExecPgm_1:
134 mov [ebp+cchArgs], ecx
135 add ecx, [ebp+cchFilename] ; filename
136 add ecx, 3 + 260 ; 260 = new argument from a scrip file or something.
137 ; 3 = two '\0's and a space after added argument.
138 cmp ecx, 1536 ; 1536 = Buffersize. FIXME! Define this!!!
139 jae mytkExecPgm_CalltkExecPgm_X1; jmp if argument + file + new file > buffer size
140
141 ;
142 ; Aquire a buffer
143 ;
144 call AcquireBuffer
145 or eax, eax
146 jz mytkExecPgm_CalltkExecPgm_X1; Failed to get buffer.
147 mov [ebp+pBuffer], eax
148
149 ;
150 ; Get Segment and offset for the buffer
151 ;
152 call QueryBufferSegmentOffset
153 mov cx, es
154 mov [ebp+OffBuffer], ax
155 mov [ebp+SegBuffer], es
156 test eax, 000570000h
157 jnz mytkExecPgm_CalltkExecPgm_X2
158
159 ;
160 ; Copy filename to pBuffer.
161 ;
162 push esi
163 mov edi, eax ; es:di pBuffer
164 movzx esi, dx ; ds:si Filename pointer (input ds:dx)
165 mov ecx, [ebp+cchFilename]
166 cld
167 rep movsb
168
169 ;
170 ; Copy Args to pBuffer + 261
171 ;
172 ; stack: esi, edi, es, ds, ecx, eax
173 pop esi
174 pop edi
175 push edi
176 push esi
177 add eax, 261 ; we'll use eax in the branch
178 cmp di, 4
179 jb mytkExecPgm_CalltkExecPgm_2
180 and esi, 00000ffffh ; remove high part of the register
181 mov ds, di ; ds:si -> arguments
182 mov edi, eax ; es:di -> pBuffer + 261
183 mov ecx, [ebp+cchArgs]
184 cld
185 rep movsb
186 jmp mytkExecPgm_CalltkExecPgm_3
187
188mytkExecPgm_CalltkExecPgm_2:
189 mov byte ptr es:[eax], 0 ; Terminate the empty string!
190
191 ;
192 ; Set Pointers, pszFilename and pszArguments
193 ;
194mytkExecPgm_CalltkExecPgm_3:
195 mov ax, seg FLAT:DATA32
196 mov ds, ax
197 ASSUME ds:FLAT
198 mov eax, ss:[ebp+pBuffer]
199 mov pszFilename, eax
200 add eax, 261
201 mov pszArguments, eax
202
203 ;
204 ; Restore variables pushed on the stack
205 ;
206 ; stack: esi, edi, es, ds, ecx, eax
207 pop esi
208 pop edi
209 pop es
210 pop ds
211 pop ecx
212 pop eax
213
214 ;
215 ; Set new input parameters (call g_tkExecPgm)
216 ;
217 ; ds:dx is to become SegBuffer:OffBuffer
218 ; di:si is to become SegBuffer:OffBuffer+261
219 ;
220 ; The some of the old values are stored on the stack (for the time being)
221 push ds
222 push edi
223 push esi
224
225 mov di, [ebp+SegBuffer]
226 mov ds, di
227 mov si, [ebp+OffBuffer]
228 mov dx, si ; ds:dx SegBuffer:OffBuffer
229 add si, 261 ; di:si SegBuffer:OffBuffer+261
230
231 ;
232 ; Call g_tkExecPgm
233 ;
234 push cs
235 call near ptr FLAT:g_tkExecPgm
236 pushfd
237
238 ;
239 ; Release buffer
240 ;
241 push eax
242 mov eax, [ebp + pBuffer]
243 call ReleaseBuffer
244 mov [ebp + pBuffer], 0
245 pop eax
246
247 ;
248 ; Return
249 ;
250 popfd
251 pop esi
252 pop edi
253 pop ds
254 leave
255 retf
256
257mytkExecPgm_CalltkExecPgm_X2:
258 ;
259 ; Release buffer
260 ;
261 mov eax, [ebp + pBuffer]
262 call ReleaseBuffer
263 mov [ebp + pBuffer], 0
264
265mytkExecPgm_CalltkExecPgm_X1:
266 pop edi
267 pop es
268 pop ds
269 pop ecx
270 pop eax
271
272mytkExecPgm_CalltkExecPgm:
273 call far ptr FLAT:g_tkExecPgmStub
274 leave
275 retf
276mytkExecPgm ENDP
277
278
279;;
280; Stub which jumps to g_tkExecPgmStub.
281; (This way I will hopefully get the right selector.)
282g_tkExecPgmStub PROC FAR
283 jmp near ptr FLAT:g_tkExecPgm
284g_tkExecPgmStub ENDP
285
286
287CODE32 ENDS
288END
289
Note: See TracBrowser for help on using the repository browser.