public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* mmap64() behaviour on 64-bit machines ?
@ 2005-11-22 16:34 Badari Pulavarty
  2005-11-22 20:21 ` Nicholas Miell
  0 siblings, 1 reply; 2+ messages in thread
From: Badari Pulavarty @ 2005-11-22 16:34 UTC (permalink / raw)
  To: lkml

[-- 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);	
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: mmap64() behaviour on 64-bit machines ?
  2005-11-22 16:34 mmap64() behaviour on 64-bit machines ? Badari Pulavarty
@ 2005-11-22 20:21 ` Nicholas Miell
  0 siblings, 0 replies; 2+ messages in thread
From: Nicholas Miell @ 2005-11-22 20:21 UTC (permalink / raw)
  To: Badari Pulavarty; +Cc: lkml

On Tue, 2005-11-22 at 08:34 -0800, Badari Pulavarty wrote:
> 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 ?

If I fix all the compiler warnings, it works for me.

Also, mmap/mmap64 return MAP_FAILED on failure, not 0, but the compiler
doesn't know to warn about that.

-- 
Nicholas Miell <nmiell@comcast.net>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-11-22 20:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-22 16:34 mmap64() behaviour on 64-bit machines ? Badari Pulavarty
2005-11-22 20:21 ` Nicholas Miell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox