-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
212a563
commit bb50f59
Showing
10 changed files
with
260 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -520,15 +520,14 @@ static int debug_memory_add (const char *name, void *address, size_t size, const | |
return 0; | ||
} | ||
|
||
static int debug_memory_check (void *address, const char *command, const char *func, const char *file, const int line) | ||
static int debug_memory_check_actual (void *address, const char *command, const char *func, const char *file, const int line) | ||
{ | ||
int rcu; | ||
int rco; | ||
struct hmemory_memory *m; | ||
if (address == NULL) { | ||
return 0; | ||
} | ||
hmemory_lock(); | ||
HASH_FIND_PTR(debug_memory, &address, m); | ||
if (m != NULL) { | ||
goto found_m; | ||
|
@@ -544,7 +543,6 @@ static int debug_memory_check (void *address, const char *command, const char *f | |
hinfof(" at: [email protected]"); | ||
hdebug_unlock(); | ||
hassert((m != NULL) && "invalid address"); | ||
hmemory_unlock(); | ||
return -1; | ||
found_m: | ||
hdebug_lock(); | ||
|
@@ -562,6 +560,13 @@ static int debug_memory_check (void *address, const char *command, const char *f | |
} | ||
hdebug_unlock(); | ||
hassert(((rcu == 0) && (rco == 0)) && "memory corruption"); | ||
return 0; | ||
} | ||
|
||
static int debug_memory_check (void *address, const char *command, const char *func, const char *file, const int line) | ||
{ | ||
hmemory_lock(); | ||
debug_memory_check_actual(address, command, func, file, line); | ||
hmemory_unlock(); | ||
return 0; | ||
} | ||
|
@@ -599,15 +604,61 @@ static int debug_memory_del (void *address, const char *command, const char *fun | |
return 0; | ||
} | ||
|
||
static int hmemory_worker_started = 0; | ||
static int hmemory_worker_running = 0; | ||
static pthread_t hmemory_thread; | ||
|
||
static void * hmemory_worker (void *arg) | ||
{ | ||
unsigned int v; | ||
struct hmemory_memory *m; | ||
struct hmemory_memory *nm; | ||
(void) arg; | ||
while (1) { | ||
v = hmemory_getenv_int(HMEMORY_CORRUPTION_CHECK_INTERVAL_NAME); | ||
if (v == (unsigned int) -1) { | ||
v = HMEMORY_CORRUPTION_CHECK_INTERVAL; | ||
} | ||
usleep(v * 1000); | ||
hmemory_lock(); | ||
if (hmemory_worker_running == 0) { | ||
hmemory_unlock(); | ||
break; | ||
} | ||
HASH_ITER(hh, debug_memory, m, nm) { | ||
debug_memory_check_actual(m->address, "worker check", __FUNCTION__, __FILE__, __LINE__); | ||
} | ||
hmemory_unlock(); | ||
} | ||
return NULL; | ||
} | ||
|
||
static void __attribute__ ((constructor)) hmemory_init (void) | ||
{ | ||
int rc; | ||
hmemory_lock(); | ||
hmemory_worker_started = 1; | ||
hmemory_worker_running = 1; | ||
rc = pthread_create(&hmemory_thread, NULL, hmemory_worker, NULL); | ||
if (rc != 0) { | ||
herrorf("failed to create worker"); | ||
hmemory_worker_started = 0; | ||
hmemory_worker_running = 0; | ||
} | ||
hmemory_unlock(); | ||
} | ||
|
||
static void __attribute__ ((destructor)) hmemory_fini (void) | ||
{ | ||
struct hmemory_memory *m; | ||
struct hmemory_memory *nm; | ||
hmemory_lock(); | ||
if (hmemory_worker_running == 1) { | ||
hmemory_worker_running = 0; | ||
} | ||
hmemory_unlock(); | ||
pthread_join(hmemory_thread, NULL); | ||
hmemory_lock(); | ||
hdebug_lock(); | ||
hinfof("memory information:") | ||
hinfof(" current: %llu bytes (%.02f mb)", memory_current, ((double) memory_current) / (1024.00 * 1024.00)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2008-2013 Alper Akcan <[email protected]> | ||
* | ||
* This program is free software. It comes without any warranty, to | ||
* the extent permitted by applicable law. You can redistribute it | ||
* and/or modify it under the terms of the Do What The Fuck You Want | ||
* To Public License, Version 2, as published by Sam Hocevar. See | ||
* http://www.wtfpl.net/ for more details. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
int main (int argc, char *argv[]) | ||
{ | ||
void *rc; | ||
(void) argc; | ||
(void) argv; | ||
rc = malloc(1024); | ||
if (rc == NULL) { | ||
fprintf(stderr, "malloc failed\n"); | ||
exit(-1); | ||
} | ||
memset(rc + 10, 0, 1024); | ||
sleep(1); | ||
free(rc); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2008-2013 Alper Akcan <[email protected]> | ||
* | ||
* This program is free software. It comes without any warranty, to | ||
* the extent permitted by applicable law. You can redistribute it | ||
* and/or modify it under the terms of the Do What The Fuck You Want | ||
* To Public License, Version 2, as published by Sam Hocevar. See | ||
* http://www.wtfpl.net/ for more details. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
int main (int argc, char *argv[]) | ||
{ | ||
void *rc; | ||
(void) argc; | ||
(void) argv; | ||
rc = malloc(1024); | ||
if (rc == NULL) { | ||
fprintf(stderr, "malloc failed\n"); | ||
exit(-1); | ||
} | ||
memset(rc - 10, 0, 1024); | ||
sleep(1); | ||
free(rc); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2008-2013 Alper Akcan <[email protected]> | ||
* | ||
* This program is free software. It comes without any warranty, to | ||
* the extent permitted by applicable law. You can redistribute it | ||
* and/or modify it under the terms of the Do What The Fuck You Want | ||
* To Public License, Version 2, as published by Sam Hocevar. See | ||
* http://www.wtfpl.net/ for more details. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
int main (int argc, char *argv[]) | ||
{ | ||
void *rc; | ||
(void) argc; | ||
(void) argv; | ||
rc = malloc(1024); | ||
if (rc == NULL) { | ||
fprintf(stderr, "malloc failed\n"); | ||
exit(-1); | ||
} | ||
memset(rc - 10, 0, 1044); | ||
sleep(1); | ||
free(rc); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2008-2013 Alper Akcan <[email protected]> | ||
* | ||
* This program is free software. It comes without any warranty, to | ||
* the extent permitted by applicable law. You can redistribute it | ||
* and/or modify it under the terms of the Do What The Fuck You Want | ||
* To Public License, Version 2, as published by Sam Hocevar. See | ||
* http://www.wtfpl.net/ for more details. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
int main (int argc, char *argv[]) | ||
{ | ||
void *rc; | ||
(void) argc; | ||
(void) argv; | ||
rc = malloc(1024); | ||
if (rc == NULL) { | ||
fprintf(stderr, "malloc failed\n"); | ||
exit(-1); | ||
} | ||
memset(rc, 0, 1024); | ||
sleep(1); | ||
free(rc); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2008-2013 Alper Akcan <[email protected]> | ||
* | ||
* This program is free software. It comes without any warranty, to | ||
* the extent permitted by applicable law. You can redistribute it | ||
* and/or modify it under the terms of the Do What The Fuck You Want | ||
* To Public License, Version 2, as published by Sam Hocevar. See | ||
* http://www.wtfpl.net/ for more details. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
int main (int argc, char *argv[]) | ||
{ | ||
void *rc; | ||
(void) argc; | ||
(void) argv; | ||
rc = malloc(1024); | ||
if (rc == NULL) { | ||
fprintf(stderr, "malloc failed\n"); | ||
exit(-1); | ||
} | ||
memset(rc, 0, 1024); | ||
sleep(1); | ||
free(rc); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2008-2013 Alper Akcan <[email protected]> | ||
* | ||
* This program is free software. It comes without any warranty, to | ||
* the extent permitted by applicable law. You can redistribute it | ||
* and/or modify it under the terms of the Do What The Fuck You Want | ||
* To Public License, Version 2, as published by Sam Hocevar. See | ||
* http://www.wtfpl.net/ for more details. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
int main (int argc, char *argv[]) | ||
{ | ||
void *rc; | ||
(void) argc; | ||
(void) argv; | ||
rc = malloc(1024); | ||
if (rc == NULL) { | ||
fprintf(stderr, "malloc failed\n"); | ||
exit(-1); | ||
} | ||
memset(rc, 0, 1024); | ||
sleep(1); | ||
free(rc); | ||
return 0; | ||
} |