delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/11/19/09:57:35

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Message-ID: <2e7d31500811190656k28244d3ev89a3c6b5ffd571e7@mail.gmail.com>
Date: Wed, 19 Nov 2008 22:56:35 +0800
From: "Carlo Florendo" <subscribermail AT gmail DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: mmap call gives invalid argument
In-Reply-To: <20081119112813.GG10351@calimero.vinschen.de>
MIME-Version: 1.0
References: <2e7d31500811182249m6c38119cv67686eaaf2e1e5e1 AT mail DOT gmail DOT com> <20081119112813 DOT GG10351 AT calimero DOT vinschen DOT de>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Note-from-DJ: This may be spam

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019