~ubuntu-branches/ubuntu/wily/trafficserver/wily

« back to all changes in this revision

Viewing changes to lib/ts/ink_resource.cc

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2012-12-17 22:28:16 UTC
  • mfrom: (5.1.8 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121217222816-7xwjsx5k76zkb63d
Tags: 3.2.0-1ubuntu1
* Revert FreeBSD strerror_r() fixes that give errors with glibc 2.16.
* Apply patch from Konstantinos Margaritis to define barriers on ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "ink_resource.h"
30
30
#include "ink_stack_trace.h"
31
31
 
32
 
volatile int64_t resource_allocated_mem = 0;
33
32
volatile int res_track_memory = RES_TRACK_MEMORY_DEFAULT;
34
33
 
35
 
#ifdef TRACK_MEMORY
36
 
 
37
 
#define FENCE_POST_SIZE   16
38
 
 
39
 
// TODO: Move this to ink_align.h
40
 
#define ADJUST(mem,x)  (((char*) (mem)) + x)
41
 
// TODO: Use INK_ALIGN instead
42
 
#define ROUND(x,l)     (((x) + ((l) - 1L)) & ~((l) - 1L))
43
 
#define TSIZE          16387
44
 
 
45
 
#define MAKE_MAGIC(m)    (((char*) (m)) - 1)
46
 
#define CHECK_MAGIC(m,c) ((char*) (m) == MAKE_MAGIC (c))
47
 
 
48
 
 
49
 
typedef struct ResMemInfo ResMemInfo;
50
 
typedef struct Resource Resource;
51
 
 
52
 
struct ResMemInfo
53
 
{
54
 
  void *magic;
55
 
  unsigned int size:31;
56
 
  unsigned int fence_post:1;
57
 
  Resource *res;
58
 
};
59
 
 
60
 
 
61
 
static unsigned int res_hash(const char *s);
62
 
Resource *res_lookup(const char *path);
63
 
 
64
 
 
65
 
static const int res_extra_space = ROUND(sizeof(ResMemInfo), sizeof(double));
66
 
static volatile Resource *res_table[TSIZE];
67
 
 
68
 
static const char fence_post_pattern[FENCE_POST_SIZE] = {
69
 
  (char) 0xde, (char) 0xad, (char) 0xbe, (char) 0xef,
70
 
  (char) 0xde, (char) 0xad, (char) 0xbe, (char) 0xef,
71
 
  (char) 0xde, (char) 0xad, (char) 0xbe, (char) 0xef,
72
 
  (char) 0xde, (char) 0xad, (char) 0xbe, (char) 0xef,
73
 
};
74
 
 
75
 
 
76
 
volatile int res_zorch_mem = 0;
77
 
volatile int res_fence_post = 0;
78
 
 
79
 
#define res_memadd(_x_) \
80
 
   ink_atomic_increment64(&resource_allocated_mem, (int64_t) (_x_));
81
 
 
82
 
#define res_memsub(_x_) \
83
 
   ink_atomic_increment64(&resource_allocated_mem, (int64_t) -(_x_));
84
 
 
85
 
static int
86
 
_xres_init()
87
 
{
88
 
  res_zorch_mem = (getenv("ZORCH_MEM") != NULL);
89
 
  res_fence_post = (getenv("FENCE_POST") != NULL);
90
 
 
91
 
  if (res_zorch_mem) {
92
 
    fprintf(stderr, "memory zorching enabled\n");
93
 
  }
94
 
 
95
 
  if (res_fence_post) {
96
 
    fprintf(stderr, "memory fence posting enabled\n");
97
 
  }
98
 
 
99
 
  return 0;
100
 
}
101
 
 
102
 
static int dummy_var = _xres_init();
103
 
 
104
 
 
105
 
/* INKqa03012 - Digital OSF seems to issue some bad frees in
106
 
 *  the iostream destructor.  These variables and the the exit_cb()
107
 
 *  let us know if exit has been called.  If exit has been, called
108
 
 *  we will refrain from issuing warnings regarding bad frees
109
 
 */
110
 
static int exit_called = 0;
111
 
static void
112
 
exit_cb()
113
 
{
114
 
  exit_called = 1;
115
 
}
116
 
static int unused = atexit(exit_cb);
117
 
 
118
 
 
119
 
/*-------------------------------------------------------------------------
120
 
  -------------------------------------------------------------------------*/
121
 
 
122
 
#define res_inc(res,delta) \
123
 
   ink_atomic_increment64 (&res->value, delta); \
124
 
   res_memadd(delta)
125
 
 
126
 
#define res_check(res) \
127
 
    if (res && !CHECK_MAGIC ((res)->magic, (res))) { \
128
 
        fprintf (stderr, "FATAL: resource table is corrupt [%d]\n", __LINE__); \
129
 
        abort (); \
130
 
    }
131
 
 
132
 
/*-------------------------------------------------------------------------
133
 
  -------------------------------------------------------------------------*/
134
 
 
135
 
 
136
 
unsigned int
137
 
res_hash(const char *s)
138
 
{
139
 
#if !defined(linux) && !defined(freebsd) && !defined(__i386__)
140
 
#define HASH_ONE(h,one)       ((h << 3) + (one) + (h >> 29))
141
 
#define WORD_HAS_NULLBYTE(w)  ((((w) - 0x01010101) ^ (w)) & 0x80808080)
142
 
 
143
 
  unsigned int h;
144
 
  unsigned int ibp;
145
 
 
146
 
  ink_assert(!((uintptr_t) s & 3));
147
 
 
148
 
  for (h = 0;;) {
149
 
    ibp = *(unsigned int *) s;
150
 
 
151
 
    if (WORD_HAS_NULLBYTE(ibp)) {
152
 
      unsigned char t[4];
153
 
 
154
 
      if (!s[0]) {
155
 
        return h;
156
 
      } else if (!s[1]) {
157
 
        *(unsigned int *) &t[0] = ibp;
158
 
        t[2] = 0;
159
 
        t[3] = 0;
160
 
        h = HASH_ONE(h, *(unsigned int *) &t[0]);
161
 
        return h;
162
 
      } else if (!s[2]) {
163
 
        *(unsigned int *) &t[0] = ibp;
164
 
        t[3] = 0;
165
 
        h = HASH_ONE(h, *(unsigned int *) &t[0]);
166
 
        return h;
167
 
      } else if (!s[3]) {
168
 
        h = HASH_ONE(h, ibp);
169
 
        return h;
170
 
      }
171
 
    } else {
172
 
      h = HASH_ONE(h, ibp);
173
 
    }
174
 
    s += 4;
175
 
  }
176
 
 
177
 
#undef HASH_ONE
178
 
#undef WORD_HAS_NULLBYTE
179
 
#else
180
 
  unsigned int h = 0, g;
181
 
 
182
 
  for (; *s; s++) {
183
 
    h = (h << 4) + *s;
184
 
    if ((g = h & 0xf0000000))
185
 
      h = (h ^ (g >> 24)) ^ g;
186
 
  }
187
 
  return h;
188
 
#endif
189
 
}
190
 
 
191
 
/*-------------------------------------------------------------------------
192
 
  -------------------------------------------------------------------------*/
193
 
 
194
 
Resource *
195
 
res_lookup(const char *path)
196
 
{
197
 
  unsigned int hash_val;
198
 
  Resource *node;
199
 
  Resource *old;
200
 
 
201
 
  hash_val = res_hash(path) % TSIZE;
202
 
 
203
 
  for (;;) {
204
 
    old = (Resource *) res_table[hash_val];
205
 
    node = old;
206
 
 
207
 
    while (node) {
208
 
      res_check(node);
209
 
      if ((path == node->path) || (strcmp(path, node->path) == 0)) {
210
 
        return node;
211
 
      }
212
 
      node = node->next;
213
 
    }
214
 
 
215
 
    if (old == res_table[hash_val]) {
216
 
      node = (Resource *) _xmalloc(sizeof(Resource), NULL);
217
 
      node->magic = MAKE_MAGIC(node);
218
 
      node->path = path;
219
 
      node->value = 0;
220
 
      node->snapshot = 0;
221
 
      node->baseline = 0;
222
 
      node->next = old;
223
 
 
224
 
      if (ink_atomic_cas_ptr((pvvoidp) & res_table[hash_val], old, node))
225
 
        return node;
226
 
 
227
 
      _xfree(node);
228
 
      node = NULL;
229
 
    }
230
 
  }
231
 
  return NULL;                  // DEC compiler complains
232
 
}
233
 
 
234
 
 
235
 
/*-------------------------------------------------------------------------
236
 
  -------------------------------------------------------------------------*/
237
 
 
238
 
static Resource *
239
 
res_stat(const char *path, int64_t value)
240
 
{
241
 
  if (path) {
242
 
    Resource *res;
243
 
 
244
 
    res = res_lookup(path);
245
 
    res_inc(res, value);
246
 
 
247
 
    return res;
248
 
  } else {
249
 
    return NULL;
250
 
  }
251
 
}
252
 
 
253
 
 
254
 
#if defined(linux) || defined(freebsd)
255
 
static const int magic_array_offset = 0;
256
 
#else
257
 
#error "I do not know about this platform."
258
 
#endif
259
 
 
260
 
 
261
 
/*-------------------------------------------------------------------------
262
 
  -------------------------------------------------------------------------*/
263
 
 
264
 
int
265
 
_xcheck_fence_post(char *mem, unsigned int size)
266
 
{
267
 
  if (memcmp(mem, fence_post_pattern, FENCE_POST_SIZE) != 0) {
268
 
    return 1;
269
 
  }
270
 
  if (memcmp(mem + size - FENCE_POST_SIZE, fence_post_pattern, FENCE_POST_SIZE) != 0) {
271
 
    return 1;
272
 
  }
273
 
  return 0;
274
 
}
275
 
 
276
 
void
277
 
_xvalidate(void *ptr, char *file, int line)
278
 
{
279
 
  ResMemInfo *info;
280
 
 
281
 
  info = (ResMemInfo *) ADJUST(ptr, -res_extra_space);
282
 
  if (!CHECK_MAGIC(info->magic, info)) {
283
 
    info = (ResMemInfo *) ADJUST(info, -magic_array_offset);
284
 
  }
285
 
  if (!CHECK_MAGIC(info->magic, info)) {
286
 
    ink_debug_assert(!"bad pointer");
287
 
  } else {
288
 
    if (info->res) {
289
 
      res_check(info->res);
290
 
    }
291
 
    char *mem = (char *) info;
292
 
 
293
 
    if (info->fence_post) {
294
 
      mem -= FENCE_POST_SIZE;
295
 
      if (_xcheck_fence_post(mem, info->size + res_extra_space + FENCE_POST_SIZE * 2)) {
296
 
        fprintf(stderr, "MEMORY: free: fence-post mangled [%s]\n", info->res ? info->res->path : "<unknown>");
297
 
        abort();
298
 
      }
299
 
    }
300
 
  }
301
 
}
302
 
 
303
 
/*-------------------------------------------------------------------------
304
 
  -------------------------------------------------------------------------*/
305
 
 
306
 
void
307
 
_xfree(void *ptr)
308
 
{
309
 
  if (!ptr) {
310
 
    // fprintf (stderr, "WARNING: freeing NULL pointer\n");
311
 
  } else {
312
 
    ResMemInfo *info;
313
 
 
314
 
    info = (ResMemInfo *) ADJUST(ptr, -res_extra_space);
315
 
    if (!CHECK_MAGIC(info->magic, info)) {
316
 
      info = (ResMemInfo *) ADJUST(info, -magic_array_offset);
317
 
    }
318
 
 
319
 
    if (CHECK_MAGIC(info->magic, info)) {
320
 
      char *mem;
321
 
 
322
 
      if (info->res) {
323
 
        res_check(info->res);
324
 
        res_inc(info->res, -((int64_t) info->size));
325
 
      }
326
 
 
327
 
      mem = (char *) info;
328
 
 
329
 
      if (info->fence_post) {
330
 
        mem -= FENCE_POST_SIZE;
331
 
        if (_xcheck_fence_post(mem, info->size + res_extra_space + FENCE_POST_SIZE * 2)) {
332
 
          fprintf(stderr, "MEMORY: free: fence-post mangled [%s]\n", info->res ? info->res->path : "<unknown>");
333
 
          abort();
334
 
        }
335
 
      }
336
 
 
337
 
      if (res_zorch_mem) {
338
 
        memset(info, 0x81, info->size + res_extra_space);
339
 
      }
340
 
 
341
 
      memset(info, 0, res_extra_space);
342
 
 
343
 
      free(mem);
344
 
 
345
 
    } else {
346
 
      /* This is a bad free. Let it leak.  Issue a
347
 
       *  warning if we are not in an exit routine
348
 
       * (INKqa03012)
349
 
       */
350
 
      if (exit_called == 0) {
351
 
        fprintf(stderr, "WARNING: freeing bad pointer\n");
352
 
        ink_debug_assert(!"WARNING: freeing bad pointer");
353
 
      }
354
 
    }
355
 
  }
356
 
}
357
 
 
358
 
void *
359
 
_xfree_null(void *ptr)
360
 
{
361
 
  _xfree(ptr);
362
 
  return NULL;
363
 
}
364
 
 
365
 
/*-------------------------------------------------------------------------
366
 
  -------------------------------------------------------------------------*/
367
 
 
368
 
void *
369
 
_xmalloc(unsigned int size, const char *path)
370
 
{
371
 
  ResMemInfo *info;
372
 
  char *mem;
373
 
  int extra;
374
 
  int fence_post;
375
 
 
376
 
  extra = res_extra_space;
377
 
 
378
 
  fence_post = res_fence_post;
379
 
 
380
 
  if (fence_post) {
381
 
    extra += FENCE_POST_SIZE * 2;
382
 
  }
383
 
 
384
 
  mem = (char *) malloc(size + extra);
385
 
 
386
 
  if (unlikely(mem == NULL)) {
387
 
    fprintf(stderr, "FATAL: _xmalloc could not allocate %u + %u bytes [%s]\n",
388
 
            size, extra, path ? path : "memory/anonymous");
389
 
    xdump();
390
 
    _exit(1);
391
 
  }
392
 
 
393
 
  if (fence_post) {
394
 
    memcpy(mem, fence_post_pattern, FENCE_POST_SIZE);
395
 
    memcpy(mem + size + extra - FENCE_POST_SIZE, fence_post_pattern, FENCE_POST_SIZE);
396
 
    mem += FENCE_POST_SIZE;
397
 
  }
398
 
 
399
 
  memset(mem, 0, res_extra_space);
400
 
 
401
 
  info = (ResMemInfo *) mem;
402
 
  info->magic = MAKE_MAGIC(mem);
403
 
  info->size = size;
404
 
  info->fence_post = fence_post;
405
 
 
406
 
  if (res_track_memory) {
407
 
    info->res = res_stat(path, size);
408
 
    res_check(info->res);
409
 
  } else {
410
 
    info->res = NULL;
411
 
  }
412
 
 
413
 
  mem = mem + res_extra_space;
414
 
 
415
 
  return mem;
416
 
}
417
 
 
418
 
/*-------------------------------------------------------------------------
419
 
  -------------------------------------------------------------------------*/
420
 
 
421
 
char *
422
 
_xstrdup(const char *str, int64_t length, const char *path)
423
 
{
424
 
  char *newstr;
425
 
 
426
 
  if (unlikely(str == NULL)) {
427
 
    return NULL;
428
 
  }
429
 
 
430
 
  if (length < 0) {
431
 
    length = (int) strlen(str);
432
 
  }
433
 
 
434
 
  newstr = (char *) _xmalloc(length + 1, path);
435
 
  strncpy(newstr, str, length);
436
 
  newstr[length] = '\0';
437
 
 
438
 
  return newstr;
439
 
}
440
 
 
441
 
/*-------------------------------------------------------------------------
442
 
  -------------------------------------------------------------------------*/
443
 
 
444
 
void *
445
 
_xrealloc(void *ptr, unsigned int size, const char *path)
446
 
{
447
 
  if (!ptr) {
448
 
    return _xmalloc(size, path);
449
 
  } else {
450
 
    ResMemInfo *info;
451
 
    char *mem;
452
 
    int extra;
453
 
    int fence_post;
454
 
 
455
 
    info = (ResMemInfo *) ADJUST(ptr, -res_extra_space);
456
 
    if (!CHECK_MAGIC(info->magic, info)) {
457
 
      info = (ResMemInfo *) ADJUST(info, -magic_array_offset);
458
 
    }
459
 
 
460
 
    if (info->res) {
461
 
      res_check(info->res);
462
 
      res_inc(info->res, -((int64_t) info->size));
463
 
    }
464
 
 
465
 
    mem = (char *) info;
466
 
    extra = res_extra_space;
467
 
 
468
 
    if (info->fence_post) {
469
 
      mem -= FENCE_POST_SIZE;
470
 
      if (_xcheck_fence_post(mem, info->size + res_extra_space + FENCE_POST_SIZE * 2)) {
471
 
        fprintf(stderr, "MEMORY: realloc: fence-post mangled [%s] [%s]\n",
472
 
                info->res ? info->res->path : "<unknown>", path);
473
 
        abort();
474
 
      }
475
 
    }
476
 
 
477
 
    memset(info, 0, res_extra_space);
478
 
 
479
 
    fence_post = res_fence_post;
480
 
 
481
 
    if (fence_post) {
482
 
      extra += FENCE_POST_SIZE * 2;
483
 
    }
484
 
 
485
 
    mem = (char *) realloc(mem, size + extra);
486
 
    if (unlikely(mem == NULL)) {
487
 
      fprintf(stderr, "FATAL: could not reallocate %u + %u bytes [%s]\n",
488
 
              size, extra, path ? path : "memory/anonymous");
489
 
      xdump();
490
 
      _exit(1);
491
 
    }
492
 
 
493
 
    if (fence_post) {
494
 
      memcpy(mem, fence_post_pattern, FENCE_POST_SIZE);
495
 
      memcpy(mem + size + extra - FENCE_POST_SIZE, fence_post_pattern, FENCE_POST_SIZE);
496
 
      mem += FENCE_POST_SIZE;
497
 
    }
498
 
 
499
 
    memset(mem, 0, res_extra_space);
500
 
 
501
 
    info = (ResMemInfo *) mem;
502
 
    info->magic = MAKE_MAGIC(mem);
503
 
    info->size = size;
504
 
    info->fence_post = fence_post;
505
 
 
506
 
    if (res_track_memory) {
507
 
      info->res = res_stat(path, size);
508
 
      res_check(info->res);
509
 
    } else {
510
 
      info->res = NULL;
511
 
    }
512
 
 
513
 
    mem = mem + res_extra_space;
514
 
 
515
 
    return mem;
516
 
  }
517
 
}
518
 
 
519
 
/*-------------------------------------------------------------------------
520
 
  -------------------------------------------------------------------------*/
521
 
 
522
 
void *
523
 
_xtrack(void *ptr, const char *path)
524
 
{
525
 
  if (unlikely(ptr == NULL)) {
526
 
    fprintf(stderr, "WARNING: cannot track NULL pointer\n");
527
 
    return ptr;
528
 
  } else {
529
 
    ResMemInfo *info;
530
 
 
531
 
    info = (ResMemInfo *) ADJUST(ptr, -res_extra_space);
532
 
    if (!CHECK_MAGIC(info->magic, info)) {
533
 
      info = (ResMemInfo *) ADJUST(info, -magic_array_offset);
534
 
    }
535
 
 
536
 
    if (!CHECK_MAGIC(info->magic, info)) {
537
 
      return ptr;
538
 
    }
539
 
 
540
 
    if (info->res) {
541
 
      res_check(info->res);
542
 
      res_inc(info->res, -((int64_t) info->size));
543
 
    }
544
 
 
545
 
    if (res_track_memory) {
546
 
      info->res = res_stat(path, info->size);
547
 
      res_check(info->res);
548
 
    } else {
549
 
      info->res = NULL;
550
 
    }
551
 
 
552
 
    return ptr;
553
 
  }
554
 
}
555
 
 
556
 
void
557
 
xdump_snap_baseline()
558
 
{
559
 
  int i;
560
 
  Resource *res;
561
 
 
562
 
  for (i = 0; i < TSIZE; i++) {
563
 
    res = (Resource *) res_table[i];
564
 
    while (res) {
565
 
      res_check(res);
566
 
      res->baseline = res->value;
567
 
      res = res->next;
568
 
    }
569
 
  }
570
 
}
571
 
 
572
 
void
573
 
xdump_to_file_baseline_rel(FILE * fp)
574
 
{
575
 
  Resource *res;
576
 
  int64_t value;
577
 
  int64_t diff;
578
 
  int i;
579
 
  struct timeval timestamp;
580
 
  char time_string[32], *time_str;
581
 
  int length_to_write;
582
 
 
583
 
  ink_gethrtimeofday(&timestamp, NULL);
584
 
  time_str = ctime((time_t *) & timestamp.tv_sec);
585
 
 
586
 
  length_to_write = squid_timestamp_to_buf(time_string, 32, timestamp.tv_sec, timestamp.tv_usec);
587
 
  time_string[length_to_write] = '\0';
588
 
 
589
 
  fprintf(fp, "PID: %d %s  %s", getpid(), time_string, time_str);
590
 
  fprintf(fp, "   value    |   delta    |   location\n");
591
 
  fprintf(fp, "rel. to base|            |           \n");
592
 
  fprintf(fp, "------------|------------|-----------------------------------------------\n");
593
 
 
594
 
  for (i = 0; i < TSIZE; i++) {
595
 
    res = (Resource *) res_table[i];
596
 
    while (res) {
597
 
      res_check(res);
598
 
 
599
 
      value = res->value - res->baseline;
600
 
      diff = res->value - res->snapshot;
601
 
      if (value != 0) {
602
 
        fprintf(fp, " % 10d | % 10d | %s\n", (int) value, (int) diff, res->path);
603
 
      }
604
 
 
605
 
      res->snapshot = res->value;
606
 
      res = res->next;
607
 
    }
608
 
  }
609
 
}
610
 
 
611
 
/*-------------------------------------------------------------------------
612
 
  -------------------------------------------------------------------------*/
613
 
 
614
 
void
615
 
xdump_to_file(FILE * fp)
616
 
{
617
 
  Resource *res;
618
 
  int64_t value;
619
 
  int64_t diff;
620
 
  int i;
621
 
  struct timeval timestamp;
622
 
  char time_string[32], *time_str;
623
 
  int length_to_write;
624
 
 
625
 
  ink_gethrtimeofday(&timestamp, NULL);
626
 
  time_str = ctime((time_t *) & timestamp.tv_sec);
627
 
 
628
 
  length_to_write = squid_timestamp_to_buf(time_string, 32, timestamp.tv_sec, timestamp.tv_usec);
629
 
  time_string[length_to_write] = '\0';
630
 
 
631
 
  fprintf(fp, "PID: %d %s  %s", getpid(), time_string, time_str);
632
 
  fprintf(fp, "   value    |   delta    |   location\n");
633
 
  fprintf(fp, "------------|------------|-----------------------------------------------\n");
634
 
 
635
 
  for (i = 0; i < TSIZE; i++) {
636
 
    res = (Resource *) res_table[i];
637
 
    while (res) {
638
 
      res_check(res);
639
 
      if (strncmp(res->path, "memory/IOBuffer/", strlen("memory/IOBuffer/"))
640
 
          != 0) {
641
 
        value = res->value;
642
 
        diff = value - res->snapshot;
643
 
        if (diff != 0) {
644
 
          fprintf(fp, " % 10d | % 10d | %s\n", (int) value, (int) diff, res->path);
645
 
        }
646
 
        res->snapshot = res->value;
647
 
      }
648
 
      res = res->next;
649
 
    }
650
 
  }
651
 
 
652
 
  fprintf(fp, "   value    |   delta    |   location\n");
653
 
  fprintf(fp, "------------|------------|-----------------------------------------------\n");
654
 
  for (i = 0; i < TSIZE; i++) {
655
 
    res = (Resource *) res_table[i];
656
 
    while (res) {
657
 
      res_check(res);
658
 
      if (strncmp(res->path, "memory/IOBuffer/", strlen("memory/IOBuffer/"))
659
 
          == 0) {
660
 
        value = res->value;
661
 
        diff = value - res->snapshot;
662
 
        if (diff != 0) {
663
 
          fprintf(fp, " % 10d | % 10d | %s\n", (int) value, (int) diff, res->path);
664
 
        }
665
 
        res->snapshot = res->value;
666
 
      }
667
 
      res = res->next;
668
 
    }
669
 
  }
670
 
}
671
 
 
672
 
/*-------------------------------------------------------------------------
673
 
  -------------------------------------------------------------------------*/
674
 
 
675
 
void
676
 
xdump()
677
 
{
678
 
  ink_stack_trace_dump();
679
 
  xdump_to_file(stderr);
680
 
}
681
 
 
682
 
/*-------------------------------------------------------------------------
683
 
  -------------------------------------------------------------------------*/
684
 
 
685
 
void
686
 
xsnap()
687
 
{
688
 
  Resource *res;
689
 
  int i;
690
 
 
691
 
  for (i = 0; i < TSIZE; i++) {
692
 
    res = (Resource *) res_table[i];
693
 
    while (res) {
694
 
      res_check(res);
695
 
      res->snapshot = res->value;
696
 
      res = res->next;
697
 
    }
698
 
  }
699
 
}
700
 
 
701
 
 
702
 
#else /* TRACK_MEMORY */
703
 
 
704
34
/*-------------------------------------------------------------------------
705
35
-------------------------------------------------------------------------*/
706
 
void
707
 
_xfree(void *mem)
708
 
{
709
 
  if (likely(mem))
710
 
    ink_free(mem);
711
 
}
712
 
 
713
 
void *
714
 
_xfree_null(void *mem)
715
 
{
716
 
  if (likely(mem))
717
 
    ink_free(mem);
718
 
  return NULL;
719
 
}
720
 
 
721
 
 
722
 
void *
723
 
_xmalloc(unsigned int size, const char *path)
724
 
{
725
 
  NOWARN_UNUSED(path);
726
 
  return ink_malloc(size);
727
 
}
728
 
 
729
 
void *
730
 
_xrealloc(void *ptr, unsigned int size, const char *path)
731
 
{
732
 
  NOWARN_UNUSED(path);
733
 
  return ink_realloc(ptr, size);
734
 
}
735
 
 
736
36
char *
737
37
_xstrdup(const char *str, int length, const char *path)
738
38
{
740
40
  char *newstr;
741
41
 
742
42
  if (likely(str)) {
743
 
    if (length < 0) {
 
43
    if (length < 0)
744
44
      length = strlen(str);
745
 
    }
746
 
    newstr = (char *) ink_malloc(length + 1);
747
 
    if (likely(newstr != NULL)) {
748
 
      strncpy(newstr, str, length);
749
 
      newstr[length] = '\0';
750
 
      return newstr;
751
 
    }
752
 
    fprintf(stderr, "FATAL: could not allocate %d bytes in _xstrdup\n", length + 1);
753
 
    ink_stack_trace_dump();
754
 
    _exit(1);
 
45
 
 
46
    newstr = (char *)ats_malloc(length + 1);
 
47
    ink_strlcpy(newstr, str, length + 1);
 
48
    return newstr;
755
49
  }
756
50
  return NULL;
757
51
}
770
64
{
771
65
  ink_stack_trace_dump();
772
66
}
773
 
 
774
 
 
775
 
#endif /* TRACK_MEMORY */