delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
X-SWARE-Spam-Status: | No, hits=-0.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,SPF_HELO_PASS,T_RP_MATCHES_RCVD,T_TO_NO_BRKTS_FREEMAIL |
X-Spam-Check-By: | sourceware.org |
To: | cygwin AT cygwin DOT com |
From: | Jason Curl <jcurlnews AT arcor DOT de> |
Subject: | Bug in fork() while in a thread |
Date: | Sun, 15 Aug 2010 19:42:01 +0200 |
Lines: | 76 |
Message-ID: | <i498t9$tot$1@dough.gmane.org> |
Mime-Version: | 1.0 |
User-Agent: | Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.11) Gecko/20100711 Thunderbird/3.0.6 |
X-IsSubscribed: | yes |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
--------------050504020400060204090100 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hello, Is it allowed to issue the fork() system call while not in the main thread? When I read the OpenGroup specifications I don't seem to find anything against allowing this. In particular, if I create a thread, then issue a fork(), data that exists on the stack is corrupted after the fork() is in the child. Using data on the heap doesn't show any issues (and is currently my workaround, in case this is a bug). I've created a minimal example: $ gcc -g -O0 forktestcase.c -o forktestcase.exe $ ./forktest Pointer BEFORE THE FORK env is 0x28cd00 This is the child Pointer env is 0x28cd00 env[0] is env[1] is Child exited with 0 Further, a stackdump is now present, probably while iterating through the null terminated array at 0x28cd00 after the fork(). If you have a look at the attached code, I believe the expected output is $ ./forktest Pointer BEFORE THE FORK env is 0x28cd00 This is the child Pointer env is 0x28cd00 Child exited with 0 This bug is not recreatable if we execute fork() in the main thread and not a separate thread. Please find attached the test case. --------------050504020400060204090100 Content-Type: text/plain; name="forktestcase.c" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="forktestcase.c" I2luY2x1ZGUgPHN0ZGxpYi5oPg0KI2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5j bHVkZSA8dW5pc3RkLmg+DQojaW5jbHVkZSA8cHRocmVhZC5oPg0KDQpzdHJ1 Y3QgbXlkYXQgew0KCXB0aHJlYWRfdCBwdGg7DQoJY2hhciAgICAqKmVudjsN CglwaWRfdCAgICAgcGlkOw0KCWludCAgICAgICBzdGF0dXM7DQp9Ow0KDQpl eHRlcm4gY2hhciAqKmVudmlyb247DQoNCnZvaWQgKmNhbGxmdW5jKHZvaWQg KmRhdGEpDQp7DQoJc3RydWN0IG15ZGF0ICpkYXQgPSBkYXRhOw0KCWludCBw aWQ7DQoJaW50IGk7DQoJDQoJcHJpbnRmKCJQb2ludGVyIEJFRk9SRSBUSEUg Rk9SSyBlbnYgaXMgJXBcbiIsIGRhdC0+ZW52KTsNCglpID0gMDsNCgl3aGls ZSAoZGF0LT5lbnZbaV0pIHsNCgkJcHJpbnRmKCIgZW52WyVkXSBpcyAlc1xu IiwgaSwgZGF0LT5lbnZbaV0pOw0KCQlpKys7DQoJfQ0KDQoNCglwaWQgPSBm b3JrKCk7DQoJaWYgKHBpZCA9PSAwKSB7DQoJCWludCBpOw0KCQlwcmludGYo IlRoaXMgaXMgdGhlIGNoaWxkXG4iKTsNCgkJDQoJCXByaW50ZigiUG9pbnRl ciBlbnYgaXMgJXBcbiIsIGRhdC0+ZW52KTsNCgkJaSA9IDA7DQoJCXdoaWxl IChkYXQtPmVudltpXSkgew0KCQkJcHJpbnRmKCIgZW52WyVkXSBpcyAlc1xu IiwgaSwgZGF0LT5lbnZbaV0pOw0KCQkJaSsrOw0KCQl9DQoJCQ0KCQlleGl0 KDApOw0KCX0gZWxzZSB7DQoJCWludCBzdGF0dXM7DQoJCQ0KCQlkYXQtPnBp ZCA9IHBpZDsNCgkJd2FpdHBpZChwaWQsICZzdGF0dXMsIDApOw0KCQlkYXQt PnN0YXR1cyA9IHN0YXR1czsNCgkJcHJpbnRmKCJDaGlsZCBleGl0ZWQgd2l0 aCAlZFxuIiwgV0VYSVRTVEFUVVMoc3RhdHVzKSk7DQoJfQ0KfQ0KDQp2b2lk IG5ld3RocmVhZChzdHJ1Y3QgbXlkYXQgKmRhdCkNCnsNCglpZiAocHRocmVh ZF9jcmVhdGUoJmRhdC0+cHRoLCBOVUxMLCBjYWxsZnVuYywgZGF0KSkgew0K CQlwZXJyb3IoIkNvdWxkbid0IGNyZWF0ZSB0aHJlYWRcbiIpOw0KCQlyZXR1 cm47DQoJfQ0KCQ0KCXB0aHJlYWRfam9pbihkYXQtPnB0aCwgTlVMTCk7DQp9 DQoNCmludCBtYWluKGludCBhcmdjLCBjaGFyICoqYXJndikNCnsNCglzdHJ1 Y3QgbXlkYXQgKmRhdDsNCglpbnQgICB2YWx1ZTE7DQoJaW50ICAgdmFsdWVi MSwgdmFsdWViMjsNCglpbnQgICBmZDEsIGZkMjsNCgljaGFyICplbnYyW10g PSB7ICJBUFBURVNUUkVTVUxUPTQyIiwgKGNoYXIgKikwIH07DQoJY2hhciAq ZW52W10gPSB7IChjaGFyICopMCB9Ow0KCQ0KCWRhdCA9IG1hbGxvYyhzaXpl b2Yoc3RydWN0IG15ZGF0KSk7DQoNCglkYXQtPmVudiA9IGVudjsNCgluZXd0 aHJlYWQoZGF0KTsNCgkNCglmcmVlKGRhdCk7DQp9 --------------050504020400060204090100 Content-Type: text/plain; charset=us-ascii -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple --------------050504020400060204090100--
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |