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:
Corinna Vinschen 2009-12-18 20:32:04 +00:00
parent 333a47d316
commit f16706de97
28 changed files with 103 additions and 89 deletions

View File

@ -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> 2009-12-18 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (fhandler_registry::value_name): Convert to wchar_t*. * fhandler.h (fhandler_registry::value_name): Convert to wchar_t*.

View File

@ -609,7 +609,8 @@ child_info_spawn::handle_spawn ()
cygheap_fixup_in_child (true); cygheap_fixup_in_child (true);
memory_init (false); memory_init (false);
if (!moreinfo->myself_pinfo || 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)) FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
h = NULL; h = NULL;
myself.thisproc (h); myself.thisproc (h);
@ -660,7 +661,7 @@ disable_dep ()
} }
if (dep_system_policy < OptIn) if (dep_system_policy < OptIn)
return; return;
if (!GetProcessDEPPolicy (hMainProc, &ppolicy, &perm)) if (!GetProcessDEPPolicy (GetCurrentProcess (), &ppolicy, &perm))
{ {
debug_printf ("GetProcessDEPPolicy: %E"); debug_printf ("GetProcessDEPPolicy: %E");
return; return;
@ -694,15 +695,7 @@ dll_crt0_0 ()
user_data->impure_ptr = _impure_ptr; user_data->impure_ptr = _impure_ptr;
user_data->impure_ptr_ptr = &_impure_ptr; user_data->impure_ptr_ptr = &_impure_ptr;
if (!DuplicateHandle (GetCurrentProcess (), GetCurrentProcess (), OpenProcessToken (GetCurrentProcess (), MAXIMUM_ALLOWED, &hProcToken);
GetCurrentProcess (), &hMainProc, 0, FALSE,
DUPLICATE_SAME_ACCESS))
hMainProc = GetCurrentProcess ();
DuplicateHandle (hMainProc, GetCurrentThread (), hMainProc,
&hMainThread, 0, false, DUPLICATE_SAME_ACCESS);
OpenProcessToken (hMainProc, MAXIMUM_ALLOWED, &hProcToken);
set_cygwin_privileges (hProcToken); set_cygwin_privileges (hProcToken);
device::init (); device::init ();
@ -788,9 +781,6 @@ dll_crt0_1 (void *)
small_printf ("cmalloc returns %p\n", cmalloc (HEAP_STR, n)); small_printf ("cmalloc returns %p\n", cmalloc (HEAP_STR, n));
#endif #endif
ProtectHandle (hMainProc);
ProtectHandle (hMainThread);
cygheap->cwd.init (); cygheap->cwd.init ();
/* Initialize pthread mainthread when not forked and it is safe to call new, /* Initialize pthread mainthread when not forked and it is safe to call new,

View File

@ -177,9 +177,6 @@ dtable::stdio_init ()
{ {
/* Since this code is not invoked for forked tasks, we don't have /* Since this code is not invoked for forked tasks, we don't have
to worry about the close-on-exec flag here. */ 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, if (!DuplicateHandle (GetCurrentProcess (), out,
GetCurrentProcess (), &err, GetCurrentProcess (), &err,
0, TRUE, DUPLICATE_SAME_ACCESS)) 0, TRUE, DUPLICATE_SAME_ACCESS))

View File

@ -484,7 +484,7 @@ _cygtls::handle_exceptions (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT
if (debugging && ++debugging < 500000) if (debugging && ++debugging < 500000)
{ {
SetThreadPriority (hMainThread, THREAD_PRIORITY_NORMAL); SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_NORMAL);
return 0; return 0;
} }
@ -1307,7 +1307,7 @@ exit_sig:
{ {
CONTEXT c; CONTEXT c;
c.ContextFlags = CONTEXT_FULL; c.ContextFlags = CONTEXT_FULL;
GetThreadContext (hMainThread, &c); GetThreadContext (GetCurrentThread (), &c);
use_tls->copy_context (&c); use_tls->copy_context (&c);
si.si_signo |= 0x80; si.si_signo |= 0x80;
} }

View File

@ -1143,8 +1143,9 @@ fhandler_base::dup (fhandler_base *child)
HANDLE nh; HANDLE nh;
if (!nohandle ()) if (!nohandle ())
{ {
if (!DuplicateHandle (hMainProc, get_handle (), hMainProc, &nh, 0, TRUE, if (!DuplicateHandle (GetCurrentProcess (), get_handle (),
DUPLICATE_SAME_ACCESS)) GetCurrentProcess (), &nh,
0, TRUE, DUPLICATE_SAME_ACCESS))
{ {
debug_printf ("dup(%s) failed, handle %x, %E", debug_printf ("dup(%s) failed, handle %x, %E",
get_name (), get_handle ()); get_name (), get_handle ());
@ -1319,8 +1320,8 @@ fhandler_base::fork_fixup (HANDLE parent, HANDLE &h, const char *name)
bool res = false; bool res = false;
if (/* !is_socket () && */ !close_on_exec ()) if (/* !is_socket () && */ !close_on_exec ())
debug_printf ("handle %p already opened", h); debug_printf ("handle %p already opened", h);
else if (!DuplicateHandle (parent, h, hMainProc, &h, 0, !close_on_exec (), else if (!DuplicateHandle (parent, h, GetCurrentProcess (), &h,
DUPLICATE_SAME_ACCESS)) 0, !close_on_exec (), DUPLICATE_SAME_ACCESS))
system_printf ("%s - %E, handle %s<%p>", get_name (), name, h); system_printf ("%s - %E, handle %s<%p>", get_name (), name, h);
else else
{ {

View File

@ -301,7 +301,8 @@ fhandler_fifo::dup (fhandler_base *child)
fhandler_fifo *fifo_child = (fhandler_fifo *) child; fhandler_fifo *fifo_child = (fhandler_fifo *) child;
if (res == 0 && dummy_client) if (res == 0 && dummy_client)
{ {
bool dres = DuplicateHandle (hMainProc, dummy_client, hMainProc, bool dres = DuplicateHandle (GetCurrentProcess (), dummy_client,
GetCurrentProcess (),
&fifo_child->dummy_client, 0, &fifo_child->dummy_client, 0,
TRUE, DUPLICATE_SAME_ACCESS); TRUE, DUPLICATE_SAME_ACCESS);
if (!dres) if (!dres)

View File

@ -699,14 +699,16 @@ fhandler_socket::dup (fhandler_base *child)
debug_printf ("here"); debug_printf ("here");
fhandler_socket *fhs = (fhandler_socket *) child; fhandler_socket *fhs = (fhandler_socket *) child;
if (!DuplicateHandle (hMainProc, wsock_mtx, hMainProc, &fhs->wsock_mtx, 0, if (!DuplicateHandle (GetCurrentProcess (), wsock_mtx,
TRUE, DUPLICATE_SAME_ACCESS)) GetCurrentProcess (), &fhs->wsock_mtx,
0, TRUE, DUPLICATE_SAME_ACCESS))
{ {
__seterrno (); __seterrno ();
return -1; return -1;
} }
if (!DuplicateHandle (hMainProc, wsock_evt, hMainProc, &fhs->wsock_evt, 0, if (!DuplicateHandle (GetCurrentProcess (), wsock_evt,
TRUE, DUPLICATE_SAME_ACCESS)) GetCurrentProcess (), &fhs->wsock_evt,
0, TRUE, DUPLICATE_SAME_ACCESS))
{ {
__seterrno (); __seterrno ();
NtClose (fhs->wsock_mtx); NtClose (fhs->wsock_mtx);
@ -751,7 +753,7 @@ fhandler_socket::dup (fhandler_base *child)
if (!fhs->fixup_before_fork_exec (GetCurrentProcessId ())) if (!fhs->fixup_before_fork_exec (GetCurrentProcessId ()))
{ {
cygheap->user.reimpersonate (); cygheap->user.reimpersonate ();
fhs->fixup_after_fork (hMainProc); fhs->fixup_after_fork (GetCurrentProcess ());
if (fhs->get_io_handle() != (HANDLE) INVALID_SOCKET) if (fhs->get_io_handle() != (HANDLE) INVALID_SOCKET)
return 0; return 0;
} }

View File

@ -1428,8 +1428,9 @@ fhandler_dev_tape::dup (fhandler_base *child)
{ {
lock (-1); lock (-1);
fhandler_dev_tape *fh = (fhandler_dev_tape *) child; fhandler_dev_tape *fh = (fhandler_dev_tape *) child;
if (!DuplicateHandle (hMainProc, mt_mtx, hMainProc, &fh->mt_mtx, 0, TRUE, if (!DuplicateHandle (GetCurrentProcess (), mt_mtx,
DUPLICATE_SAME_ACCESS)) GetCurrentProcess (), &fh->mt_mtx,
0, TRUE, DUPLICATE_SAME_ACCESS))
{ {
debug_printf ("dup(%s) failed, mutex handle %x, %E", debug_printf ("dup(%s) failed, mutex handle %x, %E",
get_name (), mt_mtx); get_name (), mt_mtx);
@ -1438,8 +1439,9 @@ fhandler_dev_tape::dup (fhandler_base *child)
} }
fh->mt_evt = NULL; fh->mt_evt = NULL;
if (mt_evt && if (mt_evt &&
!DuplicateHandle (hMainProc, mt_evt, hMainProc, &fh->mt_evt, 0, TRUE, !DuplicateHandle (GetCurrentProcess (), mt_evt,
DUPLICATE_SAME_ACCESS)) GetCurrentProcess (), &fh->mt_evt,
0, TRUE, DUPLICATE_SAME_ACCESS))
{ {
debug_printf ("dup(%s) failed, event handle %x, %E", debug_printf ("dup(%s) failed, event handle %x, %E",
get_name (), mt_evt); get_name (), mt_evt);

View File

@ -556,7 +556,7 @@ fhandler_tty_slave::open (int flags, mode_t)
} }
if (!DuplicateHandle (tty_owner, get_ttyp ()->from_master, if (!DuplicateHandle (tty_owner, get_ttyp ()->from_master,
hMainProc, &from_master_local, 0, TRUE, GetCurrentProcess (), &from_master_local, 0, TRUE,
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
{ {
termios_printf ("can't duplicate input from %u/%p, %E", 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); VerifyHandle (from_master_local);
if (!DuplicateHandle (tty_owner, get_ttyp ()->to_master, if (!DuplicateHandle (tty_owner, get_ttyp ()->to_master,
hMainProc, &to_master_local, 0, TRUE, GetCurrentProcess (), &to_master_local, 0, TRUE,
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
{ {
termios_printf ("can't duplicate output, %E"); termios_printf ("can't duplicate output, %E");
@ -1459,10 +1459,10 @@ fhandler_pty_master::fixup_after_fork (HANDLE parent)
if (arch->dwProcessId != wpid) if (arch->dwProcessId != wpid)
{ {
tty& t = *get_ttyp (); 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)) &arch->from_master, 0, false, DUPLICATE_SAME_ACCESS))
system_printf ("couldn't duplicate from_parent(%p), %E", arch->from_master); 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)) &arch->to_master, 0, false, DUPLICATE_SAME_ACCESS))
system_printf ("couldn't duplicate to_parent(%p), %E", arch->from_master); system_printf ("couldn't duplicate to_parent(%p), %E", arch->from_master);
if (myself->pid == t.master_pid) if (myself->pid == t.master_pid)

View File

@ -155,7 +155,8 @@ allow_others_to_sync ()
to avoid having to alloc 64K from the stack. */ to avoid having to alloc 64K from the stack. */
tmp_pathbuf tp; tmp_pathbuf tp;
PSECURITY_DESCRIPTOR sd = (PSECURITY_DESCRIPTOR) tp.w_get (); 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); NT_MAX_PATH * sizeof (WCHAR), &len);
if (!NT_SUCCESS (status)) if (!NT_SUCCESS (status))
{ {
@ -182,7 +183,7 @@ allow_others_to_sync ()
} }
dacl->AclSize = (char *) ace - (char *) dacl; dacl->AclSize = (char *) ace - (char *) dacl;
/* Write the DACL back. */ /* Write the DACL back. */
status = NtSetSecurityObject (hMainProc, DACL_SECURITY_INFORMATION, sd); status = NtSetSecurityObject (NtCurrentProcess (), DACL_SECURITY_INFORMATION, sd);
if (!NT_SUCCESS (status)) if (!NT_SUCCESS (status))
{ {
debug_printf ("NtSetSecurityObject: %p", status); debug_printf ("NtSetSecurityObject: %p", status);

View File

@ -263,8 +263,9 @@ slow_pid_reuse (HANDLE h)
windows from reusing the same pid. */ windows from reusing the same pid. */
if (last_fork_procs[nfork_procs]) if (last_fork_procs[nfork_procs])
ForceCloseHandle1 (last_fork_procs[nfork_procs], fork_stupidity); ForceCloseHandle1 (last_fork_procs[nfork_procs], fork_stupidity);
if (DuplicateHandle (hMainProc, h, hMainProc, &last_fork_procs[nfork_procs], if (DuplicateHandle (GetCurrentProcess (), h,
0, FALSE, DUPLICATE_SAME_ACCESS)) GetCurrentProcess (), &last_fork_procs[nfork_procs],
0, FALSE, DUPLICATE_SAME_ACCESS))
ProtectHandle1 (last_fork_procs[nfork_procs], fork_stupidity); ProtectHandle1 (last_fork_procs[nfork_procs], fork_stupidity);
else else
{ {
@ -287,7 +288,7 @@ frok::parent (volatile char * volatile stack_here)
pinfo child; pinfo child;
static char errbuf[256]; static char errbuf[256];
int c_flags = GetPriorityClass (hMainProc); int c_flags = GetPriorityClass (GetCurrentProcess ());
debug_printf ("priority class %d", c_flags); debug_printf ("priority class %d", c_flags);
/* If we don't have a console, then don't create a console for the /* If we don't have a console, then don't create a console for the

View File

@ -18,8 +18,6 @@ details. */
#include <malloc.h> #include <malloc.h>
#include <cygwin/version.h> #include <cygwin/version.h>
HANDLE NO_COPY hMainProc = (HANDLE) -1;
HANDLE NO_COPY hMainThread;
HANDLE NO_COPY hProcToken; HANDLE NO_COPY hProcToken;
HANDLE NO_COPY hProcImpToken; HANDLE NO_COPY hProcImpToken;
HMODULE NO_COPY cygwin_hmodule; HMODULE NO_COPY cygwin_hmodule;

View File

@ -75,7 +75,7 @@ respawn_wow64_process ()
/* Unfortunately there's no simpler way to retrieve the /* Unfortunately there's no simpler way to retrieve the
parent process in NT, as far as I know. Hints welcome. */ parent process in NT, as far as I know. Hints welcome. */
ret = NtQueryInformationProcess (GetCurrentProcess (), ret = NtQueryInformationProcess (NtCurrentProcess (),
ProcessBasicInformation, ProcessBasicInformation,
&pbi, sizeof pbi, NULL); &pbi, sizeof pbi, NULL);
if (NT_SUCCESS (ret) if (NT_SUCCESS (ret)

View File

@ -253,7 +253,7 @@ low_priority_sleep (DWORD secs)
if (GetCurrentThreadId () == cygthread::main_thread_id) if (GetCurrentThreadId () == cygthread::main_thread_id)
new_prio = THREAD_PRIORITY_LOWEST; new_prio = THREAD_PRIORITY_LOWEST;
else else
new_prio = GetThreadPriority (hMainThread); new_prio = GetThreadPriority (GetCurrentThread ());
if (curr_prio != new_prio) if (curr_prio != new_prio)
/* Force any threads in normal priority to be scheduled */ /* Force any threads in normal priority to be scheduled */

View File

@ -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 Note: Retrying the mapping might be unnecessary, now that mmap64 checks
for a valid memory area first. */ 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); &offset, &viewsize, ViewShare, alloc_type, protect);
if (!NT_SUCCESS (ret) && addr && !fixed (flags)) if (!NT_SUCCESS (ret) && addr && !fixed (flags))
{ {
base = NULL; base = NULL;
ret = NtMapViewOfSection (h, GetCurrentProcess (), &base, 0, commitsize, ret = NtMapViewOfSection (h, NtCurrentProcess (), &base, 0, commitsize,
&offset, &viewsize, ViewShare, 0, protect); &offset, &viewsize, ViewShare, 0, protect);
} }
if (!NT_SUCCESS (ret)) if (!NT_SUCCESS (ret))
@ -1290,7 +1290,8 @@ mlock (const void *addr, size_t len)
NTSTATUS status = 0; NTSTATUS status = 0;
do 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) if (status == STATUS_WORKING_SET_QUOTA)
{ {
/* The working set is too small, try to increase it so that the /* 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 further, or until NtLockVirtualMemory returns successfully (or
with another error). */ with another error). */
ULONG min, max; ULONG min, max;
if (!GetProcessWorkingSetSize (hMainProc, &min, &max)) if (!GetProcessWorkingSetSize (GetCurrentProcess (), &min, &max))
{ {
set_errno (ENOMEM); set_errno (ENOMEM);
break; break;
@ -1317,7 +1318,7 @@ mlock (const void *addr, size_t len)
min += pagesize; min += pagesize;
if (max < min) if (max < min)
max = min; max = min;
if (!SetProcessWorkingSetSize (hMainProc, min, max)) if (!SetProcessWorkingSetSize (GetCurrentProcess (), min, max))
{ {
set_errno (ENOMEM); set_errno (ENOMEM);
break; break;
@ -1346,7 +1347,7 @@ munlock (const void *addr, size_t len)
size_t pagesize = getpagesize (); size_t pagesize = getpagesize ();
PVOID base = (PVOID) rounddown((uintptr_t) addr, pagesize); PVOID base = (PVOID) rounddown((uintptr_t) addr, pagesize);
ULONG size = roundup2 (((uintptr_t) addr - (uintptr_t) base) + len, 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); LOCK_VM_IN_RAM);
if (!NT_SUCCESS (status)) if (!NT_SUCCESS (status))
__seterrno_from_nt_status (status); __seterrno_from_nt_status (status);
@ -1482,7 +1483,7 @@ fhandler_dev_zero::mmap (caddr_t *addr, size_t len, int prot,
__seterrno (); __seterrno ();
else else
{ {
NtUnmapViewOfSection (GetCurrentProcess (), base); NtUnmapViewOfSection (NtCurrentProcess (), base);
set_errno (EINVAL); set_errno (EINVAL);
debug_printf ("MapView: address shift with MAP_FIXED given"); 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); VirtualFree (addr, 0, MEM_RELEASE);
else else
{ {
NtUnmapViewOfSection (GetCurrentProcess (), addr); NtUnmapViewOfSection (NtCurrentProcess (), addr);
NtClose (h); NtClose (h);
} }
return 0; return 0;
@ -1562,7 +1563,7 @@ fhandler_disk_file::mmap (caddr_t *addr, size_t len, int prot,
__seterrno (); __seterrno ();
else else
{ {
NtUnmapViewOfSection (GetCurrentProcess (), base); NtUnmapViewOfSection (NtCurrentProcess (), base);
set_errno (EINVAL); set_errno (EINVAL);
debug_printf ("MapView: address shift with MAP_FIXED given"); 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 int
fhandler_disk_file::munmap (HANDLE h, caddr_t addr, size_t len) fhandler_disk_file::munmap (HANDLE h, caddr_t addr, size_t len)
{ {
NtUnmapViewOfSection (GetCurrentProcess (), addr); NtUnmapViewOfSection (NtCurrentProcess (), addr);
NtClose (h); NtClose (h);
return 0; return 0;
} }
@ -1656,7 +1657,7 @@ fhandler_dev_mem::mmap (caddr_t *addr, size_t len, int prot,
__seterrno (); __seterrno ();
else else
{ {
NtUnmapViewOfSection (GetCurrentProcess (), base); NtUnmapViewOfSection (NtCurrentProcess (), base);
set_errno (EINVAL); set_errno (EINVAL);
debug_printf ("MapView: address shift with MAP_FIXED given"); 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) fhandler_dev_mem::munmap (HANDLE h, caddr_t addr, size_t len)
{ {
NTSTATUS ret; NTSTATUS ret;
if (!NT_SUCCESS (ret = NtUnmapViewOfSection (GetCurrentProcess (), addr))) if (!NT_SUCCESS (ret = NtUnmapViewOfSection (NtCurrentProcess (), addr)))
{ {
__seterrno_from_nt_status (ret); __seterrno_from_nt_status (ret);
return -1; return -1;

View File

@ -859,6 +859,10 @@ typedef enum _EVENT_INFORMATION_CLASS
/* Function declarations for ntdll.dll. These don't appear in any /* Function declarations for ntdll.dll. These don't appear in any
standard Win32 header. */ standard Win32 header. */
#define NtCurrentProcess() ((HANDLE) 0xffffffff)
#define NtCurrentThread() ((HANDLE) 0xfffffffe)
extern "C" extern "C"
{ {
NTSTATUS NTAPI NtAdjustPrivilegesToken (HANDLE, BOOLEAN, PTOKEN_PRIVILEGES, NTSTATUS NTAPI NtAdjustPrivilegesToken (HANDLE, BOOLEAN, PTOKEN_PRIVILEGES,

View File

@ -105,7 +105,7 @@ pinfo_init (char **envp, int envc)
myself->uid = ILLEGAL_UID; myself->uid = ILLEGAL_UID;
myself->gid = UNKNOWN_GID; myself->gid = UNKNOWN_GID;
environ_init (NULL, 0); /* call after myself has been set up */ 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); 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 /* FIXME: There is a potential race between an execed process and its
parent here. I hated to add a mutex just for that, though. */ parent here. I hated to add a mutex just for that, though. */
struct rusage r; struct rusage r;
fill_rusage (&r, hMainProc); fill_rusage (&r, GetCurrentProcess ());
add_rusage (&self->rusage_self, &r); add_rusage (&self->rusage_self, &r);
int exitcode = self->exitcode & 0xffff; int exitcode = self->exitcode & 0xffff;
if (!self->cygstarted) if (!self->cygstarted)
@ -920,8 +920,8 @@ _pinfo::dup_proc_pipe (HANDLE hProcess)
parent sees it. */ parent sees it. */
if (this != myself || is_toplevel_proc) if (this != myself || is_toplevel_proc)
flags |= DUPLICATE_CLOSE_SOURCE; flags |= DUPLICATE_CLOSE_SOURCE;
bool res = DuplicateHandle (hMainProc, wr_proc_pipe, hProcess, &wr_proc_pipe, bool res = DuplicateHandle (GetCurrentProcess (), wr_proc_pipe,
0, FALSE, flags); hProcess, &wr_proc_pipe, 0, FALSE, flags);
if (!res && WaitForSingleObject (hProcess, 0) != WAIT_OBJECT_0) if (!res && WaitForSingleObject (hProcess, 0) != WAIT_OBJECT_0)
{ {
wr_proc_pipe = orig_wr_proc_pipe; wr_proc_pipe = orig_wr_proc_pipe;

View File

@ -117,7 +117,7 @@ fhandler_pipe::open (int flags, mode_t mode)
goto out; goto out;
} }
inh = !(flags & O_NOINHERIT); 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)) 0, inh, DUPLICATE_SAME_ACCESS))
{ {
__seterrno (); __seterrno ();

View File

@ -94,7 +94,7 @@ getrusage (int intwho, struct rusage *rusage_in)
if (intwho == RUSAGE_SELF) if (intwho == RUSAGE_SELF)
{ {
memset (&r, 0, sizeof (r)); memset (&r, 0, sizeof (r));
fill_rusage (&r, hMainProc); fill_rusage (&r, GetCurrentProcess ());
*rusage_in = r; *rusage_in = r;
} }
else if (intwho == RUSAGE_CHILDREN) else if (intwho == RUSAGE_CHILDREN)

View File

@ -158,7 +158,7 @@ get_session_parent_dir ()
if (!dir) if (!dir)
{ {
PROCESS_SESSION_INFORMATION psi; PROCESS_SESSION_INFORMATION psi;
status = NtQueryInformationProcess (GetCurrentProcess (), status = NtQueryInformationProcess (NtCurrentProcess (),
ProcessSessionInformation, ProcessSessionInformation,
&psi, sizeof psi, NULL); &psi, sizeof psi, NULL);
if (!NT_SUCCESS (status) || psi.SessionId == 0) if (!NT_SUCCESS (status) || psi.SessionId == 0)

View File

@ -136,7 +136,7 @@ fixup_shms_after_fork ()
NTSTATUS status; NTSTATUS status;
vm_object_t ptr = sph_entry->ptr; vm_object_t ptr = sph_entry->ptr;
ULONG viewsize = sph_entry->parent->size; 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, &ptr, 0, sph_entry->parent->size, NULL,
&viewsize, ViewShare, 0, sph_entry->access); &viewsize, ViewShare, 0, sph_entry->access);
if (!NT_SUCCESS (status) || ptr != sph_entry->ptr) 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; vm_object_t ptr = NULL;
ULONG viewsize = ssh_entry->size; ULONG viewsize = ssh_entry->size;
ULONG access = (shmflg & SHM_RDONLY) ? PAGE_READONLY : PAGE_READWRITE; 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, ssh_entry->size, NULL, &viewsize, ViewShare,
MEM_TOP_DOWN, access); MEM_TOP_DOWN, access);
if (!NT_SUCCESS (status)) if (!NT_SUCCESS (status))

View File

@ -608,8 +608,8 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
goto out; goto out;
} }
VerifyHandle (hp); VerifyHandle (hp);
if (!DuplicateHandle (hp, dupsig, hMainProc, &sendsig, false, 0, if (!DuplicateHandle (hp, dupsig, GetCurrentProcess (), &sendsig, false,
DUPLICATE_SAME_ACCESS) || !sendsig) 0, DUPLICATE_SAME_ACCESS) || !sendsig)
{ {
__seterrno (); __seterrno ();
sigproc_printf ("DuplicateHandle failed, %E"); sigproc_printf ("DuplicateHandle failed, %E");
@ -631,7 +631,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
__seterrno (); __seterrno ();
goto out; goto out;
} }
if (!DuplicateHandle (hMainProc, tome, hp, &tome, false, 0, if (!DuplicateHandle (GetCurrentProcess (), tome, hp, &tome, false, 0,
DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)) DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
{ {
sigproc_printf ("DuplicateHandle for __SIGCOMMUNE failed, %E"); 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 /* Create an inheritable handle to pass to the child process. This will
allow the child to duplicate handles from the parent to itself. */ allow the child to duplicate handles from the parent to itself. */
parent = NULL; parent = NULL;
if (!DuplicateHandle (hMainProc, hMainProc, hMainProc, &parent, 0, TRUE, if (!DuplicateHandle (GetCurrentProcess (), GetCurrentProcess (),
GetCurrentProcess (), &parent, 0, TRUE,
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
system_printf ("couldn't create handle to myself for child, %E"); system_printf ("couldn't create handle to myself for child, %E");
} }

View File

@ -420,9 +420,9 @@ spawn_guts (const char *prog_arg, const char *const *argv,
moreinfo->argv = newargv; moreinfo->argv = newargv;
if (mode != _P_OVERLAY || if (mode != _P_OVERLAY ||
!DuplicateHandle (hMainProc, myself.shared_handle (), hMainProc, !DuplicateHandle (GetCurrentProcess (), myself.shared_handle (),
&moreinfo->myself_pinfo, 0, TRUE, GetCurrentProcess (), &moreinfo->myself_pinfo,
DUPLICATE_SAME_ACCESS)) 0, TRUE, DUPLICATE_SAME_ACCESS))
moreinfo->myself_pinfo = NULL; moreinfo->myself_pinfo = NULL;
else else
VerifyHandle (moreinfo->myself_pinfo); VerifyHandle (moreinfo->myself_pinfo);
@ -445,7 +445,7 @@ spawn_guts (const char *prog_arg, const char *const *argv,
si.cb = sizeof (si); si.cb = sizeof (si);
c_flags = GetPriorityClass (hMainProc); c_flags = GetPriorityClass (GetCurrentProcess ());
sigproc_printf ("priority class %d", c_flags); sigproc_printf ("priority class %d", c_flags);
c_flags |= CREATE_SEPARATE_WOW_VDM | CREATE_UNICODE_ENVIRONMENT; 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? */ generating its own pids again? */
if (cygheap->pid_handle) if (cygheap->pid_handle)
/* already done previously */; /* already done previously */;
else if (DuplicateHandle (hMainProc, hMainProc, hMainProc, else if (DuplicateHandle (GetCurrentProcess (), GetCurrentProcess (),
&cygheap->pid_handle, PROCESS_QUERY_INFORMATION, GetCurrentProcess (), &cygheap->pid_handle,
TRUE, 0)) PROCESS_QUERY_INFORMATION, TRUE, 0))
ProtectHandleINH (cygheap->pid_handle); ProtectHandleINH (cygheap->pid_handle);
else else
system_printf ("duplicate to pid_handle failed, %E"); 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 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. is not a brief period during which the pid is not available.
However, we should try to find another way to do this eventually. */ However, we should try to find another way to do this eventually. */
DuplicateHandle (hMainProc, child.shared_handle (), pi.hProcess, DuplicateHandle (GetCurrentProcess (), child.shared_handle (),
NULL, 0, 0, DUPLICATE_SAME_ACCESS); pi.hProcess, NULL, 0, 0, DUPLICATE_SAME_ACCESS);
child->start_time = time (NULL); /* Register child's starting time. */ child->start_time = time (NULL); /* Register child's starting time. */
child->nice = myself->nice; child->nice = myself->nice;
if (!child.remember (mode == _P_DETACH)) if (!child.remember (mode == _P_DETACH))

View File

@ -100,8 +100,9 @@ close_all_files (bool norelease)
debug_printf ("closing fd %d", i); debug_printf ("closing fd %d", i);
#endif #endif
if (i == 2) if (i == 2)
DuplicateHandle (GetCurrentProcess (), fh->get_output_handle (), GetCurrentProcess (), &h, 0, false, DuplicateHandle (GetCurrentProcess (), fh->get_output_handle (),
DUPLICATE_SAME_ACCESS); GetCurrentProcess (), &h,
0, false, DUPLICATE_SAME_ACCESS);
fh->close (); fh->close ();
if (!norelease) if (!norelease)
cygheap->fdtab.release (i); cygheap->fdtab.release (i);
@ -3131,7 +3132,7 @@ setpriority (int which, id_t who, int value)
who = myself->pid; who = myself->pid;
if ((pid_t) who == myself->pid) if ((pid_t) who == myself->pid)
{ {
if (!SetPriorityClass (hMainProc, prio)) if (!SetPriorityClass (GetCurrentProcess (), prio))
{ {
set_errno (EACCES); set_errno (EACCES);
return -1; return -1;

View File

@ -312,8 +312,9 @@ pthread::init_mainthread ()
set_tls_self_pointer (thread); set_tls_self_pointer (thread);
thread->thread_id = GetCurrentThreadId (); thread->thread_id = GetCurrentThreadId ();
if (!DuplicateHandle (hMainProc, GetCurrentThread (), hMainProc, if (!DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
&thread->win32_obj_id, 0, FALSE, DUPLICATE_SAME_ACCESS)) GetCurrentProcess (), &thread->win32_obj_id,
0, FALSE, DUPLICATE_SAME_ACCESS))
api_fatal ("failed to create mainthread handle"); api_fatal ("failed to create mainthread handle");
if (!thread->create_cancel_event ()) if (!thread->create_cancel_event ())
api_fatal ("couldn't create cancel event for main thread"); api_fatal ("couldn't create cancel event for main thread");

View File

@ -77,7 +77,7 @@ times (struct tms *buf)
overflow. */ overflow. */
clock_t tc = (clock_t) (ticks * CLOCKS_PER_SEC / 1000); 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); &kernel_time, &user_time);
syscall_printf ("ticks %d, CLOCKS_PER_SEC %d", ticks, CLOCKS_PER_SEC); syscall_printf ("ticks %d, CLOCKS_PER_SEC %d", ticks, CLOCKS_PER_SEC);

View File

@ -78,8 +78,8 @@ cygheap_user::init ()
if (!SetTokenInformation (hProcToken, TokenDefaultDacl, &dacl, if (!SetTokenInformation (hProcToken, TokenDefaultDacl, &dacl,
sizeof (dacl))) sizeof (dacl)))
system_printf ("SetTokenInformation (TokenDefaultDacl), %E"); system_printf ("SetTokenInformation (TokenDefaultDacl), %E");
if ((status = NtSetSecurityObject (hMainProc, DACL_SECURITY_INFORMATION, if ((status = NtSetSecurityObject (NtCurrentProcess (),
psd))) DACL_SECURITY_INFORMATION, psd)))
system_printf ("NtSetSecurityObject, %lx", status); system_printf ("NtSetSecurityObject, %lx", status);
} }
else else

View File

@ -544,7 +544,7 @@ wincapc::init ()
== VER_SUITE_TERMINAL) == VER_SUITE_TERMINAL)
((wincaps *)caps)->ts_has_dep_problem = true; ((wincaps *)caps)->ts_has_dep_problem = true;
} }
if (NT_SUCCESS (NtQueryInformationProcess (GetCurrentProcess (), if (NT_SUCCESS (NtQueryInformationProcess (NtCurrentProcess (),
ProcessWow64Information, ProcessWow64Information,
&wow64, sizeof wow64, NULL)) &wow64, sizeof wow64, NULL))
&& !wow64) && !wow64)