-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
Copy pathpal_runtimeinformation.c
104 lines (97 loc) · 2.15 KB
/
pal_runtimeinformation.c
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include "pal_config.h"
#include "pal_runtimeinformation.h"
#include "pal_types.h"
#include <stdio.h>
#include <string.h>
#include <sys/utsname.h>
#if defined(TARGET_ANDROID)
#include <sys/system_properties.h>
#endif
const char* SystemNative_GetUnixName()
{
return PAL_UNIX_NAME;
}
char* SystemNative_GetUnixRelease()
{
#if defined(TARGET_ANDROID)
// get the Android API level
char sdk_ver_str[PROP_VALUE_MAX];
if (__system_property_get("ro.build.version.sdk", sdk_ver_str))
{
return strdup(sdk_ver_str);
}
else
{
return NULL;
}
#else
struct utsname _utsname;
return uname(&_utsname) != -1 ?
strdup(_utsname.release) :
NULL;
#endif
}
int32_t SystemNative_GetUnixVersion(char* version, int* capacity)
{
struct utsname _utsname;
if (uname(&_utsname) != -1)
{
int r = snprintf(version, (size_t)(*capacity), "%s %s %s", _utsname.sysname, _utsname.release, _utsname.version);
if (r > *capacity)
{
*capacity = r + 1;
return -1;
}
}
return 0;
}
/* Returns an int representing the OS Architecture:
0 - x86
1 - x64
2 - ARM
3 - ARM64
4 - WASM */
int32_t SystemNative_GetOSArchitecture()
{
#if defined(TARGET_ARM)
return ARCH_ARM;
#elif defined(TARGET_ARM64)
return ARCH_ARM64;
#elif defined(TARGET_AMD64)
return ARCH_X64;
#elif defined(TARGET_X86)
return ARCH_X86;
#elif defined(TARGET_WASM)
return ARCH_WASM;
#elif defined(TARGET_S390X)
return ARCH_S390X;
#else
#error Unidentified Architecture
#endif
}
/* Returns an int representing the OS Architecture:
0 - x86
1 - x64
2 - ARM
3 - ARM64
4 - WASM */
int32_t SystemNative_GetProcessArchitecture()
{
#if defined(TARGET_ARM)
return ARCH_ARM;
#elif defined(TARGET_ARM64)
return ARCH_ARM64;
#elif defined(TARGET_AMD64)
return ARCH_X64;
#elif defined(TARGET_X86)
return ARCH_X86;
#elif defined(TARGET_WASM)
return ARCH_WASM;
#elif defined(TARGET_S390X)
return ARCH_S390X;
#else
#error Unidentified Architecture
#endif
}