haiku.c
Go to the documentation of this file.
1 /* Copyright libuv project contributors. All rights reserved.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  * IN THE SOFTWARE.
20  */
21 
22 #include "uv.h"
23 #include "internal.h"
24 
25 #include <FindDirectory.h> /* find_path() */
26 #include <OS.h>
27 
28 
29 void uv_loadavg(double avg[3]) {
30  avg[0] = 0;
31  avg[1] = 0;
32  avg[2] = 0;
33 }
34 
35 
36 int uv_exepath(char* buffer, size_t* size) {
37  char abspath[B_PATH_NAME_LENGTH];
38  status_t status;
39  ssize_t abspath_len;
40 
41  if (buffer == NULL || size == NULL || *size == 0)
42  return UV_EINVAL;
43 
44  status = find_path(B_APP_IMAGE_SYMBOL, B_FIND_PATH_IMAGE_PATH, NULL, abspath,
45  sizeof(abspath));
46  if (status != B_OK)
47  return UV__ERR(status);
48 
49  abspath_len = uv__strscpy(buffer, abspath, *size);
50  *size -= 1;
51  if (abspath_len >= 0 && *size > (size_t)abspath_len)
52  *size = (size_t)abspath_len;
53 
54  return 0;
55 }
56 
57 
59  status_t status;
60  system_info sinfo;
61 
62  status = get_system_info(&sinfo);
63  if (status != B_OK)
64  return 0;
65 
66  return (sinfo.max_pages - sinfo.used_pages) * B_PAGE_SIZE;
67 }
68 
69 
71  status_t status;
72  system_info sinfo;
73 
74  status = get_system_info(&sinfo);
75  if (status != B_OK)
76  return 0;
77 
78  return sinfo.max_pages * B_PAGE_SIZE;
79 }
80 
81 
83  return 0; /* Memory constraints are unknown. */
84 }
85 
86 
87 int uv_resident_set_memory(size_t* rss) {
88  area_info area;
89  ssize_t cookie;
90  status_t status;
91  thread_info thread;
92 
93  status = get_thread_info(find_thread(NULL), &thread);
94  if (status != B_OK)
95  return UV__ERR(status);
96 
97  cookie = 0;
98  *rss = 0;
99  while (get_next_area_info(thread.team, &cookie, &area) == B_OK)
100  *rss += area.ram_size;
101 
102  return 0;
103 }
104 
105 
106 int uv_uptime(double* uptime) {
107  /* system_time() returns time since booting in microseconds */
108  *uptime = (double)system_time() / 1000000;
109  return 0;
110 }
111 
112 
113 int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
114  cpu_topology_node_info* topology_infos;
115  int i;
116  status_t status;
117  system_info system;
118  uint32_t topology_count;
119  uint64_t cpuspeed;
120  uv_cpu_info_t* cpu_info;
121 
122  if (cpu_infos == NULL || count == NULL)
123  return UV_EINVAL;
124 
125  status = get_cpu_topology_info(NULL, &topology_count);
126  if (status != B_OK)
127  return UV__ERR(status);
128 
129  topology_infos = uv__malloc(topology_count * sizeof(*topology_infos));
130  if (topology_infos == NULL)
131  return UV_ENOMEM;
132 
133  status = get_cpu_topology_info(topology_infos, &topology_count);
134  if (status != B_OK) {
135  uv__free(topology_infos);
136  return UV__ERR(status);
137  }
138 
139  cpuspeed = 0;
140  for (i = 0; i < (int)topology_count; i++) {
141  if (topology_infos[i].type == B_TOPOLOGY_CORE) {
142  cpuspeed = topology_infos[i].data.core.default_frequency;
143  break;
144  }
145  }
146 
147  uv__free(topology_infos);
148 
149  status = get_system_info(&system);
150  if (status != B_OK)
151  return UV__ERR(status);
152 
153  *cpu_infos = uv__calloc(system.cpu_count, sizeof(**cpu_infos));
154  if (*cpu_infos == NULL)
155  return UV_ENOMEM;
156 
157  /* CPU time and model are not exposed by Haiku. */
158  cpu_info = *cpu_infos;
159  for (i = 0; i < (int)system.cpu_count; i++) {
160  cpu_info->model = uv__strdup("unknown");
161  cpu_info->speed = (int)(cpuspeed / 1000000);
162  cpu_info++;
163  }
164  *count = system.cpu_count;
165 
166  return 0;
167 }
uv_cpu_info_s
Definition: uv.h:1079
find_path
static WCHAR * find_path(WCHAR *env)
Definition: win/process.c:831
uv__malloc
void * uv__malloc(size_t size)
Definition: uv-common.c:75
uv_resident_set_memory
int uv_resident_set_memory(size_t *rss)
Definition: haiku.c:87
status
absl::Status status
Definition: rls.cc:251
uv_get_constrained_memory
uint64_t uv_get_constrained_memory(void)
Definition: haiku.c:82
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
uv_uptime
int uv_uptime(double *uptime)
Definition: haiku.c:106
uv_exepath
int uv_exepath(char *buffer, size_t *size)
Definition: haiku.c:36
ssize_t
intptr_t ssize_t
Definition: win.h:27
xds_interop_client.int
int
Definition: xds_interop_client.py:113
uv_cpu_info
int uv_cpu_info(uv_cpu_info_t **cpu_infos, int *count)
Definition: haiku.c:113
uv__strdup
char * uv__strdup(const char *s)
Definition: uv-common.c:55
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
uv__calloc
void * uv__calloc(size_t count, size_t size)
Definition: uv-common.c:92
uv__free
void uv__free(void *ptr)
Definition: uv-common.c:81
UV__ERR
#define UV__ERR(x)
Definition: errno.h:29
buffer
char buffer[1024]
Definition: libuv/docs/code/idle-compute/main.c:8
uv_cpu_info_s::model
char * model
Definition: uv.h:1080
uv.h
uv_get_free_memory
uint64_t uv_get_free_memory(void)
Definition: haiku.c:58
internal.h
uv__strscpy
ssize_t uv__strscpy(char *d, const char *s, size_t n)
Definition: strscpy.c:4
uv_loadavg
void uv_loadavg(double avg[3])
Definition: haiku.c:29
count
int * count
Definition: bloaty/third_party/googletest/googlemock/test/gmock_stress_test.cc:96
uv_get_total_memory
uint64_t uv_get_total_memory(void)
Definition: haiku.c:70
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
uv_cpu_info_s::speed
int speed
Definition: uv.h:1081
thread
static uv_thread_t thread
Definition: test-async-null-cb.c:29
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:00