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) || defined(PIPE_OS_SOLARIS)
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
;
74 const char *filename
= os_get_option("GALLIUM_LOG_FILE");
76 const char *mode
= "w";
77 if (filename
[0] == '+') {
78 /* If the filename is prefixed with '+' then open the file for
79 * appending instead of normal writing.
82 filename
++; /* skip the '+' */
84 fout
= fopen(filename
, mode
);
91 #if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
92 OutputDebugStringA(message
);
93 if(GetConsoleWindow() && !IsDebuggerPresent()) {
98 else if (fout
!= stderr
) {
102 #else /* !PIPE_SUBSYSTEM_WINDOWS */
104 fputs(message
, fout
);
110 #if !defined(PIPE_SUBSYSTEM_EMBEDDED)
112 os_get_option(const char *name
)
116 #endif /* !PIPE_SUBSYSTEM_EMBEDDED */
120 * Return the size of the total physical memory.
121 * \param size returns the size of the total physical memory
122 * \return true for success, or false on failure
125 os_get_total_physical_memory(uint64_t *size
)
127 #if defined(PIPE_OS_LINUX) || defined(PIPE_OS_CYGWIN) || defined(PIPE_OS_SOLARIS)
128 const long phys_pages
= sysconf(_SC_PHYS_PAGES
);
129 const long page_size
= sysconf(_SC_PAGE_SIZE
);
131 if (phys_pages
<= 0 || page_size
<= 0)
134 *size
= (uint64_t)phys_pages
* (uint64_t)page_size
;
136 #elif defined(PIPE_OS_APPLE) || defined(PIPE_OS_BSD)
137 size_t len
= sizeof(*size
);
141 #if defined(PIPE_OS_APPLE)
143 #elif defined(PIPE_OS_NETBSD) || defined(PIPE_OS_OPENBSD)
144 mib
[1] = HW_PHYSMEM64
;
145 #elif defined(PIPE_OS_FREEBSD)
147 #elif defined(PIPE_OS_DRAGONFLY)
150 #error Unsupported *BSD
153 return (sysctl(mib
, 2, size
, &len
, NULL
, 0) == 0);
154 #elif defined(PIPE_OS_HAIKU)
158 ret
= get_system_info(&info
);
159 if (ret
!= B_OK
|| info
.max_pages
<= 0)
162 *size
= (uint64_t)info
.max_pages
* (uint64_t)B_PAGE_SIZE
;
164 #elif defined(PIPE_OS_WINDOWS)
165 MEMORYSTATUSEX status
;
168 status
.dwLength
= sizeof(status
);
169 ret
= GlobalMemoryStatusEx(&status
);
170 *size
= status
.ullTotalPhys
;
171 return (ret
== TRUE
);
173 #error unexpected platform in os_sysinfo.c