1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
/*
* osutil
*
* Copyright (C) 2012 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact:
* SeokYeon Hwang <syeon.hwang@samsung.com>
* MunKyu Im <munkyu.im@samsung.com>
* Sangho Park <sangho.p@samsung.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* - S-Core Co., Ltd
*
*/
/**
@file osutil-darwin.c
@brief Collection of utilities for darwin
*/
#include <sys/sysctl.h>
#include <sys/utsname.h>
#include "png.h"
#include "osutil.h"
#include "emul_state.h"
#ifndef CONFIG_DARWIN
#error
#endif
#include "new_debug_ch.h"
DECLARE_DEBUG_CHANNEL(osutil);
void make_vm_lock_os(void) {
make_vm_lock_posix();
}
void set_bin_path_os(char const *const exec_argv)
{
char *file_name = NULL;
char bin_path_os[PATH_MAX] = { 0, };
if (!exec_argv) {
return;
}
char *data = g_strdup(exec_argv);
if (!data) {
LOG_WARNING("Fail to strdup for paring a binary directory.\n");
return;
}
file_name = g_strrstr(data, "/");
if (!file_name) {
free(data);
return;
}
g_strlcpy(bin_path_os, data, strlen(data) - strlen(file_name) + 1);
g_strlcat(bin_path_os, "/", PATH_MAX);
free(data);
bin_path = g_strdup(bin_path_os);
}
int get_number_of_processors(void)
{
int mib[2], sys_num = 0;
size_t len;
mib[0] = CTL_HW;
mib[1] = HW_AVAILCPU;
sysctl(mib, 2, &sys_num, &len, NULL, 0);
if (sys_num < 1) {
mib[1] = HW_NCPU;
sysctl(mib, 2, &sys_num, &len, NULL, 0);
if (sys_num < 1) {
sys_num = 1;
}
}
LOG_INFO("* Number of processors : %d\n", sys_num);
return sys_num;
}
void print_system_info_os(void)
{
struct utsname utsname;
LOG_INFO("* Mac\n");
LOG_INFO("* LibPNG Version : %s\n", PNG_LIBPNG_VER_STRING);
/* uname */
LOG_INFO("* Host machine uname :\n");
if (uname(&utsname) == 0) {
LOG_INFO("* Host machine uname : %s %s %s %s %s\n",
utsname.sysname, utsname.nodename,
utsname.release, utsname.version,
utsname.machine);
}
/* hw information */
int mib[2];
size_t len;
char *sys_info;
int sys_num = 0;
mib[0] = CTL_HW;
mib[1] = HW_MODEL;
sysctl(mib, 2, NULL, &len, NULL, 0);
sys_info = malloc(len * sizeof(char));
if (sysctl(mib, 2, sys_info, &len, NULL, 0) >= 0) {
LOG_INFO("* Machine model : %s\n", sys_info);
}
free(sys_info);
mib[0] = CTL_HW;
mib[1] = HW_MACHINE;
sysctl(mib, 2, NULL, &len, NULL, 0);
sys_info = malloc(len * sizeof(char));
if (sysctl(mib, 2, sys_info, &len, NULL, 0) >= 0) {
LOG_INFO("* Machine class : %s\n", sys_info);
}
free(sys_info);
#if 0
mib[0] = CTL_HW;
mib[1] = HW_NCPU;
len = sizeof(sys_num);
if (sysctl(mib, 2, &sys_num, &len, NULL, 0) >= 0) {
LOG_INFO("* Number of processors : %d\n", sys_num);
}
#endif
get_number_of_processors();
mib[0] = CTL_HW;
mib[1] = HW_PHYSMEM;
len = sizeof(sys_num);
if (sysctl(mib, 2, &sys_num, &len, NULL, 0) >= 0) {
LOG_INFO("* Total memory : %llu bytes\n", sys_num);
}
}
bool make_sdcard_lock_os(char *sdcard)
{
return make_sdcard_lock_posix(sdcard);
}
int remove_sdcard_lock_os(char *sdcard)
{
return remove_sdcard_lock_posix(sdcard);
}
|