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 **************************************************************************/
36 #ifndef WIN32_LEAN_AND_MEAN
37 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
52 # define LOG_TAG "MESA"
55 #elif DETECT_OS_LINUX || DETECT_OS_CYGWIN || DETECT_OS_SOLARIS || DETECT_OS_HURD
57 #elif DETECT_OS_APPLE || DETECT_OS_BSD
58 # include <sys/sysctl.h>
60 # include <kernel/OS.h>
61 #elif DETECT_OS_WINDOWS
64 #error unexpected platform in os_sysinfo.c
69 os_log_message(const char *message
)
71 /* If the GALLIUM_LOG_FILE environment variable is set to a valid filename,
72 * write all messages to that file.
74 static FILE *fout
= NULL
;
79 const char *filename
= os_get_option("GALLIUM_LOG_FILE");
81 const char *mode
= "w";
82 if (filename
[0] == '+') {
83 /* If the filename is prefixed with '+' then open the file for
84 * appending instead of normal writing.
87 filename
++; /* skip the '+' */
89 fout
= fopen(filename
, mode
);
97 OutputDebugStringA(message
);
98 if(GetConsoleWindow() && !IsDebuggerPresent()) {
100 fputs(message
, fout
);
103 else if (fout
!= stderr
) {
104 fputs(message
, fout
);
107 #else /* !DETECT_OS_WINDOWS */
109 fputs(message
, fout
);
111 # if DETECT_OS_ANDROID
112 LOG_PRI(ANDROID_LOG_ERROR
, LOG_TAG
, "%s", message
);
118 #if !defined(EMBEDDED_DEVICE)
120 os_get_option(const char *name
)
124 #endif /* !EMBEDDED_DEVICE */
128 * Return the size of the total physical memory.
129 * \param size returns the size of the total physical memory
130 * \return true for success, or false on failure
133 os_get_total_physical_memory(uint64_t *size
)
135 #if DETECT_OS_LINUX || DETECT_OS_CYGWIN || DETECT_OS_SOLARIS || DETECT_OS_HURD
136 const long phys_pages
= sysconf(_SC_PHYS_PAGES
);
137 const long page_size
= sysconf(_SC_PAGE_SIZE
);
139 if (phys_pages
<= 0 || page_size
<= 0)
142 *size
= (uint64_t)phys_pages
* (uint64_t)page_size
;
144 #elif DETECT_OS_APPLE || DETECT_OS_BSD
145 size_t len
= sizeof(*size
);
151 #elif DETECT_OS_NETBSD || DETECT_OS_OPENBSD
152 mib
[1] = HW_PHYSMEM64
;
153 #elif DETECT_OS_FREEBSD
155 #elif DETECT_OS_DRAGONFLY
158 #error Unsupported *BSD
161 return (sysctl(mib
, 2, size
, &len
, NULL
, 0) == 0);
162 #elif DETECT_OS_HAIKU
166 ret
= get_system_info(&info
);
167 if (ret
!= B_OK
|| info
.max_pages
<= 0)
170 *size
= (uint64_t)info
.max_pages
* (uint64_t)B_PAGE_SIZE
;
172 #elif DETECT_OS_WINDOWS
173 MEMORYSTATUSEX status
;
176 status
.dwLength
= sizeof(status
);
177 ret
= GlobalMemoryStatusEx(&status
);
178 *size
= status
.ullTotalPhys
;
179 return (ret
== TRUE
);
181 #error unexpected platform in os_sysinfo.c