This is the mail archive of the cygwin mailing list for the Cygwin project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
As part of an application we're developing, we use CreateFileMapping/MapViewOfFile to be able to share information among processes. I noticed today that if I try to reference the map immediately after calling fork() but before calling exec, that my application will crash.
I should be able to resolve this in my app but I was just curious if this was unexpected behavior or not.
###################### sdaley@sdaley2 ~ $ gcc -Wall parent_test.cpp -o parent_test
sdaley@sdaley2 ~ $ ./parent_test.exe Dumping map in parent --> length = 11 --> name = test-string Dumping map in child 17 [main] parent_test 2460 _cygtls::handle_exceptions: Error while dumping state (probably corrupted stack)
sdaley@sdaley2 ~ $ ######################
############################## parent.cpp ##############################
#include <stdio.h> #include <unistd.h> #include <windows.h>
void *view; HANDLE hFileMapping;
typedef struct usrInfo { int usrlen; unsigned char data[1]; } usrInfo;
static void* create_file_map(); static void dump_file_map();
int main(int argc, char **argv) { void *shmp = create_file_map();
if (shmp == NULL) { fprintf(stderr, "shmp == NULL\n"); exit(1); }
usrInfo *usr = (usrInfo*)shmp; usr->usrlen = strlen("test-string"); unsigned char *p = usr->data; memcpy(p, "test-string", usr->usrlen); p[usr->usrlen] = '\0';
printf("Dumping map in parent\n"); dump_file_map();
if (fork() == 0) { //const char *args[2]; //args[0] = "child_test"; //args[1] = NULL; //execvp("./child_test", (char **)args); //printf("execvp failed\n"); printf("Dumping map in child\n"); dump_file_map(); exit(1); }
UnmapViewOfFile(view); CloseHandle(hFileMapping);
return 0; }
static void dump_file_map() { usrInfo *usr = (usrInfo*)view; if (usr != NULL) { printf(" --> length = %d\n", usr->usrlen); printf(" --> name = %s\n", usr->data); } }
static void * create_file_map() { SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE;
hFileMapping = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, PAGE_READWRITE, 0, BUF_SIZE, "TEST-PAGE");
if (hFileMapping == 0) { fprintf(stderr, "CreateFileMapping failed\n"); return NULL; }
return view; }
Attachment:
cygcheck.out
Description: Binary data
-- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |