473,405 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

trying to use mmap on PC with cygwin.

I'm trying to get mmap to working, potentially large files.

Here's my data
[a0312850@LTA0312850 ~/tool_box]$ ls -l DATA/LaffAdd.1
-rwx------+ 1 a0312850 ???????? 255 Jul 24 2006 DATA/LaffAdd.1
Here's a snippett of my code
int main(int argc,char* argv[]) {
int token;
if (argc != 2) Help();
char* laff = argv[1];
fp = fopen(laff,"r");
struct stat st;
fstat(fileno(fp),&st);
buflen = st.st_size;
buffer = (char*)mmap(0,buflen,PROT_READ,MAP_SHARED,fileno(f p),0);
bufend = buffer + buflen;
long read = fread(buffer,1,buflen,fp); seg fault here

buflen is 255
Looking at buffer (in ddd) it appears to have mapped it into buffer

a bt shows
(gdb) bt
#0 0x61016545 in stack_info::walk () from /usr/bin/cygwin1.dll
#1 0x7c859dcc in OutputDebugStringA () from /cygdrive/c/WINDOWS/
system32/kernel32.dll
#2 0x40010006 in ?? ()
#3 0x00000000 in ?? ()

Apr 13 '07 #1
2 3295
In article <11**********************@n59g2000hsh.googlegroups .com>,
comp.unix.shell <bi*********@sbcglobal.netwrote:
>I'm trying to get mmap to working, potentially large files.
Well, this is not really a C problem, but:
buffer = (char*)mmap(0,buflen,PROT_READ,MAP_SHARED,fileno(f p),0);
long read = fread(buffer,1,buflen,fp); seg fault here
The idea of memory mapping is that you can access the files as memory,
and don't have to use i/o operations like fread(). buffer should already
contain the data from the file!

The segmentation fault is probably because the memory returned by
mmap() is read-only.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Apr 13 '07 #2
comp.unix.shell wrote, On 13/04/07 16:15:
I'm trying to get mmap to working, potentially large files.
mmap is off topic here. We only deal with standard C, system specific
functions are covered in the relevant system specific groups, such as
comp.unix.programmer for Unix and Unix like systems.
Here's my data
[a0312850@LTA0312850 ~/tool_box]$ ls -l DATA/LaffAdd.1
-rwx------+ 1 a0312850 ???????? 255 Jul 24 2006 DATA/LaffAdd.1
Here's a snippett of my code
Snippets are bad. If you don't know what the problem is how do you know
it is not in the code you have left out? How do we know? You should post
small COMPLETE compilable programs and they should be copied and pasted,
NOT retyped.
int main(int argc,char* argv[]) {
int token;
if (argc != 2) Help();
How can we tell that the Help function has not corrupted memory causing
the fault? We would know if you provided a complete program.
char* laff = argv[1];
fp = fopen(laff,"r");
Have you included stdio.h? We would know if you provided a complete program.

What happens if fopen fails?
struct stat st;
In C89, the most commonly implemented standard, you cannot intermix
statements and definitions. This was added in C99, but very few
compilers completely and correctly implement C99, for example GNU
document that gcc is not C99 compliant yet.
fstat(fileno(fp),&st);
Oh dear, you might have passed a null pointer to fileno, can it handle
it? Can fstat handle whatever fileno returns if it was passed a null
pointer?
buflen = st.st_size;
buffer = (char*)mmap(0,buflen,PROT_READ,MAP_SHARED,fileno(f p),0);
In C it is very rare that you need the cast. A very common reason we see
here for people adding casts is that they have made some other mistake,
such as failing to provide a prototype for a function returning a pointer.
bufend = buffer + buflen;
long read = fread(buffer,1,buflen,fp); seg fault here

buflen is 255
Looking at buffer (in ddd) it appears to have mapped it into buffer

a bt shows
(gdb) bt
#0 0x61016545 in stack_info::walk () from /usr/bin/cygwin1.dll
#1 0x7c859dcc in OutputDebugStringA () from /cygdrive/c/WINDOWS/
system32/kernel32.dll
#2 0x40010006 in ?? ()
#3 0x00000000 in ?? ()
Looks to me like you have clobbered your stack.

If comp.unix.programmer does not cover Cygwin they might still answer
questions about mmap, failing that there are mailing lists for Cygwin.
--
Flash Gordon
Apr 13 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Michael | last post by:
I'm writing an application that decodes a file containing binary records. Each record is a particular event type. Each record is translated into ASCII and then written to a file. Each file contains...
2
by: bite me if you can... | last post by:
The prototype of mmap() is: void * mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset); The second argument len is used to tell mmap() how many bytes I want to map. My...
4
by: Fabiano Sidler | last post by:
Hi folks! I created an mmap object like so: --- snip --- from mmap import mmap,MAP_ANONYMOUS,MAP_PRIVATE fl = file('/dev/zero','rw') mm = mmap(fl.fileno(), 1, MAP_PRIVATE|MAP_ANONYMOUS) ---...
2
by: beejisbrigit | last post by:
Hi there, I was wondering if anyone had experience with File I/O in Java vs. C++ using mmap(), and knew if the performance was better in one that the other, or more or less negligible. My...
1
by: koara | last post by:
Hello all, i am using the mmap module (python2.4) to access contents of a file. My question regards the relative performance of mmap.seek() vs mmap.tell(). I have a generator that returns...
2
by: Neal Becker | last post by:
On linux, I don't understand why: f = open ('/dev/eos', 'rw') m = mmap.mmap(f.fileno(), 1000000, prot=mmap.PROT_READ|mmap.PROT_WRITE, flags=mmap.MAP_SHARED) gives 'permission denied', but...
0
by: Kris Kennaway | last post by:
If I do the following: def mmap_search(f, string): fh = file(f) mm = mmap.mmap(fh.fileno(), 0, mmap.MAP_SHARED, mmap.PROT_READ) return mm.find(string) def mmap_is_in(f, string): fh =...
0
by: Gabriel Genellina | last post by:
En Thu, 29 May 2008 19:17:05 -0300, Kris Kennaway <kris@FreeBSD.org> escribió: Looks like you should define the sq_contains member in mmap_as_sequence, and the type should have the...
1
by: magnus.lycka | last post by:
Does anyone recognize this little Python crasher? I'll file a bug report unless someone notices it as an already documented bug. I found some open mmap bugs, but it wasn't obvious to me that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.