public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Badari Pulavarty <pbadari@us.ibm.com>
To: lkml <linux-kernel@vger.kernel.org>
Subject: mmap64() behaviour on 64-bit machines ?
Date: Tue, 22 Nov 2005 08:34:53 -0800	[thread overview]
Message-ID: <1132677293.24066.242.camel@localhost.localdomain> (raw)

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

Hi,

I am confused on the behaviour of mmap64() on 64-bit machines.
When I run following simple program, I get SIGSEGV in memset().
But if I replace mmap64() with mmap() - it works fine.
I verified this on ppc64, em64t, amd64.

Whats happening here ? Any clues ?

Thanks,
Badari

[root@localhost ~]# ./tst junk
Segmentation fault

strace output: 
...

open("junk", O_RDWR|O_CREAT, 0644)      = 3
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"...,
4096) = 4096
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) =
0x2aaaaaaac000
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
Process 26736 detached


[-- Attachment #2: tst.c --]
[-- Type: text/x-csrc, Size: 542 bytes --]

#include <fcntl.h>
#include <stdio.h>
#include <sys/mman.h>

char buf[4096];
int main(int argc, char* argv[])
{
  int fd;
  char *start;

  if (argc < 2) {
	printf("Usage: %s <filename>\n", argv[0]);
	exit(1);
  }
  fd = open(argv[1], O_RDWR | O_CREAT , 0644);
  if (fd < 0) {
	perror("open");
	exit(1);
  }
  if (write(fd, buf, 4096) < 0) {
	perror("write");
	exit(2);
  } 
  start = (char *)mmap64(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (!start) {
	perror("mmap64");
	exit(2);
  }
  memset(start, 0, 4096);
  exit(0);	
}

             reply	other threads:[~2005-11-22 16:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-22 16:34 Badari Pulavarty [this message]
2005-11-22 20:21 ` mmap64() behaviour on 64-bit machines ? Nicholas Miell

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=1132677293.24066.242.camel@localhost.localdomain \
    --to=pbadari@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    /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