Git development
 help / color / mirror / Atom feed
From: Johannes Sixt <j.sixt@viscovery.net>
To: Vasyl Vavrychuk <vvavrychuk@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] mmap implementation for mingw.
Date: Fri, 21 Nov 2008 08:59:21 +0100	[thread overview]
Message-ID: <49266A59.4010404@viscovery.net> (raw)
In-Reply-To: <loom.20081121T024302-370@post.gmane.org>

Vasyl Vavrychuk schrieb:
> Here is simple and restricted implementation of mmap using CreateFileMapping, 
> MapViewOfFile.

Thanks. Sign-off?

Did you notice any differences with this? Or is this change just
because-we-can?

It doesn't pass the test suite, for example t5301-sliding-window.sh fails.

> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -994,3 +994,30 @@ void mingw_open_html(const char *unixpath)
>  	printf("Launching default browser to display HTML ...\n");
>  	ShellExecute(NULL, "open", htmlpath, NULL, "\\", 0);
>  }
> +
> +void *mingw_mmap(void *start, size_t length, int prot, int flags, int fd, 
> off_t offset)
> +{
> +	HANDLE handle;
> +
> +	if (start != NULL || !(flags & MAP_PRIVATE))
> +		die("Invalid usage of mingw_mmap");

I tend to use this idiom:

		return errno = EINVAL,
			 error("Invalid usage of mingw_mmap");

> +	if (offset % getpagesize() != 0)
> +		die("Offset does not match the memory allocation granularity");

This is dangerous. Because on MinGW getpagesize() is hard-coded to 0x1000.
getpagesize() does not consult GetSystemInfo(). Just skip the check;
MapViewOfFile() will report the error later anyway. Or better carefully
compute a suitable offset and adjust the length accordingly.

> +
> +	handle = CreateFileMapping((HANDLE)_get_osfhandle(fd), NULL, 
> PAGE_WRITECOPY,
> +			0, 0, NULL);
> +
> +	if (handle != NULL) {
> +		start = MapViewOfFile(handle, FILE_MAP_COPY, 0, offset, 
> length);
> +		CloseHandle(handle);
> +	}
> +
> +	return start;

Upon failure you should return MAP_FAILED, not NULL.

> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -175,10 +175,12 @@ static inline const char *skip_prefix(const char *str, 
> const char *prefix)
>  #define MAP_FAILED ((void*)-1)
>  #endif
>  
> +#ifndef __MINGW32__
>  #define mmap git_mmap
>  #define munmap git_munmap
>  extern void *git_mmap(void *start, size_t length, int prot, int flags, int fd, 
> off_t offset);
>  extern int git_munmap(void *start, size_t length);
> +#endif
>  
>  /* This value must be multiple of (pagesize * 2) */
>  #define DEFAULT_PACKED_GIT_WINDOW_SIZE (1 * 1024 * 1024)

This is inside #ifdef NO_MMAP ... #else section. Isn't that a bit strange?
I.e. we say NO_MMAP, but then we do have mmap() now?

-- Hannes

  reply	other threads:[~2008-11-21  8:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-21  2:50 [PATCH] mmap implementation for mingw Vasyl Vavrychuk
2008-11-21  7:59 ` Johannes Sixt [this message]
2008-11-21  8:57   ` Vasyl' Vavrychuk
2008-11-21  9:44     ` Johannes Sixt
2008-11-21 10:48     ` Johannes Schindelin
2008-11-21 20:25       ` Bryan Donlan
2008-11-21 20:51         ` Johannes Schindelin

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=49266A59.4010404@viscovery.net \
    --to=j.sixt@viscovery.net \
    --cc=git@vger.kernel.org \
    --cc=vvavrychuk@gmail.com \
    /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