1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/sys_info.h"
7 #include <ApplicationServices/ApplicationServices.h>
8 #include <CoreServices/CoreServices.h>
9 #include <mach/mach_host.h>
10 #include <mach/mach_init.h>
11 #include <sys/sysctl.h>
12 #include <sys/types.h>
14 #include "base/logging.h"
15 #include "base/mac/scoped_mach_port.h"
16 #include "base/strings/stringprintf.h"
21 std::string
SysInfo::OperatingSystemName() {
26 std::string
SysInfo::OperatingSystemVersion() {
27 int32 major
, minor
, bugfix
;
28 OperatingSystemVersionNumbers(&major
, &minor
, &bugfix
);
29 return base::StringPrintf("%d.%d.%d", major
, minor
, bugfix
);
33 void SysInfo::OperatingSystemVersionNumbers(int32
* major_version
,
35 int32
* bugfix_version
) {
36 Gestalt(gestaltSystemVersionMajor
,
37 reinterpret_cast<SInt32
*>(major_version
));
38 Gestalt(gestaltSystemVersionMinor
,
39 reinterpret_cast<SInt32
*>(minor_version
));
40 Gestalt(gestaltSystemVersionBugFix
,
41 reinterpret_cast<SInt32
*>(bugfix_version
));
45 int64
SysInfo::AmountOfPhysicalMemory() {
46 struct host_basic_info hostinfo
;
47 mach_msg_type_number_t count
= HOST_BASIC_INFO_COUNT
;
48 base::mac::ScopedMachSendRight
host(mach_host_self());
49 int result
= host_info(host
,
51 reinterpret_cast<host_info_t
>(&hostinfo
),
53 if (result
!= KERN_SUCCESS
) {
57 DCHECK_EQ(HOST_BASIC_INFO_COUNT
, count
);
58 return static_cast<int64
>(hostinfo
.max_mem
);
62 int64
SysInfo::AmountOfAvailablePhysicalMemory() {
63 base::mac::ScopedMachSendRight
host(mach_host_self());
64 vm_statistics_data_t vm_info
;
65 mach_msg_type_number_t count
= HOST_VM_INFO_COUNT
;
67 if (host_statistics(host
.get(),
69 reinterpret_cast<host_info_t
>(&vm_info
),
70 &count
) != KERN_SUCCESS
) {
75 return static_cast<int64
>(
76 vm_info
.free_count
- vm_info
.speculative_count
) * PAGE_SIZE
;
80 std::string
SysInfo::CPUModelName() {
82 size_t len
= arraysize(name
);
83 if (sysctlbyname("machdep.cpu.brand_string", &name
, &len
, NULL
, 0) == 0)
88 std::string
SysInfo::HardwareModelName() {
90 size_t len
= sizeof(model
);
91 if (sysctlbyname("hw.model", model
, &len
, NULL
, 0) == 0)
92 return std::string(model
, 0, len
);