[email protected] | 167ec82 | 2011-10-24 22:05:27 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 5f5ac6a | 2009-11-23 21:57:11 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/sys_info.h" |
| 6 | |
[email protected] | e43eddf1 | 2009-12-29 00:32:52 | [diff] [blame] | 7 | #include <sys/sysctl.h> |
| 8 | |
[email protected] | 5f5ac6a | 2009-11-23 21:57:11 | [diff] [blame] | 9 | #include "base/logging.h" |
| 10 | |
| 11 | namespace base { |
| 12 | |
avi | dd4e61435 | 2015-12-09 00:44:49 | [diff] [blame] | 13 | int64_t SysInfo::AmountOfPhysicalMemory() { |
[email protected] | 5f5ac6a | 2009-11-23 21:57:11 | [diff] [blame] | 14 | int pages, page_size; |
| 15 | size_t size = sizeof(pages); |
| 16 | sysctlbyname("vm.stats.vm.v_page_count", &pages, &size, NULL, 0); |
| 17 | sysctlbyname("vm.stats.vm.v_page_size", &page_size, &size, NULL, 0); |
| 18 | if (pages == -1 || page_size == -1) { |
| 19 | NOTREACHED(); |
| 20 | return 0; |
| 21 | } |
avi | dd4e61435 | 2015-12-09 00:44:49 | [diff] [blame] | 22 | return static_cast<int64_t>(pages) * page_size; |
[email protected] | 5f5ac6a | 2009-11-23 21:57:11 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | // static |
avi | dd4e61435 | 2015-12-09 00:44:49 | [diff] [blame] | 26 | uint64_t SysInfo::MaxSharedMemorySize() { |
[email protected] | 5f5ac6a | 2009-11-23 21:57:11 | [diff] [blame] | 27 | size_t limit; |
| 28 | size_t size = sizeof(limit); |
[email protected] | 167ec82 | 2011-10-24 22:05:27 | [diff] [blame] | 29 | if (sysctlbyname("kern.ipc.shmmax", &limit, &size, NULL, 0) < 0) { |
| 30 | NOTREACHED(); |
| 31 | return 0; |
| 32 | } |
avi | dd4e61435 | 2015-12-09 00:44:49 | [diff] [blame] | 33 | return static_cast<uint64_t>(limit); |
[email protected] | 5f5ac6a | 2009-11-23 21:57:11 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | } // namespace base |