1 // Copyright 2011 The Chromium Authors
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/system/sys_info.h"
6
7 #include <stddef.h>
8 #include <stdint.h>
9 #include <sys/sysctl.h>
10
11 #include "base/notreached.h"
12
13 namespace base {
14
AmountOfPhysicalMemoryImpl()15 int64_t SysInfo::AmountOfPhysicalMemoryImpl() {
16 int pages, page_size;
17 size_t size = sizeof(pages);
18 sysctlbyname("vm.stats.vm.v_page_count", &pages, &size, NULL, 0);
19 sysctlbyname("vm.stats.vm.v_page_size", &page_size, &size, NULL, 0);
20 if (pages == -1 || page_size == -1) {
21 NOTREACHED();
22 }
23 return static_cast<int64_t>(pages) * page_size;
24 }
25
26 // static
MaxSharedMemorySize()27 uint64_t SysInfo::MaxSharedMemorySize() {
28 size_t limit;
29 size_t size = sizeof(limit);
30 if (sysctlbyname("kern.ipc.shmmax", &limit, &size, NULL, 0) < 0) {
31 NOTREACHED();
32 }
33 return static_cast<uint64_t>(limit);
34 }
35
36 } // namespace base
37