📄 unifiedkernel-0.2.0-w0.9.11.diff
字号:
diff -Nru wine-0.9.11.ori/dlls/kernel/process.c wine-0.9.11/dlls/kernel/process.c--- wine-0.9.11.ori/dlls/kernel/process.c 2006-03-31 20:38:26.000000000 +0800+++ wine-0.9.11/dlls/kernel/process.c 2007-03-23 09:53:02.000000000 +0800@@ -150,7 +150,7 @@ return TRUE; } -+#ifndef UNIFIED_KERNEL /*********************************************************************** * open_builtin_exe_file *@@ -254,7 +254,7 @@ return FALSE; }-+#endif /*********************************************************************** * build_initial_environment@@ -671,6 +671,7 @@ * * Initialize the windows and system directories from the environment. */+#include <stdio.h> static void init_windows_dirs(void) { extern void __wine_init_windows_dir( const WCHAR *windir, const WCHAR *sysdir );@@ -726,13 +727,23 @@ * * Main process initialisation code */+#ifndef UNIFIED_KERNEL static BOOL process_init(void)+#else+/*+ * In Unified Kernel, process_init will be called in LdrInitializeThunk,+ * and pthread/kthread mode will not be used.+ */+BOOL process_init(void)+#endif { static const WCHAR kernel32W[] = {'k','e','r','n','e','l','3','2',0}; PEB *peb = NtCurrentTeb()->Peb; RTL_USER_PROCESS_PARAMETERS *params = peb->ProcessParameters; +#ifndef UNIFIED_KERNEL PTHREAD_Init();+#endif setbuf(stdout,NULL); setbuf(stderr,NULL);@@ -945,7 +956,7 @@ ExitProcess( GetLastError() ); } -+#ifndef UNIFIED_KERNEL /*********************************************************************** * build_argv *@@ -1065,6 +1076,7 @@ return ret; } + /*********************************************************************** * build_envp *@@ -1584,7 +1596,7 @@ HeapFree( GetProcessHeap(), 0, name ); return ret; }-+#endif /********************************************************************** * CreateProcessA (KERNEL32.@)@@ -1627,7 +1639,7 @@ return ret; } -+#ifndef UNIFIED_KERNEL /********************************************************************** * CreateProcessW (KERNEL32.@) */@@ -1765,7 +1777,707 @@ HeapFree( GetProcessHeap(), 0, unixdir ); return retv; }+#else+#define PEB_BASE 0x7ffdf000+void BaseProcessStart(unsigned long start_address, void *param);++extern VOID RtlRosR32AttribsToNativeAttribs(OUT OBJECT_ATTRIBUTES * NativeAttribs, + IN SECURITY_ATTRIBUTES * Ros32Attribs OPTIONAL);++extern NTSTATUS CDECL+RtlRosCreateUserThread(IN HANDLE ProcessHandle,+ IN POBJECT_ATTRIBUTES ObjectAttributes,+ IN BOOLEAN CreateSuspended,+ IN LONG StackZeroBits,+ IN OUT PULONG StackReserve OPTIONAL,+ IN OUT PULONG StackCommit OPTIONAL,+ IN PVOID BaseStartAddress,+ OUT PHANDLE ThreadHandle OPTIONAL,+ OUT PCLIENT_ID ClientId OPTIONAL,+ IN ULONG_PTR StartAddress,+ IN ULONG_PTR Parameter);++NTSTATUS WINAPI +UkOpenFile( PHANDLE handle, ACCESS_MASK access,+ POBJECT_ATTRIBUTES attr, PIO_STATUS_BLOCK io,+ ULONG sharing, ULONG options );++NTSTATUS WINAPI +UkCreateSection( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr,+ const LARGE_INTEGER *size, ULONG protect,+ ULONG sec_flags, HANDLE file ); +NTSTATUS WINAPI UkClose( HANDLE Handle );++/*+ * GetFileName+ *+ * Helper for CreateProcessW: retrieve the file name to load from the+ * app name and command line. Store the file name in buffer, and+ * return a possibly modified command line.+ *+ * FIXME: use CurDir to search for the executable file in the new working directory+ *+ * modified from ReactOS+ */+static LPWSTR GetFileName(LPCWSTR CurDir, LPCWSTR AppName, LPWSTR CmdLine, LPWSTR Buffer, + unsigned BufLen)+{+ WCHAR *Name, *Pos, *Ret = NULL;+ WCHAR Quotation[] = {'\"', 0};+ WCHAR dotExe[] = {'.','e','x','e', 0};+ const WCHAR *p;++ /* if we have an app name, everything is easy */++ if (AppName) {+ /* use the unmodified app name as file name */+ lstrcpynW(Buffer, AppName, BufLen );+ Ret = CmdLine;+ if (!Ret || L'\0' == CmdLine[0]) {+ /* no command-line, create one */+ Ret = RtlAllocateHeap(GetProcessHeap(), 0, + (strlenW(AppName) + 3) * sizeof(WCHAR));+ if (Ret) {+ Ret[0] = L'"';+ strcpyW(Ret + 1, AppName);+ strcatW(Ret, Quotation);+ }+ }+ return Ret;+ }++ if (!CmdLine) {+ SetLastError(ERROR_INVALID_PARAMETER);+ return NULL;+ }++ /* first check for a quoted file name */+ if (L'"' == CmdLine[0] && (p = strchrW(CmdLine + 1, L'"'))) {+ int Len = p - CmdLine - 1;+ /* extract the quoted portion as file name */+ Name = RtlAllocateHeap(GetProcessHeap(), 0, (Len + 1) * sizeof(WCHAR));+ if (!Name)+ return NULL;+ memcpy(Name, CmdLine + 1, Len * sizeof(WCHAR));+ Name[Len] = L'\0';++ if (SearchPathW(NULL, Name, dotExe, BufLen, Buffer, NULL))+ Ret = CmdLine; /* no change necessary */++ RtlFreeHeap(GetProcessHeap(), 0, Name);+ return Ret;+ }++ /* now try the command-line word by word */+ Name = RtlAllocateHeap(GetProcessHeap(), 0, (strlenW(CmdLine) + 1) * sizeof(WCHAR));+ if (!Name)+ return NULL;+ Pos = Name;+ p = CmdLine;++ while (L'\0' != *p) {+ do+ *Pos++ = *p++;+ while (L'\0' != *p && L' ' != *p);+ *Pos = 0;+ if (SearchPathW(NULL, Name, dotExe, BufLen, Buffer, NULL)) {+ Ret = CmdLine;+ break;+ }+ }++ if (!Ret || !strchrW(Name, L' ')) {+ RtlFreeHeap(GetProcessHeap(), 0, Name); /* no change necessary */+ return Ret;+ }++ /* now build a new command-line with quotes */+ Ret = RtlAllocateHeap(GetProcessHeap(), 0, (strlenW(CmdLine) + 3) * sizeof(WCHAR));+ if (!Ret) {+ RtlFreeHeap(GetProcessHeap(), 0, Name); /* no change necessary */+ return NULL;+ }+ Ret[0] = L'"';+ strcpyW(Ret + 1, Name);+ strcatW(Ret, Quotation);+ strcatW(Ret, p);++ RtlFreeHeap(GetProcessHeap(), 0, Name);+ return Ret;+}++/* modified from ReactOS */+HANDLE KlMapFile(LPCWSTR lpApplicationName)+{+ HANDLE hFile;+ IO_STATUS_BLOCK IoStatusBlock;+ UNICODE_STRING ApplicationNameString;+ OBJECT_ATTRIBUTES ObjectAttributes;+ PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;+ NTSTATUS Status;+ HANDLE hSection;++ hFile = NULL;++#if 0+ /* Find the application name */+ if (!RtlDosPathNameToNtPathName_U((LPWSTR)lpApplicationName,+ &ApplicationNameString,+ NULL,+ NULL))+ return NULL;+#endif+ + RtlInitUnicodeString(&ApplicationNameString, lpApplicationName);+ InitializeObjectAttributes(&ObjectAttributes,+ &ApplicationNameString,+ OBJ_CASE_INSENSITIVE,+ NULL,+ SecurityDescriptor);++ /* Try to open the executable */++ Status = UkOpenFile(&hFile,+ SYNCHRONIZE|FILE_EXECUTE|FILE_READ_DATA,+ &ObjectAttributes,+ &IoStatusBlock,+ FILE_SHARE_DELETE|FILE_SHARE_READ,+ FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE);++ RtlFreeUnicodeString (&ApplicationNameString);+ + if (Status) {+ SetLastError(Status);+ return NULL;+ }+ Status = UkCreateSection(&hSection,+ SECTION_ALL_ACCESS,+ NULL,+ NULL,+ PAGE_EXECUTE,+ SEC_IMAGE,+ hFile);+ UkClose(hFile);++ if (Status) {+ SetLastError(Status);+ return NULL;+ }++ return hSection;+}++/* modified from ReactOS */+HANDLE KlCreateFirstThread(HANDLE ProcessHandle,+ LPSECURITY_ATTRIBUTES lpThreadAttributes,+ PSECTION_IMAGE_INFORMATION Sii,+ LPTHREAD_START_ROUTINE lpStartAddress,+ DWORD dwCreationFlags,+ LPDWORD lpThreadId)+{+ OBJECT_ATTRIBUTES oaThreadAttribs;+ CLIENT_ID cidClientId;+ PVOID pTrueStartAddress = NULL;+ NTSTATUS nErrCode;+ HANDLE hThread;++ /* convert the thread attributes */+ RtlRosR32AttribsToNativeAttribs(&oaThreadAttribs, lpThreadAttributes);++ /* native image */+ if(Sii->ImageSubsystem != IMAGE_SUBSYSTEM_NATIVE)+ pTrueStartAddress = (PVOID)BaseProcessStart;+ /* Win32 image */+ /* FIXME: nothing to do with win32 image */+ else+ ERR("Nothing to do with Win32 image!\n");++ /* create the first thread */+ nErrCode = RtlRosCreateUserThread(ProcessHandle,+ &oaThreadAttribs,+ dwCreationFlags & CREATE_SUSPENDED,+ 0,+ &(Sii->StackReserved),+ &(Sii->StackCommit),+ pTrueStartAddress,+ &hThread,+ &cidClientId,+ (ULONG_PTR)lpStartAddress,+ (ULONG_PTR)PEB_BASE);+ /* failure */+ if(nErrCode) {+ SetLastError(nErrCode);+ return NULL;+ }++ /* success */+ if(lpThreadId) + *lpThreadId = (DWORD)cidClientId.UniqueThread;+ + return hThread;+}++static NTSTATUS KlInitPeb(HANDLE ProcessHandle,+ PRTL_USER_PROCESS_PARAMETERS Ppb,+ PVOID * ImageBaseAddress,+ ULONG ImageSubSystem)+{+ PWCHAR ptr;+ PVOID EnvPtr = NULL;+ PVOID ParentEnv = NULL;+ PVOID PpbBase = NULL;+ ULONG offset = 0;+ ULONG EnvSize = 0, PpbSize = 0;+ ULONG EnvSize1 = 0;+ ULONG ByteWritten = 0;+ ULONG peb_base = 0x7FFDF000;+ NTSTATUS Status;+ + if (Ppb->Environment) {+ ptr = Ppb->Environment;+ while (*ptr)+ while (*ptr++);+ ptr++;+ EnvSize = ((ULONG)ptr - (ULONG)Ppb->Environment);+ ParentEnv = Ppb->Environment;+ }++ if (EnvSize != 0) {+ EnvSize1 = EnvSize;+ Status = NtAllocateVirtualMemory(ProcessHandle,+ &EnvPtr,+ 0,+ &EnvSize1,+ MEM_RESERVE | MEM_COMMIT,+ PAGE_READWRITE);+ if (Status) {+ return(Status);+ }++ NtWriteVirtualMemory(ProcessHandle,+ EnvPtr,+ ParentEnv,+ EnvSize,+ &ByteWritten);+ }++ /* create ppb in child space*/+ PpbSize = Ppb->AllocationSize;+ Status = NtAllocateVirtualMemory(ProcessHandle,+ &PpbBase,+ 0,+ &PpbSize,+ MEM_RESERVE | MEM_COMMIT,+ PAGE_READWRITE);+ if (Status)+ return Status;++ NtWriteVirtualMemory(ProcessHandle,+ PpbBase,+ Ppb,+ Ppb->AllocationSize,+ &ByteWritten);++ /* write environment */+ offset = FIELD_OFFSET(RTL_USER_PROCESS_PARAMETERS, Environment);+ NtWriteVirtualMemory(ProcessHandle,+ (PVOID)((ULONG)PpbBase + offset),+ &EnvPtr,+ sizeof(EnvPtr),+ &ByteWritten);++ /* write point to ppb */+ offset = FIELD_OFFSET(PEB, ProcessParameters);+ NtWriteVirtualMemory(ProcessHandle,+ (PVOID)(peb_base + offset),+ &PpbBase,+ sizeof(PpbBase),+ &ByteWritten);++ /* FIXME: write image subsystem ? */+ offset = FIELD_OFFSET(PEB, ImageSubSystem);+ NtWriteVirtualMemory(ProcessHandle,+ (PVOID)(peb_base + offset),+ &ImageSubSystem,+ sizeof(ImageSubSystem),+ &ByteWritten);++ /* read image base address */+ offset = FIELD_OFFSET(PEB, ImageBaseAddress);+ NtReadVirtualMemory(ProcessHandle,+ (PVOID)(peb_base + offset),+ ImageBaseAddress,+ sizeof(PVOID),+ &ByteWritten);++ return STATUS_SUCCESS;+}++BOOL WINAPI+CreateProcessW(LPCWSTR lpApplicationName,+ LPWSTR lpCommandLine,+ LPSECURITY_ATTRIBUTES lpProcessAttributes,+ LPSECURITY_ATTRIBUTES lpThreadAttributes,+ BOOL bInheritHandles,+ DWORD dwCreationFlags,+ LPVOID lpEnvironment,+ LPCWSTR lpCurrentDirectory,+ LPSTARTUPINFOW lpStartupInfo,+ LPPROCESS_INFORMATION lpProcessInformation)+{+ HANDLE hSection, hProcess, hThread;+ HANDLE hStdIn, hStdOut, hStdErr;+ HANDLE process_info;+ ULONG ProcAttributes = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -