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]

Re: mmap call gives invalid argument


On Wed, Nov 19, 2008 at 7:28 PM, Corinna Vinschen wrote:
> On Nov 19 14:49, Carlo Florendo wrote:
>> Good day Cygwin gurus,
>>
<snip>
>> $ ./dmidecode.exe
>> # dmidecode 2.9
>> SMBIOS 2.5 present.
>> 54 structures occupying 1495 bytes.
>> Table at 0x3BEE3000.
>>
>> /dev/mem: mmap: Invalid argument
>
> Can you please extract the mmap call from the source and show it
> to us?  Apparently the new dmidecode release uses some argument
> not supported by Cygwin (or not in this circumstances).
>

Thanks Corinna.

The file that calls mmap is:

$ grep -nre mmap *.c
util.c:125:      * Please note that we don't use mmap() for
performance reasons here,
util.c:129:     mmp=mmap(0, mmoffset+len, PROT_READ, MAP_SHARED, fd,
base-mmoffset);
util.c:133:             perror("mmap");

The relevant portion in the file util.c that calls mmap is:

#ifdef USE_MMAP
#ifdef _SC_PAGESIZE
        mmoffset=base%sysconf(_SC_PAGESIZE);
#else
        mmoffset=base%getpagesize();
#endif /* _SC_PAGESIZE */
        /*
         * Please note that we don't use mmap() for performance reasons here,
         * but to workaround problems many people encountered when trying
         * to read from /dev/mem using regular read() calls.
         */
        mmp=mmap(0, mmoffset+len, PROT_READ, MAP_SHARED, fd, base-mmoffset);
        if(mmp==MAP_FAILED)
        {
                fprintf(stderr, "%s: ", devmem);
                perror("mmap");
                free(p);
                return NULL;
        }

        memcpy(p, (u8 *)mmp+mmoffset, len);

        if(munmap(mmp, mmoffset+len)==-1)
        {
                fprintf(stderr, "%s: ", devmem);
                perror("munmap");
        }
#else /* USE_MMAP */


This is the only part of the entire code suite that calls mmap.

The build structure is straightforward and doesn't require
autoconf/configure.  In the code config.h, and if I'm not mistaken, it
is the only file where we could tweak and alter the build directives,
there is code that specifies whether mmap would be used or not:

/*
 * Configuration
 */

#ifndef CONFIG_H
#define CONFIG_H

/* Default memory device file */
#ifdef __BEOS__
#define DEFAULT_MEM_DEV "/dev/misc/mem"
#else
#define DEFAULT_MEM_DEV "/dev/mem"
#endif

/* Use mmap or not */
#ifndef __BEOS__
#define USE_MMAP
#endif

/* Use memory alignment workaround or not */
#ifdef __ia64__
#define ALIGNMENT_WORKAROUND
#endif

#endif

If I undefine USE_MMAP, then rebuild, then I get an lseek error
instead of an mmap error, shown below:

$ ./dmidecode.exe
# dmidecode 2.9
SMBIOS 2.5 present.
54 structures occupying 1495 bytes.
Table at 0x3BEE3000.

/dev/mem: lseek: Invalid argument
Table is unreachable, sorry. Try compiling dmidecode with -DUSE_MMAP.

I'm still at a loss :)

Thank you very much.

Best Regards,

Carlo



-- 
Carlo Florendo
Software Engineer
Astra Philippines - Software Development and Outsourcing
R&D: http://astra.ph, Astra Group: http://astra.co.jp

--
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]