37 #if defined(HAVE_SYS_SYSCTL_H) && !defined(_WIN32) && !defined(__linux__)
38 #include <sys/sysctl.h>
41 #if defined(HW_PHYSMEM64)
43 #define INT64_HW_MEM HW_PHYSMEM64
44 #elif defined(HW_MEMSIZE)
46 #define INT64_HW_MEM HW_MEMSIZE
56 #if defined(__linux__)
59 unsigned long long result=0;
73 if (sscanf(cp,
"MemTotal: %llu kB\n", &result) != 1)
86 #elif defined (_WIN32)
89 memset(&ms, 0,
sizeof(ms));
90 ms.dwLength =
sizeof(ms);
91 if (! GlobalMemoryStatusEx(&ms))
94 return ms.ullTotalPhys;
96 #elif defined(HAVE_SYSCTL) && defined(INT64_HW_MEM)
100 size_t len =
sizeof(memsize);
101 int mib[2] = {CTL_HW, INT64_HW_MEM};
102 if (sysctl(mib,2,&memsize,&len,NULL,0))
107 #elif defined(HAVE_SYSCTL) && defined(HW_PHYSMEM)
111 size_t len =
sizeof(memsize);
112 int mib[2] = {CTL_HW, HW_PHYSMEM};
113 if (sysctl(mib,2,&memsize,&len,NULL,0))
131 static size_t mem_cached=0;
136 if (0 == mem_cached) {
142 *mem_out = mem_cached;
147 #if SIZE_MAX != UINT64_MAX
156 *mem_out = mem_cached = (size_t) m;
Utility macros to handle different features and behavior in different compilers.
Wrappers for reading and writing data to files on disk.
int tor_open_cloexec(const char *path, int flags, unsigned mode)
char * read_file_to_str_until_eof(int fd, size_t max_bytes_to_read, size_t *sz_out) ATTR_MALLOC
Headers for util_malloc.c.
static uint64_t get_total_system_memory_impl(void)
int get_total_system_memory(size_t *mem_out)
#define MOCK_IMPL(rv, funcname, arglist)
Integer definitions used throughout Tor.
const char * find_str_at_start_of_line(const char *haystack, const char *needle)
Header for util_string.c.