Throughout, replace hMainProc with GetCurrentProcess/NtCurrentProcess
according to context. Throughout, replace hMainThread with GetCurrentThread/NtCurrentThread according to context. * dcrt0.cc (dll_crt0_0): Drop duplication of GetCurrentProcess to hMainProc. Drop duplication of GetCurrentThread to hMainThread. * dtable.cc (dtable::stdio_init): Remove useless comment. * globals.cc (hMainProc): Remove. (hMainThread): Remove. * ntdll.h (NtCurrentProcess): Define. (NtCurrentThread: Define.
This commit is contained in:
		
							parent
							
								
									333a47d316
								
							
						
					
					
						commit
						f16706de97
					
				|  | @ -1,3 +1,16 @@ | |||
| 2009-12-18  Corinna Vinschen  <corinna@vinschen.de> | ||||
| 
 | ||||
| 	Throughout, replace hMainProc with GetCurrentProcess/NtCurrentProcess | ||||
| 	according to context.  Throughout, replace hMainThread with | ||||
| 	GetCurrentThread/NtCurrentThread according to context. | ||||
| 	* dcrt0.cc (dll_crt0_0): Drop duplication of GetCurrentProcess to | ||||
| 	hMainProc.  Drop duplication of GetCurrentThread to hMainThread. | ||||
| 	* dtable.cc (dtable::stdio_init): Remove useless comment. | ||||
| 	* globals.cc (hMainProc): Remove. | ||||
| 	(hMainThread): Remove. | ||||
| 	* ntdll.h (NtCurrentProcess): Define. | ||||
| 	(NtCurrentThread: Define. | ||||
| 
 | ||||
| 2009-12-18  Corinna Vinschen  <corinna@vinschen.de> | ||||
| 
 | ||||
| 	* fhandler.h (fhandler_registry::value_name): Convert to wchar_t*. | ||||
|  |  | |||
|  | @ -609,7 +609,8 @@ child_info_spawn::handle_spawn () | |||
|   cygheap_fixup_in_child (true); | ||||
|   memory_init (false); | ||||
|   if (!moreinfo->myself_pinfo || | ||||
|       !DuplicateHandle (hMainProc, moreinfo->myself_pinfo, hMainProc, &h, 0, | ||||
|       !DuplicateHandle (GetCurrentProcess (), moreinfo->myself_pinfo, | ||||
| 			GetCurrentProcess (), &h, 0, | ||||
| 			FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)) | ||||
|     h = NULL; | ||||
|   myself.thisproc (h); | ||||
|  | @ -660,7 +661,7 @@ disable_dep () | |||
|     } | ||||
|   if (dep_system_policy < OptIn) | ||||
|     return; | ||||
|   if (!GetProcessDEPPolicy (hMainProc, &ppolicy, &perm)) | ||||
|   if (!GetProcessDEPPolicy (GetCurrentProcess (), &ppolicy, &perm)) | ||||
|     { | ||||
|       debug_printf ("GetProcessDEPPolicy: %E"); | ||||
|       return; | ||||
|  | @ -694,15 +695,7 @@ dll_crt0_0 () | |||
|   user_data->impure_ptr = _impure_ptr; | ||||
|   user_data->impure_ptr_ptr = &_impure_ptr; | ||||
| 
 | ||||
|   if (!DuplicateHandle (GetCurrentProcess (), GetCurrentProcess (), | ||||
| 		       GetCurrentProcess (), &hMainProc, 0, FALSE, | ||||
| 			DUPLICATE_SAME_ACCESS)) | ||||
|     hMainProc = GetCurrentProcess (); | ||||
| 
 | ||||
|   DuplicateHandle (hMainProc, GetCurrentThread (), hMainProc, | ||||
| 		   &hMainThread, 0, false, DUPLICATE_SAME_ACCESS); | ||||
| 
 | ||||
|   OpenProcessToken (hMainProc, MAXIMUM_ALLOWED, &hProcToken); | ||||
|   OpenProcessToken (GetCurrentProcess (), MAXIMUM_ALLOWED, &hProcToken); | ||||
|   set_cygwin_privileges (hProcToken); | ||||
| 
 | ||||
|   device::init (); | ||||
|  | @ -788,9 +781,6 @@ dll_crt0_1 (void *) | |||
|     small_printf ("cmalloc returns %p\n", cmalloc (HEAP_STR, n)); | ||||
| #endif | ||||
| 
 | ||||
|   ProtectHandle (hMainProc); | ||||
|   ProtectHandle (hMainThread); | ||||
| 
 | ||||
|   cygheap->cwd.init (); | ||||
| 
 | ||||
|   /* Initialize pthread mainthread when not forked and it is safe to call new,
 | ||||
|  |  | |||
|  | @ -177,9 +177,6 @@ dtable::stdio_init () | |||
|     { | ||||
|       /* Since this code is not invoked for forked tasks, we don't have
 | ||||
| 	 to worry about the close-on-exec flag here.  */ | ||||
|       /* CV 2009-11-26: Using hMainProc results in ERROR_INVALID_PARAMETER
 | ||||
| 	 when trying to duplicate a console handle.  It only works using | ||||
| 	 the GetCurrentProcess () pseudo handle for some unknown reason. */ | ||||
|       if (!DuplicateHandle (GetCurrentProcess (), out, | ||||
| 			    GetCurrentProcess (), &err, | ||||
| 			    0, TRUE, DUPLICATE_SAME_ACCESS)) | ||||
|  |  | |||
|  | @ -484,7 +484,7 @@ _cygtls::handle_exceptions (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT | |||
| 
 | ||||
|   if (debugging && ++debugging < 500000) | ||||
|     { | ||||
|       SetThreadPriority (hMainThread, THREAD_PRIORITY_NORMAL); | ||||
|       SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_NORMAL); | ||||
|       return 0; | ||||
|     } | ||||
| 
 | ||||
|  | @ -1307,7 +1307,7 @@ exit_sig: | |||
|     { | ||||
|       CONTEXT c; | ||||
|       c.ContextFlags = CONTEXT_FULL; | ||||
|       GetThreadContext (hMainThread, &c); | ||||
|       GetThreadContext (GetCurrentThread (), &c); | ||||
|       use_tls->copy_context (&c); | ||||
|       si.si_signo |= 0x80; | ||||
|     } | ||||
|  |  | |||
|  | @ -1143,8 +1143,9 @@ fhandler_base::dup (fhandler_base *child) | |||
|   HANDLE nh; | ||||
|   if (!nohandle ()) | ||||
|     { | ||||
|       if (!DuplicateHandle (hMainProc, get_handle (), hMainProc, &nh, 0, TRUE, | ||||
| 			    DUPLICATE_SAME_ACCESS)) | ||||
|       if (!DuplicateHandle (GetCurrentProcess (), get_handle (), | ||||
| 			    GetCurrentProcess (), &nh, | ||||
| 			    0, TRUE, DUPLICATE_SAME_ACCESS)) | ||||
| 	{ | ||||
| 	  debug_printf ("dup(%s) failed, handle %x, %E", | ||||
| 			get_name (), get_handle ()); | ||||
|  | @ -1319,8 +1320,8 @@ fhandler_base::fork_fixup (HANDLE parent, HANDLE &h, const char *name) | |||
|   bool res = false; | ||||
|   if (/* !is_socket () && */ !close_on_exec ()) | ||||
|     debug_printf ("handle %p already opened", h); | ||||
|   else if (!DuplicateHandle (parent, h, hMainProc, &h, 0, !close_on_exec (), | ||||
| 			     DUPLICATE_SAME_ACCESS)) | ||||
|   else if (!DuplicateHandle (parent, h, GetCurrentProcess (), &h, | ||||
| 			     0, !close_on_exec (), DUPLICATE_SAME_ACCESS)) | ||||
|     system_printf ("%s - %E, handle %s<%p>", get_name (), name, h); | ||||
|   else | ||||
|     { | ||||
|  |  | |||
|  | @ -301,7 +301,8 @@ fhandler_fifo::dup (fhandler_base *child) | |||
|   fhandler_fifo *fifo_child = (fhandler_fifo *) child; | ||||
|   if (res == 0 && dummy_client) | ||||
|     { | ||||
|       bool dres = DuplicateHandle (hMainProc, dummy_client, hMainProc, | ||||
|       bool dres = DuplicateHandle (GetCurrentProcess (), dummy_client, | ||||
| 				   GetCurrentProcess (), | ||||
| 				   &fifo_child->dummy_client, 0, | ||||
| 				   TRUE, DUPLICATE_SAME_ACCESS); | ||||
|       if (!dres) | ||||
|  |  | |||
|  | @ -699,14 +699,16 @@ fhandler_socket::dup (fhandler_base *child) | |||
|   debug_printf ("here"); | ||||
|   fhandler_socket *fhs = (fhandler_socket *) child; | ||||
| 
 | ||||
|   if (!DuplicateHandle (hMainProc, wsock_mtx, hMainProc, &fhs->wsock_mtx, 0, | ||||
| 			TRUE, DUPLICATE_SAME_ACCESS)) | ||||
|   if (!DuplicateHandle (GetCurrentProcess (), wsock_mtx, | ||||
| 			GetCurrentProcess (), &fhs->wsock_mtx, | ||||
| 			0, TRUE, DUPLICATE_SAME_ACCESS)) | ||||
|     { | ||||
|       __seterrno (); | ||||
|       return -1; | ||||
|     } | ||||
|   if (!DuplicateHandle (hMainProc, wsock_evt, hMainProc, &fhs->wsock_evt, 0, | ||||
| 			TRUE, DUPLICATE_SAME_ACCESS)) | ||||
|   if (!DuplicateHandle (GetCurrentProcess (), wsock_evt, | ||||
| 			GetCurrentProcess (), &fhs->wsock_evt, | ||||
| 			0, TRUE, DUPLICATE_SAME_ACCESS)) | ||||
|     { | ||||
|       __seterrno (); | ||||
|       NtClose (fhs->wsock_mtx); | ||||
|  | @ -751,7 +753,7 @@ fhandler_socket::dup (fhandler_base *child) | |||
|   if (!fhs->fixup_before_fork_exec (GetCurrentProcessId ())) | ||||
|     { | ||||
|       cygheap->user.reimpersonate (); | ||||
|       fhs->fixup_after_fork (hMainProc); | ||||
|       fhs->fixup_after_fork (GetCurrentProcess ()); | ||||
|       if (fhs->get_io_handle() != (HANDLE) INVALID_SOCKET) | ||||
| 	return 0; | ||||
|     } | ||||
|  |  | |||
|  | @ -1428,8 +1428,9 @@ fhandler_dev_tape::dup (fhandler_base *child) | |||
| { | ||||
|   lock (-1); | ||||
|   fhandler_dev_tape *fh = (fhandler_dev_tape *) child; | ||||
|   if (!DuplicateHandle (hMainProc, mt_mtx, hMainProc, &fh->mt_mtx, 0, TRUE, | ||||
| 			DUPLICATE_SAME_ACCESS)) | ||||
|   if (!DuplicateHandle (GetCurrentProcess (), mt_mtx, | ||||
|   			GetCurrentProcess (), &fh->mt_mtx, | ||||
| 			0, TRUE, DUPLICATE_SAME_ACCESS)) | ||||
|     { | ||||
|       debug_printf ("dup(%s) failed, mutex handle %x, %E", | ||||
| 		    get_name (), mt_mtx); | ||||
|  | @ -1438,8 +1439,9 @@ fhandler_dev_tape::dup (fhandler_base *child) | |||
|     } | ||||
|   fh->mt_evt = NULL; | ||||
|   if (mt_evt && | ||||
|       !DuplicateHandle (hMainProc, mt_evt, hMainProc, &fh->mt_evt, 0, TRUE, | ||||
| 			DUPLICATE_SAME_ACCESS)) | ||||
|       !DuplicateHandle (GetCurrentProcess (), mt_evt, | ||||
| 			GetCurrentProcess (), &fh->mt_evt, | ||||
| 			0, TRUE, DUPLICATE_SAME_ACCESS)) | ||||
|     { | ||||
|       debug_printf ("dup(%s) failed, event handle %x, %E", | ||||
| 		    get_name (), mt_evt); | ||||
|  |  | |||
|  | @ -556,7 +556,7 @@ fhandler_tty_slave::open (int flags, mode_t) | |||
| 	} | ||||
| 
 | ||||
|       if (!DuplicateHandle (tty_owner, get_ttyp ()->from_master, | ||||
| 			    hMainProc, &from_master_local, 0, TRUE, | ||||
| 			    GetCurrentProcess (), &from_master_local, 0, TRUE, | ||||
| 			    DUPLICATE_SAME_ACCESS)) | ||||
| 	{ | ||||
| 	  termios_printf ("can't duplicate input from %u/%p, %E", | ||||
|  | @ -567,7 +567,7 @@ fhandler_tty_slave::open (int flags, mode_t) | |||
| 
 | ||||
|       VerifyHandle (from_master_local); | ||||
|       if (!DuplicateHandle (tty_owner, get_ttyp ()->to_master, | ||||
| 			  hMainProc, &to_master_local, 0, TRUE, | ||||
| 			  GetCurrentProcess (), &to_master_local, 0, TRUE, | ||||
| 			  DUPLICATE_SAME_ACCESS)) | ||||
| 	{ | ||||
| 	  termios_printf ("can't duplicate output, %E"); | ||||
|  | @ -1459,10 +1459,10 @@ fhandler_pty_master::fixup_after_fork (HANDLE parent) | |||
|   if (arch->dwProcessId != wpid) | ||||
|     { | ||||
|       tty& t = *get_ttyp (); | ||||
|       if (!DuplicateHandle (parent, arch->from_master, hMainProc, | ||||
|       if (!DuplicateHandle (parent, arch->from_master, GetCurrentProcess (), | ||||
| 			    &arch->from_master, 0, false, DUPLICATE_SAME_ACCESS)) | ||||
| 	system_printf ("couldn't duplicate from_parent(%p), %E", arch->from_master); | ||||
|       if (!DuplicateHandle (parent, arch->to_master, hMainProc, | ||||
|       if (!DuplicateHandle (parent, arch->to_master, GetCurrentProcess (), | ||||
| 			    &arch->to_master, 0, false, DUPLICATE_SAME_ACCESS)) | ||||
| 	system_printf ("couldn't duplicate to_parent(%p), %E", arch->from_master); | ||||
|       if (myself->pid == t.master_pid) | ||||
|  |  | |||
|  | @ -155,7 +155,8 @@ allow_others_to_sync () | |||
|      to avoid having to alloc 64K from the stack. */ | ||||
|   tmp_pathbuf tp; | ||||
|   PSECURITY_DESCRIPTOR sd = (PSECURITY_DESCRIPTOR) tp.w_get (); | ||||
|   status = NtQuerySecurityObject (hMainProc, DACL_SECURITY_INFORMATION, sd, | ||||
|   status = NtQuerySecurityObject (NtCurrentProcess (), | ||||
| 				  DACL_SECURITY_INFORMATION, sd, | ||||
| 				  NT_MAX_PATH * sizeof (WCHAR), &len); | ||||
|   if (!NT_SUCCESS (status)) | ||||
|     { | ||||
|  | @ -182,7 +183,7 @@ allow_others_to_sync () | |||
|     } | ||||
|   dacl->AclSize = (char *) ace - (char *) dacl; | ||||
|   /* Write the DACL back. */ | ||||
|   status = NtSetSecurityObject (hMainProc, DACL_SECURITY_INFORMATION, sd); | ||||
|   status = NtSetSecurityObject (NtCurrentProcess (), DACL_SECURITY_INFORMATION, sd); | ||||
|   if (!NT_SUCCESS (status)) | ||||
|     { | ||||
|       debug_printf ("NtSetSecurityObject: %p", status); | ||||
|  |  | |||
|  | @ -263,8 +263,9 @@ slow_pid_reuse (HANDLE h) | |||
|      windows from reusing the same pid.  */ | ||||
|   if (last_fork_procs[nfork_procs]) | ||||
|     ForceCloseHandle1 (last_fork_procs[nfork_procs], fork_stupidity); | ||||
|   if (DuplicateHandle (hMainProc, h, hMainProc, &last_fork_procs[nfork_procs], | ||||
| 			0, FALSE, DUPLICATE_SAME_ACCESS)) | ||||
|   if (DuplicateHandle (GetCurrentProcess (), h, | ||||
| 		       GetCurrentProcess (), &last_fork_procs[nfork_procs], | ||||
| 		       0, FALSE, DUPLICATE_SAME_ACCESS)) | ||||
|     ProtectHandle1 (last_fork_procs[nfork_procs], fork_stupidity); | ||||
|   else | ||||
|     { | ||||
|  | @ -287,7 +288,7 @@ frok::parent (volatile char * volatile stack_here) | |||
|   pinfo child; | ||||
|   static char errbuf[256]; | ||||
| 
 | ||||
|   int c_flags = GetPriorityClass (hMainProc); | ||||
|   int c_flags = GetPriorityClass (GetCurrentProcess ()); | ||||
|   debug_printf ("priority class %d", c_flags); | ||||
| 
 | ||||
|   /* If we don't have a console, then don't create a console for the
 | ||||
|  |  | |||
|  | @ -18,8 +18,6 @@ details. */ | |||
| #include <malloc.h> | ||||
| #include <cygwin/version.h> | ||||
| 
 | ||||
| HANDLE NO_COPY hMainProc = (HANDLE) -1; | ||||
| HANDLE NO_COPY hMainThread; | ||||
| HANDLE NO_COPY hProcToken; | ||||
| HANDLE NO_COPY hProcImpToken; | ||||
| HMODULE NO_COPY cygwin_hmodule; | ||||
|  |  | |||
|  | @ -75,7 +75,7 @@ respawn_wow64_process () | |||
| 
 | ||||
|   /* Unfortunately there's no simpler way to retrieve the
 | ||||
|      parent process in NT, as far as I know.  Hints welcome. */ | ||||
|   ret = NtQueryInformationProcess (GetCurrentProcess (), | ||||
|   ret = NtQueryInformationProcess (NtCurrentProcess (), | ||||
| 				   ProcessBasicInformation, | ||||
| 				   &pbi, sizeof pbi, NULL); | ||||
|   if (NT_SUCCESS (ret) | ||||
|  |  | |||
|  | @ -253,7 +253,7 @@ low_priority_sleep (DWORD secs) | |||
|       if (GetCurrentThreadId () == cygthread::main_thread_id) | ||||
| 	new_prio = THREAD_PRIORITY_LOWEST; | ||||
|       else | ||||
| 	new_prio = GetThreadPriority (hMainThread); | ||||
| 	new_prio = GetThreadPriority (GetCurrentThread ()); | ||||
| 
 | ||||
|       if (curr_prio != new_prio) | ||||
| 	/* Force any threads in normal priority to be scheduled */ | ||||
|  |  | |||
|  | @ -208,12 +208,12 @@ MapView (HANDLE h, void *addr, size_t len, DWORD openflags, | |||
| 
 | ||||
|      Note: Retrying the mapping might be unnecessary, now that mmap64 checks | ||||
| 	   for a valid memory area first. */ | ||||
|   ret = NtMapViewOfSection (h, GetCurrentProcess (), &base, 0, commitsize, | ||||
|   ret = NtMapViewOfSection (h, NtCurrentProcess (), &base, 0, commitsize, | ||||
| 			    &offset, &viewsize, ViewShare, alloc_type, protect); | ||||
|   if (!NT_SUCCESS (ret) && addr && !fixed (flags)) | ||||
|     { | ||||
|       base = NULL; | ||||
|       ret = NtMapViewOfSection (h, GetCurrentProcess (), &base, 0, commitsize, | ||||
|       ret = NtMapViewOfSection (h, NtCurrentProcess (), &base, 0, commitsize, | ||||
| 				&offset, &viewsize, ViewShare, 0, protect); | ||||
|     } | ||||
|   if (!NT_SUCCESS (ret)) | ||||
|  | @ -1290,7 +1290,8 @@ mlock (const void *addr, size_t len) | |||
|   NTSTATUS status = 0; | ||||
|   do | ||||
|     { | ||||
|       status = NtLockVirtualMemory (hMainProc, &base, &size, LOCK_VM_IN_RAM); | ||||
|       status = NtLockVirtualMemory (NtCurrentProcess (), &base, &size, | ||||
| 				    LOCK_VM_IN_RAM); | ||||
|       if (status == STATUS_WORKING_SET_QUOTA) | ||||
| 	{ | ||||
| 	  /* The working set is too small, try to increase it so that the
 | ||||
|  | @ -1304,7 +1305,7 @@ mlock (const void *addr, size_t len) | |||
| 	     further, or until NtLockVirtualMemory returns successfully (or | ||||
| 	     with another error).  */ | ||||
| 	  ULONG min, max; | ||||
| 	  if (!GetProcessWorkingSetSize (hMainProc, &min, &max)) | ||||
| 	  if (!GetProcessWorkingSetSize (GetCurrentProcess (), &min, &max)) | ||||
| 	    { | ||||
| 	      set_errno (ENOMEM); | ||||
| 	      break; | ||||
|  | @ -1317,7 +1318,7 @@ mlock (const void *addr, size_t len) | |||
| 	    min += pagesize; | ||||
| 	  if (max < min) | ||||
| 	    max = min; | ||||
| 	  if (!SetProcessWorkingSetSize (hMainProc, min, max)) | ||||
| 	  if (!SetProcessWorkingSetSize (GetCurrentProcess (), min, max)) | ||||
| 	    { | ||||
| 	      set_errno (ENOMEM); | ||||
| 	      break; | ||||
|  | @ -1346,7 +1347,7 @@ munlock (const void *addr, size_t len) | |||
|   size_t pagesize = getpagesize (); | ||||
|   PVOID base = (PVOID) rounddown((uintptr_t) addr, pagesize); | ||||
|   ULONG size = roundup2 (((uintptr_t) addr - (uintptr_t) base) + len, pagesize); | ||||
|   NTSTATUS status = NtUnlockVirtualMemory (hMainProc, &base, &size, | ||||
|   NTSTATUS status = NtUnlockVirtualMemory (NtCurrentProcess (), &base, &size, | ||||
| 					   LOCK_VM_IN_RAM); | ||||
|   if (!NT_SUCCESS (status)) | ||||
|     __seterrno_from_nt_status (status); | ||||
|  | @ -1482,7 +1483,7 @@ fhandler_dev_zero::mmap (caddr_t *addr, size_t len, int prot, | |||
| 	    __seterrno (); | ||||
| 	  else | ||||
| 	    { | ||||
| 	      NtUnmapViewOfSection (GetCurrentProcess (), base); | ||||
| 	      NtUnmapViewOfSection (NtCurrentProcess (), base); | ||||
| 	      set_errno (EINVAL); | ||||
| 	      debug_printf ("MapView: address shift with MAP_FIXED given"); | ||||
| 	    } | ||||
|  | @ -1501,7 +1502,7 @@ fhandler_dev_zero::munmap (HANDLE h, caddr_t addr, size_t len) | |||
|     VirtualFree (addr, 0, MEM_RELEASE); | ||||
|   else | ||||
|     { | ||||
|       NtUnmapViewOfSection (GetCurrentProcess (), addr); | ||||
|       NtUnmapViewOfSection (NtCurrentProcess (), addr); | ||||
|       NtClose (h); | ||||
|     } | ||||
|   return 0; | ||||
|  | @ -1562,7 +1563,7 @@ fhandler_disk_file::mmap (caddr_t *addr, size_t len, int prot, | |||
| 	__seterrno (); | ||||
|       else | ||||
| 	{ | ||||
| 	  NtUnmapViewOfSection (GetCurrentProcess (), base); | ||||
| 	  NtUnmapViewOfSection (NtCurrentProcess (), base); | ||||
| 	  set_errno (EINVAL); | ||||
| 	  debug_printf ("MapView: address shift with MAP_FIXED given"); | ||||
| 	} | ||||
|  | @ -1577,7 +1578,7 @@ fhandler_disk_file::mmap (caddr_t *addr, size_t len, int prot, | |||
| int | ||||
| fhandler_disk_file::munmap (HANDLE h, caddr_t addr, size_t len) | ||||
| { | ||||
|   NtUnmapViewOfSection (GetCurrentProcess (), addr); | ||||
|   NtUnmapViewOfSection (NtCurrentProcess (), addr); | ||||
|   NtClose (h); | ||||
|   return 0; | ||||
| } | ||||
|  | @ -1656,7 +1657,7 @@ fhandler_dev_mem::mmap (caddr_t *addr, size_t len, int prot, | |||
| 	__seterrno (); | ||||
|       else | ||||
| 	{ | ||||
| 	  NtUnmapViewOfSection (GetCurrentProcess (), base); | ||||
| 	  NtUnmapViewOfSection (NtCurrentProcess (), base); | ||||
| 	  set_errno (EINVAL); | ||||
| 	  debug_printf ("MapView: address shift with MAP_FIXED given"); | ||||
| 	} | ||||
|  | @ -1672,7 +1673,7 @@ int | |||
| fhandler_dev_mem::munmap (HANDLE h, caddr_t addr, size_t len) | ||||
| { | ||||
|   NTSTATUS ret; | ||||
|   if (!NT_SUCCESS (ret = NtUnmapViewOfSection (GetCurrentProcess (), addr))) | ||||
|   if (!NT_SUCCESS (ret = NtUnmapViewOfSection (NtCurrentProcess (), addr))) | ||||
|     { | ||||
|       __seterrno_from_nt_status (ret); | ||||
|       return -1; | ||||
|  |  | |||
|  | @ -859,6 +859,10 @@ typedef enum _EVENT_INFORMATION_CLASS | |||
| 
 | ||||
| /* Function declarations for ntdll.dll.  These don't appear in any
 | ||||
|    standard Win32 header.  */ | ||||
| 
 | ||||
| #define NtCurrentProcess() ((HANDLE) 0xffffffff) | ||||
| #define NtCurrentThread()  ((HANDLE) 0xfffffffe) | ||||
| 
 | ||||
| extern "C" | ||||
| { | ||||
|   NTSTATUS NTAPI NtAdjustPrivilegesToken (HANDLE, BOOLEAN, PTOKEN_PRIVILEGES, | ||||
|  |  | |||
|  | @ -105,7 +105,7 @@ pinfo_init (char **envp, int envc) | |||
|       myself->uid = ILLEGAL_UID; | ||||
|       myself->gid = UNKNOWN_GID; | ||||
|       environ_init (NULL, 0);	/* call after myself has been set up */ | ||||
|       myself->nice = winprio_to_nice (GetPriorityClass (hMainProc)); | ||||
|       myself->nice = winprio_to_nice (GetPriorityClass (GetCurrentProcess ())); | ||||
|       debug_printf ("Set nice to %d", myself->nice); | ||||
|     } | ||||
| 
 | ||||
|  | @ -185,7 +185,7 @@ pinfo::exit (DWORD n) | |||
|   /* FIXME:  There is a potential race between an execed process and its
 | ||||
|      parent here.  I hated to add a mutex just for that, though.  */ | ||||
|   struct rusage r; | ||||
|   fill_rusage (&r, hMainProc); | ||||
|   fill_rusage (&r, GetCurrentProcess ()); | ||||
|   add_rusage (&self->rusage_self, &r); | ||||
|   int exitcode = self->exitcode & 0xffff; | ||||
|   if (!self->cygstarted) | ||||
|  | @ -920,8 +920,8 @@ _pinfo::dup_proc_pipe (HANDLE hProcess) | |||
|      parent sees it.  */ | ||||
|   if (this != myself || is_toplevel_proc) | ||||
|     flags |= DUPLICATE_CLOSE_SOURCE; | ||||
|   bool res = DuplicateHandle (hMainProc, wr_proc_pipe, hProcess, &wr_proc_pipe, | ||||
| 			      0, FALSE, flags); | ||||
|   bool res = DuplicateHandle (GetCurrentProcess (), wr_proc_pipe, | ||||
| 			      hProcess, &wr_proc_pipe, 0, FALSE, flags); | ||||
|   if (!res && WaitForSingleObject (hProcess, 0) != WAIT_OBJECT_0) | ||||
|     { | ||||
|       wr_proc_pipe = orig_wr_proc_pipe; | ||||
|  |  | |||
|  | @ -117,7 +117,7 @@ fhandler_pipe::open (int flags, mode_t mode) | |||
|       goto out; | ||||
|     } | ||||
|   inh = !(flags & O_NOINHERIT); | ||||
|   if (!DuplicateHandle (proc, pipe_hdl, hMainProc, &nio_hdl, | ||||
|   if (!DuplicateHandle (proc, pipe_hdl, GetCurrentProcess (), &nio_hdl, | ||||
| 			0, inh, DUPLICATE_SAME_ACCESS)) | ||||
|     { | ||||
|       __seterrno (); | ||||
|  |  | |||
|  | @ -94,7 +94,7 @@ getrusage (int intwho, struct rusage *rusage_in) | |||
|   if (intwho == RUSAGE_SELF) | ||||
|     { | ||||
|       memset (&r, 0, sizeof (r)); | ||||
|       fill_rusage (&r, hMainProc); | ||||
|       fill_rusage (&r, GetCurrentProcess ()); | ||||
|       *rusage_in = r; | ||||
|     } | ||||
|   else if (intwho == RUSAGE_CHILDREN) | ||||
|  |  | |||
|  | @ -158,7 +158,7 @@ get_session_parent_dir () | |||
|   if (!dir) | ||||
|     { | ||||
|       PROCESS_SESSION_INFORMATION psi; | ||||
|       status = NtQueryInformationProcess (GetCurrentProcess (), | ||||
|       status = NtQueryInformationProcess (NtCurrentProcess (), | ||||
| 					  ProcessSessionInformation, | ||||
| 					  &psi, sizeof psi, NULL); | ||||
|       if (!NT_SUCCESS (status) || psi.SessionId == 0) | ||||
|  |  | |||
|  | @ -136,7 +136,7 @@ fixup_shms_after_fork () | |||
|       NTSTATUS status; | ||||
|       vm_object_t ptr = sph_entry->ptr; | ||||
|       ULONG viewsize = sph_entry->parent->size; | ||||
|       status = NtMapViewOfSection (sph_entry->parent->hdl, GetCurrentProcess (), | ||||
|       status = NtMapViewOfSection (sph_entry->parent->hdl, NtCurrentProcess (), | ||||
| 				   &ptr, 0, sph_entry->parent->size, NULL, | ||||
| 				   &viewsize, ViewShare, 0, sph_entry->access); | ||||
|       if (!NT_SUCCESS (status) || ptr != sph_entry->ptr) | ||||
|  | @ -221,7 +221,7 @@ shmat (int shmid, const void *shmaddr, int shmflg) | |||
|   vm_object_t ptr = NULL; | ||||
|   ULONG viewsize = ssh_entry->size; | ||||
|   ULONG access = (shmflg & SHM_RDONLY) ? PAGE_READONLY : PAGE_READWRITE; | ||||
|   status = NtMapViewOfSection (ssh_entry->hdl, GetCurrentProcess (), &ptr, 0, | ||||
|   status = NtMapViewOfSection (ssh_entry->hdl, NtCurrentProcess (), &ptr, 0, | ||||
| 			       ssh_entry->size, NULL, &viewsize, ViewShare, | ||||
| 			       MEM_TOP_DOWN, access); | ||||
|   if (!NT_SUCCESS (status)) | ||||
|  |  | |||
|  | @ -608,8 +608,8 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls) | |||
| 	  goto out; | ||||
| 	} | ||||
|       VerifyHandle (hp); | ||||
|       if (!DuplicateHandle (hp, dupsig, hMainProc, &sendsig, false, 0, | ||||
| 			    DUPLICATE_SAME_ACCESS) || !sendsig) | ||||
|       if (!DuplicateHandle (hp, dupsig, GetCurrentProcess (), &sendsig, false, | ||||
| 			    0, DUPLICATE_SAME_ACCESS) || !sendsig) | ||||
| 	{ | ||||
| 	  __seterrno (); | ||||
| 	  sigproc_printf ("DuplicateHandle failed, %E"); | ||||
|  | @ -631,7 +631,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls) | |||
| 	      __seterrno (); | ||||
| 	      goto out; | ||||
| 	    } | ||||
| 	  if (!DuplicateHandle (hMainProc, tome, hp, &tome, false, 0, | ||||
| 	  if (!DuplicateHandle (GetCurrentProcess (), tome, hp, &tome, false, 0, | ||||
| 				DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)) | ||||
| 	    { | ||||
| 	      sigproc_printf ("DuplicateHandle for __SIGCOMMUNE failed, %E"); | ||||
|  | @ -818,7 +818,8 @@ child_info::child_info (unsigned in_cb, child_info_types chtype, bool need_subpr | |||
|   /* Create an inheritable handle to pass to the child process.  This will
 | ||||
|      allow the child to duplicate handles from the parent to itself. */ | ||||
|   parent = NULL; | ||||
|   if (!DuplicateHandle (hMainProc, hMainProc, hMainProc, &parent, 0, TRUE, | ||||
|   if (!DuplicateHandle (GetCurrentProcess (), GetCurrentProcess (), | ||||
| 			GetCurrentProcess (), &parent, 0, TRUE, | ||||
| 			DUPLICATE_SAME_ACCESS)) | ||||
|     system_printf ("couldn't create handle to myself for child, %E"); | ||||
| } | ||||
|  |  | |||
|  | @ -420,9 +420,9 @@ spawn_guts (const char *prog_arg, const char *const *argv, | |||
|       moreinfo->argv = newargv; | ||||
| 
 | ||||
|       if (mode != _P_OVERLAY || | ||||
| 	  !DuplicateHandle (hMainProc, myself.shared_handle (), hMainProc, | ||||
| 			    &moreinfo->myself_pinfo, 0, TRUE, | ||||
| 			    DUPLICATE_SAME_ACCESS)) | ||||
| 	  !DuplicateHandle (GetCurrentProcess (), myself.shared_handle (), | ||||
| 			    GetCurrentProcess (), &moreinfo->myself_pinfo, | ||||
| 			    0, TRUE, DUPLICATE_SAME_ACCESS)) | ||||
| 	moreinfo->myself_pinfo = NULL; | ||||
|       else | ||||
| 	VerifyHandle (moreinfo->myself_pinfo); | ||||
|  | @ -445,7 +445,7 @@ spawn_guts (const char *prog_arg, const char *const *argv, | |||
| 
 | ||||
|   si.cb = sizeof (si); | ||||
| 
 | ||||
|   c_flags = GetPriorityClass (hMainProc); | ||||
|   c_flags = GetPriorityClass (GetCurrentProcess ()); | ||||
|   sigproc_printf ("priority class %d", c_flags); | ||||
|   c_flags |= CREATE_SEPARATE_WOW_VDM | CREATE_UNICODE_ENVIRONMENT; | ||||
| 
 | ||||
|  | @ -473,9 +473,9 @@ spawn_guts (const char *prog_arg, const char *const *argv, | |||
| 	 generating its own pids again? */ | ||||
|       if (cygheap->pid_handle) | ||||
| 	/* already done previously */; | ||||
|       else if (DuplicateHandle (hMainProc, hMainProc, hMainProc, | ||||
|       				&cygheap->pid_handle, PROCESS_QUERY_INFORMATION, | ||||
| 				TRUE, 0)) | ||||
|       else if (DuplicateHandle (GetCurrentProcess (), GetCurrentProcess (), | ||||
| 				GetCurrentProcess (), &cygheap->pid_handle, | ||||
| 				PROCESS_QUERY_INFORMATION, TRUE, 0)) | ||||
| 	ProtectHandleINH (cygheap->pid_handle); | ||||
|       else | ||||
| 	system_printf ("duplicate to pid_handle failed, %E"); | ||||
|  | @ -729,8 +729,8 @@ loop: | |||
| 	 the fields filled out by child.remember do not disappear and so there | ||||
| 	 is not a brief period during which the pid is not available. | ||||
| 	 However, we should try to find another way to do this eventually. */ | ||||
|       DuplicateHandle (hMainProc, child.shared_handle (), pi.hProcess, | ||||
| 			      NULL, 0, 0, DUPLICATE_SAME_ACCESS); | ||||
|       DuplicateHandle (GetCurrentProcess (), child.shared_handle (), | ||||
| 		       pi.hProcess, NULL, 0, 0, DUPLICATE_SAME_ACCESS); | ||||
|       child->start_time = time (NULL); /* Register child's starting time. */ | ||||
|       child->nice = myself->nice; | ||||
|       if (!child.remember (mode == _P_DETACH)) | ||||
|  |  | |||
|  | @ -100,8 +100,9 @@ close_all_files (bool norelease) | |||
| 	debug_printf ("closing fd %d", i); | ||||
| #endif | ||||
| 	if (i == 2) | ||||
| 	  DuplicateHandle (GetCurrentProcess (), fh->get_output_handle (), GetCurrentProcess (), &h, 0, false, | ||||
| 			   DUPLICATE_SAME_ACCESS); | ||||
| 	  DuplicateHandle (GetCurrentProcess (), fh->get_output_handle (), | ||||
| 			   GetCurrentProcess (), &h, | ||||
| 			   0, false, DUPLICATE_SAME_ACCESS); | ||||
| 	fh->close (); | ||||
| 	if (!norelease) | ||||
| 	  cygheap->fdtab.release (i); | ||||
|  | @ -3131,7 +3132,7 @@ setpriority (int which, id_t who, int value) | |||
| 	who = myself->pid; | ||||
|       if ((pid_t) who == myself->pid) | ||||
| 	{ | ||||
| 	  if (!SetPriorityClass (hMainProc, prio)) | ||||
| 	  if (!SetPriorityClass (GetCurrentProcess (), prio)) | ||||
| 	    { | ||||
| 	      set_errno (EACCES); | ||||
| 	      return -1; | ||||
|  |  | |||
|  | @ -312,8 +312,9 @@ pthread::init_mainthread () | |||
| 
 | ||||
|   set_tls_self_pointer (thread); | ||||
|   thread->thread_id = GetCurrentThreadId (); | ||||
|   if (!DuplicateHandle (hMainProc, GetCurrentThread (), hMainProc, | ||||
| 			&thread->win32_obj_id, 0, FALSE, DUPLICATE_SAME_ACCESS)) | ||||
|   if (!DuplicateHandle (GetCurrentProcess (), GetCurrentThread (), | ||||
| 			GetCurrentProcess (), &thread->win32_obj_id, | ||||
| 			0, FALSE, DUPLICATE_SAME_ACCESS)) | ||||
|     api_fatal ("failed to create mainthread handle"); | ||||
|   if (!thread->create_cancel_event ()) | ||||
|     api_fatal ("couldn't create cancel event for main thread"); | ||||
|  |  | |||
|  | @ -77,7 +77,7 @@ times (struct tms *buf) | |||
|      overflow. */ | ||||
|   clock_t tc = (clock_t) (ticks * CLOCKS_PER_SEC / 1000); | ||||
| 
 | ||||
|   GetProcessTimes (hMainProc, &creation_time, &exit_time, | ||||
|   GetProcessTimes (GetCurrentProcess (), &creation_time, &exit_time, | ||||
| 		   &kernel_time, &user_time); | ||||
| 
 | ||||
|   syscall_printf ("ticks %d, CLOCKS_PER_SEC %d", ticks, CLOCKS_PER_SEC); | ||||
|  |  | |||
|  | @ -78,8 +78,8 @@ cygheap_user::init () | |||
|       if (!SetTokenInformation (hProcToken, TokenDefaultDacl, &dacl, | ||||
|       				sizeof (dacl))) | ||||
| 	system_printf ("SetTokenInformation (TokenDefaultDacl), %E"); | ||||
|       if ((status = NtSetSecurityObject (hMainProc, DACL_SECURITY_INFORMATION, | ||||
| 					 psd))) | ||||
|       if ((status = NtSetSecurityObject (NtCurrentProcess (), | ||||
| 					 DACL_SECURITY_INFORMATION, psd))) | ||||
| 	system_printf ("NtSetSecurityObject, %lx", status); | ||||
|     } | ||||
|   else | ||||
|  |  | |||
|  | @ -544,7 +544,7 @@ wincapc::init () | |||
| 	     == VER_SUITE_TERMINAL) | ||||
| 	((wincaps *)caps)->ts_has_dep_problem = true; | ||||
|     } | ||||
|   if (NT_SUCCESS (NtQueryInformationProcess (GetCurrentProcess (), | ||||
|   if (NT_SUCCESS (NtQueryInformationProcess (NtCurrentProcess (), | ||||
| 					     ProcessWow64Information, | ||||
| 					     &wow64, sizeof wow64, NULL)) | ||||
|       && !wow64) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue