Rizin
unix-like reverse engineering framework and cli tools
haiku.c File Reference
#include "uv.h"
#include "internal.h"
#include <FindDirectory.h>
#include <OS.h>

Go to the source code of this file.

Functions

void uv_loadavg (double avg[3])
 
int uv_exepath (char *buffer, size_t *size)
 
uint64_t uv_get_free_memory (void)
 
uint64_t uv_get_total_memory (void)
 
uint64_t uv_get_constrained_memory (void)
 
int uv_resident_set_memory (size_t *rss)
 
int uv_uptime (double *uptime)
 
int uv_cpu_info (uv_cpu_info_t **cpu_infos, int *count)
 

Function Documentation

◆ uv_cpu_info()

int uv_cpu_info ( uv_cpu_info_t **  cpu_infos,
int count 
)

Definition at line 113 of file haiku.c.

113  {
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 }
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
#define UV__ERR(x)
Definition: errno.h:29
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
int type
Definition: mipsasm.c:17
static int
Definition: sfsocketcall.h:114
unsigned int uint32_t
Definition: sftypes.h:29
unsigned long uint64_t
Definition: sftypes.h:28
char * model
Definition: uv.h:1091
int speed
Definition: uv.h:1092
char * uv__strdup(const char *s)
Definition: uv-common.c:55
void * uv__malloc(size_t size)
Definition: uv-common.c:75
void * uv__calloc(size_t count, size_t size)
Definition: uv-common.c:92
void uv__free(void *ptr)
Definition: uv-common.c:81

References count, i, int, uv_cpu_info_s::model, NULL, uv_cpu_info_s::speed, status, type, uv__calloc(), UV__ERR, uv__free(), uv__malloc(), and uv__strdup().

◆ uv_exepath()

int uv_exepath ( char *  buffer,
size_t size 
)

Definition at line 36 of file haiku.c.

36  {
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 }
voidpf void uLong size
Definition: ioapi.h:138
int size_t
Definition: sftypes.h:40
int ssize_t
Definition: sftypes.h:39
ssize_t uv__strscpy(char *d, const char *s, size_t n)
Definition: strscpy.c:25
Definition: buffer.h:15
static WCHAR * find_path(WCHAR *env)
Definition: process.c:831

References find_path(), NULL, status, UV__ERR, and uv__strscpy().

◆ uv_get_constrained_memory()

uint64_t uv_get_constrained_memory ( void  )

Definition at line 82 of file haiku.c.

82  {
83  return 0; /* Memory constraints are unknown. */
84 }

◆ uv_get_free_memory()

uint64_t uv_get_free_memory ( void  )

Definition at line 58 of file haiku.c.

58  {
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 }

References status.

◆ uv_get_total_memory()

uint64_t uv_get_total_memory ( void  )

Definition at line 70 of file haiku.c.

70  {
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 }

References status.

◆ uv_loadavg()

void uv_loadavg ( double  avg[3])

Definition at line 29 of file haiku.c.

29  {
30  avg[0] = 0;
31  avg[1] = 0;
32  avg[2] = 0;
33 }

◆ uv_resident_set_memory()

int uv_resident_set_memory ( size_t rss)

Definition at line 87 of file haiku.c.

87  {
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 }
static PTHREAD_ITEM find_thread(RzDebug *dbg, int tid)
Definition: windows_debug.c:99

References find_thread(), NULL, status, and UV__ERR.

◆ uv_uptime()

int uv_uptime ( double *  uptime)

Definition at line 106 of file haiku.c.

106  {
107  /* system_time() returns time since booting in microseconds */
108  *uptime = (double)system_time() / 1000000;
109  return 0;
110 }