Skip to contentSkip to conversation

[5778] Use MAP_ANON also for FreeBSD (Juergen Lock)

Qemu-devel Blue Swirl 6 participants 12 messages Nov 22, 2008 – Nov 28, 2008

lore
Share & tools
lore

Blue Swirl

author
#0 lore raw

Revision: 5778

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5778
Author:   blueswir1
Date:     2008-11-22 20:43:01 +0000 (Sat, 22 Nov 2008)

Log Message:
-----------
Use MAP_ANON also for FreeBSD (Juergen Lock)

Modified Paths:
--------------
trunk/osdep.c

Modified: trunk/osdep.c
===================================================================

osdep.c +5 -2
@@ -75,8 +75,10 @@
 #include <sys/types.h>
 #include <sys/mount.h>
 #else
+#ifndef __FreeBSD__
 #include <sys/vfs.h>
 #endif
+#endif
 
 #include <sys/mman.h>
 #include <fcntl.h>
@@ -87,7 +89,8 @@
     static int phys_ram_size = 0;
     void *ptr;
 
-#ifdef __OpenBSD__ /* no need (?) for a dummy file on OpenBSD */
+/* no need (?) for a dummy file on OpenBSD/FreeBSD */
+#if defined(__OpenBSD__) || defined(__FreeBSD__)
     int map_anon = MAP_ANON;
 #else
     int map_anon = 0;
@@ -154,7 +157,7 @@
     }
     size = (size + 4095) & ~4095;
     ftruncate(phys_ram_fd, phys_ram_size + size);
-#endif /* !__OpenBSD__ */
+#endif /* !(__OpenBSD__ || __FreeBSD__) */
     ptr = mmap(NULL,
                size,
                PROT_WRITE | PROT_READ, map_anon | MAP_SHARED,
#1 lore raw

osdep.c line 93

Quoted 3 lines · Blue Swirl
osdep.c +2 -1
-#ifdef __OpenBSD__ /* no need (?) for a dummy file on OpenBSD */
+/* no need (?) for a dummy file on OpenBSD/FreeBSD */
+#if defined(__OpenBSD__) || defined(__FreeBSD__)

The same is true for Linux, btw.

#2 lore raw
Quoted 6 lines · On Sunday 23 November 2008 10:10:06 Christoph Hellwig wrote:

osdep.c line 93

Quoted 3 lines · Blue Swirl
osdep.c +2 -1
-#ifdef __OpenBSD__ /* no need (?) for a dummy file on OpenBSD */
+/* no need (?) for a dummy file on OpenBSD/FreeBSD */
+#if defined(__OpenBSD__) || defined(__FreeBSD__)

The same is true for Linux, btw.

and NetBSD, too. and Solaris, too.

Actually, this is POSIX.
Therefore, the #if line should be turned into

#ifndef _WIN32

Christoph

Signature · 12 lines
AMD Saxony, Dresden, Germany
Operating System Research Center

Legal Information:
AMD Saxony Limited Liability Company & Co. KG
Sitz (Geschäftsanschrift):
   Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland
Registergericht Dresden: HRA 4896
vertretungsberechtigter Komplementär:
   AMD Saxony LLC (Sitz Wilmington, Delaware, USA)
Geschäftsführer der AMD Saxony LLC:
   Dr. Hans-R. Deppe, Thomas McCoy
#3 lore raw
Quoted 11 lines · Christoph Egger
Quoted 6 lines · On Sunday 23 November 2008 10:10:06 Christoph Hellwig wrote:

osdep.c line 93

Quoted 3 lines · Blue Swirl
osdep.c +2 -1
-#ifdef __OpenBSD__ /* no need (?) for a dummy file on OpenBSD */
+/* no need (?) for a dummy file on OpenBSD/FreeBSD */
+#if defined(__OpenBSD__) || defined(__FreeBSD__)

The same is true for Linux, btw.

and NetBSD, too. and Solaris, too.

Actually, this is POSIX.

MAP_ANON/MAP_ANONYMOUS are not in Posix.

#4 lore raw
Quoted 9 lines · On Monday 24 November 2008 12:07:45 Christoph Hellwig wrote:
Quoted 8 lines · Christoph Egger
Quoted 6 lines · On Sunday 23 November 2008 10:10:06 Christoph Hellwig wrote:

osdep.c line 93

Quoted 3 lines · Blue Swirl
osdep.c +2 -1
-#ifdef __OpenBSD__ /* no need (?) for a dummy file on OpenBSD */
+/* no need (?) for a dummy file on OpenBSD/FreeBSD */
+#if defined(__OpenBSD__) || defined(__FreeBSD__)

The same is true for Linux, btw.

Quoted 5 lines
Quoted 3 lines

and NetBSD, too. and Solaris, too.

Actually, this is POSIX.

MAP_ANON/MAP_ANONYMOUS are not in Posix.

MAP_ANONYMOUS is GNU, MAP_ANON is Unix at least.

Christoph

Signature · 12 lines
AMD Saxony, Dresden, Germany
Operating System Research Center

Legal Information:
AMD Saxony Limited Liability Company & Co. KG
Sitz (Geschäftsanschrift):
   Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland
Registergericht Dresden: HRA 4896
vertretungsberechtigter Komplementär:
   AMD Saxony LLC (Sitz Wilmington, Delaware, USA)
Geschäftsführer der AMD Saxony LLC:
   Dr. Hans-R. Deppe, Thomas McCoy
#5 lore raw
In reply to Blue Swirl

osdep.c line 96

Quoted 6 lines · Blue Swirl
osdep.c +2 -1
-#ifdef __OpenBSD__ /* no need (?) for a dummy file on OpenBSD */
+/* no need (?) for a dummy file on OpenBSD/FreeBSD */
+#if defined(__OpenBSD__) || defined(__FreeBSD__)
     int map_anon = MAP_ANON;
 #else
     int map_anon = 0;

How about, simply:

#ifdef MAP_ANON

(Btw, on some OSes it has the name MAP_ANONYMOUS, so in my own portable code I look for both.)

-- Jamie

#6 lore raw
Quoted 10 lines · Jamie Lokier

osdep.c line 96

Quoted 6 lines · Blue Swirl
osdep.c +2 -1
-#ifdef __OpenBSD__ /* no need (?) for a dummy file on OpenBSD */
+/* no need (?) for a dummy file on OpenBSD/FreeBSD */
+#if defined(__OpenBSD__) || defined(__FreeBSD__)
     int map_anon = MAP_ANON;
 #else
     int map_anon = 0;

How about, simply:

Quoted 4 lines

#ifdef MAP_ANON

(Btw, on some OSes it has the name MAP_ANONYMOUS, so in my own portable code I look for both.)

I'm pretty sure there are OSes around that have MAP_ANON/MAP_ANONYMOUS but don't support it in combination with MAP_SHARED.

#7 lore raw
Quoted 2 lines · Christoph Hellwig

I'm pretty sure there are OSes around that have MAP_ANON/MAP_ANONYMOUS but don't support it in combination with MAP_SHARED.

Sorry, I wasn't paying attention. You're right, there are several such OSes, and I believe Linux was one of them once.

-- Jamie (will pay closer attention in future...)

#8 lore raw
In reply to Blue Swirl
Quoted 8 lines · On Saturday 22 November 2008 21:43:01 Blue Swirl wrote:

Revision: 5778

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5778
Author:   blueswir1
Date:     2008-11-22 20:43:01 +0000 (Sat, 22 Nov 2008)

Log Message:
-----------
Use MAP_ANON also for FreeBSD (Juergen Lock)

This is for *BSD in general.

osdep.c line 93

Quoted 7 lines
osdep.c +2 -1
@@ -87,7 +89,8 @@
     static int phys_ram_size = 0;
     void *ptr;
 
-#ifdef __OpenBSD__ /* no need (?) for a dummy file on OpenBSD */
+/* no need (?) for a dummy file on OpenBSD/FreeBSD */
+#if defined(__OpenBSD__) || defined(__FreeBSD__)

This should be:

#ifdef _BSD

osdep.c line 160

Quoted 9 lines
osdep.c +1 -1
     int map_anon = MAP_ANON;
 #else
     int map_anon = 0;
@@ -154,7 +157,7 @@
     }
     size = (size + 4095) & ~4095;
     ftruncate(phys_ram_fd, phys_ram_size + size);
-#endif /* !__OpenBSD__ */
+#endif /* !(__OpenBSD__ || __FreeBSD__) */

This should be

#endif /* !_BSD */

Quoted 3 lines
osdep.c +0 -0
     ptr = mmap(NULL,
                size,
                PROT_WRITE | PROT_READ, map_anon | MAP_SHARED,
Signature · 12 lines
AMD Saxony, Dresden, Germany
Operating System Research Center

Legal Information:
AMD Saxony Limited Liability Company & Co. KG
Sitz (Geschäftsanschrift):
   Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland
Registergericht Dresden: HRA 4896
vertretungsberechtigter Komplementär:
   AMD Saxony LLC (Sitz Wilmington, Delaware, USA)
Geschäftsführer der AMD Saxony LLC:
   Dr. Hans-R. Deppe, Thomas McCoy
#9 lore raw

In message: <[email protected]>
Christoph Egger <[email protected]> writes:
: On Saturday 22 November 2008 21:43:01 Blue Swirl wrote:
: > Revision: 5778

: >           http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5778
: > Author:   blueswir1
: > Date:     2008-11-22 20:43:01 +0000 (Sat, 22 Nov 2008)

: >
: > Log Message:
: > -----------
: > Use MAP_ANON also for FreeBSD (Juergen Lock)
:
: This is for *BSD in general.
:
: > @@ -87,7 +89,8 @@
: > static int phys_ram_size = 0;
: > void *ptr;
: >
: > -#ifdef __OpenBSD__ /* no need (?) for a dummy file on OpenBSD */ : > +/* no need (?) for a dummy file on OpenBSD/FreeBSD */ : > +#if defined(__OpenBSD__) || defined(__FreeBSD__)
:
: This should be:
:
: #ifdef _BSD

What defines _BSD? It is in the compiler's name space, but _BSD isn't defined by the compiler...

Warner

#10 lore raw
Quoted 28 lines · On Monday 24 November 2008 18:40:56 M. Warner Losh wrote:

In message: <[email protected]>

Christoph Egger <[email protected]> writes:
: On Saturday 22 November 2008 21:43:01 Blue Swirl wrote:
: > Revision: 5778
: >
: > http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5778 Author:
: > blueswir1
: > Date: 2008-11-22 20:43:01 +0000 (Sat, 22 Nov 2008)
: >
: > Log Message:
: > -----------
: > Use MAP_ANON also for FreeBSD (Juergen Lock)
:
: This is for *BSD in general.
:
: > @@ -87,7 +89,8 @@
: > static int phys_ram_size = 0;
: > void *ptr;
: >
: > -#ifdef __OpenBSD__ /* no need (?) for a dummy file on OpenBSD */ : > +/* no need (?) for a dummy file on OpenBSD/FreeBSD */
: > +#if defined(__OpenBSD__) || defined(__FreeBSD__)
:
: This should be:
:
: #ifdef _BSD

Quoted 2 lines

What defines _BSD? It is in the compiler's name space, but _BSD isn't defined by the compiler...

config-host.h generated by configure.

Christoph

Signature · 12 lines
AMD Saxony, Dresden, Germany
Operating System Research Center

Legal Information:
AMD Saxony Limited Liability Company & Co. KG
Sitz (Geschäftsanschrift):
   Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland
Registergericht Dresden: HRA 4896
vertretungsberechtigter Komplementär:
   AMD Saxony LLC (Sitz Wilmington, Delaware, USA)
Geschäftsführer der AMD Saxony LLC:
   Dr. Hans-R. Deppe, Thomas McCoy
#11 lore raw
Quoted 6 lines · Christoph Egger
Quoted 2 lines · On Monday 24 November 2008 18:40:56 M. Warner Losh wrote:

What defines _BSD? It is in the compiler's name space, but _BSD isn't defined by the compiler...

config-host.h generated by configure.

Hmm, why don't we have CONFIG_BSD? (We have CONFIG_WIN32, CONFIG_DARWIN, CONFIG_AIX and HOST_SOLARIS...)

Signature · 1 line
Stuart Brady