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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/*
* Copyright © 2022 Collabora, Ltd.
*
* Based on Fossilize DB:
* Copyright © 2020 Valve Corporation
*
* SPDX-License-Identifier: MIT
*/
#ifndef MESA_CACHE_DB_H
#define MESA_CACHE_DB_H
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "detect_os.h"
#include "simple_mtx.h"
#ifdef __cplusplus
extern "C" {
#endif
struct mesa_cache_db_file {
FILE *file;
char *path;
off_t offset;
uint64_t uuid;
};
struct mesa_cache_db {
struct hash_table_u64 *index_db;
struct mesa_cache_db_file cache;
struct mesa_cache_db_file index;
uint64_t max_cache_size;
simple_mtx_t flock_mtx;
void *mem_ctx;
uint64_t uuid;
bool alive;
};
#if DETECT_OS_WINDOWS == 0
bool
mesa_cache_db_open(struct mesa_cache_db *db, const char *cache_path);
void
mesa_cache_db_close(struct mesa_cache_db *db);
void
mesa_cache_db_set_size_limit(struct mesa_cache_db *db,
uint64_t max_cache_size);
unsigned int
mesa_cache_db_file_entry_size(void);
void *
mesa_cache_db_read_entry(struct mesa_cache_db *db,
const uint8_t *cache_key_160bit,
size_t *size);
bool
mesa_cache_db_entry_write(struct mesa_cache_db *db,
const uint8_t *cache_key_160bit,
const void *blob, size_t blob_size);
bool
mesa_cache_db_entry_remove(struct mesa_cache_db *db,
const uint8_t *cache_key_160bit);
bool
mesa_db_wipe_path(const char *cache_path);
bool
mesa_cache_db_has_space(struct mesa_cache_db *db, size_t blob_size);
double
mesa_cache_db_eviction_score(struct mesa_cache_db *db);
#else
static inline bool
mesa_cache_db_open(struct mesa_cache_db *db, const char *cache_path)
{
return false;
}
static inline void
mesa_cache_db_close(struct mesa_cache_db *db)
{
}
static inline void
mesa_cache_db_set_size_limit(struct mesa_cache_db *db,
uint64_t max_cache_size)
{
}
static inline unsigned int
mesa_cache_db_file_entry_size(void)
{
return 0;
}
static inline void *
mesa_cache_db_read_entry(struct mesa_cache_db *db,
const uint8_t *cache_key_160bit,
size_t *size)
{
return NULL;
}
static inline bool
mesa_cache_db_entry_write(struct mesa_cache_db *db,
const uint8_t *cache_key_160bit,
const void *blob, size_t blob_size)
{
return false;
}
static inline bool
mesa_cache_db_entry_remove(struct mesa_cache_db *db,
const uint8_t *cache_key_160bit)
{
return false;
}
static inline bool
mesa_db_wipe_path(const char *cache_path)
{
return false;
}
static inline bool
mesa_cache_db_has_space(struct mesa_cache_db *db, size_t blob_size)
{
return false;
}
static inline double
mesa_cache_db_eviction_score(struct mesa_cache_db *db)
{
return 0;
}
#endif /* DETECT_OS_WINDOWS */
#ifdef __cplusplus
}
#endif
#endif /* MESA_CACHE_DB_H */
|