Commit Graph

195 Commits

Author SHA1 Message Date
Corinna Vinschen 3bb346d593 Cygwin: fix formatting: collapse whitespace-only lines
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-03-11 13:45:58 +01:00
Michael Haubenwallner ece7282f32 forkables: On fork failure, retry with hardlinks.
To support in-cygwin package managers, the fork() implementation must
not rely on .exe and .dll files to stay in their original location, as
the package manager's job is to replace these files.  Instead, when the
first fork try fails, and we have NTFS, we use hardlinks to the original
binaries in /var/run/cygfork/ to create the child process during the
second fork try, along the main.exe.local file to enable the "DotLocal
Dll Redirection" feature for the dlls.

The (probably few) users that need an update-safe fork manually have to
create the /var/run/cygfork/ directory for now, using:
mkdir --mode=a=rwxt /var/run/cygfork

	* child_info.h: Bump CURR_CHILD_INFO_MAGIC.
	(enum child_status): Add _CI_SILENTFAIL flag.
	(struct child_info): Add silentfail setter and getter.
	* winsup.h (child_copy): Add bool silentfail parameter.
	* cygheap.cc: Pass silentfail parameter to child_copy.
	* dcrt0.cc: Ditto.
	* dll_init.h (struct dll): Define public inline method forkedntname.
	(struct dll_list): Declare private method find_by_forkedntname.
	* dll_init.cc (struct dll_list): Implement find_by_forkedntname.
	(dll_list::alloc): Use find_by_forkedntname when in load after fork.
	(dll_list::load_after_fork_impl): Load dlls using dll::forkedntname.
	* fork.cc (frok::parent): Set silentfail child info flag.  Pass
	silentfail parameter to child_copy.  Use forkedntname of
	dlls.main_executable.
	(fork): When first dofork run failed and did not use forkables,
	run dofork again with_forkables set to true.
	(child_copy): Use debug_printf if silentfail is true,
	system_printf otherwise.
2019-02-07 15:58:02 +01:00
Corinna Vinschen 866901441b Cygwin: cygheap: convert installation paths to UNICODE_STRINGS
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-25 01:06:34 +01:00
Corinna Vinschen d16a56306d Consolidate wctomb/mbtowc calls for POSIX-1.2008
- Remove charset parameter from low level __foo_wctomb/__foo_mbtowc calls.
- Instead, create array of function for ISO and Windows codepages to point
  to function which does not require to evaluate the charset string on
  each call.  Create matching helper functions.  I.e., __iso_wctomb,
  __iso_mbtowc, __cp_wctomb and __cp_mbtowc are functions returning the
  right function pointer now.
- Create __WCTOMB/__MBTOWC macros utilizing per-reent locale and replace
  calls to __wctomb/__mbtowc with calls to __WCTOMB/__MBTOWC.
- Drop global __wctomb/__mbtowc vars.
- Utilize aforementioned changes in Cygwin to get rid of charset in other,
  calling functions and simplify the code.
- In Cygwin restrict global cygheap locale info to the job performed
  by internal_setlocale.  Use UTF-8 instead of ASCII on the fly in
  internal conversion functions.
- In Cygwin dll_entry, make sure to initialize a TLS area with a NULL
  _REENT->_locale pointer.  Add comment to explain why.

Signed-off by: Corinna Vinschen <corinna@vinschen.de>
2016-08-15 10:56:57 +02:00
Corinna Vinschen 6e623e9320 Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option
Bump GPLv2+ to GPLv3+ for some files, clarify BSD 2-clause.

Everything else stays under GPLv3+.

New Linking Exception exempts resulting executables from LGPLv3 section 4.

Add CONTRIBUTORS file to keep track of licensing.

Remove 'Copyright Red Hat Inc' comments.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-06-23 10:09:17 +02:00
Corinna Vinschen 8e732f7f7f Remove MALLOC_CHECK and calls to it entirely
MALLOC_CHECK got useless with commit b259af5.  Remove it throughout.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-04-01 14:04:09 +02:00
Corinna Vinschen e42f66d00f Remove ill-advised cygwin_props
Cygwin_props have been invented to allow switching off the unique
installation keys in the first place, supposedly for debugging.
This never really was a good idea, after all we *want* the installations
to be independent and there's no good reason to break that, not even
for debugging purposes.

Other than that, cygwin_props were meant to be used for some other global
settings which never took place.  There's just no good reason to tweak
the DLL binary invisibly where a setting could be done in a file or the
environment.

This patch removes the cygwin_props entirely, including the related
settings in cygcheck.

cygwin:
	* cygprops.h: Remove file.
	* globals.cc (cygwin_props): Remove.
	* cygheap.cc (init_cygheap::init_installation_root): Drop removing
	installation key.

utils:
	* cygcheck.cc: Drop including cygprops.h.  Remove now unused option
	values.
	(unique_object_name_opt): Remove.
	(handle_unique_object_name): Remove function.
	(usage): Remove text for unique-object-names options.
	(longopts): Remove unique-object-names options.
	(main): Drop handling unique-object-names options.

doc:
	* utils.xml (cygcheck): Remove text for unique-object-names options.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-03-19 13:21:18 +01:00
Mark Geisert 5807ba83e4 Support profiling of multi-threaded apps.
This patch set modifies Cygwin's profiling support to sample PC values
of all an app's threads, not just the main thread. There is no change
to how profiling is requested: just compile and link the app with "-pg"
as usual. The profiling info is dumped into file gmon.out as always.

A new facility enabled via the environment variable GMON_OUT_PREFIX.
This facility is intended to match an undocumented Linux glibc feature.
Exporting the variable with a non-empty value such as "foo" causes the
profiling info to go to a file named foo.$pid instead of the default.
With that, both resulting processes of a fork() can have their profiling
data captured in separate files. gprof already knows how to accumulate
data from multiple files if they all pertain to the same app.

There is no change to the normal Cygwin execution paths if profiling is
not enabled. And when it is enabled, only the one profiling thread per
profiled app is doing more work than it used to.

	* include/sys/cygwin.h: Add CW_CYGHEAP_PROFTHR_ALL.
	* cygheap.cc (cygheap_profthr_all): New C-callable function that
	runs cygheap's threadlist handing each pthread's thread handle in
	turn to profthr_byhandle().
	* external.cc (cygwin_internal): Add case CW_CYGHEAP_PROFTHR_ALL.
	* gmon.c (_mcleanup): Add support for multiple simultaneous
	gmon.out* files named via environment variable GMON_OUT_PREFIX.
	* gmon.h (struct gmonparam): Make state decl volatile.
	* mcount.c (_MCOUNT_DECL): Change stores into gmonparam.state to use
	Interlocked operations. Add #include "winsup.h", update commentary.
	* profil.c (profthr_byhandle): New function abstracting out the
	updating of profile counters based on a thread handle.
	(profthr_func): Update to call profthr_byhandle() to sample the main
	thread then call cygheap_profthr_all() indirectly through
	cygwin_internal(CW_CYGHEAP_PROFTHR_ALL) to sample all other threads.
	(profile_off): Zero targthr to indicate profiling was turned off.
	(profile_on): Fix handle leak on failure path.
	(profile_child): New callback func to restart profiling in child
	process after a fork if the parent was being profiled.
	(profile_ctl): Call pthread_atfork() to set profile_child callback.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-03-10 20:39:46 +01:00
Corinna Vinschen f5dc13757f * cygheap.cc (init_cygheap::init_installation_root): Fix typo in
comment.
2014-12-02 09:59:53 +00:00
Corinna Vinschen 26158dc3e9 * cygheap.cc (init_cygheap::init_tls_list): Accommodate threadlist
having a new type threadlist_t *.  Convert commented out code into an
	#if 0.  Create thread mutex.  Explain why.
	(init_cygheap::remove_tls): Drop timeout value.  Always wait infinitely
	for tls_sentry.  Return mutex HANDLE of just deleted threadlist entry.
	(init_cygheap::find_tls): New implementation taking tls pointer as
	search parameter.  Return threadlist_t *.
	(init_cygheap::find_tls): Return threadlist_t *.  Define ix as auto
	variable.  Drop exception handling since crash must be made impossible
	due to correct synchronization.  Return with locked mutex.
	* cygheap.h (struct threadlist_t): Define.
	(struct init_cygheap): Convert threadlist to threadlist_t type.
	(init_cygheap::remove_tls): Align declaration to above change.
	(init_cygheap::find_tls): Ditto.
	(init_cygheap::unlock_tls): Define.
	* cygtls.cc (_cygtls::remove): Unlock and close mutex when finishing.
	* exceptions.cc (sigpacket::process): Lock _cygtls area of thread before
	accessing it.
	* fhandler_termios.cc (fhandler_termios::bg_check): Ditto.
	* sigproc.cc (sig_send): Ditto.
	* thread.cc (pthread::exit): Ditto.  Add comment.
	(pthread::cancel): Ditto.
2014-11-28 20:46:13 +00:00
Corinna Vinschen 9d2eff6684 * cygheap.cc (init_cygheap::find_tls): Add comment.
* cygtls.cc (well_known_dlls): Rephrase comment.
	(bloda_detect): New function.
	(_cygtls::call2): Call init_thread and bloda_detect for non-pthread
	threads only.
	(_cygtls::remove): Move remove_tls and remove_wq calls up to run first.
	* miscfuncs.cc (struct pthread_wrapper_arg): Rename from struct
	thread_wrapper_arg.
	(pthread_wrapper): Rename from thread_wrapper and drop "static".  Fix
	comment.  Drop call to _cygtls::remove.  Call api_fatal rather than
	ExitThread.  Explain why.
	* miscfuncs.h (pthread_wrapper): Declare pthread_wrapper.
	* thread.cc (pthread::exit): Add a FIXME comment.  Call _cygtls::remove
	before calling ExitThread.
2014-11-28 12:10:12 +00:00
Corinna Vinschen db880b5642 * cygheap.cc (init_cygheap::find_tls): Allow to keep loop going after
access to threadlist[ix] faulted.  In case of an exception, remove
	threadlist[ix] from threadlist only.  Add comment.
2014-11-27 16:20:14 +00:00
Corinna Vinschen c5d751a658 * cygheap.cc: Fix formatting. 2014-11-03 15:30:59 +00:00
Corinna Vinschen 5da7a22be0 * cygheap.cc (init_cygheap::init_installation_root): Create content of
installation_dir as non-prefixed path, if possible.
2014-10-29 10:40:47 +00:00
Corinna Vinschen f7cb52eec7 * cygheap.cc (cygheap_fixup_in_child): Drop call to set_dll_dir.
(init_cygheap::init_installation_root): Set installation_dir_len.
	(setup_cygheap): Drop call to set_dll_dir.
	* cygheap.h (struct init_cygheap): Add installation_dir_len member.
	(init_cygheap::set_dll_dir): Remove.
	* environ.cc (win_env::add_cache): Use stpcpy for speed.
	(posify_maybe): Use tmp_pathbuf buffer instead of stack.
	(raise_envblock): New function to resize Windows environment block.
	(build_env): Fix indentation.  Call raise_envblock function.  Check if
	$PATH exists and is non-empty.  If not, add PATH variable with Cygwin
	installation directory as content to Windows environment.  Explain why.

	* uinfo.cc (cygheap_pwdgrp::_nss_init): Fill UNICODE_STRING members
	on the fly.  Drop call to RtlInitUnicodeString.
	(pwdgrp::check_file): Ditto.
2014-10-27 11:33:53 +00:00
Corinna Vinschen cc5a7d7519 * cygheap.cc (cygheap_fixup_in_child): Call set_dll_dir.
(init_cygheap::init_installation_root): Just memmove contents of
	installation_root instead of calling GetModuleFileNameW again.
	Copy installation_root to installation_dir before stripping of
	"bin" dir.  Don't call SetDllDirectory here.  Explain what we do.
	(setup_cygheap): New function taking over initial cygheap setup
	from memory_init.  Additionally call set_dll_dir.
	* cygheap.h (struct init_cygheap): Add installation_dir member.
	(init_cygheap::set_dll_dir): Define.
	(setup_cygheap): Declare.
	* dcrt0.cc: Throughout drop parameter from memory_init call.
	(dll_crt0_0): Call setup_cygheap prior to memory_init.
	* dlfcn.cc (dlopen): Change comment to point to the right function.
	* shared.cc (memory_init): Drop parameter.  Drop cygheap setup.
	* shared_info.h (memory_init): Change declaration accordingly.
2014-10-17 14:36:59 +00:00
Corinna Vinschen 1dd75c50d5 * cygheap.cc (init_cygheap::init_installation_root): Install Cygwin's
installation dir as DLL search path, instead of ".".
	* cygheap.h (class cwdstuff): Add parameter names in function
	declarations for readability.
	(cwdstuff::get): Ad inline implementation fetching the CWD as wide char
	string.
	* dlfcn.cc (dlopen): Add searching for dependent DLLs in DLL
	installation dir or CWD, if all else failed.
	Add comment to explain scenarios this is accommodating.
2014-10-14 19:14:33 +00:00
Corinna Vinschen 3f3bd10104 * Throughout, use __try/__except/__endtry blocks, rather than myfault
handler.
	* cygtls.cc (_cygtls::remove): Accommodate the fact that pathbufs
	has been moved from _local_storage to _cygtls.
	* cygtls.h (class tls_pathbuf): Add comment to hint to gendef usage
	of counters.  Change type of counters to uint32_t for clarity.
	Remove _cygtls as friend class.
	(struct _local_storage): Move pathbufs from here...
	(struct _cygtls): ...to here, allowing to access it from _sigbe.
	(class san): Only define on 32 bit.  Remove errno, _c_cnt and _w_cnt
	members.
	(san::setup): Drop parameter.  Don't initialize removed members.
	(san::leave): Don't set removed members.
	(class myfault): Only define on 32 bit.
	(myfault::faulted): Only keep implementation not taking any parameter.
	Drop argument in call to sebastian.setup.
	(__try/__leave/__except/__endtry): Implement to support real SEH.  For
	now stick to SJLJ on 32 bit.
	* dcrt0.cc (dll_crt0_0): Drop 64 bit call to
	exception::install_myfault_handler.
	* exception.h (exception_handler): Define with EXCEPTION_DISPOSITION
	as return type.
	(PDISPATCHER_CONTEXT): Define as void * on 32 bit.  Define as pointer
	to _DISPATCHER_CONTEXT on 64 bit.
	(class exception): Define separately for 32 and 64 bit.
	(exception::myfault): Add handler for myfault SEH handling on 64 bit.
	(exception::exception): Fix mangled method name to account for change
	in type of last parameter.
	(exception::install_myfault_handler): Remove.
	* exceptions.cc (exception::myfault_handle): Remove.
	(exception::myfault): New SEH handler for 64 bit.
	* gendef (_sigbe): Set tls_pathbuf counters to 0 explicitely when
	returning to the caller.
	* ntdll.h: Move a comment to a better place.
	(struct _SCOPE_TABLE): Define on 64 bit.
	* thread.cc (verifyable_object_isvalid): Remove gcc 4.7 workaround.
	* tls_pbuf.cc (tls_pbuf): Fix to accommodate new place of pathbufs.
	(tls_pathbuf::destroy): Change type of loop variables to uint32_t.
	* tls_pbuf.h (class tmp_pathbuf): Change type of buffer counters to
	uint32_t.  Accommodate new place of pathbufs.
	* tlsoffsets.h: Regenerate.
	* tlsoffsets64.h: Regenerate.
2014-08-22 09:21:33 +00:00
Corinna Vinschen ebb09f85e1 * cygheap.cc (cwcsdup): Change parameter to correct PWCSTR.
(cwcsdup1): Ditto.
	* cygheap_malloc.h: Change declarations accordingly.
2014-02-10 20:15:58 +00:00
Christopher Faylor 24557e9caa * cygheap.cc (cmalloc): Use size_t for size field.
(cmalloc_abort): Ditto.
(crealloc): Ditto.
(crealloc_abort): Ditto.
(ccalloc): Ditto.
(ccalloc_abort): Ditto.
* cygheap_malloc.h (HEAP_USER): Add.
(cmalloc): Use size_t for size field in declaration.
(cmalloc_abort): Ditto.
(crealloc): Ditto.
(crealloc_abort): Ditto.
(ccalloc): Ditto.
(ccalloc_abort): Ditto.
* path.cc (normalize_posix_path): Don't check existence of / or // dir in
parent dir check.
2013-07-31 14:43:05 +00:00
Corinna Vinschen 61522196c7 * Merge in cygwin-64bit-branch. 2013-04-23 09:44:36 +00:00
Christopher Faylor f653639a22 * cygheap.cc (init_cygheap::find_tls): Add a comment.
* dcrt0.cc (parent_sigmask): Delete.
(dll_crt0_1): Use spawn_info->moreinfo->sigmask rather than saved parent signal
mask.
* thread.cc (pthread::thread_init_wrapper): Add comment stressing the
importance of maintaining ordering of statements.
2013-04-07 23:53:00 +00:00
Christopher Faylor 8f8eeb70ba * child_info.h (cygheap_exec_info::sigmask): Declare new field.
* cygheap.cc (init_cygheap::find_tls): Rename threadlist_ix -> ix.  Only take
one pass through thread list, looking for eligible threads to signal.  Set a
new param indicating that function has found a sigwait* mask.
* cygheap.h (init_cygheap::find_tls): Reflect new parameter.
* dcrt0.cc (parent_sigmask): New variable.
(child_info_spawn::handle_spawn): Save parent's signal mask here.
(dll_crt0_1): Restore parent's signal mask to tls sigmask as appropriate.  Call
sig_dispatch_pending to flush signal queue when we can finally do something
with signals.
* exceptions.cc (sigpacket::process): Avoid attempting to handle signals if we
haven't finished initializing.  Rely on the fact that find_tls will do mask
checking and don't do it again.  Delete ill-named 'dummy' variable.
* sigproc.cc (cygheap_exec_info::alloc): Save calling thread's signal mask in
new sigmask field.
(wait_sig): Try to debug when WFSO fails and DEBUGGING is defined.
* thread.cc (pthread::set_tls_self_pointer): Make this a true automatic method
rather than inexplicably relying on a thread parameter.
(pthread::thread_init_wrapper): Accommodate set_tls_self_pointer change to
non-static.  Initialize sigmask before setting tid or suffer signal races.
* ehread.h (pthread::set_tls_self_pointer): Make non-static, delete parameter.
2013-03-31 12:35:44 +00:00
Christopher Faylor 6e75c72b89 Throughout, change __attribute__ ((regparm (N))) to just __regN. Throughout,
(mainly in fhandler*) start fixing gcc 4.7.2 mismatch between regparm
definitions and declarations.
* gendef: Define some functions to take @ declaration to accommodate _regN
defines which use __stdcall.
* gentls_offsets: Define __regN macros as empty.
* autoload.cc (wsock_init): Remove unneeded regparm attribute.
* winsup.h (__reg1): Define.
(__reg2): Define.
(__reg3): Define.
* advapi32.cc (DuplicateTokenEx): Coerce some initializers to avoid warnings
from gcc 4.7.2.
* exceptions.cc (status_info): Declare struct to use NTSTATUS.
(cygwin_exception::dump_exception): Coerce e->ExceptionCode to NTSTATUS.
* fhandler_clipboard.cc (cygnativeformat): Redefine as UINT to avoid gcc 4.7.2
warnings.
(fhandler_dev_clipboard::read): Ditto.
2013-01-21 04:34:52 +00:00
Christopher Faylor d01efdbe6e * cygheap.cc (init_cygheap::find_tls): Don't consider unitialized threads.
* cygtls.cc (_cygtls::operator HANDLE): Return NULL when tid is not set.
* exceptions.cc (setup_handler): Don't try to suspend a thread if it has no
handle.
2012-08-16 17:11:41 +00:00
Christopher Faylor 52d2371da5 * DevNotes: Add entry cgf-000014.
* cygheap.cc (tls_sentry): Move here, rename from 'sentry' in cygtls.cc
(tls_sentry::lock): Ditto.
(nthreads): Move from cygtls.cc
(THREADLIST_CHUNK): Ditto.
(cygheap_init): Call init_tls_list().
(init_cygheap::init_tls_list): Define new function.
(init_cygheap::add_tls): Ditto.
(init_cygheap::remove_tls): Ditto.
(init_cygheap::find_tls): Ditto.  Semi-resurrect from _cygtls::find_tls.
* cygheap.h (init_cygheap::init_tls_list): Declare new function.
(init_cygheap::add_tls): Ditto.
(init_cygheap::remove_tls): Ditto.
(init_cygheap::find_tls): Ditto.
* cygtls.cc (sentry): Delete.
(sentry::lock): Ditto.
(nthreads): Ditto.
(THREADLIST_CHUNK): Ditto.
(_cygtls::init): Delete definition.
(_cygtls::init_thread): Call cygheap->add_tls() to add thread to global list.
(_cygtls::remove): cygheap->remove_tls() to remove thread from global list.
* cygtls.h (_cygtls::init): Delete declaration.
* dcrt0.cc (dll_crt0_0): Delete call to _cygtls::init().
* exceptions.cc (sigpacket::process): When no thread is specified, try to find
one via cygheap->find_tls.
2012-08-09 19:58:53 +00:00
Corinna Vinschen 099817c3db * cygheap.cc (init_cygheap::init_installation_root): Rearrange code
creating valid native NT installation_root path.  Only strip last
	backslash from path if the result is a valid NT path.  Explain why.
2012-06-18 20:17:15 +00:00
Corinna Vinschen 8895d962d5 * cygheap.cc (init_cygheap::init_installation_root): Convert function
init_installation_root into a cygheap method.
	* cygheap.h (struct init_cygheap): Move installation_root,
	installation_key, and installation_key_buf from shared
	.cygwin_dll_common DLL section to cygheap.  Declare new method
	init_installation_root.
	* dtable.cc (handle_to_fn): Accommodate the move of installation strings
	to the cygheap.
	* external.cc (cygwin_internal): Ditto.
	* fhandler_console.cc (fhandler_console::open_shared_console): Ditto.
	* fhandler_mailslot.cc (fhandler_mailslot::get_object_attr): Ditto.
	* fhandler_tty.cc: Ditto, throughout.
	* mount.cc (mount_info::init): Ditto.
	* pipe.cc (fhandler_pipe::create): Ditto.
	* shared.cc: Ditto, throughout.
	(installation_root): Remove.
	(installation_key): Move to cygheap.
	(installation_key_buf): Ditto.
	(installation_root_inited): Remove.
	(SPIN_WAIT): Remove.
	(init_installation_root): Move to cygheap.
	(memory_init): Call cygheap->init_installation_root right after
	cygheap->user.init.  Drop call of init_installation_root function.
	* shared_info.h (init_installation_root): Drop declaration.
	(installation_root): Ditto.
	(installation_key): Ditto.
	* uinfo.cc (pwdgrp::load): Accommodate the move of installation strings
	to the cygheap.
2012-02-14 11:27:43 +00:00
Christopher Faylor 3e9c8f2e81 * cygheap.cc (init_cygheap::manage_console_count): Delete.
* cygheap.h (init_cygheap::manage_console_count): Ditto.
(init_cygheap::console_count): Ditto.
* fhandler.h (fhandler_console::has_a): Ditto.
(fhandler_console::free_console): Declare new function.
* fhandler_console.cc (fhandler_console::free_console): Define new function.
(fhandler_console::open_setup): Delete call to manage_console_count.
(fhandler_console::close): Ditto.  Replace with call to free_console().
* fhandler_tty.cc (fhandler_pty_slave::open): Delete call to
manage_console_count.
(fhandler_pty_slave::cleanup): Ditto.
(fhandler_pty_slave::close): Call fhandler_console::free_console() if this is
our controlling tty.
* pinfo.cc (_pinfo::set_ctty): Skip function if tty in question == our ctty.
Delete call to manage_console_count.
* syscalls.cc (close_all_files): Avoid locking and avoid setting errno when
iterating over fds.
2012-02-07 16:54:14 +00:00
Corinna Vinschen 177dc6c7f6 Throughout use wincap.allocation_granularity instead of getpagesize.
Throughout use wincap.page_size instead of getsystempagesize.
	Throughout use "status" as variable name to hold NTSTATUS values.
	* fhandler_mem.cc: Check for NT_SUCCESS rather than for STATUS_SUCCESS.
	Fix debug_printf output.  Rectify long statements.  Fix comment
	formatting.
	* fhandler_proc.cc: Ditto.
	(format_proc_swaps): Drop useless test for ERROR_PROC_NOT_FOUND.
	* fhandler_process.cc: Ditto as in fhandler_mem.cc.
	(get_process_state): Rearrange allocation loop.  Use malloc/realloc.
	(get_mem_values): Fix potential NULL pointer usage.  Drop unused
	variable.
	* pinfo.cc (winpids::enum_processes): Handle low memory gracefully.
	* sec_auth.cc (get_priv_list): Drop local variable ret.
	* shared.cc (memory_init): Drop outdated call to getpagesize.
	* syscalls.cc (getsystempagesize): Remove.
	* sysconf.cc: Check for NT_SUCCESS rather than for STATUS_SUCCESS.
	(sysinfo): Constify sizeof_stodi.  Drop useless test for
	ERROR_PROC_NOT_FOUND.
	* thread.cc (pthread_getattr_np): Cast pointers to uintptr_t rather
	than to int for pointer arithmetic.
	* winsup.h (getsystempagesize): Drop declaration.
2011-12-22 11:02:36 +00:00
Christopher Faylor 480b13a37a * sigproc.cc (remove_proc): Don't terminate the currently executing thread. 2011-11-29 15:34:49 +00:00
Christopher Faylor 18eaa70b5b Remove erroneously checked-in debugging statements.
* cygheap.cc (cygheap_fixup_in_child): Here.
* debug.cc (delete_handle): Here.
* sigproc.cc (child_info_spawn::cleanup): Here.
* spawn.cc (child_info_spawn::worker): Here.
2011-11-14 01:45:42 +00:00
Christopher Faylor 56a1971526 Throughout use "have_execed" macro rather than "hExeced" global handle.
Throughout rename _PROC_* to _CH_*.
* child_info.h: Include "pinfo.h".
(child_info_types): Rename _PROC_* -> _CH_* to avoid confusion with similarly
named constants.
(_PROC_*): Delete unneeded aliases.
(PROC_*): Ditto.
(CURR_CHILD_INFO_MAGIC): Ditto.
(cchildren): Define using "pinfo_minimal".
(child_info::set_saw_ctrl_c): Move to
(child_info_spawn::set_saw_ctrl_c): Here.
(child_info_spawn::lock): New field.
(child_info_spawn::hExeced): Ditto.
(child_info_spawn::ev): Ditto.
(child_info_spawn::~child_info_spawn): Move to sigproc.cc.
(child_info_spawn::child_info_spawn): Ditto.
(child_info_spawn::cleanup): Declare new function.
(child_info_spawn::set_saw_ctrl_c): Move to this class.  Set flag only when
execed and return true when we have set the flag.
(child_info_spawn::child_info_spawn::signal_myself_exited): New function.
(child_info_spawn::wait_for_myself): Ditto.
(child_info_spawn::has_execed_cygwin): Ditto.
(child_info_spawn::has_execed): Ditto.  Replaces "hExeced" test.
(child_info_spawn::operator HANDLE&): New operator.
(child_info_spawn::worker): Define old "spawn_guts" as class member.
(ch_spawn): Declare.
(have_execed): Define.
(have_execed_cygwin): Ditto.
* cygheap.h: Update comment.
* dcrt0.cc (get_cygwin_startup_info): Use _CH_* enums.
(child_info_spawn::handle_spawn): Ditto.
(dll_crt0_0): Ditto.
(multiple_cygwin_problem): Ditto.
* exceptions.cc (chExeced): Delete obsolete declaration.
(ctrl_c_handler): Reference set_saw_ctrl_c via new ch_spawn global.
* globals.cc (hExeced): Delete.
* pinfo.cc (pinfo::thisproc): Refer to cygheap as ::cygheap for consistency in
handle naming when -DDEBUGGING.
(pinfo::init): Accommodate case where myself.h is known but h0 is passed in.
(pinfo::pinfo): New constructor for setting up a pinfo passed in by previous
exec'or.
(pinfo::proc_waiter): Don't handle subprocess if we're in the process of
exiting due to an exec of a cygwin process.  Don't close rd_proc_pipe here.
Close it when we actually are finished with the process.  Use new
ch_spawn.signal_myself_exited function to let exec stub know that subprocess
has exited.
(pinfo::wait): Clarify debugging output.
(pinfo::release): Use "close_h" to close all handles to avoid races.
(winpids::add): Assume that elements of the array do not need to be zeroed and
are properly initialized or suffer problems on pinfo::release.  Don't close
hProcess since release does that now.
* pinfo.h: Update comment.
(pinfo_minimal): Move some elements from pinfo here so that child_info_spawn
can use them.
(pinfo): Inherit from pinfo_minimal.
(pinfo::pinfo): Modify to accommodate new pinfo_minimal.
(pinfo::allow_remove): New function.
* sigproc.cc (proc_subproc): Use boolean values for true/false.  Implement
PROC_EXEC_CLEANUP.
(proc_terminate): Set ppid = 1 since the procs list will only be iterated when
the process has not execed.  Don't do any cleanup here since it is now handled
in pinfo::release.
(sigproc_init): Initialize sync_proc_subproc earlier.
(child_info::child_info): Assume that all important fields are properly
initialized and avoid memset().
(child_info_spawn::child_info_spawn): Specifically test for execing and then
set up appropriate fields in the struct.
(child_info_spawn::cleanup): Define new function.
(child_info_spawn::record_children): Specifically test for being execed here.
Fill in pinfo_minimal part of children array.
(child_info_spawn::reattach_children): Use constructor to duplicate information
for previous exec'or.  Add more debugging output.
(remove_proc): Force deletion of thread when exiting due to exec.  Rely on
pinfo::cleanup in release.
* sigproc.h (PROC_EXEC_CLEANUP): New enum.
(PROC_DETACHED_CHILD): Delete.
* spawn.cc (chExeced): Delete.
(child_info_spawn::worker): Rename from spawn_guts.  Use elements of
child_info_spawn throughout rather than ch.whatever.  Use ::cygheap to refer to
global rather than element of child_info.  Use wait_for_myself() rather than
waitpid().  Call child_info_spawn::cleanup on function return.
(spawnve): Reflect movement of spawn_guts functionality into
child_info_spawn::worker.
* syscalls.cc (popen): Ditto.
* winsup.h (spawn_guts): Delete declaration.
2011-11-14 01:29:49 +00:00
Christopher Faylor b86f999af1 whitespace elimination 2011-06-06 05:02:13 +00:00
Christopher Faylor 3a88e09e7f * cygheap.cc (cygheap_dummy): Rename from cygheap_at_start.
(cygheap): Accommodate name change to cygheap_dummy.
(cygheap_init): Ditto.
(cygheap_fixup_in_child): Simplify slightly.
* fork.cc (fork): Add an advisory comment.
2011-05-30 06:24:53 +00:00
Christopher Faylor 92ddb74290 * cygheap.cc (cygheap::close_ctty): Close ctty via close_with_arch().
* debug.cc (close_handle): Call debugger on failure.
* devices.in (device::tty_to_real_device): Delete.
* devices.h (device::tty_to_real_device): Ditto.
* devices.cc: Regenerate.
* dtable.cc: Delete old ifdef'ed vfork code.
(dtable::release): Don't handle archetype here.
(dtable::init_std_file_from_handle): Consolidate console tests.  Generate
major/minor for tty ASAP.  Fix incorrect setting of DEV_TTYS* for serial.
(fh_alloc): New function derived from build_fh_pc.  Pass current tty when
building tty.
(build_pc_pc): Use fh_alloc to create.  Set name from fh->dev if appropriate.
Generate an archetype or point to one here.
(dtable::dup_worker): Deal with archetypes.  Rely on = operator copying whole
class rather than just fhandler_base.
(dtable::fixup_after_exec): Call close_with_arch to handle closing of fhandlers
with archetypes.
* fhandler.cc (fhandler_base::operator =): Call memcpy with fhandler's size()
rather than sizeof fhandler_base.
(fhandler_base::open_with_arch): New function.  Handles opening of fhandler's
with archetypes, dealing with usecounts, etc.
(fhandler_base::close_with_arch): Ditto for close.
* fhandler.h: Many changes for archetypes.
(fhandler_base::set_name): Set both normalized path and regular path.
(fhandler_base::open_with_arch): New function.
(fhandler_base::open_setup): Ditto.
(fhandler_base::use_archetype): Ditto.
(fhandler_base::_archetype_usecount): Ditto.
(fhandler_*::size): Ditto.
(fhandler_dev_tape::open): Remove virtual decoration.
(fhandler_console::use_archetype): New function.  Return true.
(fhandler_console::open_setup): New function.
(fhandler_console::dup): Delete.
(fhandler_tty_slave::fhandler_tty_slave): Redeclare to take an argument.
(fhandler_tty_slave::use_archetype): New function.  Return true.
(fhandler_tty_slave::cleanup): New function.
(fhandler_pty_master::use_archetype): New function.  Return true.
(fhandler_pty_master::cleanup): New function.
(fhandler_pty_master::is_tty_master): New function.  Return false.
(fhandler_tty_master::is_tty_master): New function.  Return true.
(fhandler_dev_dsp::fhandler_dev_dsp): New function.  Return true.
(report_tty_counts): Only report on archetype's usecount if there is one.
* fhandler_console.cc (fhandler_console::get_tty_stuff): Remove handling of
setsid, set_ctty, set_flags, and manage_console_count.
(fhandler_console::open_setup): New function.  Implement functionality removed
from get_tty_stuff.
(fhandler_console::dup): Delete.
(fhandler_console::output_tcsetattr): Set errno on error.
(fhandler_console::fhandler_console): Set device early.
(fhandler_console::init): Use open_with_arch to open console handles.
(fhandler_console::fixup_after_fork_exec): Nuke most of the stuff for dealing
with console handles.
* fhandler_dsp.cc (fhandler_dev_dsp::open): Remove archetype handling.
(fhandler_dev_dsp::write): Ditto.
(fhandler_dev_dsp::read): Ditto.
(fhandler_dev_dsp::close): Ditto.
(fhandler_dev_dsp::dup): Ditto.
(fhandler_dev_dsp::ioctl): Ditto.
(fhandler_dev_dsp::fixup_after_fork): Ditto.
(fhandler_dev_dsp::fixup_after_exec): Ditto.
* fhandler_tty.cc (fhandler_tty_common::__acquire_output_mutex): Add a little
more debugging.
(fhandler_tty_common::__release_output_mutex): Ditto.
(fhandler_pty_master::process_slave_output): Ditto.  Don't do signal handling
or pthread_cancel handling in the tty master thread.
(process_output): Minor reorg.
(fhandler_tty_slave::fhandler_tty_slave): Set device based on new ntty
argument.
(fhandler_tty_slave::open): Remove archetype handling.  Move some processing
into open_setup().
(fhandler_tty_slave::open_setup): New function.
(fhandler_tty_slave::cleanup): New function.
(fhandler_tty_slave::close): Remove archetype handling.  Move some processing
into cleanup().
(fhandler_tty_slave::init): Rename argument from f to h.  Open device using
open_with_arch().  Remove archetype handling.
(fhandler_pty_master::dup): Ditto.
(fhandler_pty_master::open): Ditto.
(fhandler_pty_master::close): Ditto.  Move some handling to cleanup().
(fhandler_pty_master::cleanup): New function.
(fhandler_tty_master::init_console): Give unique name to captive console
fhandler.
* pinfo.cc (_pinfo::set_ctty): Rename argument from arch to fh.  Eliminate
archetype assumption.
* syscalls.cc (close_all_files): Use close_with_arch for closing.
(open): Use open_with_arch() rather than open().
(close): Use close_with_arch() rather than close().
2011-05-05 22:30:53 +00:00
Christopher Faylor 71c17c5402 * cygheap.cc (init_cygheap::close_ctty): Avoid closing console-cttys since they
don't use archetypes and this will just result in double frees.
* dll_init.cc (dll_list::protect): Define.
(dll_list::alloc): Guard list access.
(dll_list::detach): Ditto.
* dll_init.h (dll_list::protect): Declare new muto.
(dll_list::guard): Define/declare function to guard list access.
* fhandler_termios.cc (fhandler_termios::sigflush): Avoid SEGV in pathological
condition of get_ttyp() == NULL.
2011-04-21 00:53:55 +00:00
Corinna Vinschen 3591470260 * Throughout fix copyright dates. 2011-02-15 15:56:03 +00:00
Christopher Faylor 41f06f51ac * cygwin.sc: Eliminate __cygheap_mid.
* cygheap.cc: Ditto.
2011-02-11 16:18:34 +00:00
Christopher Faylor cc25fb3641 * cygheap.cc (_cygheap_mid): Drop unneeded section attribute.
(cygheap_init): Just zero cygheap structure.
* cygwin.sc: Keep 16 byte alignment but drop all other alignments related to
cygheap.  Eliminate unused __cygheap_end1.
2011-02-11 16:05:26 +00:00
Christopher Faylor ca1953eeee * cygheap.cc: Add some __stdcall decoration where appropriate.
* lib/cygwin_crt0.c: __attribute -> __attribute__.
2011-02-10 02:22:36 +00:00
Corinna Vinschen 685e55e254 * cygheap.cc (cygheap_user::set_name): Allow to change the user name
if it only differs by case.
2010-05-31 18:52:02 +00:00
Corinna Vinschen 9e40fe8112 * cygheap.h (struct init_cygheap): Add rlim_core member.
* cygheap.cc (cygheap_init): Initialize rlim_core to RLIM_INFINITY.
	* exceptions.cc (stackdump): Drop extern declaration of rlim_core.
	Refer to cygheap->rlim_core instead.
	(exception::handle): Disable stackdumping if cygheap->rlim_core is 0.
	Don't set WCOREDUMP flag in exit code, if cygheap->rlim_core is 0.
	(sigpacket::process): Ditto.
	* resource.cc (rlim_core): Remove.
	(getrlimit): Fetch RLIMIT_CORE value from cygheap->rlim_core.
	(setrlimit): Store RLIMIT_CORE value in cygheap->rlim_core.
2010-04-20 10:44:52 +00:00
Corinna Vinschen 2bba259eb7 * cygheap.cc (cwcsdup): Fix allocation size to accommodate sizeof WCHAR.
(cwcsdup1): Ditto.
2010-04-13 10:01:34 +00:00
Corinna Vinschen d856640e1c * cygheap.cc (cygheap_init): Default locale.charset to "UTF-8".
* dcrt0.cc (dll_crt0_1): Call setlocale (LC_CTYPE, "") here, just
	before resetting application locale to "C".
	* environ.cc (environ_init): Drop code setting locale here.
	* syscalls.cc (check_codepage): Break out check for required codepage
	from internal_setlocale.
	(internal_setlocale): Just convert CWD and $PATH from old charset to
	new charset and set internal charset.
	(setlocale): Change accordingly.  Don't require LC_ALL or LC_CTYPE to
	store old locale value.  Always call internal_setlocale if charset
	changed due to locale environment changes.
2009-09-28 10:43:49 +00:00
Christopher Faylor fafbf75509 * cygheap_malloc.h: New file.
* cygheap.h: Remove stuff now included in cygheap_malloc.h and include that
file.  Make cygheap_init a standard c++ function.  Remove unneeded child_info
declaration.
* path.h: Include cygheap_malloc.h.  Remove extra cstrdup declaration.
(path_conv): Reorganize to group variables together.
(path_conv::path): Make const char *.
(path_conv::known_suffix): Ditto.
(path_conv::normalized_path): Ditto.
(path_conv::path_conv): Reorganize initializers to reflect new element
ordering.
(path_conv::get_win32): Change return value to const char *.
(path_conv::set_path): Move back here from spawn.cc.
(parh_conv::modifiable_path): New function.
* path.cc (path_conv::add_ext_from_sym): Accommodate const'ness of
known_suffixes.
(path_conv::set_normalized_path): Ditto for normalized_path.
(path_conv::check): Use modifiable_path whereever we need to modify the path
element.  Use set_path to set the path.
(path_conv::~path_conv): Accommodate new const'ness.
* spawn.cc (perhaps_suffix): Declare ext as const since that's what is being
returned.
(path_conv::set_path): Move back to path.h.
* winf.f (linebuf): Perform minor cleanup.
(linebuf::fromargv): Change second parameter to const.
* winf.cc (linebuf::fromargv): Ditto.
2009-08-01 19:52:46 +00:00
Christopher Faylor 71f53a2f62 * cygheap.h (mini_cygheap): New struct.
(init_cygheap): Inherit locale field via mini_cygheap.
* cygheap.cc (cygheap_at_start): Define new variable.
(cygheap): Initialize as cygheap_at_start so that locale information is always
available.
(cygheap_init): Initialize cygheap iff it is set to cygheap_at_start.
* shared_info.h (memory_init): Accommodate argument change.
* memory.cc (memory_init): Accept an argument indicating whether cygheap should
be initialized or not.
* dcrt0.cc (child_info_fork::handle_fork): Pass false to memory_init().
(child_info_spawn::handle_spawn): Ditto.
(dll_crt0_0): Pass true to memory_init when not forking or execing.
* cygheap.h (cygheap_types::HEAP_2_DLL): New enum.
* dll_init.h (dll): Remove unused namelen field.
(dll_list::load_after_fork): Accommodate change in arguments.
* dll_init.cc (dll_list::alloc): Allocate dll information in the cygwin heap.
(dll_list::detach): Free dll information from the cygwin heap.
(dll_list::load_after_fork): Use dll information in the cygwin heap directly
rather than querying parent.
* fork.cc (frok::first_dll): Delete.
(frok::child): Don't report on first_dll.  Don't pass it to load_on_fork.
(frok::parent): Don't set first_dll.
(fork): Ditto.
2009-06-08 03:53:40 +00:00
Corinna Vinschen 6f401eccfb * cygheap.cc (cygheap_init): Set Cygwin default locale values.
* cygheap.h (struct cygheap_locale): New structure.
	(struct user_heap_info): Add cygheap_locale member locale.
	* dcrt0.cc (dll_crt0_1): Revert to calling _setlocale_r so that only
	the applications locale is reverted to "C".
	* environ.cc (environ_init): Remove unused got_lc variable.
	* fhandler.h (class dev_console): Remove now unsed locale variables.
	* fhandler_console.cc (fhandler_console::get_tty_stuff): Remove
	setting dev_console's locale members.
	(dev_console::con_to_str): Use internal locale settings.  Default to
	__ascii_wctomb if charset is "ASCII".
	(fhandler_console::write_normal): Ditto.
	* strfuncs.cc (__ascii_wctomb): Drop declaration.
	(__db_wctomb): Use fixed value 2 instead of not
	necessarily matching MB_CUR_MAX.
	(__eucjp_wctomb): Use 3 instead of MB_CUR_MAX.
	(sys_cp_wcstombs): Remove special case for "C" locale.
	(sys_wcstombs): Implement here.  Use internal locale data stored on
	cygheap.
	(sys_cp_mbstowcs): Remove special case for "C" locale.
	(sys_mbstowcs): Implement here.  Use internal locale data stored on
	cygheap.
	* syscalls.cc (internal_setlocale): New function to set cygheap locale
	data and to reset CWD posix path.
	(setlocale): Just call internal_setlocale from here if necessary.
	* wchar.h (__ascii_wctomb): Declare.
	(sys_wcstombs): Don't define inline, just declare.
	(sys_mbstowcs): Ditto.
2009-05-14 19:49:37 +00:00
Corinna Vinschen 764d88e4a7 * cygheap.cc (cygheap_init): Set umask to a sane default.
* uinfo.cc (cygheap_user::ontherange): Don't use HOMEDRIVE/HOMEPATH
	to set HOME.  Default to /home/USERNAME.
2009-05-06 11:52:20 +00:00
Christopher Faylor 9fe25af7a6 * cygheap.cc (cygheap_user::~cygheap_user): Remove unneeded if 0'ed code.
* fhandler_registry.cc (fhandler_registry::exists): Recode goto as if/else to
avoid a gcc4 compiler warning.
(fhandler_registry::open): Ditto.  Use one goto rather than two.
* gentls_offsets: Fix compiler warning in generated output.
* tlsoffsets.h: Regenerate.
* mount.cc (fillout_mntent): slashify native paths returned via getmntent.
2008-12-13 21:05:31 +00:00