blob: ff1ec5c1e69bb8b1cdce2eb08fc1db703c780402 [file] [log] [blame]
[email protected]c6d5f8c2012-07-11 12:15:081// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]71aa16c2009-02-24 16:37:132// 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]c8587632009-11-12 02:17:197#include <ApplicationServices/ApplicationServices.h>
[email protected]71aa16c2009-02-24 16:37:138#include <CoreServices/CoreServices.h>
[email protected]c8587632009-11-12 02:17:199#include <mach/mach_host.h>
10#include <mach/mach_init.h>
avi9b6f42932015-12-26 22:15:1411#include <stddef.h>
12#include <stdint.h>
[email protected]d5df0c8c2012-09-08 09:53:0113#include <sys/sysctl.h>
14#include <sys/types.h>
[email protected]c8587632009-11-12 02:17:1915
16#include "base/logging.h"
[email protected]431d0a12012-10-16 20:17:5817#include "base/mac/scoped_mach_port.h"
avi9b6f42932015-12-26 22:15:1418#include "base/macros.h"
[email protected]c851cfd2013-06-10 20:11:1419#include "base/strings/stringprintf.h"
[email protected]71aa16c2009-02-24 16:37:1320
21namespace base {
22
23// static
[email protected]6e001bb2011-05-25 20:53:1824std::string SysInfo::OperatingSystemName() {
25 return "Mac OS X";
26}
27
28// static
29std::string SysInfo::OperatingSystemVersion() {
avidd4e614352015-12-09 00:44:4930 int32_t major, minor, bugfix;
[email protected]6e001bb2011-05-25 20:53:1831 OperatingSystemVersionNumbers(&major, &minor, &bugfix);
32 return base::StringPrintf("%d.%d.%d", major, minor, bugfix);
33}
34
35// static
avidd4e614352015-12-09 00:44:4936void SysInfo::OperatingSystemVersionNumbers(int32_t* major_version,
37 int32_t* minor_version,
38 int32_t* bugfix_version) {
[email protected]0203ed72009-07-02 13:59:0839 Gestalt(gestaltSystemVersionMajor,
[email protected]3a3e5b32009-08-21 22:30:4740 reinterpret_cast<SInt32*>(major_version));
[email protected]0203ed72009-07-02 13:59:0841 Gestalt(gestaltSystemVersionMinor,
[email protected]3a3e5b32009-08-21 22:30:4742 reinterpret_cast<SInt32*>(minor_version));
[email protected]0203ed72009-07-02 13:59:0843 Gestalt(gestaltSystemVersionBugFix,
[email protected]3a3e5b32009-08-21 22:30:4744 reinterpret_cast<SInt32*>(bugfix_version));
[email protected]71aa16c2009-02-24 16:37:1345}
46
[email protected]c8587632009-11-12 02:17:1947// static
avidd4e614352015-12-09 00:44:4948int64_t SysInfo::AmountOfPhysicalMemory() {
[email protected]c8587632009-11-12 02:17:1949 struct host_basic_info hostinfo;
50 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
[email protected]a07893f82014-05-28 23:40:0851 base::mac::ScopedMachSendRight host(mach_host_self());
markda902e182015-10-20 18:36:1352 int result = host_info(host.get(),
[email protected]c8587632009-11-12 02:17:1953 HOST_BASIC_INFO,
54 reinterpret_cast<host_info_t>(&hostinfo),
55 &count);
[email protected]c8587632009-11-12 02:17:1956 if (result != KERN_SUCCESS) {
57 NOTREACHED();
58 return 0;
59 }
[email protected]c6d5f8c2012-07-11 12:15:0860 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
avidd4e614352015-12-09 00:44:4961 return static_cast<int64_t>(hostinfo.max_mem);
[email protected]c8587632009-11-12 02:17:1962}
63
[email protected]d5df0c8c2012-09-08 09:53:0164// static
avidd4e614352015-12-09 00:44:4965int64_t SysInfo::AmountOfAvailablePhysicalMemory() {
[email protected]a07893f82014-05-28 23:40:0866 base::mac::ScopedMachSendRight host(mach_host_self());
[email protected]e6085c32012-11-07 06:58:1467 vm_statistics_data_t vm_info;
68 mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
69
70 if (host_statistics(host.get(),
71 HOST_VM_INFO,
72 reinterpret_cast<host_info_t>(&vm_info),
73 &count) != KERN_SUCCESS) {
74 NOTREACHED();
75 return 0;
76 }
77
avidd4e614352015-12-09 00:44:4978 return static_cast<int64_t>(vm_info.free_count - vm_info.speculative_count) *
79 PAGE_SIZE;
[email protected]52bdcda2012-10-27 06:10:3780}
81
82// static
[email protected]d5df0c8c2012-09-08 09:53:0183std::string SysInfo::CPUModelName() {
84 char name[256];
85 size_t len = arraysize(name);
86 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0)
87 return name;
88 return std::string();
89}
90
jeremyba4eca92014-11-06 18:47:1091std::string SysInfo::HardwareModelName() {
92 char model[256];
93 size_t len = sizeof(model);
94 if (sysctlbyname("hw.model", model, &len, NULL, 0) == 0)
95 return std::string(model, 0, len);
96 return std::string();
97}
98
[email protected]71aa16c2009-02-24 16:37:1399} // namespace base