version 1.19, 2010/05/22 21:47:07
|
version 1.26, 2010/06/17 11:00:23
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.0.15 |
RPL/2 (R) version 4.0.16 |
Copyright (C) 1989-2010 Dr. BERTRAND Joël |
Copyright (C) 1989-2010 Dr. BERTRAND Joël |
|
|
This file is part of RPL/2. |
This file is part of RPL/2. |
Line 1121 liberation(struct_processus *s_etat_proc
|
Line 1121 liberation(struct_processus *s_etat_proc
|
.nombre_references--; |
.nombre_references--; |
|
|
BUG((*(*((struct_processus_fils *) (*s_objet).objet)).thread) |
BUG((*(*((struct_processus_fils *) (*s_objet).objet)).thread) |
.nombre_references < 0, printf("(*(*((struct_processus_fils" |
.nombre_references < 0, uprintf( |
|
"(*(*((struct_processus_fils" |
" *) (*s_objet).objet)).thread).nombre_references = %d\n", |
" *) (*s_objet).objet)).thread).nombre_references = %d\n", |
(int) (*(*((struct_processus_fils *) (*s_objet).objet)) |
(int) (*(*((struct_processus_fils *) (*s_objet).objet)) |
.thread).nombre_references)); |
.thread).nombre_references)); |
Line 2267 copie_objet(struct_processus *s_etat_pro
|
Line 2268 copie_objet(struct_processus *s_etat_pro
|
|
|
(*((struct_processus_fils *) (*s_nouvel_objet).objet)) = |
(*((struct_processus_fils *) (*s_nouvel_objet).objet)) = |
(*((struct_processus_fils *) (*s_objet).objet)); |
(*((struct_processus_fils *) (*s_objet).objet)); |
|
|
break; |
break; |
} |
} |
|
|
Line 3565 copie_etat_processus(struct_processus *s
|
Line 3567 copie_etat_processus(struct_processus *s
|
#undef malloc |
#undef malloc |
#undef realloc |
#undef realloc |
#undef free |
#undef free |
|
#undef fork |
|
|
#ifdef return |
#ifdef return |
# undef return |
# undef return |
#endif |
#endif |
|
|
#undef fprintf |
|
|
|
#ifdef __BACKTRACE |
#ifdef __BACKTRACE |
|
#define PROFONDEUR_PILE 64 |
#define return(a) { if (a == NULL) \ |
#define return(a) { if (a == NULL) \ |
{ BACKTRACE(20); fprintf(stderr, ">>> MEDITATION %d\n", __LINE__); } \ |
{ BACKTRACE(PROFONDEUR_PILE); \ |
|
fprintf(stderr, ">>> MEDITATION %d\n", __LINE__); } \ |
return(a); } while(0) |
return(a); } while(0) |
#define PROFONDEUR_PILE 64 |
|
#endif |
#endif |
|
|
|
#undef fprintf |
|
#define check(a, b) ((strcmp(#a, fonction) == 0) && (ligne == b)) |
|
#undef CORE_DUMP |
|
|
typedef struct memoire |
typedef struct memoire |
{ |
{ |
void *pointeur; |
void *pointeur; |
Line 3596 typedef struct memoire
|
Line 3602 typedef struct memoire
|
|
|
static struct_memoire *debug = NULL; |
static struct_memoire *debug = NULL; |
static unsigned long long ordre = 0; |
static unsigned long long ordre = 0; |
static pthread_mutex_t mutex_allocation = PTHREAD_MUTEX_INITIALIZER; |
static pthread_mutex_t mutex_allocation; |
|
|
#define check(a, b) ((strcmp(#a, fonction) == 0) && (ligne == b)) |
void |
#undef CORE_DUMP |
debug_memoire_initialisation() |
|
{ |
|
pthread_mutexattr_t attributs_mutex; |
|
|
|
pthread_mutexattr_init(&attributs_mutex); |
|
pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_RECURSIVE); |
|
pthread_mutex_init(&mutex_allocation, &attributs_mutex); |
|
pthread_mutexattr_destroy(&attributs_mutex); |
|
|
|
return; |
|
} |
|
|
void * |
void * |
debug_memoire_ajout(size_t taille, const unsigned char *fonction, |
debug_memoire_ajout(size_t taille, const unsigned char *fonction, |
Line 3607 debug_memoire_ajout(size_t taille, const
|
Line 3623 debug_memoire_ajout(size_t taille, const
|
{ |
{ |
struct_memoire *ancienne_base; |
struct_memoire *ancienne_base; |
|
|
|
void *pointeur; |
|
|
pthread_mutex_lock(&mutex_allocation); |
pthread_mutex_lock(&mutex_allocation); |
|
|
ancienne_base = debug; |
ancienne_base = debug; |
Line 3628 debug_memoire_ajout(size_t taille, const
|
Line 3646 debug_memoire_ajout(size_t taille, const
|
(*debug).taille = taille; |
(*debug).taille = taille; |
(*debug).ordre = ordre; |
(*debug).ordre = ordre; |
|
|
|
pointeur = (*debug).pointeur; |
|
|
# ifdef __BACKTRACE |
# ifdef __BACKTRACE |
(*debug).profondeur = backtrace((*debug).pile, PROFONDEUR_PILE); |
(*debug).profondeur = backtrace((*debug).pile, PROFONDEUR_PILE); |
# endif |
# endif |
Line 3649 debug_memoire_ajout(size_t taille, const
|
Line 3669 debug_memoire_ajout(size_t taille, const
|
strcpy((*debug).fonction, fonction); |
strcpy((*debug).fonction, fonction); |
strcpy((*debug).argument, argument); |
strcpy((*debug).argument, argument); |
|
|
|
memset((*debug).pointeur, 0, (*debug).taille); |
|
|
pthread_mutex_unlock(&mutex_allocation); |
pthread_mutex_unlock(&mutex_allocation); |
ordre++; |
ordre++; |
|
|
return((*debug).pointeur); |
return(pointeur); |
} |
} |
|
|
void * |
void * |
Line 3666 debug_memoire_modification(void *pointeu
|
Line 3688 debug_memoire_modification(void *pointeu
|
{ |
{ |
if (taille == 0) |
if (taille == 0) |
{ |
{ |
// Revient à free() |
// Revient à free(). Il n'y a pas de parenthèses car on ne veut |
|
// pas utiliser la macro return(). |
|
|
debug_memoire_retrait(pointeur); |
debug_memoire_retrait(pointeur); |
return(NULL); |
return NULL ; |
} |
} |
else |
else |
{ |
{ |
Line 3691 debug_memoire_modification(void *pointeu
|
Line 3715 debug_memoire_modification(void *pointeu
|
if (element_courant == NULL) |
if (element_courant == NULL) |
{ |
{ |
pthread_mutex_unlock(&mutex_allocation); |
pthread_mutex_unlock(&mutex_allocation); |
return(NULL); |
|
} |
|
|
|
if (((*element_courant).pointeur = realloc(pointeur, taille)) |
uprintf("[%d-%llu] ILLEGAL POINTER (realloc)\n", |
== NULL) |
getpid(), (unsigned long long) pthread_self()); |
{ |
# ifdef __BACKTRACE |
pthread_mutex_unlock(&mutex_allocation); |
BACKTRACE(PROFONDEUR_PILE); |
return(NULL); |
# endif |
|
|
|
return(realloc(pointeur, taille)); |
} |
} |
|
else |
|
{ |
|
if (((*element_courant).pointeur = realloc(pointeur, taille)) |
|
== NULL) |
|
{ |
|
pthread_mutex_unlock(&mutex_allocation); |
|
return(NULL); |
|
} |
|
|
(*element_courant).ligne = ligne; |
(*element_courant).ligne = ligne; |
(*element_courant).taille = taille; |
(*element_courant).taille = taille; |
free((*element_courant).fonction); |
free((*element_courant).fonction); |
free((*element_courant).argument); |
free((*element_courant).argument); |
|
|
if (((*element_courant).fonction = malloc((strlen(fonction) + 1) * |
if (((*element_courant).fonction = malloc((strlen(fonction) |
sizeof(unsigned char))) == NULL) |
+ 1) * sizeof(unsigned char))) == NULL) |
{ |
{ |
pthread_mutex_unlock(&mutex_allocation); |
pthread_mutex_unlock(&mutex_allocation); |
return(NULL); |
return(NULL); |
} |
} |
|
|
if (((*element_courant).argument = malloc((strlen(argument) + 1) * |
if (((*element_courant).argument = malloc((strlen(argument) |
sizeof(unsigned char))) == NULL) |
+ 1) * sizeof(unsigned char))) == NULL) |
{ |
{ |
pthread_mutex_unlock(&mutex_allocation); |
pthread_mutex_unlock(&mutex_allocation); |
return(NULL); |
return(NULL); |
} |
} |
|
|
strcpy((*element_courant).fonction, fonction); |
strcpy((*element_courant).fonction, fonction); |
strcpy((*element_courant).argument, argument); |
strcpy((*element_courant).argument, argument); |
|
|
pthread_mutex_unlock(&mutex_allocation); |
pthread_mutex_unlock(&mutex_allocation); |
|
|
return((*element_courant).pointeur); |
return((*element_courant).pointeur); |
|
} |
} |
} |
} |
} |
else |
else |
Line 3760 debug_memoire_retrait(void *pointeur)
|
Line 3793 debug_memoire_retrait(void *pointeur)
|
(*element_precedent).suivant = (*element_courant).suivant; |
(*element_precedent).suivant = (*element_courant).suivant; |
} |
} |
|
|
|
if (pointeur != NULL) |
|
{ |
|
memset(pointeur, 0, (*element_courant).taille); |
|
} |
|
|
free((*element_courant).fonction); |
free((*element_courant).fonction); |
free((*element_courant).argument); |
free((*element_courant).argument); |
free(element_courant); |
free(element_courant); |
Line 3773 debug_memoire_retrait(void *pointeur)
|
Line 3811 debug_memoire_retrait(void *pointeur)
|
|
|
pthread_mutex_unlock(&mutex_allocation); |
pthread_mutex_unlock(&mutex_allocation); |
|
|
free(pointeur); |
if (element_courant == NULL) |
|
{ |
|
uprintf("[%d-%llu] ILLEGAL POINTER (free)\n", |
|
getpid(), (unsigned long long) pthread_self()); |
|
# ifdef __BACKTRACE |
|
BACKTRACE(PROFONDEUR_PILE); |
|
# endif |
|
} |
|
|
|
free(pointeur); |
return; |
return; |
} |
} |
|
|
Line 3876 debug_memoire_verification()
|
Line 3922 debug_memoire_verification()
|
} |
} |
|
|
pthread_mutex_unlock(&mutex_allocation); |
pthread_mutex_unlock(&mutex_allocation); |
|
pthread_mutex_destroy(&mutex_allocation); |
|
|
fprintf(stderr, "[%d-%llu] END OF LIST\n", getpid(), |
fprintf(stderr, "[%d-%llu] END OF LIST\n", getpid(), |
(unsigned long long) pthread_self()); |
(unsigned long long) pthread_self()); |
Line 3883 debug_memoire_verification()
|
Line 3930 debug_memoire_verification()
|
return; |
return; |
} |
} |
|
|
void |
pid_t |
debug_memoire_reinitialisation() |
debug_fork() |
{ |
{ |
ordre = 0; |
pid_t pid; |
debug = NULL; |
|
|
|
pthread_mutex_trylock(&mutex_allocation); |
pthread_mutex_lock(&mutex_allocation); |
pthread_mutex_unlock(&mutex_allocation); |
pid = fork(); |
|
|
return; |
if (pid == 0) |
|
{ |
|
pthread_mutex_destroy(&mutex_allocation); |
|
debug_memoire_initialisation(); |
|
} |
|
else |
|
{ |
|
pthread_mutex_unlock(&mutex_allocation); |
|
} |
|
|
|
// Pas de parenthèses pour ne pas remplacer return par sa macro. |
|
return pid; |
} |
} |
|
|
void |
void |