File: util_misc.cpp

package info (click to toggle)
dmtcp 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,496 kB
  • sloc: cpp: 33,592; ansic: 28,099; sh: 6,735; makefile: 1,950; perl: 1,690; python: 1,241; asm: 138; java: 13
file content (724 lines) | stat: -rw-r--r-- 19,072 bytes parent folder | download
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
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
/****************************************************************************
 *   Copyright (C) 2006-2013 by Jason Ansel, Kapil Arya, and Gene Cooperman *
 *   jansel@csail.mit.edu, kapil@ccs.neu.edu, gene@ccs.neu.edu              *
 *                                                                          *
 *  This file is part of DMTCP.                                             *
 *                                                                          *
 *  DMTCP is free software: you can redistribute it and/or                  *
 *  modify it under the terms of the GNU Lesser General Public License as   *
 *  published by the Free Software Foundation, either version 3 of the      *
 *  License, or (at your option) any later version.                         *
 *                                                                          *
 *  DMTCP is distributed in the hope that it will be useful,                *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 *  GNU Lesser General Public License for more details.                     *
 *                                                                          *
 *  You should have received a copy of the GNU Lesser General Public        *
 *  License along with DMTCP:dmtcp/src.  If not, see                        *
 *  <http://www.gnu.org/licenses/>.                                         *
 ****************************************************************************/

#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include  "util.h"
#include  "membarrier.h"
#include  "syscallwrappers.h"
#include  "dmtcp.h"
#include  "protectedfds.h"
#include  "../jalib/jassert.h"
#include  "../jalib/jfilesystem.h"

using namespace dmtcp;

void Util::lockFile(int fd)
{
  struct flock fl;

  fl.l_type   = F_WRLCK;  // F_RDLCK, F_WRLCK, F_UNLCK
  fl.l_whence = SEEK_SET; // SEEK_SET, SEEK_CUR, SEEK_END
  fl.l_start  = 0;        // Offset from l_whence
  fl.l_len    = 0;        // length, 0 = to EOF
  //fl.l_pid    = _real_getpid(); // our PID

  int result = -1;
  errno = 0;
  do {
    result = _real_fcntl(fd, F_SETLKW, &fl);  /* F_GETLK, F_SETLK, F_SETLKW */
  } while (result == -1 && errno == EINTR);

  JASSERT (result != -1) (JASSERT_ERRNO)
    .Text("Unable to lock the PID MAP file");
#if (__arm__ || __aarch64__)
  WMB;  // DMB, ensure writes by others to memory have completed before we
        //      we enter protected region.
#endif
}

void Util::unlockFile(int fd)
{
  struct flock fl;
  int result;

#if (__arm__ || __aarch64__)
  RMB; WMB; // DMB, ensure accesses to protected memory have completed
            //      before releasing lock
#endif
  fl.l_type   = F_UNLCK;  // tell it to unlock the region
  fl.l_whence = SEEK_SET; // SEEK_SET, SEEK_CUR, SEEK_END
  fl.l_start  = 0;        // Offset from l_whence
  fl.l_len    = 0;        // length, 0 = to EOF

#if (__arm__ || __aarch64__)
  WMB;  // DSB, ensure update of fl before seen by other CPUs
#endif

  result = _real_fcntl(fd, F_SETLK, &fl); /* set the region to unlocked */

  JASSERT (result != -1 || errno == ENOLCK) (JASSERT_ERRNO)
    .Text("Unlock Failed");
}

bool Util::strStartsWith(const char *str, const char *pattern)
{
  if (str == NULL || pattern == NULL) {
    return false;
  }
  int len1 = strlen(str);
  int len2 = strlen(pattern);
  if (len1 >= len2) {
    return strncmp(str, pattern, len2) == 0;
  }
  return false;
}

bool Util::strEndsWith(const char *str, const char *pattern)
{
  if (str == NULL || pattern == NULL) {
    return false;
  }
  int len1 = strlen(str);
  int len2 = strlen(pattern);
  if (len1 >= len2) {
    size_t idx = len1 - len2;
    return strncmp(str+idx, pattern, len2) == 0;
  }
  return false;
}

bool Util::strStartsWith(const string& str, const char *pattern)
{
  return strStartsWith(str.c_str(), pattern);
}

bool Util::strEndsWith(const string& str, const char *pattern)
{
  return strEndsWith(str.c_str(), pattern);
}

string Util::joinStrings(vector<string> v, const string& delim)
{
  string result;
  if (v.size() > 0) {
    result = v[0];
    for (size_t i = 1; i < v.size(); i++) {
      result += delim + v[i];
    }
  }
  return result;
}


string Util::removeSuffix(const string& s, const string& suffix)
{
  if (strEndsWith(s, suffix.c_str())) {
    string result(s, s.length() - suffix.length());
    return result;
  }
  return s;
}


// Tokenizes the string using the delimiters.
// Empty tokens will not be included in the result.
vector<string> Util::tokenizeString(const string& s, const string& delims)
{
  size_t offset = 0;
  vector<string> tokens;

  while (true) {
    size_t i = s.find_first_not_of(delims, offset);
    if (i == string::npos) {
      break;
    }

    size_t j = s.find_first_of(delims, i);
    if (j == string::npos) {
      tokens.push_back(s.substr(i));
      offset = s.length();
      continue;
    }

    tokens.push_back(s.substr(i, j - i));
    offset = j;
  }
  return tokens;
}

// Add it back if needed.
#if 0
// Splits the string using the provided delimiters.
// The string is split each time at the first character
// that matches any of the characters specified in delims.
// Empty tokens are allowed in the result.
// Optionally, maximum number of tokens to be returned
// can be specified.
inline vector<string> split(
    const string& s,
    const string& delims,
    const Option<unsigned int>& n = None())
{
  vector<string> tokens;
  size_t offset = 0;
  size_t next = 0;

  while (n.isNone() || n.get() > 0) {
    next = s.find_first_of(delims, offset);
    if (next == string::npos) {
      tokens.push_back(s.substr(offset));
      break;
    }

    tokens.push_back(s.substr(offset, next - offset));
    offset = next + 1;

    // Finish splitting if we've found enough tokens.
    if (n.isSome() && tokens.size() == n.get() - 1) {
      tokens.push_back(s.substr(offset));
      break;
    }
  }
  return tokens;
}
#endif

bool Util::createDirectoryTree(const string& path)
{
  size_t index = path.rfind('/');

  if (index == string::npos)
    return true;

  string dir = path.substr(0, index);

  index = path.find('/');
  while (index != string::npos) {
    if (index > 1) {
      string dirName = path.substr(0, index);

      errno = 0;
      int res = mkdir(dirName.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
#ifdef STAMPEDE_LUSTRE_FIX
      if (res < 0) {
        if (errno == EACCES) {
          struct stat buff;
          int ret = stat(dirName.c_str(), &buff);
          if (ret != 0) {
            return false;
          };
        } else if (errno == EEXIST) {
          /* do nothing */
        } else {
          return false;
        }
      }
#else
      if (res == -1 && errno != EEXIST) {
        return false;
      }
#endif
    }
    index = path.find('/', index+1);
  }
  return true;
}

// Fails or does entire write (returns count)
ssize_t Util::writeAll(int fd, const void *buf, size_t count)
{
  const char *ptr = (const char *) buf;
  size_t num_written = 0;

  do {
    ssize_t rc = _real_write (fd, ptr + num_written, count - num_written);
    if (rc == -1) {
      if (errno == EINTR || errno == EAGAIN)
	continue;
      else
        return rc;
    }
    else if (rc == 0)
      break;
    else // else rc > 0
      num_written += rc;
  } while (num_written < count);
  JASSERT (num_written == count) (num_written) (count);
  return num_written;
}

// Fails, succeeds, or partial read due to EOF (returns num read)
// return value:
//    -1: unrecoverable error
//   <n>: number of bytes read
ssize_t Util::readAll(int fd, void *buf, size_t count)
{
  ssize_t rc;
  char *ptr = (char *) buf;
  size_t num_read = 0;
  for (num_read = 0; num_read < count;) {
    rc = _real_read (fd, ptr + num_read, count - num_read);
    if (rc == -1) {
      if (errno == EINTR || errno == EAGAIN)
	continue;
      else
        return -1;
    }
    else if (rc == 0)
      break;
    else // else rc > 0
      num_read += rc;
  }
  return num_read;
}

ssize_t Util::skipBytes(int fd, size_t count)
{
  char buf[1024];
  ssize_t rc;
  ssize_t totalSkipped = 0;
  while (count > 0) {
    rc = Util::readAll(fd, buf, MIN(count, sizeof(buf)));

    if (rc == -1) {
      break;
    }
    count -= rc;
    totalSkipped += rc;
  }
  return totalSkipped;
}

void Util::changeFd(int oldfd, int newfd)
{
  if (oldfd != newfd) {
    JASSERT(_real_dup2(oldfd, newfd) == newfd);
    _real_close(oldfd);
  }
}

void Util::dupFds(int oldfd, const vector<int>& newfds)
{
  changeFd(oldfd, newfds[0]);
  for (size_t i = 1; i < newfds.size(); i++) {
    JASSERT(_real_dup2(newfds[0], newfds[i]) == newfds[i]);
  }
}


/* Begin miscellaneous/helper functions. */

/* Reads from fd until count bytes are read, or
 * newline encountered.
 *
 * Side effects: Copies the characters, including
 * the newline, read from the fd into the buf.
 *
 * Returns num of chars read on success;
 *         -1 on read failure or invalid args; and
 *         -2 if the buffer is too small
 */
int Util::readLine(int fd, char *buf, int count)
{
  int i = 0;
  char c;
  JASSERT(fd >= 0 && buf != NULL) (fd) ((void*)buf);
#define NEWLINE '\n' // Linux, OSX
  while (i < count) {
    ssize_t rc = read(fd, &c, 1);
    if (rc == 0) {
      break;
    } else if (rc < 0) {
      buf[i] = '\0';
      return -1;
    } else {
      buf[i++] = c;
      if (c == NEWLINE) break;
    }
  }
  buf[i] = '\0';
  if (i >= count)
    return -2;
  else
    return i;
}

/* Read decimal number, return value and terminating character */

char Util::readDec (int fd, VA *value)
{
  char c;
  unsigned long int v;

  v = 0;
  while (1) {
    c = readChar (fd);
    if ((c >= '0') && (c <= '9')) c -= '0';
    else break;
    v = v * 10 + c;
  }
  *value = (VA)v;
  return (c);
}

/* Read decimal number, return value and terminating character */

char Util::readHex (int fd, VA *value)
{
  char c;
  unsigned long int v;

  v = 0;
  while (1) {
    c = readChar (fd);
         if ((c >= '0') && (c <= '9')) c -= '0';
    else if ((c >= 'a') && (c <= 'f')) c -= 'a' - 10;
    else if ((c >= 'A') && (c <= 'F')) c -= 'A' - 10;
    else break;
    v = v * 16 + c;
  }
  *value = (VA)v;
  return (c);
}

/* Read non-null character, return null if EOF */

char Util::readChar (int fd)
{
  char c;
  int rc;

  do {
    rc = _real_read (fd, &c, 1);
  } while ( rc == -1 && errno == EINTR );
  if (rc <= 0) return (0);
  return (c);
}


int Util::readProcMapsLine(int mapsfd, ProcMapsArea *area)
{
  char c, rflag, sflag, wflag, xflag;
  int i;
  off_t offset;
  unsigned int long devmajor, devminor, inodenum;
  VA startaddr, endaddr;

  c = readHex (mapsfd, &startaddr);
  if ((c == 0) && (startaddr == 0)) return (0);
  if (c != '-') {
    goto skipeol;
  }
  c = readHex (mapsfd, &endaddr);
  if (c != ' ') goto skipeol;
  if (endaddr < startaddr) goto skipeol;

  rflag = c = readChar (mapsfd);
  if ((c != 'r') && (c != '-')) goto skipeol;
  wflag = c = readChar (mapsfd);
  if ((c != 'w') && (c != '-')) goto skipeol;
  xflag = c = readChar (mapsfd);
  if ((c != 'x') && (c != '-')) goto skipeol;
  sflag = c = readChar (mapsfd);
  if ((c != 's') && (c != 'p')) goto skipeol;

  c = readChar (mapsfd);
  if (c != ' ') goto skipeol;

  c = readHex (mapsfd, (VA *)&offset);
  if (c != ' ') goto skipeol;
  area -> offset = offset;

  c = readHex (mapsfd, (VA *)&devmajor);
  if (c != ':') goto skipeol;
  c = readHex (mapsfd, (VA *)&devminor);
  if (c != ' ') goto skipeol;
  c = readDec (mapsfd, (VA *)&inodenum);
  area -> name[0] = '\0';
  while (c == ' ') c = readChar (mapsfd);
  if (c == '/' || c == '[' || c == '(') {
    // absolute pathname, or [stack], [vdso], etc.
    // On some machines, deleted files have a " (deleted)" prefix to the
    // filename.
    i = 0;
    do {
      area -> name[i++] = c;
      if (i == sizeof area -> name) goto skipeol;
      c = readChar (mapsfd);
    } while (c != '\n');
    area -> name[i] = '\0';
  }

  if (c != '\n') goto skipeol;

  area -> addr = startaddr;
  area -> size = endaddr - startaddr;
  area -> endAddr = endaddr;
  area -> prot = 0;
  if (rflag == 'r') area -> prot |= PROT_READ;
  if (wflag == 'w') area -> prot |= PROT_WRITE;
  if (xflag == 'x') area -> prot |= PROT_EXEC;
  area -> flags = MAP_FIXED;
  if (sflag == 's') area -> flags |= MAP_SHARED;
  if (sflag == 'p') area -> flags |= MAP_PRIVATE;
  if (area -> name[0] == '\0') area -> flags |= MAP_ANONYMOUS;

  area->devmajor = devmajor;
  area->devminor = devminor;
  area->inodenum = inodenum;
  return (1);

skipeol:
  JASSERT(false) .Text("Not Reached");
  return (0);  /* NOTREACHED : stop compiler warning */
}

int Util::memProtToOpenFlags(int prot)
{
  if (prot & (PROT_READ | PROT_WRITE)) return O_RDWR;
  if (prot & PROT_READ) return O_RDONLY;
  if (prot & PROT_WRITE) return O_WRONLY;
  return 0;
}

#define TRACER_PID_STR "TracerPid:"
pid_t Util::getTracerPid(pid_t tid)
{
  if (!dmtcp_real_to_virtual_pid) {
    return 0;
  }

  char buf[512];
  char *str;
  static int tracerStrLen = strlen(TRACER_PID_STR);
  int fd;

  if (tid == -1) {
    tid = dmtcp_gettid();
  }
  sprintf(buf, "/proc/%d/status", tid);
  fd = _real_open(buf, O_RDONLY, 0);
  JASSERT(fd != -1) (buf) (JASSERT_ERRNO);
  readAll(fd, buf, sizeof buf);
  _real_close(fd);
  str = strstr(buf, TRACER_PID_STR);
  JASSERT(str != NULL);
  str += tracerStrLen;

  while (*str == ' ' || *str == '\t') {
    str++;
  }

  pid_t tracerPid = (pid_t) strtol(str, NULL, 10);
  return tracerPid == 0 ? tracerPid : dmtcp_real_to_virtual_pid(tracerPid);
}

bool Util::isPtraced()
{
  return getTracerPid() != 0;
}

bool Util::isValidFd(int fd)
{
  return _real_fcntl(fd, F_GETFL, 0) != -1;
}

size_t Util::pageSize()
{
  static size_t page_size = sysconf(_SC_PAGESIZE);
  return page_size;
}

size_t Util::pageMask()
{
  static size_t page_mask = ~(pageSize() - 1);
  return page_mask;
}

/* This function detects if the given pages are zero pages or not. There is
 * scope of improving this function using some optimizations.
 *
 * TODO: One can use /proc/self/pagemap to detect if the page is backed by a
 * shared zero page.
 */
bool Util::areZeroPages(void *addr, size_t numPages)
{
  static size_t page_size = pageSize();
  long long *buf = (long long*) addr;
  size_t i;
  size_t end = numPages * page_size / sizeof (*buf);
  long long res = 0;
  for (i = 0; i + 7 < end; i += 8) {
    res = buf[i+0] | buf[i+1] | buf[i+2] | buf[i+3] |
          buf[i+4] | buf[i+5] | buf[i+6] | buf[i+7];
    if (res != 0) {
      break;
    }
  }
  return res == 0;
}

/* Caller must allocate exec_path of size at least MTCP_MAX_PATH */
char *Util::findExecutable(char *executable, const char* path_env,
                                  char *exec_path)
{
  char *path;
  const char *tmp_env;
  int len;

  JASSERT(exec_path != NULL);
  if (path_env == NULL) {
    path_env = ""; // Will try stdpath later in this function
  }
  tmp_env = path_env;

  while (*tmp_env != '\0') {
    path = exec_path;
    len = 0;
    while (*tmp_env != ':' && *tmp_env != '\0' && ++len < PATH_MAX - 1)
      *path++ = *tmp_env++;
    if (*tmp_env == ':') /* but if *tmp_env == '\0', will exit while loop */
      tmp_env++;
    *path++ = '/'; /* '...//... is same as .../... in POSIX */
    len++;
    *path++ = '\0';
    strncat(exec_path, executable, PATH_MAX - len - 1);
    if (access(exec_path, X_OK) == 0){
      // Artem: Additionally check that this is regular file.
      // From access point of view directories are executables too :)
      // I ran into problem on the system where user home dir was in the PATH
      // and I create a directory named "hbict" in it.
      // Eventually home path was before my sandbox path and DMTCP was
      // trying to call a directory :)
      struct stat buf;
      if( stat(exec_path, &buf) ){
        continue;
      }
      if( S_ISREG(buf.st_mode) )
        return exec_path;
    }
  }

  // In case we're running with PATH environment variable unset:
  const char * stdpath = "/usr/local/bin:/usr/bin:/bin";
  if (strcmp(path_env, stdpath) == 0) {
    return NULL;  // Already tried stdpath
  } else {
    return findExecutable(executable, stdpath, exec_path);
  }
}

// Check for NSCD area.
bool Util::isNscdArea(const ProcMapsArea& area)
{
  if (strStartsWith(area.name, "/run/nscd") || // OpenSUSE (newer)
      strStartsWith(area.name, "/var/run/nscd") || // OpenSUSE (older)
      strStartsWith(area.name, "/var/cache/nscd") || // Debian/Ubuntu
      strStartsWith(area.name, "/var/db/nscd") || // RedHat/Fedora
      strStartsWith(area.name, "/ram/var/run/nscd")) {  // CentOS
    return true;
  }
  return false;
}

// Check for Sys V shared memory area.
bool Util::isSysVShmArea(const ProcMapsArea& area)
{
  return strStartsWith(area.name, "/SYSV");
}

// Check for Sys V shared memory area.
bool Util::isIBShmArea(const ProcMapsArea& area)
{
  return strStartsWith(area.name, "/dev/infiniband/uverbs");
}

void Util::allowGdbDebug(int currentDebugLevel)
{
  if (Util::isValidFd(PROTECTED_DEBUG_SOCKET_FD)) {
    int requestedDebugLevel = 0;
    // Inform parent of current level
    JASSERT(write(PROTECTED_DEBUG_SOCKET_FD,
                  &currentDebugLevel,
                  sizeof(currentDebugLevel))
            == sizeof(currentDebugLevel));
    // Read the requested level from the parent
    JASSERT(read(PROTECTED_DEBUG_SOCKET_FD,
                 &requestedDebugLevel,
                 sizeof(requestedDebugLevel))
            == sizeof(requestedDebugLevel));
    if (currentDebugLevel == requestedDebugLevel) {
      // Wait for GDB to connect if the requested level
      // matches the current level
      sleep(3);
    }
  }
}

static inline uint32_t
stringToEnumMask(const char *s)
{
  uint32_t m = jassert_internal::UNKNOWN;
  if (strcmp(s, "JTRACE") == 0) {
    m = jassert_internal::JTRACE;
  } else if (strcmp(s, "ALLOC") == 0) {
    m = jassert_internal::ALLOC;
  } else if (strcmp(s, "DL") == 0) {
    m = jassert_internal::DL;
  } else if (strcmp(s, "DMTCP") == 0) {
    m = jassert_internal::DMTCP;
  } else if (strcmp(s, "EVENT") == 0) {
    m = jassert_internal::EVENT;
  } else if (strcmp(s, "FILEP") == 0) {
    m = jassert_internal::FILEP;
  } else if (strcmp(s, "SOCKET") == 0) {
    m = jassert_internal::SOCKET;
  } else if (strcmp(s, "SSH") == 0) {
    m = jassert_internal::SSH;
  } else if (strcmp(s, "IPC") == 0) {
    m = jassert_internal::IPC;
  } else if (strcmp(s, "PID") == 0) {
    m = jassert_internal::PID;
  } else if (strcmp(s, "SYSV") == 0) {
    m = jassert_internal::SYSV;
  } else if (strcmp(s, "TIMER") == 0) {
    m = jassert_internal::TIMER;
  } else if (strcmp(s, "ALL") == 0) {
    m = jassert_internal::ALL;
  } else {
    m = jassert_internal::UNKNOWN;
  }
  return m;
}

uint32_t
Util::processDebugLogsArg(char *logString)
{
  char *logSrc = strtok(logString, ":");
  uint32_t mask = jassert_internal::JTRACE;
  while (logSrc) {
    mask |= stringToEnumMask(logSrc);
    logSrc = strtok(NULL, ":");
  }
  return mask;
}