Rizin
unix-like reverse engineering framework and cli tools
fs-fd-hash-inl.h File Reference
#include "uv.h"
#include "internal.h"

Go to the source code of this file.

Classes

struct  uv__fd_info_s
 
struct  uv__fd_hash_entry_s
 
struct  uv__fd_hash_entry_group_s
 
struct  uv__fd_hash_bucket_s
 

Macros

#define UV__FD_HASH_SIZE   256
 
#define UV__FD_HASH_GROUP_SIZE   16
 
#define FIND_COMMON_VARIABLES
 
#define FIND_IN_GROUP_PTR(group_size)
 
#define FIND_IN_BUCKET_PTR()
 

Functions

static INLINE void uv__fd_hash_init (void)
 
static INLINE int uv__fd_hash_get (int fd, struct uv__fd_info_s *info)
 
static INLINE void uv__fd_hash_add (int fd, struct uv__fd_info_s *info)
 
static INLINE int uv__fd_hash_remove (int fd, struct uv__fd_info_s *info)
 

Variables

static uv_mutex_t uv__fd_hash_mutex
 
static struct uv__fd_hash_entry_group_s uv__fd_hash_entry_initial [UV__FD_HASH_SIZE *UV__FD_HASH_GROUP_SIZE]
 
static struct uv__fd_hash_bucket_s uv__fd_hash [UV__FD_HASH_SIZE]
 

Macro Definition Documentation

◆ FIND_COMMON_VARIABLES

#define FIND_COMMON_VARIABLES
Value:
unsigned i; \
unsigned bucket = fd % ARRAY_SIZE(uv__fd_hash); \
struct uv__fd_hash_entry_s* entry_ptr = NULL; \
struct uv__fd_hash_entry_group_s* group_ptr; \
struct uv__fd_hash_bucket_s* bucket_ptr = &uv__fd_hash[bucket];
#define ARRAY_SIZE(a)
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
static struct uv__fd_hash_bucket_s uv__fd_hash[UV__FD_HASH_SIZE]
static const z80_opcode fd[]
Definition: z80_tab.h:997

Definition at line 92 of file fs-fd-hash-inl.h.

◆ FIND_IN_BUCKET_PTR

#define FIND_IN_BUCKET_PTR ( )
Value:
do { \
size_t first_group_size = bucket_ptr->size % UV__FD_HASH_GROUP_SIZE; \
if (bucket_ptr->size != 0 && first_group_size == 0) \
first_group_size = UV__FD_HASH_GROUP_SIZE; \
group_ptr = bucket_ptr->data; \
FIND_IN_GROUP_PTR(first_group_size); \
for (group_ptr = group_ptr->next; \
group_ptr != NULL && entry_ptr == NULL; \
group_ptr = group_ptr->next) \
FIND_IN_GROUP_PTR(UV__FD_HASH_GROUP_SIZE); \
} while (0)
#define UV__FD_HASH_GROUP_SIZE

Definition at line 109 of file fs-fd-hash-inl.h.

◆ FIND_IN_GROUP_PTR

#define FIND_IN_GROUP_PTR (   group_size)
Value:
do { \
for (i = 0; i < group_size; ++i) { \
if (group_ptr->entries[i].fd == fd) { \
entry_ptr = &group_ptr->entries[i]; \
break; \
} \
} \
} while (0)

Definition at line 99 of file fs-fd-hash-inl.h.

◆ UV__FD_HASH_GROUP_SIZE

#define UV__FD_HASH_GROUP_SIZE   16

Definition at line 43 of file fs-fd-hash-inl.h.

◆ UV__FD_HASH_SIZE

#define UV__FD_HASH_SIZE   256

Definition at line 42 of file fs-fd-hash-inl.h.

Function Documentation

◆ uv__fd_hash_add()

static INLINE void uv__fd_hash_add ( int  fd,
struct uv__fd_info_s info 
)
static

Definition at line 137 of file fs-fd-hash-inl.h.

137  {
139 
141 
143 
144  if (entry_ptr == NULL) {
145  i = bucket_ptr->size % UV__FD_HASH_GROUP_SIZE;
146 
147  if (bucket_ptr->size != 0 && i == 0) {
148  struct uv__fd_hash_entry_group_s* new_group_ptr =
149  uv__malloc(sizeof(*new_group_ptr));
150  if (new_group_ptr == NULL) {
151  uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
152  }
153  new_group_ptr->next = bucket_ptr->data;
154  bucket_ptr->data = new_group_ptr;
155  }
156 
157  bucket_ptr->size += 1;
158  entry_ptr = &bucket_ptr->data->entries[i];
159  entry_ptr->fd = fd;
160  }
161 
162  entry_ptr->info = *info;
163 
165 }
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
void uv_fatal_error(const int errorno, const char *syscall)
Definition: error.c:35
static uv_mutex_t uv__fd_hash_mutex
#define FIND_COMMON_VARIABLES
#define FIND_IN_BUCKET_PTR()
struct uv__fd_hash_entry_group_s * next
struct uv__fd_hash_entry_s entries[UV__FD_HASH_GROUP_SIZE]
uv_file fd
void * uv__malloc(size_t size)
Definition: uv-common.c:75
UV_EXTERN void uv_mutex_lock(uv_mutex_t *handle)
Definition: thread.c:330
UV_EXTERN void uv_mutex_unlock(uv_mutex_t *handle)
Definition: thread.c:350

References uv__fd_hash_entry_group_s::entries, fd, uv__fd_hash_entry_s::fd, FIND_COMMON_VARIABLES, FIND_IN_BUCKET_PTR, i, info(), uv__fd_hash_entry_group_s::next, NULL, UV__FD_HASH_GROUP_SIZE, uv__fd_hash_mutex, uv__malloc(), uv_fatal_error(), uv_mutex_lock(), and uv_mutex_unlock().

Referenced by fs__ftruncate(), fs__open(), fs__read_filemap(), and fs__write_filemap().

◆ uv__fd_hash_get()

static INLINE int uv__fd_hash_get ( int  fd,
struct uv__fd_info_s info 
)
static

Definition at line 122 of file fs-fd-hash-inl.h.

122  {
124 
126 
128 
129  if (entry_ptr != NULL) {
130  *info = entry_ptr->info;
131  }
132 
134  return entry_ptr != NULL;
135 }

References FIND_COMMON_VARIABLES, FIND_IN_BUCKET_PTR, info(), NULL, uv__fd_hash_mutex, uv_mutex_lock(), and uv_mutex_unlock().

Referenced by fs__ftruncate(), fs__read(), and fs__write().

◆ uv__fd_hash_init()

static INLINE void uv__fd_hash_init ( void  )
static

Definition at line 76 of file fs-fd-hash-inl.h.

76  {
77  size_t i;
78  int err;
79 
81  if (err) {
82  uv_fatal_error(err, "uv_mutex_init");
83  }
84 
85  for (i = 0; i < ARRAY_SIZE(uv__fd_hash); ++i) {
86  uv__fd_hash[i].size = 0;
87  uv__fd_hash[i].data =
89  }
90 }
static bool err
Definition: armass.c:435
static struct uv__fd_hash_entry_group_s uv__fd_hash_entry_initial[UV__FD_HASH_SIZE *UV__FD_HASH_GROUP_SIZE]
struct uv__fd_hash_entry_group_s * data
UV_EXTERN int uv_mutex_init(uv_mutex_t *handle)
Definition: thread.c:282

References ARRAY_SIZE, uv__fd_hash_bucket_s::data, err, i, uv__fd_hash_bucket_s::size, uv__fd_hash, uv__fd_hash_entry_initial, UV__FD_HASH_GROUP_SIZE, uv__fd_hash_mutex, uv_fatal_error(), and uv_mutex_init().

Referenced by uv_fs_init().

◆ uv__fd_hash_remove()

static INLINE int uv__fd_hash_remove ( int  fd,
struct uv__fd_info_s info 
)
static

Definition at line 167 of file fs-fd-hash-inl.h.

167  {
169 
171 
173 
174  if (entry_ptr != NULL) {
175  *info = entry_ptr->info;
176 
177  bucket_ptr->size -= 1;
178 
179  i = bucket_ptr->size % UV__FD_HASH_GROUP_SIZE;
180  if (entry_ptr != &bucket_ptr->data->entries[i]) {
181  *entry_ptr = bucket_ptr->data->entries[i];
182  }
183 
184  if (bucket_ptr->size != 0 &&
185  bucket_ptr->size % UV__FD_HASH_GROUP_SIZE == 0) {
186  struct uv__fd_hash_entry_group_s* old_group_ptr = bucket_ptr->data;
187  bucket_ptr->data = old_group_ptr->next;
188  uv__free(old_group_ptr);
189  }
190  }
191 
193  return entry_ptr != NULL;
194 }
void uv__free(void *ptr)
Definition: uv-common.c:81

References FIND_COMMON_VARIABLES, FIND_IN_BUCKET_PTR, i, info(), uv__fd_hash_entry_group_s::next, NULL, UV__FD_HASH_GROUP_SIZE, uv__fd_hash_mutex, uv__free(), uv_mutex_lock(), and uv_mutex_unlock().

Referenced by fs__close().

Variable Documentation

◆ uv__fd_hash

struct uv__fd_hash_bucket_s uv__fd_hash[UV__FD_HASH_SIZE]
static

Definition at line 69 of file fs-fd-hash-inl.h.

Referenced by uv__fd_hash_init().

◆ uv__fd_hash_entry_initial

struct uv__fd_hash_entry_group_s uv__fd_hash_entry_initial[UV__FD_HASH_SIZE *UV__FD_HASH_GROUP_SIZE]
static

Definition at line 69 of file fs-fd-hash-inl.h.

Referenced by uv__fd_hash_init().

◆ uv__fd_hash_mutex

uv_mutex_t uv__fd_hash_mutex
static