wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / ntdll / env.c
blob1ed52b9728f928ab32425f86499280539d91059c
1 /*
2 * Ntdll environment functions
4 * Copyright 1996, 1998 Alexandre Julliard
5 * Copyright 2003 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <assert.h>
23 #include <stdarg.h>
24 #include <sys/types.h>
26 #include "ntstatus.h"
27 #define WIN32_NO_STATUS
28 #include "windef.h"
29 #include "winternl.h"
30 #include "wine/debug.h"
31 #include "ntdll_misc.h"
32 #include "winnt.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(environ);
36 static WCHAR empty[] = L"";
37 static const UNICODE_STRING empty_str = { 0, sizeof(empty), empty };
38 static const UNICODE_STRING null_str = { 0, 0, NULL };
40 static const BOOL is_win64 = (sizeof(void *) > sizeof(int));
42 static inline SIZE_T get_env_length( const WCHAR *env )
44 const WCHAR *end = env;
45 while (*end) end += wcslen(end) + 1;
46 return end + 1 - env;
50 /***********************************************************************
51 * set_wow64_environment
53 * Set the environment variables that change across 32/64/Wow64.
55 static void set_wow64_environment( WCHAR **env )
57 static WCHAR archW[] = L"PROCESSOR_ARCHITECTURE";
58 static WCHAR arch6432W[] = L"PROCESSOR_ARCHITEW6432";
60 WCHAR buf[256];
61 UNICODE_STRING arch_strW = { sizeof(archW) - sizeof(WCHAR), sizeof(archW), archW };
62 UNICODE_STRING arch6432_strW = { sizeof(arch6432W) - sizeof(WCHAR), sizeof(arch6432W), arch6432W };
63 UNICODE_STRING valW = { 0, sizeof(buf), buf };
64 UNICODE_STRING nameW;
66 /* set the PROCESSOR_ARCHITECTURE variable */
68 if (!RtlQueryEnvironmentVariable_U( *env, &arch6432_strW, &valW ))
70 if (is_win64)
72 RtlSetEnvironmentVariable( env, &arch_strW, &valW );
73 RtlSetEnvironmentVariable( env, &arch6432_strW, NULL );
76 else if (NtCurrentTeb64() && !RtlQueryEnvironmentVariable_U( *env, &arch_strW, &valW ))
78 RtlSetEnvironmentVariable( env, &arch6432_strW, &valW );
79 RtlInitUnicodeString( &nameW, L"x86" );
80 RtlSetEnvironmentVariable( env, &arch_strW, &nameW );
83 /* set the ProgramFiles variables */
85 RtlInitUnicodeString( &nameW, is_win64 ? L"ProgramW6432" : L"ProgramFiles(x86)" );
86 if (!RtlQueryEnvironmentVariable_U( *env, &nameW, &valW ))
88 RtlInitUnicodeString( &nameW, L"ProgramFiles" );
89 RtlSetEnvironmentVariable( env, &nameW, &valW );
92 /* set the CommonProgramFiles variables */
94 RtlInitUnicodeString( &nameW, is_win64 ? L"CommonProgramW6432" : L"CommonProgramFiles(x86)" );
95 if (!RtlQueryEnvironmentVariable_U( *env, &nameW, &valW ))
97 RtlInitUnicodeString( &nameW, L"CommonProgramFiles" );
98 RtlSetEnvironmentVariable( env, &nameW, &valW );
101 RtlReAllocateHeap( GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY, *env,
102 get_env_length(*env) * sizeof(WCHAR) );
106 /******************************************************************************
107 * RtlCreateEnvironment [NTDLL.@]
109 NTSTATUS WINAPI RtlCreateEnvironment(BOOLEAN inherit, PWSTR* env)
111 SIZE_T size;
113 TRACE("(%u,%p)!\n", inherit, env);
115 if (inherit)
117 RtlAcquirePebLock();
118 size = get_env_length( NtCurrentTeb()->Peb->ProcessParameters->Environment ) * sizeof(WCHAR);
119 if ((*env = RtlAllocateHeap( GetProcessHeap(), 0, size )))
120 memcpy( *env, NtCurrentTeb()->Peb->ProcessParameters->Environment, size );
121 RtlReleasePebLock();
123 else *env = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR) );
125 return *env ? STATUS_SUCCESS : STATUS_NO_MEMORY;
128 /******************************************************************************
129 * RtlDestroyEnvironment [NTDLL.@]
131 NTSTATUS WINAPI RtlDestroyEnvironment(PWSTR env)
133 RtlFreeHeap( GetProcessHeap(), 0, env );
134 return STATUS_SUCCESS;
137 static LPCWSTR ENV_FindVariable(PCWSTR var, PCWSTR name, unsigned namelen)
139 while (*var)
141 /* match var names, but avoid setting a var with a name including a '='
142 * (a starting '=' is valid though)
144 unsigned int len = wcslen( var );
145 if (len > namelen &&
146 var[namelen] == '=' &&
147 !RtlCompareUnicodeStrings( var, namelen, name, namelen, TRUE ) &&
148 wcschr(var + 1, '=') == var + namelen)
150 return var + namelen + 1;
152 var += len + 1;
154 return NULL;
157 /******************************************************************
158 * RtlQueryEnvironmentVariable_U [NTDLL.@]
160 * NOTES: when the buffer is too small, the string is not written, but if the
161 * terminating null char is the only char that cannot be written, then
162 * all chars (except the null) are written and success is returned
163 * (behavior of Win2k at least)
165 NTSTATUS WINAPI RtlQueryEnvironmentVariable_U(PWSTR env,
166 PUNICODE_STRING name,
167 PUNICODE_STRING value)
169 NTSTATUS nts = STATUS_VARIABLE_NOT_FOUND;
170 PCWSTR var;
171 unsigned namelen;
173 TRACE("%p %s %p\n", env, debugstr_us(name), value);
175 value->Length = 0;
176 namelen = name->Length / sizeof(WCHAR);
177 if (!namelen) return nts;
179 if (!env)
181 RtlAcquirePebLock();
182 var = NtCurrentTeb()->Peb->ProcessParameters->Environment;
184 else var = env;
186 var = ENV_FindVariable(var, name->Buffer, namelen);
187 if (var != NULL)
189 value->Length = wcslen(var) * sizeof(WCHAR);
191 if (value->Length <= value->MaximumLength)
193 memmove(value->Buffer, var, min(value->Length + sizeof(WCHAR), value->MaximumLength));
194 nts = STATUS_SUCCESS;
196 else nts = STATUS_BUFFER_TOO_SMALL;
199 if (!env) RtlReleasePebLock();
201 return nts;
205 /******************************************************************
206 * RtlQueryEnvironmentVariable [NTDLL.@]
208 NTSTATUS WINAPI RtlQueryEnvironmentVariable( WCHAR *env, const WCHAR *name, SIZE_T namelen,
209 WCHAR *value, SIZE_T value_length, SIZE_T *return_length )
211 NTSTATUS nts = STATUS_VARIABLE_NOT_FOUND;
212 SIZE_T len = 0;
213 const WCHAR *var;
215 if (!namelen) return nts;
217 if (!env)
219 RtlAcquirePebLock();
220 var = NtCurrentTeb()->Peb->ProcessParameters->Environment;
222 else var = env;
224 var = ENV_FindVariable(var, name, namelen);
225 if (var != NULL)
227 len = wcslen(var);
228 if (len <= value_length)
230 memcpy(value, var, min(len + 1, value_length) * sizeof(WCHAR));
231 nts = STATUS_SUCCESS;
233 else
235 len++;
236 nts = STATUS_BUFFER_TOO_SMALL;
239 *return_length = len;
241 if (!env) RtlReleasePebLock();
243 return nts;
246 /******************************************************************
247 * RtlSetCurrentEnvironment [NTDLL.@]
250 void WINAPI RtlSetCurrentEnvironment(PWSTR new_env, PWSTR* old_env)
252 WCHAR *prev;
254 TRACE("(%p %p)\n", new_env, old_env);
256 RtlAcquirePebLock();
258 prev = NtCurrentTeb()->Peb->ProcessParameters->Environment;
259 NtCurrentTeb()->Peb->ProcessParameters->Environment = new_env;
260 NtCurrentTeb()->Peb->ProcessParameters->EnvironmentSize = RtlSizeHeap( GetProcessHeap(), 0, new_env );
262 RtlReleasePebLock();
264 if (old_env)
265 *old_env = prev;
266 else
267 RtlDestroyEnvironment( prev );
271 /******************************************************************************
272 * RtlSetEnvironmentVariable [NTDLL.@]
274 NTSTATUS WINAPI RtlSetEnvironmentVariable(PWSTR* penv, PUNICODE_STRING name,
275 PUNICODE_STRING value)
277 INT varlen, len, old_size;
278 LPWSTR p, env;
279 NTSTATUS nts = STATUS_VARIABLE_NOT_FOUND;
281 TRACE("(%p, %s, %s)\n", penv, debugstr_us(name), debugstr_us(value));
283 if (!name || !name->Buffer || !name->Length)
284 return STATUS_INVALID_PARAMETER_1;
286 len = name->Length / sizeof(WCHAR);
288 /* variable names can't contain a '=' except as a first character */
289 for (p = name->Buffer + 1; p < name->Buffer + len; p++)
290 if (*p == '=') return STATUS_INVALID_PARAMETER;
292 if (!penv)
294 RtlAcquirePebLock();
295 env = NtCurrentTeb()->Peb->ProcessParameters->Environment;
296 } else env = *penv;
298 old_size = get_env_length( env );
300 /* Find a place to insert the string */
301 for (p = env; *p; p += varlen + 1)
303 varlen = wcslen(p);
304 if (varlen > len && p[len] == '=' &&
305 !RtlCompareUnicodeStrings( name->Buffer, len, p, len, TRUE )) break;
307 if (!value && !*p) goto done; /* Value to remove doesn't exist */
309 /* Realloc the buffer */
310 len = value ? len + value->Length / sizeof(WCHAR) + 2 : 0;
311 if (*p) len -= wcslen(p) + 1; /* The name already exists */
313 if (len < 0)
315 LPWSTR next = p + wcslen(p) + 1; /* We know there is a next one */
316 memmove(next + len, next, (old_size - (next - env)) * sizeof(WCHAR));
319 if ((old_size + len) * sizeof(WCHAR) > RtlSizeHeap( GetProcessHeap(), 0, env ))
321 SIZE_T new_size = (old_size + len) * sizeof(WCHAR);
322 LPWSTR new_env = RtlAllocateHeap( GetProcessHeap(), 0, new_size );
324 if (!new_env)
326 nts = STATUS_NO_MEMORY;
327 goto done;
329 memcpy(new_env, env, (p - env) * sizeof(WCHAR));
330 memcpy(new_env + (p - env) + len, p, (old_size - (p - env)) * sizeof(WCHAR));
331 p = new_env + (p - env);
333 RtlDestroyEnvironment(env);
334 if (!penv)
336 NtCurrentTeb()->Peb->ProcessParameters->Environment = new_env;
337 NtCurrentTeb()->Peb->ProcessParameters->EnvironmentSize = new_size;
339 else *penv = new_env;
341 else
343 if (len > 0) memmove(p + len, p, (old_size - (p - env)) * sizeof(WCHAR));
346 /* Set the new string */
347 if (value)
349 memcpy( p, name->Buffer, name->Length );
350 p += name->Length / sizeof(WCHAR);
351 *p++ = '=';
352 memcpy( p, value->Buffer, value->Length );
353 p[value->Length / sizeof(WCHAR)] = 0;
355 nts = STATUS_SUCCESS;
357 done:
358 if (!penv) RtlReleasePebLock();
360 return nts;
363 /******************************************************************************
364 * RtlExpandEnvironmentStrings (NTDLL.@)
366 NTSTATUS WINAPI RtlExpandEnvironmentStrings( const WCHAR *renv, WCHAR *src, SIZE_T src_len,
367 WCHAR *dst, SIZE_T count, SIZE_T *plen )
369 SIZE_T len, total_size = 1; /* 1 for terminating '\0' */
370 LPCWSTR env, var;
372 if (!renv)
374 RtlAcquirePebLock();
375 env = NtCurrentTeb()->Peb->ProcessParameters->Environment;
377 else env = renv;
379 while (src_len)
381 if (*src != '%')
383 for (len = 0; len < src_len; len++) if (src[len] == '%') break;
384 var = src;
385 src += len;
386 src_len -= len;
388 else /* we are at the start of a variable */
390 for (len = 1; len < src_len; len++) if (src[len] == '%') break;
391 if (len < src_len)
393 if ((var = ENV_FindVariable( env, src + 1, len - 1 )))
395 src += len + 1; /* Skip the variable name */
396 src_len -= len + 1;
397 len = wcslen(var);
399 else
401 var = src; /* Copy original name instead */
402 len++;
403 src += len;
404 src_len -= len;
407 else /* unfinished variable name, ignore it */
409 var = src;
410 src += len;
411 src_len = 0;
414 total_size += len;
415 if (dst)
417 if (count < len) len = count;
418 memcpy(dst, var, len * sizeof(WCHAR));
419 count -= len;
420 dst += len;
424 if (!renv) RtlReleasePebLock();
426 if (dst && count) *dst = '\0';
427 if (plen) *plen = total_size;
429 return (count) ? STATUS_SUCCESS : STATUS_BUFFER_TOO_SMALL;
432 /******************************************************************
433 * RtlExpandEnvironmentStrings_U (NTDLL.@)
435 NTSTATUS WINAPI RtlExpandEnvironmentStrings_U( const WCHAR *env, const UNICODE_STRING *src,
436 UNICODE_STRING *dst, ULONG *plen )
438 SIZE_T len;
439 NTSTATUS ret;
441 ret = RtlExpandEnvironmentStrings( env, src->Buffer, src->Length / sizeof(WCHAR),
442 dst->Buffer, dst->MaximumLength / sizeof(WCHAR), &len );
443 if (plen) *plen = len * sizeof(WCHAR); /* FIXME: check for overflow? */
444 if (len > UNICODE_STRING_MAX_CHARS) ret = STATUS_BUFFER_TOO_SMALL;
445 if (!ret) dst->Length = (len - 1) * sizeof(WCHAR);
446 return ret;
449 static inline void normalize( void *base, WCHAR **ptr )
451 if (*ptr) *ptr = (WCHAR *)((char *)base + (UINT_PTR)*ptr);
454 /******************************************************************************
455 * RtlNormalizeProcessParams [NTDLL.@]
457 PRTL_USER_PROCESS_PARAMETERS WINAPI RtlNormalizeProcessParams( RTL_USER_PROCESS_PARAMETERS *params )
459 if (params && !(params->Flags & PROCESS_PARAMS_FLAG_NORMALIZED))
461 normalize( params, &params->CurrentDirectory.DosPath.Buffer );
462 normalize( params, &params->DllPath.Buffer );
463 normalize( params, &params->ImagePathName.Buffer );
464 normalize( params, &params->CommandLine.Buffer );
465 normalize( params, &params->WindowTitle.Buffer );
466 normalize( params, &params->Desktop.Buffer );
467 normalize( params, &params->ShellInfo.Buffer );
468 normalize( params, &params->RuntimeInfo.Buffer );
469 params->Flags |= PROCESS_PARAMS_FLAG_NORMALIZED;
471 return params;
475 static inline void denormalize( const void *base, WCHAR **ptr )
477 if (*ptr) *ptr = (WCHAR *)(UINT_PTR)((char *)*ptr - (const char *)base);
480 /******************************************************************************
481 * RtlDeNormalizeProcessParams [NTDLL.@]
483 PRTL_USER_PROCESS_PARAMETERS WINAPI RtlDeNormalizeProcessParams( RTL_USER_PROCESS_PARAMETERS *params )
485 if (params && (params->Flags & PROCESS_PARAMS_FLAG_NORMALIZED))
487 denormalize( params, &params->CurrentDirectory.DosPath.Buffer );
488 denormalize( params, &params->DllPath.Buffer );
489 denormalize( params, &params->ImagePathName.Buffer );
490 denormalize( params, &params->CommandLine.Buffer );
491 denormalize( params, &params->WindowTitle.Buffer );
492 denormalize( params, &params->Desktop.Buffer );
493 denormalize( params, &params->ShellInfo.Buffer );
494 denormalize( params, &params->RuntimeInfo.Buffer );
495 params->Flags &= ~PROCESS_PARAMS_FLAG_NORMALIZED;
497 return params;
501 #define ROUND_SIZE(size) (((size) + sizeof(void *) - 1) & ~(sizeof(void *) - 1))
503 /* append a unicode string to the process params data; helper for RtlCreateProcessParameters */
504 static void append_unicode_string( void **data, const UNICODE_STRING *src,
505 UNICODE_STRING *dst )
507 dst->Length = src->Length;
508 dst->MaximumLength = src->MaximumLength;
509 if (dst->MaximumLength)
511 dst->Buffer = *data;
512 memcpy( dst->Buffer, src->Buffer, dst->Length );
513 *data = (char *)dst->Buffer + ROUND_SIZE( dst->MaximumLength );
515 else dst->Buffer = NULL;
519 /******************************************************************************
520 * RtlCreateProcessParametersEx [NTDLL.@]
522 NTSTATUS WINAPI RtlCreateProcessParametersEx( RTL_USER_PROCESS_PARAMETERS **result,
523 const UNICODE_STRING *ImagePathName,
524 const UNICODE_STRING *DllPath,
525 const UNICODE_STRING *CurrentDirectoryName,
526 const UNICODE_STRING *CommandLine,
527 PWSTR Environment,
528 const UNICODE_STRING *WindowTitle,
529 const UNICODE_STRING *Desktop,
530 const UNICODE_STRING *ShellInfo,
531 const UNICODE_STRING *RuntimeInfo,
532 ULONG flags )
534 UNICODE_STRING curdir;
535 const RTL_USER_PROCESS_PARAMETERS *cur_params;
536 SIZE_T size, env_size = 0;
537 void *ptr;
538 NTSTATUS status = STATUS_SUCCESS;
540 RtlAcquirePebLock();
541 cur_params = NtCurrentTeb()->Peb->ProcessParameters;
542 if (!DllPath) DllPath = &null_str;
543 if (!CurrentDirectoryName)
545 if (NtCurrentTeb()->Tib.SubSystemTib) /* FIXME: hack */
546 curdir = ((WIN16_SUBSYSTEM_TIB *)NtCurrentTeb()->Tib.SubSystemTib)->curdir.DosPath;
547 else
548 curdir = cur_params->CurrentDirectory.DosPath;
550 else curdir = *CurrentDirectoryName;
551 curdir.MaximumLength = MAX_PATH * sizeof(WCHAR);
553 if (!CommandLine) CommandLine = ImagePathName;
554 if (!Environment && cur_params) Environment = cur_params->Environment;
555 if (!WindowTitle) WindowTitle = &empty_str;
556 if (!Desktop) Desktop = &empty_str;
557 if (!ShellInfo) ShellInfo = &empty_str;
558 if (!RuntimeInfo) RuntimeInfo = &null_str;
560 if (Environment) env_size = get_env_length( Environment ) * sizeof(WCHAR);
562 size = (sizeof(RTL_USER_PROCESS_PARAMETERS)
563 + ROUND_SIZE( ImagePathName->MaximumLength )
564 + ROUND_SIZE( DllPath->MaximumLength )
565 + ROUND_SIZE( curdir.MaximumLength )
566 + ROUND_SIZE( CommandLine->MaximumLength )
567 + ROUND_SIZE( WindowTitle->MaximumLength )
568 + ROUND_SIZE( Desktop->MaximumLength )
569 + ROUND_SIZE( ShellInfo->MaximumLength )
570 + ROUND_SIZE( RuntimeInfo->MaximumLength ));
572 if ((ptr = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, size + ROUND_SIZE( env_size ) )))
574 RTL_USER_PROCESS_PARAMETERS *params = ptr;
575 params->AllocationSize = size;
576 params->Size = size;
577 params->Flags = PROCESS_PARAMS_FLAG_NORMALIZED;
578 params->EnvironmentSize = ROUND_SIZE( env_size );
579 if (cur_params) params->ConsoleFlags = cur_params->ConsoleFlags;
580 /* all other fields are zero */
582 ptr = params + 1;
583 append_unicode_string( &ptr, &curdir, &params->CurrentDirectory.DosPath );
584 append_unicode_string( &ptr, DllPath, &params->DllPath );
585 append_unicode_string( &ptr, ImagePathName, &params->ImagePathName );
586 append_unicode_string( &ptr, CommandLine, &params->CommandLine );
587 append_unicode_string( &ptr, WindowTitle, &params->WindowTitle );
588 append_unicode_string( &ptr, Desktop, &params->Desktop );
589 append_unicode_string( &ptr, ShellInfo, &params->ShellInfo );
590 append_unicode_string( &ptr, RuntimeInfo, &params->RuntimeInfo );
591 if (Environment) params->Environment = memcpy( ptr, Environment, env_size );
592 *result = params;
593 if (!(flags & PROCESS_PARAMS_FLAG_NORMALIZED)) RtlDeNormalizeProcessParams( params );
595 else status = STATUS_NO_MEMORY;
597 RtlReleasePebLock();
598 return status;
602 /******************************************************************************
603 * RtlCreateProcessParameters [NTDLL.@]
605 NTSTATUS WINAPI RtlCreateProcessParameters( RTL_USER_PROCESS_PARAMETERS **result,
606 const UNICODE_STRING *image,
607 const UNICODE_STRING *dllpath,
608 const UNICODE_STRING *curdir,
609 const UNICODE_STRING *cmdline,
610 PWSTR env,
611 const UNICODE_STRING *title,
612 const UNICODE_STRING *desktop,
613 const UNICODE_STRING *shellinfo,
614 const UNICODE_STRING *runtime )
616 return RtlCreateProcessParametersEx( result, image, dllpath, curdir, cmdline,
617 env, title, desktop, shellinfo, runtime, 0 );
621 /******************************************************************************
622 * RtlDestroyProcessParameters [NTDLL.@]
624 void WINAPI RtlDestroyProcessParameters( RTL_USER_PROCESS_PARAMETERS *params )
626 RtlFreeHeap( GetProcessHeap(), 0, params );
630 /***********************************************************************
631 * init_user_process_params
633 * Fill the initial RTL_USER_PROCESS_PARAMETERS structure from the server.
635 void init_user_process_params(void)
637 WCHAR *env;
638 SIZE_T env_size;
639 RTL_USER_PROCESS_PARAMETERS *new_params, *params = NtCurrentTeb()->Peb->ProcessParameters;
640 UNICODE_STRING curdir;
642 /* environment needs to be a separate memory block */
643 env_size = params->EnvironmentSize;
644 if ((env = RtlAllocateHeap( GetProcessHeap(), 0, max( env_size, sizeof(WCHAR) ))))
646 if (env_size) memcpy( env, params->Environment, env_size );
647 else env[0] = 0;
650 params->Environment = NULL; /* avoid copying it */
651 if (RtlCreateProcessParametersEx( &new_params, &params->ImagePathName, &params->DllPath,
652 &params->CurrentDirectory.DosPath,
653 &params->CommandLine, NULL, &params->WindowTitle, &params->Desktop,
654 &params->ShellInfo, &params->RuntimeInfo,
655 PROCESS_PARAMS_FLAG_NORMALIZED ))
656 return;
658 new_params->Environment = env;
659 new_params->DebugFlags = params->DebugFlags;
660 new_params->ConsoleHandle = params->ConsoleHandle;
661 new_params->ConsoleFlags = params->ConsoleFlags;
662 new_params->hStdInput = params->hStdInput;
663 new_params->hStdOutput = params->hStdOutput;
664 new_params->hStdError = params->hStdError;
665 new_params->dwX = params->dwX;
666 new_params->dwY = params->dwY;
667 new_params->dwXSize = params->dwXSize;
668 new_params->dwYSize = params->dwYSize;
669 new_params->dwXCountChars = params->dwXCountChars;
670 new_params->dwYCountChars = params->dwYCountChars;
671 new_params->dwFillAttribute = params->dwFillAttribute;
672 new_params->dwFlags = params->dwFlags;
673 new_params->wShowWindow = params->wShowWindow;
675 NtCurrentTeb()->Peb->ProcessParameters = params = new_params;
677 if (RtlSetCurrentDirectory_U( &params->CurrentDirectory.DosPath ))
679 MESSAGE("wine: could not open working directory %s, starting in the Windows directory.\n",
680 debugstr_w( params->CurrentDirectory.DosPath.Buffer ));
681 RtlInitUnicodeString( &curdir, windows_dir );
682 RtlSetCurrentDirectory_U( &curdir );
684 set_wow64_environment( &params->Environment );
685 params->EnvironmentSize = RtlSizeHeap( GetProcessHeap(), 0, params->Environment );