Rizin
unix-like reverse engineering framework and cli tools
aix-common.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 <stdint.h>
26 #include <stdlib.h>
27 #include <string.h>
28 
29 #include <sys/types.h>
30 
31 #include <sys/time.h>
32 #include <unistd.h>
33 
34 #include <procinfo.h>
35 
36 #include <ctype.h>
37 
38 extern char* original_exepath;
41 extern void init_process_title_mutex_once(void);
42 
44  uint64_t G = 1000000000;
45  timebasestruct_t t;
46  read_wall_time(&t, TIMEBASE_SZ);
47  time_base_to_time(&t, TIMEBASE_SZ);
48  return (uint64_t) t.tb_high * G + t.tb_low;
49 }
50 
51 
52 /*
53  * We could use a static buffer for the path manipulations that we need outside
54  * of the function, but this function could be called by multiple consumers and
55  * we don't want to potentially create a race condition in the use of snprintf.
56  * There is no direct way of getting the exe path in AIX - either through /procfs
57  * or through some libc APIs. The below approach is to parse the argv[0]'s pattern
58  * and use it in conjunction with PATH environment variable to craft one.
59  */
60 int uv_exepath(char* buffer, size_t* size) {
61  int res;
62  char args[UV__PATH_MAX];
63  size_t cached_len;
64  struct procsinfo pi;
65 
66  if (buffer == NULL || size == NULL || *size == 0)
67  return UV_EINVAL;
68 
71  if (original_exepath != NULL) {
72  cached_len = strlen(original_exepath);
73  *size -= 1;
74  if (*size > cached_len)
75  *size = cached_len;
77  buffer[*size] = '\0';
79  return 0;
80  }
82  pi.pi_pid = getpid();
83  res = getargs(&pi, sizeof(pi), args, sizeof(args));
84 
85  if (res < 0)
86  return UV_EINVAL;
87 
88  return uv__search_path(args, buffer, size);
89 }
uint64_t uv__hrtime(uv_clocktype_t type)
Definition: aix-common.c:43
uv_once_t process_title_mutex_once
Definition: aix.c:70
void init_process_title_mutex_once(void)
Definition: aix.c:76
char * original_exepath
Definition: aix.c:68
int uv_exepath(char *buffer, size_t *size)
Definition: aix-common.c:60
uv_mutex_t process_title_mutex
Definition: aix.c:69
#define NULL
Definition: cris-opc.c:27
voidpf void uLong size
Definition: ioapi.h:138
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
int args
Definition: mipsasm.c:18
int type
Definition: mipsasm.c:17
unsigned long uint64_t
Definition: sftypes.h:28
Definition: buffer.h:15
int uv__search_path(const char *prog, char *buf, size_t *buflen)
Definition: core.c:1540
uv_clocktype_t
Definition: internal.h:146
#define UV__PATH_MAX
Definition: internal.h:68
pthread_mutex_t uv_mutex_t
Definition: unix.h:137
pthread_once_t uv_once_t
Definition: unix.h:135
UV_EXTERN void uv_mutex_lock(uv_mutex_t *handle)
Definition: thread.c:330
UV_EXTERN void uv_once(uv_once_t *guard, void(*callback)(void))
Definition: thread.c:419
UV_EXTERN void uv_mutex_unlock(uv_mutex_t *handle)
Definition: thread.c:350
#define G
Definition: zip_err_str.c:13