From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7501 invoked by alias); 2 Jun 2013 06:40:01 -0000 Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org Received: (qmail 7442 invoked by uid 48); 2 Jun 2013 06:39:50 -0000 From: "zylcf818 at 163 dot com" To: glibc-bugs@sourceware.org Subject: [Bug libc/15560] New: munmap subregion of memory maped by mmap Date: Sun, 02 Jun 2013 06:40:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: libc X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: minor X-Bugzilla-Who: zylcf818 at 163 dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-06/txt/msg00001.txt.bz2 http://sourceware.org/bugzilla/show_bug.cgi?id=15560 Bug ID: 15560 Summary: munmap subregion of memory maped by mmap Product: glibc Version: unspecified Status: NEW Severity: minor Priority: P2 Component: libc Assignee: unassigned at sourceware dot org Reporter: zylcf818 at 163 dot com CC: drepper.fsp at gmail dot com in rhel6.2, I mmap 3 pages, and munmap the middle page, but the behavior of munmap() seems to be strange, below is code: #include #include #include #include #include #include #include int main(int argc, char *argv[]) { char* addr = (char*)mmap(NULL, 4096*3, PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (addr == MAP_FAILED) printf("Failed to mmap\n"); memcpy(addr, "abc", 3); memcpy(addr+4096, "def", 3); memcpy(addr+8192, "ghi", 3); // printf("%10p\n", addr); // printf("%10p\n", addr+4096); // printf("%10p\n", addr+8192); // printf("%s\n", addr); // printf("%s\n", addr+4096); // printf("%s\n", addr+8192); int rs = munmap(addr+4096, 4096); if ( rs != 0 ) printf("failed to munmap\n"); printf("%s\n", addr); printf("%s\n", addr+4096); printf("%s\n", addr+8192); memcpy(addr, "123", 3); memcpy(addr+4096, "456", 3); memcpy(addr+8192, "789", 3); printf("%s\n", addr); printf("%s\n", addr+4096); printf("%s\n", addr+8192); exit(EXIT_SUCCESS); } /* main */ >g++ -g -o mmap mmap.cpp >./mmap abc abc ghi 123 123 789 if I comment off printf... in code, the result is what I expect: 0x7f3c4a274000 0x7f3c4a275000 0x7f3c4a276000 abc def ghi abc Segmentation fault (core dumped) <--- what I expect -- You are receiving this mail because: You are on the CC list for the bug.