Bug 3419 - Mono.Unix.Native.MmapFlags.MAP_ANON validation is wrong on Mac
Summary: Mono.Unix.Native.MmapFlags.MAP_ANON validation is wrong on Mac
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.POSIX ()
Version: master
Hardware: PC Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2012-02-13 09:00 UTC by Rolf Bjarne Kvinge [MSFT]
Modified: 2012-02-27 17:43 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Proposed patch (1.43 KB, patch)
2012-02-13 09:26 UTC, Rolf Bjarne Kvinge [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Rolf Bjarne Kvinge [MSFT] 2012-02-13 09:00:37 UTC
It's 0x1000 on Mac (x64 Lion), not 0x20 as in Linux.

Simple test program:

#include <sys/mman.h>

int main() {
        printf ("EXEC: %i R: %i W: %i MAP_ANON: 0x%x, MAP_PRIVATE: %i, sizeof(size_t): %i\n", PROT_EXEC, PROT_READ, PROT_WRITE, MAP_ANON, MAP_PRIVATE, sizeof (size_t));
    return 0;
}


Linux (x64): EXEC: 4 R: 1 W: 2 MAP_ANON: 0x1000, MAP_PRIVATE: 2, sizeof(size_t): 8
Mac (x64): EXEC: 4 R: 1 W: 2 MAP_ANON: 0x1000, MAP_PRIVATE: 2, sizeof(size_t): 8
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-02-13 09:01:12 UTC
err, c&p error, the correct is:

Linux: EXEC: 4 R: 1 W: 2 MAP_ANON: 0x20, MAP_PRIVATE: 2, sizeof(size_t): 8
Comment 2 Rolf Bjarne Kvinge [MSFT] 2012-02-13 09:26:11 UTC
Created attachment 1353 [details]
Proposed patch

The issue is really that the parameter validation is wrong. See attached patch for more information (in short it's impossible to pass MAP_ANON to mmap on a Mac).
Comment 3 Rolf Bjarne Kvinge [MSFT] 2012-02-20 19:25:48 UTC
So, map.c seems to be a generated file. The bug is still there though, even though the patch isn't the right one.
Comment 4 Miguel de Icaza [MSFT] 2012-02-25 01:17:13 UTC
But can you describe what the problem was?

The internal constants are not supposed to be a 1:1 mapping to the system constant, we have an intermediate layer that translates the C# values to the native values.
Comment 5 Rolf Bjarne Kvinge [MSFT] 2012-02-27 07:05:30 UTC
The problem is the parameter validation and the fact that two constants have the same value.

We fail validation if managed code sets a flag that doesn't exist in native code. We also have two flags with the same value (MAP_ANONYMOUS and MAP_ANON) in managed code. In OSX MAP_ANON doesn't exist (but MAP_ANONYMOUS does). Combining all this: when the managed MAP_ANON[YMOUS] flag is set, we enter the MAP_ANON validation in native code, which fails since MAP_ANON isn't defined on OSX.
Comment 6 Miguel de Icaza [MSFT] 2012-02-27 09:06:59 UTC
Jon, can you take over this?
Comment 7 Jonathan Pryor 2012-02-27 17:43:19 UTC
Fixed in master/163f9061

I didn't want to change map.c (it would get overwritten the next time create-native-map was executed), so I opted for the easier route of changing mph.h and having MAP_ANONYMOUS alias MAP_ANON:

+#ifdef PLATFORM_MACOSX
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS MAP_ANON
+#endif  /* ndef MAP_ANONYMOUS */
+endif  /* ndef PLATFORM_MACOSX */