public inbox for cygwin-talk@cygwin.com
 help / color / mirror / Atom feed
From: Warren Young <warren@etr-usa.com>
To: The Vulgar and Unprofessional Cygwin-Talk List <cygwin-talk@cygwin.com>
Subject: Re: Design mixed 32 and 64 bit systems.
Date: Mon, 02 Dec 2013 19:35:00 -0000	[thread overview]
Message-ID: <529CE0E4.4080804@etr-usa.com> (raw)
In-Reply-To: <6CF2FC1279D0844C9357664DC5A08BA21D7054@MLBXV06.nih.gov>

[-- Attachment #1: Type: text/plain, Size: 1878 bytes --]

On 11/27/2013 13:11, Buchbinder, Barry (NIH/NIAID) [E] wrote:
>
> My question is why 64 bit wasn't named cygwin2.dll?

While I agree that there is justification for that on "different ABI" 
grounds, it doesn't solve the core problem.

That being, the Cygwin DLL maintains a bunch of shared data structures 
to provide the POSIX emulation that Cygwin programs require.  Different 
DLLs mean different memory spaces, which means two *independent* sets of 
these data structures.

Consider a simple case: parent PID.  A 64-bit Cygwin program launches a 
32-bit Cygwin program.  What goes getppid(2) return in the child?

Take a second and think about it.

Got your guess?  Okay, now put the two attached C++ files into a 
directory that both Cygwins can see (/cygdrive/c for example) and build 
them.  The easiest way to do that is to say "make child32" from Cygwin 
32 and "make parent64" from Cygwin 64.

Now from Cygwin 64, run parent64.  Does the output match your guess?  I 
bet you'll find it surprising!

------- BEGIN SPOILER --------

This happens because POSIX PIDs are in a table that lives in 
cygwin1.dll's memory space, and because there are two DLLs, there are 
two different PID tables.

-------- END SPOILER ---------

You don't run into this problem on "real" 32/64-bit OSes because there 
is only one kernel, and the 32 vs 64 bit differences are abstracted away 
by the syscall layer, so that everything becomes 64-bit within kernel 
space.  There is no single central entity in Cygwin, since Cygwin runs 
entirely in user space.

Perhaps one could build a special 32-bit cygwin1.dll that worked like 
Wow64[*].  It may not be possible without kernel level support, from a 
driver at least.  On the other hand, it can't be any more tricky than 
building something like VirtualBox.  The question then is whether it's 
worth the effort.


[*] http://goo.gl/oYbLwg

[-- Attachment #2: child32.cpp --]
[-- Type: text/x-c++src, Size: 159 bytes --]

#include <iostream>
#include <unistd.h>

int main()
{
	std::cout << "My PID is " << getpid() << "; my parent's PID is " <<
			getppid() << '.' << std::endl;
}

[-- Attachment #3: parent64.cpp --]
[-- Type: text/x-c++src, Size: 460 bytes --]

#include <iostream>

#include <unistd.h>

#include <errno.h>
#include <string.h>

int main()
{
	std::cout << "My PID is " << getpid() << "; " << std::flush;

	switch (int pid = fork()) {
		case -1:			// error
			std::cout << "ERROR: " << strerror(errno) << std::endl;
			break;

		case 0: {			// child
			const char* cmd = "./child32";
			execl(cmd, cmd, 0);
			break;
		}

		default:			// parent
			std::cout << "created child PID " << pid << std::endl;
	}
}

  parent reply	other threads:[~2013-12-02 19:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-27 20:13 Buchbinder, Barry (NIH/NIAID) [E]
2013-11-27 22:17 ` JonY
2013-11-27 22:27   ` Christopher Faylor
2013-12-02 19:35 ` Warren Young [this message]
2013-12-02 19:56   ` Christopher Faylor
2013-12-02 20:30     ` Warren Young
2013-12-02 20:44       ` Warren Young
2013-12-02 21:07       ` Christopher Faylor
2013-12-17 20:41         ` Christopher Faylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=529CE0E4.4080804@etr-usa.com \
    --to=warren@etr-usa.com \
    --cc=cygwin-talk@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).