-
Notifications
You must be signed in to change notification settings - Fork 1
/
hook.cc
685 lines (560 loc) · 18 KB
/
hook.cc
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
//-*-c++-*-
// Time-stamp: <2016-02-01 09:04:58 dky>
//-----------------------------------------------------------------------------
// Generic library function hooking infrastructure
// Usage: LD_PRELOAD=./iotrap.so sample_program
//-----------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
#if 0
}
#endif
#endif
#define _XOPEN_SOURCE 500
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include <limits.h>
#include <sys/syscall.h>
#include <dlfcn.h>
// For intercepting POSIX calls
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/uio.h>
#include <sys/time.h>
#include <sys/resource.h>
// For intercepting AIO calls
#ifndef __USE_XOPEN2K8
#define __USE_XOPEN2K8
#endif
#include <aio.h>
#include <linux/aio_abi.h>
#ifdef _POSIX_HOOK_SRC
#define FUNC_PTR(ret, func, args) static ret (*func##_orig)args = 0
#else
#define FUNC_PTR(ret, func, args) ret (*func##_orig)args
#endif
#define DLSYM_FUNC_PTR(func) func##_orig = (typeof(func##_orig))dlsym(RTLD_NEXT, #func); assert(func##_orig)
#include <pthread.h>
bool iotrap_trace = false;
unsigned long int iotrap_fiji = 0;
static pthread_once_t posix_hook_initialized = PTHREAD_ONCE_INIT;
#ifndef NDEBUG
#define IOTRAP_TRACE(op) do { \
if (iotrap_trace) { \
(op); \
} \
} while(0)
#else
#define IOTRAP_TRACE(op)
#endif
#define POSIX_HOOK_INIT() do { \
(void)pthread_once(&posix_hook_initialized, posix_hook_init); \
IOTRAP_TRACE(fprintf(stderr, "iotrap trace: %s\n", __FUNCTION__)); \
} while(0)
// LD_PRELOAD based hook for POSIX functions
FUNC_PTR(int, creat, (const char *pathname, mode_t mode));
FUNC_PTR(int, open, (const char *pathname, int flags, ...));
FUNC_PTR(int, open64, (const char *pathname, int flags, ...));
FUNC_PTR(int, close, (int fd));
FUNC_PTR(FILE *, fdopen, (int fd, const char *mode));
FUNC_PTR(ssize_t, read, (int fd, void *buf, size_t count));
FUNC_PTR(ssize_t, write, (int fd, const void *buf, size_t count));
FUNC_PTR(int, dup, (int oldfd));
FUNC_PTR(int, dup2, (int oldfd, int newfd));
FUNC_PTR(FILE *, fopen, (const char *path, const char *mode));
FUNC_PTR(int, fclose, (FILE *fp));
FUNC_PTR(int, fcntl, (int fd, int cmd, ...));
FUNC_PTR(int, fsync, (int fd));
FUNC_PTR(ssize_t, pread, (int fd, void *buf, size_t count, off_t offset));
FUNC_PTR(ssize_t, pwrite, (int fd, const void *buf, size_t count, off_t offset));
FUNC_PTR(ssize_t, readv, (int fd, const struct iovec *iov, int iovcnt));
FUNC_PTR(ssize_t, writev, (int fd, const struct iovec *iov, int iovcnt));
FUNC_PTR(ssize_t, preadv, (int fd, const struct iovec *iov, int iovcnt, off_t offset));
FUNC_PTR(ssize_t, pwritev,(int fd, const struct iovec *iov, int iovcnt, off_t offset));
FUNC_PTR(DIR *, opendir, (const char *name));
FUNC_PTR(struct dirent *, readdir, (DIR *));
FUNC_PTR(int, readdir_r, (DIR *dirp, struct dirent *entry, struct dirent **result));
FUNC_PTR(int, readdir64_r, (DIR *dirp, struct dirent64 *entry, struct dirent64 **result));
FUNC_PTR(int, closedir, (DIR *dirp));
FUNC_PTR(int, aio_read, (struct aiocb *aiocbp));
FUNC_PTR(int, aio_read64, (struct aiocb64 *aiocbp));
FUNC_PTR(int, io_submit, (aio_context_t ctx_id, long nr, struct iocb **iocbpp));
// Needed for our state
FUNC_PTR(int, setrlimit, (__rlimit_resource_t resource, const struct rlimit *rlim));
// Setup the state based on configuration for all the heavy lifting
int posix_hook_state(void);
int posix_intercept_path(const char* path, char** relpath, char*** mount_pool, size_t* mount_pool_count);
// Intercepted FD tracking
int **fd_bitmap = NULL;
rlim_t fd_bitmap_size = 0;
#define IS_FD_HOOKED(fd) (fd_bitmap_size > (size_t)(fd) && fd_bitmap[(fd)])
#define GET_NEXT_FD(fd, iter) IS_FD_HOOKED(fd) ? fd_bitmap[fd][(size_t)++iter % fd_bitmap[fd][0]] : -1
//-----------------------------------------------------------------------------
// FIXME: Does not work with LD_PRELOAD
// Initializer function called automatically when library is loaded
// __attribute__ ((constructor))
//-----------------------------------------------------------------------------
static void posix_hook_init(void) {
iotrap_trace = !!getenv("IOTRAP_TRACE");
const char* iotrap_fiji_str = getenv("IOTRAP_FIJI");
if (iotrap_fiji_str) {
iotrap_fiji = strtoul(iotrap_fiji_str, NULL, 10);
}
struct rlimit rlim = {0};
if (getrlimit(RLIMIT_NOFILE, &rlim)) {
abort();
}
fd_bitmap = (int **)calloc(rlim.rlim_cur, sizeof(int *));
if (NULL == fd_bitmap) {
abort();
}
fd_bitmap_size = rlim.rlim_cur;
DLSYM_FUNC_PTR(creat);
DLSYM_FUNC_PTR(open);
DLSYM_FUNC_PTR(fdopen);
DLSYM_FUNC_PTR(open64);
DLSYM_FUNC_PTR(close);
DLSYM_FUNC_PTR(read);
DLSYM_FUNC_PTR(write);
DLSYM_FUNC_PTR(dup);
DLSYM_FUNC_PTR(dup2);
DLSYM_FUNC_PTR(fopen);
DLSYM_FUNC_PTR(fclose);
DLSYM_FUNC_PTR(fcntl);
DLSYM_FUNC_PTR(fsync);
DLSYM_FUNC_PTR(pread);
DLSYM_FUNC_PTR(pwrite);
DLSYM_FUNC_PTR(readv);
DLSYM_FUNC_PTR(writev);
DLSYM_FUNC_PTR(preadv);
DLSYM_FUNC_PTR(pwritev);
DLSYM_FUNC_PTR(opendir);
DLSYM_FUNC_PTR(readdir);
DLSYM_FUNC_PTR(readdir_r);
DLSYM_FUNC_PTR(readdir64_r);
DLSYM_FUNC_PTR(closedir);
DLSYM_FUNC_PTR(aio_read);
DLSYM_FUNC_PTR(aio_read64);
DLSYM_FUNC_PTR(setrlimit);
if (posix_hook_state()) {
abort();
}
const char* mount_pools = getenv("IOTRAP_MOUNT_POOLS");
#ifndef NDEBUG
fprintf(stderr, "IOTRAP framework initialized: mount pools [%s], tracing [%s], fiji [%s:%lu]\n",
mount_pools ? mount_pools : "NONE",
iotrap_trace ? "enabled" : "disabled",
iotrap_fiji ? "enabled" : "disabled", iotrap_fiji);
#else
fprintf(stderr, "IOTRAP framework initialized: mount pools [%s], fiji [%s:%lu]\n",
mount_pools ? mount_pools : "NONE",
iotrap_fiji ? "enabled" : "disabled", iotrap_fiji);
#endif
return;
}
//-----------------------------------------------------------------------------
// Hooked functions custom implementation
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Needed internally to update our fd map size tracking intercepted fd
//-----------------------------------------------------------------------------
int setrlimit(__rlimit_resource_t resource, const struct rlimit *rlim) {
POSIX_HOOK_INIT();
int ret = setrlimit_orig(resource, rlim);
if (0 == ret && RLIMIT_NOFILE == resource && fd_bitmap_size < rlim->rlim_cur) {
const int err = errno;
int **ptr = (int **)realloc(fd_bitmap, rlim->rlim_cur);
if (NULL == ptr) {
abort();
}
fd_bitmap = ptr;
fd_bitmap_size = rlim->rlim_cur;
errno = err;
}
return ret;
}
// POSIX file IO
//-----------------------------------------------------------------------------
// creat
//-----------------------------------------------------------------------------
int creat(const char *pathname, mode_t mode) {
POSIX_HOOK_INIT();
return open64(pathname, O_CREAT|O_WRONLY|O_TRUNC, mode);
}
//-----------------------------------------------------------------------------
// open
//-----------------------------------------------------------------------------
int open(const char *pathname, int flags, ...) {
POSIX_HOOK_INIT();
mode_t mode = 0;
va_list ap;
va_start(ap, flags);
mode = va_arg(ap, mode_t);
va_end(ap);
return open64(pathname, flags, mode);
}
//-----------------------------------------------------------------------------
// open64
//-----------------------------------------------------------------------------
int open64(const char *pathname, int flags, ...) {
POSIX_HOOK_INIT();
mode_t mode = 0;
va_list ap;
va_start(ap, flags);
mode = va_arg(ap, mode_t);
va_end(ap);
char buff[PATH_MAX] = {0};
char* relpath = &buff[0];
char** mount_pool = NULL;
do {
size_t mount_pool_count = 0;
if (!posix_intercept_path(pathname, &relpath, &mount_pool, &mount_pool_count)) {
break;
}
assert(mount_pool_count > 0 && mount_pool);
int* pfd = (int *)malloc(sizeof(int) * (mount_pool_count + 1));
// Too bad we could not intercept it due to memory allocation failure
if (!pfd) {
break;
}
// Let us try opening the primary path and proceed only if it succeeds
pfd[1] = open64_orig(pathname, flags, mode);
if (pfd[1] < 0) {
free(pfd);
// Let the retry happen and relay the proper error to the callers
break;
}
// Update the FD count
pfd[0] = 1;
// Add the collection to the tracker
fd_bitmap[pfd[1]] = pfd;
// Clear the create/exclusive/truncate bit for successive calls
flags &= ~O_EXCL;
flags &= ~O_TRUNC;
flags &= ~O_CREAT;
for (size_t cc = 0; cc < mount_pool_count; ++cc) {
char altpath[PATH_MAX];
snprintf(altpath, sizeof(altpath) - 1, "%s%s", mount_pool[cc], relpath);
// Skip the primary path since we have processed it
if (0 == strcmp(pathname, altpath)) {
continue;
}
const size_t idx = pfd[0] + 1;
pfd[idx] = open64_orig(altpath, flags, mode);
// Skip failed paths - being more tolerant to configuration errors
if (pfd[idx] < 0) {
continue;
}
// Add the collection to the tracker
fd_bitmap[pfd[idx]] = pfd;
// Update the FD count
++pfd[0];
}
// Return the FD corresponding to the primary path back to caller
return pfd[1];
} while(0);
return open64_orig(pathname, flags, mode);
}
//-----------------------------------------------------------------------------
// close
//-----------------------------------------------------------------------------
int close(int fd) {
POSIX_HOOK_INIT();
// Close the non primary fds
int* pfd = fd_bitmap[fd];
if (pfd) {
for (int cc = 1; cc <= pfd[0]; ++cc) {
// Let us close the primary last and relay the errors
if (fd != pfd[cc]) {
(void)close_orig(pfd[cc]);
}
// Clear the tracking entries
assert(pfd == fd_bitmap[pfd[cc]]);
fd_bitmap[pfd[cc]] = 0;
}
free(pfd);
}
return close_orig(fd);
}
//-----------------------------------------------------------------------------
// dup
//-----------------------------------------------------------------------------
int dup(int oldfd) {
POSIX_HOOK_INIT();
if (IS_FD_HOOKED(oldfd)) {
int cc = 0;
int nfd = -1, err = 0;
int* pfd = fd_bitmap[oldfd];
int* pnfd = (int *)malloc(sizeof(int)*(pfd[0] + 1));
memcpy(pnfd, pfd, sizeof(int)*(pfd[0] + 1));
for (cc = 1; cc <= pnfd[0]; ++cc) {
pnfd[cc] = dup_orig(pnfd[cc]);
if (oldfd == pfd[cc]) {
err = errno;
nfd = pnfd[cc];
}
}
// Error handling if something fails
if (!(nfd < 0)) {
fd_bitmap[nfd] = pnfd;
} else {
for (cc = 1; cc < pnfd[0]; ++cc) {
if (!(pnfd[cc] < 0)) {
(void)close_orig(pnfd[cc]);
}
}
free(pnfd);
}
errno = err;
return nfd;
}
return dup_orig(oldfd);
}
//-----------------------------------------------------------------------------
// dup2
// WIP: Need to manage the original FDs
//-----------------------------------------------------------------------------
int dup2(int oldfd, int newfd) {
POSIX_HOOK_INIT();
if (IS_FD_HOOKED(oldfd)) {
abort();
#ifdef FIXME
fprintf(stderr, "Hooking: %s(%d, %d)\n", __FUNCTION__, oldfd, newfd);
int* pfd = fd_bitmap[oldfd];
int* pnfd = NULL;
size_t cc = 0;
// Close the new fd if open
if (IS_FD_HOOKED(newfd)) {
pnfd = fd_bitmap[newfd];
for (cc = 1; cc < pnfd[0]; ++cc) {
if (!(pnfd[cc] < 0)) {
(void)close_orig(pnfd[cc]);
}
}
}
// Create new duplicates
if (!pnfd) {
pnfd = (int *)malloc(sizeof(int)*(pfd[0] + 1));
memcpy(pnfd, pfd, sizeof(int)*(pfd[0] + 1));
}
int nfd = -1;
for (cc = 1; cc < pnfd[0]; ++cc) {
if (oldfd == pfd[cc]) {
err = errno;
nfd = pnfd[cc];
}
}
// Error handling if something fails
if (!(nfd < 0)) {
fd_bitmap[nfd] = pnfd;
} else {
for (cc = 1; cc < pnfd[0]; ++cc) {
if (!(pnfd[cc] < 0)) {
(void)close_orig(pnfd[cc]);
}
}
free(pnfd);
}
errno = err;
return nfd;
#endif
}
return dup2_orig(oldfd, newfd);
}
//-----------------------------------------------------------------------------
// fcntl
//-----------------------------------------------------------------------------
int fcntl(int fd, int cmd, ...) {
POSIX_HOOK_INIT();
struct flock *pfl = NULL;
va_list ap;
va_start(ap, cmd);
pfl = va_arg(ap, struct flock*);
va_end(ap);
if (IS_FD_HOOKED(fd)) {
IOTRAP_TRACE(fprintf(stderr, "Hooking: %s(%d, %d, %p)\n", __FUNCTION__, fd, cmd, pfl));
}
return fcntl_orig(fd, cmd, pfl);
}
//-----------------------------------------------------------------------------
// fsync
//-----------------------------------------------------------------------------
int fsync(int fd) {
return 0;
#if 0
POSIX_HOOK_INIT();
// Close the non primary fds
const int* pfd = fd_bitmap[fd];
if (pfd) {
for (int cc = 1; cc <= pfd[0]; ++cc) {
// Let us close the primary last and relay the errors
if (fd != pfd[cc]) {
(void)fsync_orig(pfd[cc]);
}
}
}
return fsync_orig(fd);
#endif
}
//-----------------------------------------------------------------------------
// fdsync
//-----------------------------------------------------------------------------
int fdsync(int fd) {
return fsync(fd);
}
//-----------------------------------------------------------------------------
// io_submit
// Asynchronous IO calls from libaio - Uses syscall and bypasses dlsym
//-----------------------------------------------------------------------------
int io_submit(aio_context_t ctx_id, long nr, struct iocb **iocbpp) {
POSIX_HOOK_INIT();
int* pfd = fd_bitmap[iocbpp[0]->aio_fildes];
#ifndef NDEBUG
// Since we move pfd to actual FD
const int* pfd_orig = pfd;
#endif
do {
if (__builtin_expect(!!pfd, 1)) {
int num_fds;
if (pfd[0] > 1 && iotrap_fiji) {
// Skip the primary FD on which a lock has been taken
num_fds = pfd[0] - 1;
pfd = &pfd[2];
} else {
num_fds = pfd[0];
// Skip the index with the FD count
pfd = &pfd[1];
}
// Ensure we have a minimum of 1 FD to start
assert(num_fds > 0);
IOTRAP_TRACE(fprintf(stderr, "Hooking: %s(%lu, %ld, %p)\n", __FUNCTION__, ctx_id, nr, iocbpp));
// Handle the case with single IO vec in request
if (1 == nr) {
static size_t randomizer = 0;
iocbpp[0]->aio_fildes = pfd[++randomizer % num_fds];
break;
}
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (long cc = 0; cc < nr; ++cc) {
// Ensure all FDs in the input IO vecs are same as the first IO vec
assert(pfd_orig == fd_bitmap[iocbpp[cc]->aio_fildes]);
iocbpp[cc]->aio_fildes = pfd[cc % num_fds];
}
}
} while(0);
return syscall(__NR_io_submit, ctx_id, nr, iocbpp);
}
//-----------------------------------------------------------------------------
// Extra functions that we might want to intercept in the future
//-----------------------------------------------------------------------------
#ifndef NDEBUG
FILE *fdopen(int fd, const char *mode) {
POSIX_HOOK_INIT();
if (IS_FD_HOOKED(fd)) {
// TODO: We need to remove intercepting the fd
// Need to figure oue how to do this in multi-threaded environment when other thread
// might be using the fd set
abort();
}
return fdopen_orig(fd, mode);
}
FILE *fopen(const char *path, const char *mode) {
POSIX_HOOK_INIT();
return fopen_orig(path, mode);
}
int fclose(FILE *fp) {
POSIX_HOOK_INIT();
return fclose_orig(fp);
}
ssize_t read(int fd, void *buf, size_t count) {
POSIX_HOOK_INIT();
return read_orig(fd, buf, count);
}
ssize_t write(int fd, const void *buf, size_t count) {
POSIX_HOOK_INIT();
return write_orig(fd, buf, count);
}
ssize_t pread(int fd, void *buf, size_t count, off_t offset) {
POSIX_HOOK_INIT();
return pread_orig(fd, buf, count, offset);
}
ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) {
POSIX_HOOK_INIT();
return pwrite_orig(fd, buf, count, offset);
}
ssize_t readv(int fd, const struct iovec *iov, int iovcnt) {
POSIX_HOOK_INIT();
return readv_orig(fd, iov, iovcnt);
}
ssize_t writev(int fd, const struct iovec *iov, int iovcnt) {
POSIX_HOOK_INIT();
return writev_orig(fd, iov, iovcnt);
}
ssize_t preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset) {
POSIX_HOOK_INIT();
return preadv_orig(fd, iov, iovcnt, offset);
}
ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset) {
POSIX_HOOK_INIT();
return pwritev_orig(fd, iov, iovcnt, offset);
}
// Functions operating on directories
DIR* opendir(const char *name) {
POSIX_HOOK_INIT();
return opendir_orig(name);
}
struct dirent* readdir(DIR *dirp) {
POSIX_HOOK_INIT();
return readdir_orig(dirp);
}
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) {
POSIX_HOOK_INIT();
return readdir_r_orig(dirp, entry, result);
}
int readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result) {
POSIX_HOOK_INIT();
return readdir64_r_orig(dirp, entry, result);
}
int closedir(DIR *dirp) {
POSIX_HOOK_INIT();
return closedir_orig(dirp);
}
// AIO calls
int aio_read(struct aiocb *aiocbp) {
POSIX_HOOK_INIT();
return aio_read_orig(aiocbp);
}
int aio_read64(struct aiocb64 *aiocbp) {
POSIX_HOOK_INIT();
return aio_read64_orig(aiocbp);
}
int io_getevents(aio_context_t ctx_id, long min_nr, long nr, struct io_event *events,
struct timespec *timeout) {
POSIX_HOOK_INIT();
return syscall(__NR_io_getevents, ctx_id, min_nr, nr, events, timeout);
}
int io_cancel(aio_context_t ctx_id, struct iocb *iocb, struct io_event *result) {
POSIX_HOOK_INIT();
return syscall(__NR_io_cancel, ctx_id, iocb, result);
}
int io_destroy(aio_context_t ctx_id) {
POSIX_HOOK_INIT();
return syscall(__NR_io_destroy, ctx_id);
}
int io_setup(unsigned nr_events, aio_context_t *ctxp) {
POSIX_HOOK_INIT();
return syscall(__NR_io_setup, nr_events, ctxp);
}
#endif // not defined NDEBUG
#ifdef __cplusplus
}
#endif