* dcrt0.cc (child_info_fork::handle_fork): Set uid/gid in myself so that it can
be used by subsequent startup functions.
(dll_crt0_0): Issue a warning if DuplicateTokenEx fails and DEBUGGING.
(dll_crt0_1): Move user_data->{resourcelocks,threadinterface} initialization
here from dll_crt0_0.
* fork.cc (frok::child): Tell wait_for_sigthread that this is fork.
(frok::parent): Only initialize start_time once.  Tighten time when we're
"deimpersonated".
* sigproc.cc (signal_fixup_after_exec): Rework (futiley) sa_buf stuff.  Add
debugging output.
(wait_for_sigthread): Accept an argument which illustrates whether we are
forked or not.
(wait_sig): Avoid using myself pointer.
* winsup.h ((wait_for_sigthread): Reflect change to argument.
			
			
This commit is contained in:
		
							parent
							
								
									cdc2256b76
								
							
						
					
					
						commit
						12b3371289
					
				| 
						 | 
					@ -1,3 +1,20 @@
 | 
				
			||||||
 | 
					2006-03-29  Christopher Faylor  <cgf@timesys.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						* dcrt0.cc (child_info_fork::handle_fork): Set uid/gid in myself so
 | 
				
			||||||
 | 
						that it can be used by subsequent startup functions.
 | 
				
			||||||
 | 
						(dll_crt0_0): Issue a warning if DuplicateTokenEx fails and DEBUGGING.
 | 
				
			||||||
 | 
						(dll_crt0_1): Move user_data->{resourcelocks,threadinterface}
 | 
				
			||||||
 | 
						initialization here from dll_crt0_0.
 | 
				
			||||||
 | 
						* fork.cc (frok::child): Tell wait_for_sigthread that this is fork.
 | 
				
			||||||
 | 
						(frok::parent): Only initialize start_time once.  Tighten time when
 | 
				
			||||||
 | 
						we're "deimpersonated".
 | 
				
			||||||
 | 
						* sigproc.cc (signal_fixup_after_exec): Rework (futiley) sa_buf stuff.
 | 
				
			||||||
 | 
						Add debugging output.
 | 
				
			||||||
 | 
						(wait_for_sigthread): Accept an argument which illustrates whether we
 | 
				
			||||||
 | 
						are forked or not.
 | 
				
			||||||
 | 
						(wait_sig): Avoid using myself pointer.
 | 
				
			||||||
 | 
						* winsup.h ((wait_for_sigthread): Reflect change to argument.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
2006-03-26  Christopher Faylor  <cgf@timesys.com>
 | 
					2006-03-26  Christopher Faylor  <cgf@timesys.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	* spawn.cc (spawn_guts): Close handles if we know that we will not be
 | 
						* spawn.cc (spawn_guts): Close handles if we know that we will not be
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -653,6 +653,9 @@ child_info_fork::handle_fork ()
 | 
				
			||||||
  cygheap_fixup_in_child (false);
 | 
					  cygheap_fixup_in_child (false);
 | 
				
			||||||
  memory_init ();
 | 
					  memory_init ();
 | 
				
			||||||
  set_myself (NULL);
 | 
					  set_myself (NULL);
 | 
				
			||||||
 | 
					  myself->uid = cygheap->user.real_uid;
 | 
				
			||||||
 | 
					  myself->gid = cygheap->user.real_gid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  child_copy (parent, false,
 | 
					  child_copy (parent, false,
 | 
				
			||||||
	      "dll data", dll_data_start, dll_data_end,
 | 
						      "dll data", dll_data_start, dll_data_end,
 | 
				
			||||||
	      "dll bss", dll_bss_start, dll_bss_end,
 | 
						      "dll bss", dll_bss_start, dll_bss_end,
 | 
				
			||||||
| 
						 | 
					@ -750,9 +753,6 @@ dll_crt0_0 ()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  user_data->resourcelocks->Init ();
 | 
					 | 
				
			||||||
  user_data->threadinterface->Init ();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  _cygtls::init ();
 | 
					  _cygtls::init ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Initialize events */
 | 
					  /* Initialize events */
 | 
				
			||||||
| 
						 | 
					@ -761,10 +761,16 @@ dll_crt0_0 ()
 | 
				
			||||||
  cygheap->cwd.init ();
 | 
					  cygheap->cwd.init ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Late duplicate simplifies tweaking the process token in uinfo.cc. */
 | 
					  /* Late duplicate simplifies tweaking the process token in uinfo.cc. */
 | 
				
			||||||
  if (wincap.has_security ())
 | 
					  if (wincap.has_security ()
 | 
				
			||||||
    DuplicateTokenEx (hProcToken, MAXIMUM_ALLOWED, NULL,
 | 
					      && !DuplicateTokenEx (hProcToken, MAXIMUM_ALLOWED, NULL,
 | 
				
			||||||
		      SecurityImpersonation, TokenImpersonation,
 | 
								    SecurityImpersonation, TokenImpersonation,
 | 
				
			||||||
		      &hProcImpToken);
 | 
								    &hProcImpToken))
 | 
				
			||||||
 | 
					#ifdef DEBUGGING
 | 
				
			||||||
 | 
					    system_printf ("DuplicateTokenEx failed, %E");
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					    ;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  debug_printf ("finished dll_crt0_0 initialization");
 | 
					  debug_printf ("finished dll_crt0_0 initialization");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -784,6 +790,8 @@ dll_crt0_1 (char *)
 | 
				
			||||||
    small_printf ("cmalloc returns %p\n", cmalloc (HEAP_STR, n));
 | 
					    small_printf ("cmalloc returns %p\n", cmalloc (HEAP_STR, n));
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  user_data->resourcelocks->Init ();
 | 
				
			||||||
 | 
					  user_data->threadinterface->Init ();
 | 
				
			||||||
  ProtectHandle (hMainProc);
 | 
					  ProtectHandle (hMainProc);
 | 
				
			||||||
  ProtectHandle (hMainThread);
 | 
					  ProtectHandle (hMainThread);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -796,7 +804,7 @@ dll_crt0_1 (char *)
 | 
				
			||||||
  strace.microseconds ();
 | 
					  strace.microseconds ();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  create_signal_arrived ();
 | 
					  create_signal_arrived (); /* FIXME: move into wait_sig? */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Initialize debug muto, if DLL is built with --enable-debugging.
 | 
					  /* Initialize debug muto, if DLL is built with --enable-debugging.
 | 
				
			||||||
     Need to do this before any helper threads start. */
 | 
					     Need to do this before any helper threads start. */
 | 
				
			||||||
| 
						 | 
					@ -838,7 +846,7 @@ dll_crt0_1 (char *)
 | 
				
			||||||
    set_cygwin_privileges (hProcImpToken);
 | 
					    set_cygwin_privileges (hProcImpToken);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!old_title && GetConsoleTitle (title_buf, TITLESIZE))
 | 
					  if (!old_title && GetConsoleTitle (title_buf, TITLESIZE))
 | 
				
			||||||
      old_title = title_buf;
 | 
					    old_title = title_buf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Allocate cygheap->fdtab */
 | 
					  /* Allocate cygheap->fdtab */
 | 
				
			||||||
  dtable_init ();
 | 
					  dtable_init ();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -178,7 +178,7 @@ frok::child (void *)
 | 
				
			||||||
  ld_preload ();
 | 
					  ld_preload ();
 | 
				
			||||||
  fixup_hooks_after_fork ();
 | 
					  fixup_hooks_after_fork ();
 | 
				
			||||||
  _my_tls.fixup_after_fork ();
 | 
					  _my_tls.fixup_after_fork ();
 | 
				
			||||||
  wait_for_sigthread ();
 | 
					  wait_for_sigthread (true);
 | 
				
			||||||
  cygwin_finished_initializing = true;
 | 
					  cygwin_finished_initializing = true;
 | 
				
			||||||
  return 0;
 | 
					  return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -283,17 +283,17 @@ frok::parent (void *stack_here)
 | 
				
			||||||
  si.lpReserved2 = (LPBYTE) &ch;
 | 
					  si.lpReserved2 = (LPBYTE) &ch;
 | 
				
			||||||
  si.cbReserved2 = sizeof (ch);
 | 
					  si.cbReserved2 = sizeof (ch);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  syscall_printf ("CreateProcess (%s, %s, 0, 0, 1, %p, 0, 0, %p, %p)",
 | 
				
			||||||
 | 
							  myself->progname, myself->progname, c_flags, &si, &pi);
 | 
				
			||||||
 | 
					  bool locked = __malloc_lock ();
 | 
				
			||||||
 | 
					  time_t start_time = time (NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Remove impersonation */
 | 
					  /* Remove impersonation */
 | 
				
			||||||
  cygheap->user.deimpersonate ();
 | 
					  cygheap->user.deimpersonate ();
 | 
				
			||||||
  fix_impersonation = true;
 | 
					  fix_impersonation = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  syscall_printf ("CreateProcess (%s, %s, 0, 0, 1, %p, 0, 0, %p, %p)",
 | 
					 | 
				
			||||||
		  myself->progname, myself->progname, c_flags, &si, &pi);
 | 
					 | 
				
			||||||
  bool locked = __malloc_lock ();
 | 
					 | 
				
			||||||
  time_t start_time;
 | 
					 | 
				
			||||||
  while (1)
 | 
					  while (1)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      start_time = time (NULL);
 | 
					 | 
				
			||||||
      rc = CreateProcess (myself->progname, /* image to run */
 | 
					      rc = CreateProcess (myself->progname, /* image to run */
 | 
				
			||||||
			  myself->progname, /* what we send in arg0 */
 | 
								  myself->progname, /* what we send in arg0 */
 | 
				
			||||||
			  &sec_none_nih,
 | 
								  &sec_none_nih,
 | 
				
			||||||
| 
						 | 
					@ -345,6 +345,10 @@ frok::parent (void *stack_here)
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Restore impersonation */
 | 
				
			||||||
 | 
					  cygheap->user.reimpersonate ();
 | 
				
			||||||
 | 
					  fix_impersonation = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  child_pid = cygwin_pid (pi.dwProcessId);
 | 
					  child_pid = cygwin_pid (pi.dwProcessId);
 | 
				
			||||||
  child.init (child_pid, 1, NULL);
 | 
					  child.init (child_pid, 1, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -366,10 +370,6 @@ frok::parent (void *stack_here)
 | 
				
			||||||
     for the forkee.  */
 | 
					     for the forkee.  */
 | 
				
			||||||
  strcpy (child->progname, myself->progname);
 | 
					  strcpy (child->progname, myself->progname);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Restore impersonation */
 | 
					 | 
				
			||||||
  cygheap->user.reimpersonate ();
 | 
					 | 
				
			||||||
  fix_impersonation = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* Fill in fields in the child's process table entry.  */
 | 
					  /* Fill in fields in the child's process table entry.  */
 | 
				
			||||||
  child->dwProcessId = pi.dwProcessId;
 | 
					  child->dwProcessId = pi.dwProcessId;
 | 
				
			||||||
  child.hProcess = pi.hProcess;
 | 
					  child.hProcess = pi.hProcess;
 | 
				
			||||||
| 
						 | 
					@ -396,10 +396,10 @@ frok::parent (void *stack_here)
 | 
				
			||||||
  /* CHILD IS STOPPED */
 | 
					  /* CHILD IS STOPPED */
 | 
				
			||||||
  debug_printf ("child is alive (but stopped)");
 | 
					  debug_printf ("child is alive (but stopped)");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Initialize, in order: data, bss, heap, stack, dll data, dll bss
 | 
					  /* Initialize, in order: stack, dll data, dll bss.
 | 
				
			||||||
     Note: variables marked as NO_COPY will not be copied
 | 
					     data, bss, heap were done earlier (in dcrt0.cc)
 | 
				
			||||||
     since they are placed in a protected segment. */
 | 
					     Note: variables marked as NO_COPY will not be copied since they are
 | 
				
			||||||
 | 
					     placed in a protected segment.  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  MALLOC_CHECK;
 | 
					  MALLOC_CHECK;
 | 
				
			||||||
  const void *impure_beg;
 | 
					  const void *impure_beg;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -134,11 +134,12 @@ signal_fixup_after_exec ()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void __stdcall
 | 
					void __stdcall
 | 
				
			||||||
wait_for_sigthread ()
 | 
					wait_for_sigthread (bool forked)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PSECURITY_ATTRIBUTES sa_buf = (PSECURITY_ATTRIBUTES) alloca (1024);
 | 
					  char char_sa_buf[1024];
 | 
				
			||||||
  if (!CreatePipe (&my_readsig, &my_sendsig, sec_user_nih (sa_buf), 0))
 | 
					  PSECURITY_ATTRIBUTES sa_buf = sec_user_nih ((PSECURITY_ATTRIBUTES) char_sa_buf);
 | 
				
			||||||
    api_fatal ("couldn't create signal pipe, %E");
 | 
					  if (!CreatePipe (&my_readsig, &my_sendsig, sa_buf, 0))
 | 
				
			||||||
 | 
					    api_fatal ("couldn't create signal pipe%s, %E", forked ? " for forked process" : "");
 | 
				
			||||||
  ProtectHandle (my_readsig);
 | 
					  ProtectHandle (my_readsig);
 | 
				
			||||||
  myself->sendsig = my_sendsig;
 | 
					  myself->sendsig = my_sendsig;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -151,6 +152,7 @@ wait_for_sigthread ()
 | 
				
			||||||
  wait_sig_inited = NULL;
 | 
					  wait_sig_inited = NULL;
 | 
				
			||||||
  ForceCloseHandle1 (hsig_inited, wait_sig_inited);
 | 
					  ForceCloseHandle1 (hsig_inited, wait_sig_inited);
 | 
				
			||||||
  SetEvent (sigCONT);
 | 
					  SetEvent (sigCONT);
 | 
				
			||||||
 | 
					  sigproc_printf ("process/signal handling enabled, state %p", myself->process_state);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Get the sync_proc_subproc muto to control access to
 | 
					/* Get the sync_proc_subproc muto to control access to
 | 
				
			||||||
| 
						 | 
					@ -497,8 +499,6 @@ sigproc_init ()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  hwait_sig = new cygthread (wait_sig, 0, cygself, "sig");
 | 
					  hwait_sig = new cygthread (wait_sig, 0, cygself, "sig");
 | 
				
			||||||
  hwait_sig->zap_h ();
 | 
					  hwait_sig->zap_h ();
 | 
				
			||||||
 | 
					 | 
				
			||||||
  sigproc_printf ("process/signal handling enabled, state %p", myself->process_state);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Called on process termination to terminate signal and process threads.
 | 
					/* Called on process termination to terminate signal and process threads.
 | 
				
			||||||
| 
						 | 
					@ -1134,13 +1134,12 @@ wait_sig (VOID *)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  sigCONT = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL);
 | 
					  sigCONT = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  sigproc_printf ("myself->dwProcessId %u", myself->dwProcessId);
 | 
					 | 
				
			||||||
  SetEvent (wait_sig_inited);
 | 
					  SetEvent (wait_sig_inited);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  _sig_tls = &_my_tls;
 | 
					  _sig_tls = &_my_tls;
 | 
				
			||||||
  _sig_tls->init_threadlist_exceptions ();
 | 
					  _sig_tls->init_threadlist_exceptions ();
 | 
				
			||||||
  debug_printf ("entering ReadFile loop, my_readsig %p, myself->sendsig %p",
 | 
					  sigproc_printf ("entering ReadFile loop, my_readsig %p, my_sendsig %p",
 | 
				
			||||||
		my_readsig, myself->sendsig);
 | 
							  my_readsig, my_sendsig);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  sigpacket pack;
 | 
					  sigpacket pack;
 | 
				
			||||||
  pack.si.si_signo = __SIGHOLD;
 | 
					  pack.si.si_signo = __SIGHOLD;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -81,7 +81,7 @@ bool __stdcall pid_exists (pid_t) __attribute__ ((regparm(1)));
 | 
				
			||||||
int __stdcall sig_send (_pinfo *, siginfo_t&, class _cygtls *tls = NULL) __attribute__ ((regparm (3)));
 | 
					int __stdcall sig_send (_pinfo *, siginfo_t&, class _cygtls *tls = NULL) __attribute__ ((regparm (3)));
 | 
				
			||||||
int __stdcall sig_send (_pinfo *, int) __attribute__ ((regparm (2)));
 | 
					int __stdcall sig_send (_pinfo *, int) __attribute__ ((regparm (2)));
 | 
				
			||||||
void __stdcall signal_fixup_after_exec ();
 | 
					void __stdcall signal_fixup_after_exec ();
 | 
				
			||||||
void __stdcall wait_for_sigthread ();
 | 
					void __stdcall wait_for_sigthread (bool = false);
 | 
				
			||||||
void __stdcall sigalloc ();
 | 
					void __stdcall sigalloc ();
 | 
				
			||||||
void __stdcall create_signal_arrived ();
 | 
					void __stdcall create_signal_arrived ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue