Skip to content

Commit bb8d34f

Browse files
committed
Investigating test failure
1 parent 1025ad0 commit bb8d34f

6 files changed

Lines changed: 53 additions & 36 deletions

File tree

src/common/capio/queue.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* @tparam Mutex Type of semaphore
1919
*/
2020
template <class T, class Mutex> class Queue {
21-
private:
2221
void *_shm;
2322
const long int _max_num_elems, _elem_size; // elements size in bytes
2423
long int _buff_size; // buffer size in bytes
@@ -94,8 +93,11 @@ template <class T, class Mutex> class Queue {
9493
syscall_no_intercept_flag = true;
9594
#endif
9695
SHM_DESTROY_CHECK(_shm_name.c_str());
96+
LOG("Removed %s", _shm_name.c_str());
9797
SHM_DESTROY_CHECK(_first_elem_name.c_str());
98+
LOG("Removed %s", _first_elem_name.c_str());
9899
SHM_DESTROY_CHECK(_last_elem_name.c_str());
100+
LOG("Removed %s", _last_elem_name.c_str());
99101
#ifdef __CAPIO_POSIX
100102
syscall_no_intercept_flag = false;
101103
#endif
@@ -177,4 +179,4 @@ template <class T> using CircularBuffer = Queue<T, NamedSemaphore>;
177179

178180
// Single Producer Single Consumer queue
179181
using SPSCQueue = Queue<char, NoLock>;
180-
#endif // CAPIO_QUEUE_HPP
182+
#endif // CAPIO_QUEUE_HPP

src/common/capio/semaphore.hpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
*
1313
*/
1414
class NoLock {
15-
public:
15+
public:
1616
NoLock(const std::string &name, unsigned int init_value, bool cleanup) {
1717
START_LOG(capio_syscall(SYS_gettid), "call(name=%s, initial_value=%d)", name.c_str(),
1818
init_value);
1919
}
2020

21-
NoLock(const NoLock &) = delete;
21+
NoLock(const NoLock &) = delete;
2222
NoLock &operator=(const NoLock &) = delete;
23-
~NoLock() = default;
23+
24+
~NoLock() {
25+
START_LOG(capio_syscall(SYS_gettid), "call()");
26+
};
2427

2528
static inline void lock() { START_LOG(capio_syscall(SYS_gettid), "call()"); };
2629

@@ -33,12 +36,12 @@ class NoLock {
3336
*
3437
*/
3538
class NamedSemaphore {
36-
private:
39+
private:
3740
const std::string _name;
3841
sem_t *_sem;
3942
bool _require_cleanup;
4043

41-
public:
44+
public:
4245
NamedSemaphore(std::string name, unsigned int init_value, bool cleanup = true)
4346
: _name(std::move(name)), _require_cleanup(cleanup) {
4447
START_LOG(capio_syscall(SYS_gettid), " call(name=%s, init_value=%d, cleanup=%s)",
@@ -56,8 +59,9 @@ class NamedSemaphore {
5659
}
5760
}
5861

59-
NamedSemaphore(const NamedSemaphore &) = delete;
62+
NamedSemaphore(const NamedSemaphore &) = delete;
6063
NamedSemaphore &operator=(const NamedSemaphore &) = delete;
64+
6165
~NamedSemaphore() {
6266
START_LOG(capio_syscall(SYS_gettid), "call()");
6367
if (_require_cleanup) {
@@ -110,11 +114,11 @@ class NamedSemaphore {
110114
*
111115
*/
112116
class Semaphore {
113-
private:
117+
private:
114118
sem_t _sem{};
115119
bool _require_cleanup;
116120

117-
public:
121+
public:
118122
explicit Semaphore(unsigned int init_value, bool cleanup = true) {
119123
START_LOG(capio_syscall(SYS_gettid), "call(init_value=%d)", init_value);
120124

@@ -123,8 +127,9 @@ class Semaphore {
123127
}
124128
}
125129

126-
Semaphore(const Semaphore &) = delete;
130+
Semaphore(const Semaphore &) = delete;
127131
Semaphore &operator=(const Semaphore &) = delete;
132+
128133
~Semaphore() {
129134
START_LOG(capio_syscall(SYS_gettid), "call()");
130135
if (_require_cleanup) {

src/posix/handlers/exit.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ int exit_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg
1919
START_LOG(tid, "call()");
2020

2121
syscall_no_intercept_flag = true;
22-
22+
LOG("syscall_no_intercept_flag = true");
2323
delete_caches();
2424
LOG("Removed caches");
2525

@@ -34,15 +34,11 @@ int exit_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg
3434
bufs_response->erase(tid);
3535
LOG("Removed response buffer");
3636
}
37-
38-
delete stc_queue;
39-
delete cts_queue;
40-
LOG("Removed data queues");
41-
4237
syscall_no_intercept_flag = false;
38+
LOG("syscall_no_intercept_flag = false");
4339

4440
return CAPIO_POSIX_SYSCALL_SKIP;
4541
}
4642

4743
#endif // SYS_exit || SYS_exit_group
48-
#endif // CAPIO_POSIX_HANDLERS_EXIT_GROUP_HPP
44+
#endif // CAPIO_POSIX_HANDLERS_EXIT_GROUP_HPP

src/posix/handlers/open.hpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ std::string compute_abs_path(char *pathname, int dirfd) {
3535
#if defined(SYS_creat)
3636
int creat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) {
3737
std::string pathname(reinterpret_cast<const char *>(arg0));
38-
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));
39-
int flags = O_CREAT | O_WRONLY | O_TRUNC;
38+
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));
39+
int flags = O_CREAT | O_WRONLY | O_TRUNC;
4040
mode_t mode = static_cast<int>(arg2);
4141
START_LOG(tid, "call(path=%s, flags=%d, mode=%d)", pathname.data(), flags, mode);
4242

@@ -64,9 +64,9 @@ int creat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long ar
6464
#if defined(SYS_open)
6565
int open_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) {
6666
std::string pathname(reinterpret_cast<const char *>(arg0));
67-
int flags = static_cast<int>(arg1);
67+
int flags = static_cast<int>(arg1);
6868
mode_t mode = static_cast<int>(arg2);
69-
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));
69+
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));
7070
START_LOG(tid, "call(path=%s, flags=%d, mode=%d)", pathname.data(), flags, mode);
7171

7272
std::string path = compute_abs_path(pathname.data(), -1);
@@ -79,6 +79,9 @@ int open_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg
7979
LOG("not O_CREAT");
8080
open_request(-1, path.data(), tid);
8181
}
82+
} else {
83+
LOG("Not a CAPIO path. skipping...");
84+
return CAPIO_POSIX_SYSCALL_REQUEST_SKIP;
8285
}
8386

8487
int fd = static_cast<int>(syscall_no_intercept(SYS_open, arg0, arg1, arg2, arg3, arg4, arg5));
@@ -97,9 +100,9 @@ int open_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg
97100
int openat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long *result) {
98101
int dirfd = static_cast<int>(arg0);
99102
std::string pathname(reinterpret_cast<const char *>(arg1));
100-
int flags = static_cast<int>(arg2);
103+
int flags = static_cast<int>(arg2);
101104
mode_t mode = static_cast<int>(arg3);
102-
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));
105+
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));
103106
START_LOG(tid, "call(path=%s, flags=%d, mode=%d)", pathname.data(), flags, mode);
104107

105108
std::string path = compute_abs_path(pathname.data(), dirfd);
@@ -112,6 +115,9 @@ int openat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long a
112115
LOG("not O_CREAT");
113116
open_request(-1, path.data(), tid);
114117
}
118+
} else {
119+
LOG("Not a CAPIO path. skipping...");
120+
return CAPIO_POSIX_SYSCALL_REQUEST_SKIP;
115121
}
116122

117123
int fd = static_cast<int>(syscall_no_intercept(SYS_openat, arg0, arg1, arg2, arg3, arg4, arg5));
@@ -127,4 +133,4 @@ int openat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long a
127133
}
128134
#endif // SYS_openat
129135

130-
#endif // CAPIO_POSIX_HANDLERS_OPENAT_HPP
136+
#endif // CAPIO_POSIX_HANDLERS_OPENAT_HPP

src/posix/handlers/read.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,16 @@ int read_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg
3939
auto tid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));
4040

4141
START_LOG(capio_syscall(SYS_gettid), "call(fd=%d, tid=%d, count=%ld)", fd, tid, count);
42+
if (exists_capio_fd(fd)) {
43+
auto read_result = store_file_in_memory(get_capio_fd_path(fd), tid)
44+
? capio_read_mem(fd, count, buffer, result)
45+
: capio_read_fs(fd, count, tid);
4246

43-
auto read_result = store_file_in_memory(get_capio_fd_path(fd), tid)
44-
? capio_read_mem(fd, count, buffer, result)
45-
: capio_read_fs(fd, count, tid);
46-
47-
LOG("read result: %ld", read_result);
48-
return read_result;
47+
LOG("read result: %ld", read_result);
48+
return read_result;
49+
}
50+
LOG("Not a CAPIO fd... skipping...");
51+
return CAPIO_POSIX_SYSCALL_REQUEST_SKIP;
4952
}
5053
#endif // SYS_read
5154

src/posix/utils/cache.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ inline thread_local ReadRequestCacheMEM *read_request_cache_mem;
1717

1818
inline void init_caches() {
1919
START_LOG(capio_syscall(SYS_gettid), "call()");
20-
write_request_cache_fs = new WriteRequestCacheFS();
21-
read_request_cache_fs = new ReadRequestCacheFS();
20+
write_request_cache_fs = new WriteRequestCacheFS();
21+
read_request_cache_fs = new ReadRequestCacheFS();
2222
consent_request_cache_fs = new ConsentRequestCache();
23-
write_request_cache_mem = new WriteRequestCacheMEM();
24-
read_request_cache_mem = new ReadRequestCacheMEM();
23+
write_request_cache_mem = new WriteRequestCacheMEM();
24+
read_request_cache_mem = new ReadRequestCacheMEM();
2525
}
2626

2727
inline void delete_caches() {
@@ -31,6 +31,11 @@ inline void delete_caches() {
3131
delete consent_request_cache_fs;
3232
delete write_request_cache_mem;
3333
delete read_request_cache_mem;
34+
35+
delete cts_queue;
36+
LOG("Removed cts_queue");
37+
delete stc_queue;
38+
LOG("Removed stc_queue");
3439
}
3540

36-
#endif // CAPIO_CACHE_HPP
41+
#endif // CAPIO_CACHE_HPP

0 commit comments

Comments
 (0)