| delorie.com/archives/browse.cgi | search |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| DKIM-Filter: | OpenDKIM Filter v2.11.0 sourceware.org EA9E1384605A |
| DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; |
| s=default; t=1609535471; | |
| bh=XpOj03aCUkvLPOdlTuZ7XsX0W6PqTV9J3wdYCMOMiGc=; | |
| h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: | |
| List-Help:List-Subscribe:From:Reply-To:From; | |
| b=pG212loTjrBLIBl3lgLJSB/YeJQEE3qvX0IL4x6bIL9XPI2QlLk3Wzn1VgrOZzaUS | |
| dLVu9rXTVb74vTKdG/dEcT+yZuX0DYl5WNgKXy+dvkm6li5+dPU/Ftr8nSPVwVqdOO | |
| g1kzVGvAAoBOf/6pHUvSExURoltRGEBbu3ejCI2c= | |
| X-Original-To: | cygwin AT cygwin DOT com |
| Delivered-To: | cygwin AT cygwin DOT com |
| DMARC-Filter: | OpenDMARC Filter v1.3.2 sourceware.org 4A39638460A2 |
| To: | "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com> |
| Subject: | Segfault when accessing mmaped memory on Cygwin |
| Message-ID: | <c26a63be-f805-7983-1893-74398ac7b60f@netcologne.de> |
| Date: | Fri, 1 Jan 2021 22:11:01 +0100 |
| User-Agent: | Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 |
| Thunderbird/78.6.0 | |
| MIME-Version: | 1.0 |
| X-Spam-Status: | No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, |
| DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, | |
| SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 | |
| X-Spam-Checker-Version: | SpamAssassin 3.4.2 (2018-09-13) on |
| server2.sourceware.org | |
| X-BeenThere: | cygwin AT cygwin DOT com |
| X-Mailman-Version: | 2.1.29 |
| List-Id: | General Cygwin discussions and problem reports <cygwin.cygwin.com> |
| List-Archive: | <https://cygwin.com/pipermail/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-request AT cygwin DOT com?subject=help> |
| List-Subscribe: | <https://cygwin.com/mailman/listinfo/cygwin>, |
| <mailto:cygwin-request AT cygwin DOT com?subject=subscribe> | |
| From: | Thomas Koenig via Cygwin <cygwin AT cygwin DOT com> |
| Reply-To: | Thomas Koenig <tkoenig AT netcologne DOT de> |
| Sender: | "Cygwin" <cygwin-bounces AT cygwin DOT com> |
Hi,
when trying out uf a certain shared memory allocator would
work on Cygwin, I tried out the sample program below (which
works on Linunx, *BSD, AIX and Solaris) and got a suprising
falure with a segmentation fault at the line
*i1 = 42;
mmap() had succeeded.
Is this a known issue, and would it be possible to work
around that?
Best regards
Thomas
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#define NAME "/random_namexxx"
int main()
{
int fd;
long pagesize;
void *p1, *p2;
volatile int *i1, *i2;
size_t size1, size2;
off_t offset;
pagesize = sysconf (_SC_PAGE_SIZE);
if (pagesize == -1)
{
perror ("sysconf failed");
exit (EXIT_FAILURE);
}
fd = shm_open (NAME, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
if (fd == -1)
{
perror ("shm_open failed");
exit (EXIT_FAILURE);
}
shm_unlink (NAME);
offset = 0;
size1 = pagesize;
p1 = mmap (NULL, size1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset);
if (p1 == MAP_FAILED)
{
perror ("mmap 1 failed");
exit (EXIT_FAILURE);
}
printf ("p1 = %p\n", p1);
ftruncate (fd, size1);
i1 = p1;
*i1 = 42;
size2 = 2 * size1;
p2 = mmap (NULL, size2, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset);
if (p2 == MAP_FAILED)
{
perror ("mmap 1 failed");
exit (EXIT_FAILURE);
}
printf ("p2 = %p\n", p2);
i2 = p2;
ftruncate (fd, size2);
printf ("%d\n", *i2);
return 0;
}
--
Problem reports: https://cygwin.com/problems.html
FAQ: https://cygwin.com/faq/
Documentation: https://cygwin.com/docs.html
Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |