1 /**************************************************************************
3 * Copyright 2008-2010 Vmware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
34 #if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
36 #ifndef WIN32_LEAN_AND_MEAN
37 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
50 #if defined(PIPE_OS_LINUX) || defined(PIPE_OS_CYGWIN)
52 #elif defined(PIPE_OS_APPLE) || defined(PIPE_OS_BSD)
53 # include <sys/sysctl.h>
54 #elif defined(PIPE_OS_HAIKU)
55 # include <kernel/OS.h>
56 #elif defined(PIPE_OS_WINDOWS)
59 #error unexpected platform in os_sysinfo.c
64 os_log_message(const char *message
)
66 /* If the GALLIUM_LOG_FILE environment variable is set to a valid filename,
67 * write all messages to that file.
69 static FILE *fout
= NULL
;
73 const char *filename
= os_get_option("GALLIUM_LOG_FILE");
75 fout
= fopen(filename
, "w");
80 #if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
81 OutputDebugStringA(message
);
82 if(GetConsoleWindow() && !IsDebuggerPresent()) {
87 else if (fout
!= stderr
) {
91 #else /* !PIPE_SUBSYSTEM_WINDOWS */
100 os_get_option(const char *name
)
107 * Return the size of the total physical memory.
108 * \param size returns the size of the total physical memory
109 * \return true for success, or false on failure
112 os_get_total_physical_memory(uint64_t *size
)
114 #if defined(PIPE_OS_LINUX) || defined(PIPE_OS_CYGWIN)
115 const long phys_pages
= sysconf(_SC_PHYS_PAGES
);
116 const long page_size
= sysconf(_SC_PAGE_SIZE
);
118 *size
= phys_pages
* page_size
;
119 return (phys_pages
> 0 && page_size
> 0);
120 #elif defined(PIPE_OS_APPLE) || defined(PIPE_OS_BSD)
121 size_t len
= sizeof(size
);
125 #if defined(PIPE_OS_APPLE)
127 #elif defined(PIPE_OS_NETBSD) || defined(PIPE_OS_OPENBSD)
128 mib
[1] = HW_PHYSMEM64
;
129 #elif defined(PIPE_OS_FREEBSD)
132 #error Unsupported *BSD
135 return (sysctl(mib
, 2, &size
, &len
, NULL
, 0) == 0);
136 #elif defined(PIPE_OS_HAIKU)
140 ret
= get_system_info(&info
);
141 *size
= info
.max_pages
* B_PAGE_SIZE
;
142 return (ret
== B_OK
);
143 #elif defined(PIPE_OS_WINDOWS)
144 MEMORYSTATUSEX status
;
147 status
.dwLength
= sizeof(status
);
148 ret
= GlobalMemoryStatusEx(&status
);
149 *size
= status
.ullTotalPhys
;
150 return (ret
== TRUE
);
152 #error unexpected platform in os_sysinfo.c