version 1.17, 2010/05/16 19:36:20
|
version 1.51, 2011/06/21 15:03:58
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.0.15 |
RPL/2 (R) version 4.1.0.prerelease.1 |
Copyright (C) 1989-2010 Dr. BERTRAND Joël |
Copyright (C) 1989-2011 Dr. BERTRAND Joël |
|
|
This file is part of RPL/2. |
This file is part of RPL/2. |
|
|
Line 20
|
Line 20
|
*/ |
*/ |
|
|
|
|
#include "rpl.conv.h" |
#include "rpl-conv.h" |
|
|
|
|
/* |
/* |
Line 57 decrementation_atomique(struct_objet *s_
|
Line 57 decrementation_atomique(struct_objet *s_
|
return((*s_objet).nombre_occurrences); |
return((*s_objet).nombre_occurrences); |
} |
} |
|
|
inline void |
void |
initialisation_objet(struct_objet *s_objet) |
initialisation_objet(struct_objet *s_objet) |
{ |
{ |
pthread_mutexattr_t attributs_mutex; |
pthread_mutexattr_t attributs_mutex; |
Line 266 liberation_maillon(struct_processus *s_e
|
Line 266 liberation_maillon(struct_processus *s_e
|
================================================================================ |
================================================================================ |
Routine d'allocation d'une structure *s_objet |
Routine d'allocation d'une structure *s_objet |
================================================================================ |
================================================================================ |
Entrées : structure sur l'état du processus et objet à afficher |
Entrées : structure sur l'état du processus et objet à allouer |
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
Sorties : chaine de caractères |
Sorties : chaine de caractères |
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
Line 279 allocation(struct_processus *s_etat_proc
|
Line 279 allocation(struct_processus *s_etat_proc
|
{ |
{ |
struct_objet *s_objet; |
struct_objet *s_objet; |
|
|
|
if (pthread_mutex_lock(&((*s_etat_processus).mutex_allocation)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return(NULL); |
|
} |
|
|
if ((*s_etat_processus).pile_objets == NULL) |
if ((*s_etat_processus).pile_objets == NULL) |
{ |
{ |
|
if (pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return(NULL); |
|
} |
|
|
// Il n'existe aucune structure struct_objet disponible dans le cache. |
// Il n'existe aucune structure struct_objet disponible dans le cache. |
|
|
if ((s_objet = malloc(sizeof(struct_objet))) == NULL) |
if ((s_objet = malloc(sizeof(struct_objet))) == NULL) |
Line 299 allocation(struct_processus *s_etat_proc
|
Line 311 allocation(struct_processus *s_etat_proc
|
(*s_etat_processus).taille_pile_objets--; |
(*s_etat_processus).taille_pile_objets--; |
|
|
(*s_objet).nombre_occurrences = 1; |
(*s_objet).nombre_occurrences = 1; |
|
|
|
if (pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return(NULL); |
|
} |
} |
} |
|
|
(*s_objet).type = type; |
(*s_objet).type = type; |
Line 740 liberation(struct_processus *s_etat_proc
|
Line 758 liberation(struct_processus *s_etat_proc
|
{ |
{ |
logical1 drapeau; |
logical1 drapeau; |
|
|
|
sigset_t oldset; |
|
sigset_t set; |
|
|
struct_liste_chainee *l_element_courant; |
struct_liste_chainee *l_element_courant; |
struct_liste_chainee *l_element_suivant; |
struct_liste_chainee *l_element_suivant; |
|
|
Line 877 liberation(struct_processus *s_etat_proc
|
Line 898 liberation(struct_processus *s_etat_proc
|
{ |
{ |
if (decrementation_atomique(s_objet) > 0) |
if (decrementation_atomique(s_objet) > 0) |
{ |
{ |
liberation(s_etat_processus, (*((struct_fichier *) |
BUG((*(*((struct_fichier *) (*s_objet).objet)).format) |
(*s_objet).objet)).format); |
.nombre_occurrences <= 1, |
|
pthread_mutex_unlock(&((*s_objet).mutex)), |
|
printf("(*(*((struct_fichier *) (*s_objet).objet))" |
|
".format).nombre_occurrences=%ld\n", |
|
(*(*((struct_fichier *) (*s_objet).objet)).format) |
|
.nombre_occurrences)); |
|
|
|
liberation(s_etat_processus, |
|
(*((struct_fichier *) (*s_objet).objet)).format); |
return; |
return; |
} |
} |
|
|
liberation(s_etat_processus, |
liberation(s_etat_processus, |
(*((struct_fichier *) (*s_objet).objet)).format); |
(*((struct_fichier *) (*s_objet).objet)).format); |
|
|
free((unsigned char *) (*((struct_fichier *) |
free((unsigned char *) (*((struct_fichier *) |
(*s_objet).objet)).nom); |
(*s_objet).objet)).nom); |
free((struct_fichier *) ((*s_objet).objet)); |
free((struct_fichier *) ((*s_objet).objet)); |
Line 1097 liberation(struct_processus *s_etat_proc
|
Line 1125 liberation(struct_processus *s_etat_proc
|
return; |
return; |
} |
} |
|
|
free(s_objet); |
|
break; |
break; |
} |
} |
|
|
case PRC : |
case PRC : |
{ |
{ |
|
sigfillset(&set); |
|
pthread_sigmask(SIG_BLOCK, &set, &oldset); |
|
|
if (pthread_mutex_lock(&((*(*((struct_processus_fils *) |
if (pthread_mutex_lock(&((*(*((struct_processus_fils *) |
(*s_objet).objet)).thread).mutex)) != 0) |
(*s_objet).objet)).thread).mutex_nombre_references)) != 0) |
{ |
{ |
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
|
sigpending(&set); |
|
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
Line 1114 liberation(struct_processus *s_etat_proc
|
Line 1147 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 1130 liberation(struct_processus *s_etat_proc
|
Line 1164 liberation(struct_processus *s_etat_proc
|
} |
} |
|
|
if (pthread_mutex_unlock(&((*(*((struct_processus_fils *) |
if (pthread_mutex_unlock(&((*(*((struct_processus_fils *) |
(*s_objet).objet)).thread).mutex)) != 0) |
(*s_objet).objet)).thread).mutex_nombre_references)) != 0) |
{ |
{ |
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
|
sigpending(&set); |
|
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
|
|
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
|
sigpending(&set); |
|
|
if (drapeau == d_vrai) |
if (drapeau == d_vrai) |
{ |
{ |
pthread_mutex_destroy(&((*(*((struct_processus_fils *) |
pthread_mutex_destroy(&((*(*((struct_processus_fils *) |
(*s_objet).objet)).thread).mutex)); |
(*s_objet).objet)).thread).mutex)); |
|
pthread_mutex_destroy(&((*(*((struct_processus_fils *) |
|
(*s_objet).objet)).thread).mutex_nombre_references)); |
free((*((struct_processus_fils *) (*s_objet).objet)).thread); |
free((*((struct_processus_fils *) (*s_objet).objet)).thread); |
} |
} |
|
|
if (decrementation_atomique(s_objet) > 0) |
if (decrementation_atomique(s_objet) > 0) |
{ |
{ |
|
BUG(drapeau == d_vrai, uprintf("(*(*((struct_processus_fils" |
|
" *) (*s_objet).objet)).thread).nombre_references " |
|
"= 0 with nombre_occurrences > 0\n")); |
return; |
return; |
} |
} |
|
|
Line 1210 liberation(struct_processus *s_etat_proc
|
Line 1255 liberation(struct_processus *s_etat_proc
|
{ |
{ |
if (decrementation_atomique(s_objet) > 0) |
if (decrementation_atomique(s_objet) > 0) |
{ |
{ |
|
BUG((*(*((struct_socket *) (*s_objet).objet)).format) |
|
.nombre_occurrences <= 1, |
|
pthread_mutex_unlock(&((*s_objet).mutex)), |
|
printf("(*(*((struct_socket *) (*s_objet).objet))" |
|
".format).nombre_occurrences=%ld\n", |
|
(*(*((struct_socket *) (*s_objet).objet)).format) |
|
.nombre_occurrences)); |
|
|
liberation(s_etat_processus, (*((struct_socket *) |
liberation(s_etat_processus, (*((struct_socket *) |
(*s_objet).objet)).format); |
(*s_objet).objet)).format); |
return; |
return; |
Line 1217 liberation(struct_processus *s_etat_proc
|
Line 1270 liberation(struct_processus *s_etat_proc
|
|
|
liberation(s_etat_processus, (*((struct_socket *) |
liberation(s_etat_processus, (*((struct_socket *) |
(*s_objet).objet)).format); |
(*s_objet).objet)).format); |
|
|
free((unsigned char *) (*((struct_socket *) (*s_objet).objet)) |
free((unsigned char *) (*((struct_socket *) (*s_objet).objet)) |
.adresse); |
.adresse); |
free((unsigned char *) (*((struct_socket *) (*s_objet).objet)) |
free((unsigned char *) (*((struct_socket *) (*s_objet).objet)) |
Line 1400 liberation(struct_processus *s_etat_proc
|
Line 1454 liberation(struct_processus *s_etat_proc
|
return; |
return; |
} |
} |
|
|
if (s_etat_processus != NULL) |
if (pthread_mutex_lock(&((*s_etat_processus).mutex_allocation)) != 0) |
{ |
{ |
if ((*s_etat_processus).taille_pile_objets < TAILLE_CACHE) |
(*s_etat_processus).erreur_systeme = d_es_processus; |
{ |
return; |
(*s_objet).objet = (*s_etat_processus).pile_objets; |
} |
(*s_etat_processus).pile_objets = s_objet; |
|
(*s_etat_processus).taille_pile_objets++; |
|
} |
|
else |
|
{ |
|
if (pthread_mutex_destroy(&((*s_objet).mutex)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
free(s_objet); |
if ((*s_etat_processus).taille_pile_objets < TAILLE_CACHE) |
} |
{ |
|
(*s_objet).objet = (*s_etat_processus).pile_objets; |
|
(*s_etat_processus).pile_objets = s_objet; |
|
(*s_etat_processus).taille_pile_objets++; |
} |
} |
else |
else |
{ |
{ |
|
if (pthread_mutex_destroy(&((*s_objet).mutex)) != 0) |
|
{ |
|
pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation)); |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
free(s_objet); |
free(s_objet); |
} |
} |
|
|
|
if (pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
return; |
return; |
} |
} |
|
|
Line 1453 struct_objet *
|
Line 1513 struct_objet *
|
copie_objet(struct_processus *s_etat_processus, |
copie_objet(struct_processus *s_etat_processus, |
struct_objet *s_objet, unsigned char type) |
struct_objet *s_objet, unsigned char type) |
{ |
{ |
|
sigset_t oldset; |
|
sigset_t set; |
|
|
struct_liste_chainee *l_element_base; |
struct_liste_chainee *l_element_base; |
struct_liste_chainee *l_element_courant; |
struct_liste_chainee *l_element_courant; |
struct_liste_chainee *l_element_courant_ecriture; |
struct_liste_chainee *l_element_courant_ecriture; |
Line 2223 copie_objet(struct_processus *s_etat_pro
|
Line 2286 copie_objet(struct_processus *s_etat_pro
|
|
|
case PRC : |
case PRC : |
{ |
{ |
|
sigfillset(&set); |
|
pthread_sigmask(SIG_BLOCK, &set, &oldset); |
|
|
if (pthread_mutex_lock(&((*(*((struct_processus_fils *) |
if (pthread_mutex_lock(&((*(*((struct_processus_fils *) |
(*s_objet).objet)).thread).mutex)) != 0) |
(*s_objet).objet)).thread).mutex_nombre_references)) != 0) |
{ |
{ |
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
|
sigpending(&set); |
|
|
return(NULL); |
return(NULL); |
} |
} |
|
|
Line 2233 copie_objet(struct_processus *s_etat_pro
|
Line 2302 copie_objet(struct_processus *s_etat_pro
|
.nombre_references++; |
.nombre_references++; |
|
|
if (pthread_mutex_unlock(&((*(*((struct_processus_fils *) |
if (pthread_mutex_unlock(&((*(*((struct_processus_fils *) |
(*s_objet).objet)).thread).mutex)) != 0) |
(*s_objet).objet)).thread).mutex_nombre_references)) != 0) |
{ |
{ |
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
|
sigpending(&set); |
|
|
return(NULL); |
return(NULL); |
} |
} |
|
|
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
|
sigpending(&set); |
|
|
if (type != 'O') |
if (type != 'O') |
{ |
{ |
incrementation_atomique(s_objet); |
incrementation_atomique(s_objet); |
Line 2278 copie_objet(struct_processus *s_etat_pro
|
Line 2353 copie_objet(struct_processus *s_etat_pro
|
{ |
{ |
incrementation_atomique(s_objet); |
incrementation_atomique(s_objet); |
|
|
if (((*((struct_socket *) ((*s_nouvel_objet).objet))).format = |
if (((*((struct_socket *) ((*s_objet).objet))) |
copie_objet(s_etat_processus, (*((struct_socket *) |
.format = copie_objet(s_etat_processus, |
((*s_objet).objet))).format, 'P')) == NULL) |
(*((struct_socket *) ((*s_objet).objet))).format, 'P')) |
|
== NULL) |
{ |
{ |
return(NULL); |
return(NULL); |
} |
} |
Line 2753 copie_etat_processus(struct_processus *s
|
Line 2829 copie_etat_processus(struct_processus *s
|
# endif |
# endif |
|
|
(*s_nouvel_etat_processus).var_volatile_processus_pere = 0; |
(*s_nouvel_etat_processus).var_volatile_processus_pere = 0; |
|
(*s_nouvel_etat_processus).var_volatile_processus_racine = 0; |
(*s_nouvel_etat_processus).fichiers_graphiques = NULL; |
(*s_nouvel_etat_processus).fichiers_graphiques = NULL; |
(*s_nouvel_etat_processus).entree_standard = NULL; |
(*s_nouvel_etat_processus).entree_standard = NULL; |
(*s_nouvel_etat_processus).s_marques = NULL; |
(*s_nouvel_etat_processus).s_marques = NULL; |
Line 2783 copie_etat_processus(struct_processus *s
|
Line 2860 copie_etat_processus(struct_processus *s
|
(*s_nouvel_etat_processus).nombre_interruptions_non_affectees = 0; |
(*s_nouvel_etat_processus).nombre_interruptions_non_affectees = 0; |
|
|
(*s_nouvel_etat_processus).at_exit = NULL; |
(*s_nouvel_etat_processus).at_exit = NULL; |
|
(*s_nouvel_etat_processus).at_poke = NULL; |
|
(*s_nouvel_etat_processus).traitement_at_poke = 'N'; |
|
|
for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++) |
for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++) |
{ |
{ |
Line 2794 copie_etat_processus(struct_processus *s
|
Line 2873 copie_etat_processus(struct_processus *s
|
|
|
if ((*s_nouvel_etat_processus).generateur_aleatoire != NULL) |
if ((*s_nouvel_etat_processus).generateur_aleatoire != NULL) |
{ |
{ |
(*s_nouvel_etat_processus).generateur_aleatoire = NULL; |
if (((*s_nouvel_etat_processus).generateur_aleatoire = |
} |
gsl_rng_clone((*s_etat_processus).generateur_aleatoire)) |
|
== NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return(NULL); |
|
} |
|
|
(*s_nouvel_etat_processus).type_generateur_aleatoire = NULL; |
gsl_rng_set((*s_nouvel_etat_processus).generateur_aleatoire, |
|
gsl_rng_get((*s_etat_processus).generateur_aleatoire)); |
|
} |
|
|
// Copie de la localisation |
// Copie de la localisation |
|
|
Line 3024 copie_etat_processus(struct_processus *s
|
Line 3110 copie_etat_processus(struct_processus *s
|
* Copie de la table des variables |
* Copie de la table des variables |
*/ |
*/ |
|
|
if (((*s_nouvel_etat_processus).s_liste_variables = |
copie_arbre_variables(s_etat_processus, s_nouvel_etat_processus); |
malloc((*s_etat_processus).nombre_variables_allouees * |
|
sizeof(struct_variable))) == NULL) |
|
{ |
|
if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return(NULL); |
|
} |
|
|
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return(NULL); |
|
} |
|
|
|
for(i = 0; i < (*s_etat_processus).nombre_variables; i++) |
if ((*s_nouvel_etat_processus).erreur_systeme != d_es) |
{ |
{ |
if (((*s_nouvel_etat_processus).s_liste_variables[i].nom = |
return(NULL); |
malloc((strlen((*s_etat_processus).s_liste_variables[i].nom) |
|
+ 1) * sizeof(unsigned char))) == NULL) |
|
{ |
|
if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return(NULL); |
|
} |
|
|
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return(NULL); |
|
} |
|
|
|
strcpy((*s_nouvel_etat_processus).s_liste_variables[i].nom, |
|
(*s_etat_processus).s_liste_variables[i].nom); |
|
|
|
(*s_nouvel_etat_processus).s_liste_variables[i].origine = |
|
(*s_etat_processus).s_liste_variables[i].origine; |
|
(*s_nouvel_etat_processus).s_liste_variables[i].niveau = |
|
(*s_etat_processus).s_liste_variables[i].niveau; |
|
(*s_nouvel_etat_processus).s_liste_variables[i].variable_statique = |
|
(*s_etat_processus).s_liste_variables[i].variable_statique; |
|
(*s_nouvel_etat_processus).s_liste_variables[i].variable_partagee = |
|
(*s_etat_processus).s_liste_variables[i].variable_partagee; |
|
(*s_nouvel_etat_processus).s_liste_variables[i].variable_verrouillee = |
|
(*s_etat_processus).s_liste_variables[i].variable_verrouillee; |
|
|
|
// Les définitions sont partagées entre tous les threads. |
|
|
|
if ((*s_etat_processus).s_liste_variables[i].niveau == 0) |
|
{ |
|
(*s_nouvel_etat_processus).s_liste_variables[i].objet = |
|
(*s_etat_processus).s_liste_variables[i].objet; |
|
} |
|
else |
|
{ |
|
if (((*s_nouvel_etat_processus).s_liste_variables[i].objet = |
|
copie_objet(s_etat_processus, |
|
(*s_etat_processus).s_liste_variables[i] |
|
.objet, 'P')) == NULL) |
|
{ |
|
if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return(NULL); |
|
} |
|
|
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return(NULL); |
|
} |
|
} |
|
} |
} |
|
|
/* |
/* |
Line 3519 copie_etat_processus(struct_processus *s
|
Line 3542 copie_etat_processus(struct_processus *s
|
pthread_mutex_init(&((*s_nouvel_etat_processus).mutex), &attributs_mutex); |
pthread_mutex_init(&((*s_nouvel_etat_processus).mutex), &attributs_mutex); |
pthread_mutexattr_destroy(&attributs_mutex); |
pthread_mutexattr_destroy(&attributs_mutex); |
|
|
|
pthread_mutexattr_init(&attributs_mutex); |
|
pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL); |
|
pthread_mutex_init(&((*s_nouvel_etat_processus).mutex_allocation), |
|
&attributs_mutex); |
|
pthread_mutexattr_destroy(&attributs_mutex); |
|
|
if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) |
if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
Line 3548 copie_etat_processus(struct_processus *s
|
Line 3577 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 3579 typedef struct memoire
|
Line 3612 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 |
#define 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 3590 debug_memoire_ajout(size_t taille, const
|
Line 3633 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 3611 debug_memoire_ajout(size_t taille, const
|
Line 3656 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 |
|
|
pthread_mutex_unlock(&mutex_allocation); |
|
|
|
if (((*debug).fonction = malloc((strlen(fonction) + 1) * |
if (((*debug).fonction = malloc((strlen(fonction) + 1) * |
sizeof(unsigned char))) == NULL) |
sizeof(unsigned char))) == NULL) |
{ |
{ |
|
pthread_mutex_unlock(&mutex_allocation); |
return(NULL); |
return(NULL); |
} |
} |
|
|
if (((*debug).argument = malloc((strlen(argument) + 1) * |
if (((*debug).argument = malloc((strlen(argument) + 1) * |
sizeof(unsigned char))) == NULL) |
sizeof(unsigned char))) == NULL) |
{ |
{ |
|
pthread_mutex_unlock(&mutex_allocation); |
return(NULL); |
return(NULL); |
} |
} |
|
|
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); |
ordre++; |
ordre++; |
|
|
return((*debug).pointeur); |
return(pointeur); |
} |
} |
|
|
void * |
void * |
Line 3648 debug_memoire_modification(void *pointeu
|
Line 3698 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 3673 debug_memoire_modification(void *pointeu
|
Line 3725 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); |
|
} |
|
|
|
pthread_mutex_unlock(&mutex_allocation); |
uprintf("[%d-%llu] ILLEGAL POINTER (realloc)\n", |
|
getpid(), (unsigned long long) pthread_self()); |
|
# ifdef __BACKTRACE |
|
BACKTRACE(PROFONDEUR_PILE); |
|
# endif |
|
|
if (((*element_courant).pointeur = realloc(pointeur, taille)) |
return(realloc(pointeur, taille)); |
== NULL) |
|
{ |
|
return(NULL); |
|
} |
} |
|
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) |
{ |
{ |
return(NULL); |
pthread_mutex_unlock(&mutex_allocation); |
} |
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) |
{ |
{ |
return(NULL); |
pthread_mutex_unlock(&mutex_allocation); |
} |
return(NULL); |
|
} |
|
|
|
strcpy((*element_courant).fonction, fonction); |
|
strcpy((*element_courant).argument, argument); |
|
|
strcpy((*element_courant).fonction, fonction); |
pthread_mutex_unlock(&mutex_allocation); |
strcpy((*element_courant).argument, argument); |
|
|
|
return((*element_courant).pointeur); |
return((*element_courant).pointeur); |
|
} |
} |
} |
} |
} |
else |
else |
Line 3739 debug_memoire_retrait(void *pointeur)
|
Line 3803 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 3752 debug_memoire_retrait(void *pointeur)
|
Line 3821 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 3793 debug_memoire_verification()
|
Line 3870 debug_memoire_verification()
|
(unsigned long long) pthread_self(), |
(unsigned long long) pthread_self(), |
(*element_courant).argument); |
(*element_courant).argument); |
|
|
|
if (strstr((*element_courant).argument, "sizeof(unsigned char)") |
|
!= NULL) |
|
{ |
|
fprintf(stderr, "[%d-%llu] ", getpid(), |
|
(unsigned long long) pthread_self()); |
|
fprintf(stderr, "O: %s\n", (unsigned char *) |
|
(*element_courant).pointeur); |
|
} |
|
else if (strcmp((*element_courant).argument, "sizeof(struct_objet)") |
|
== 0) |
|
{ |
|
fprintf(stderr, "[%d-%llu] ", getpid(), |
|
(unsigned long long) pthread_self()); |
|
fprintf(stderr, "O: %d\n", (*((struct_objet *) |
|
(*element_courant).pointeur)).type); |
|
} |
|
else if (strcmp((*element_courant).argument, |
|
"sizeof(struct_liste_chainee)") == 0) |
|
{ |
|
fprintf(stderr, "[%d-%llu] ", getpid(), |
|
(unsigned long long) pthread_self()); |
|
fprintf(stderr, "O: data=%p next=%p\n", (*((struct_liste_chainee *) |
|
(*element_courant).pointeur)).donnee, |
|
(*((struct_liste_chainee *) (*element_courant).pointeur)) |
|
.suivant); |
|
} |
|
|
# ifdef __BACKTRACE |
# ifdef __BACKTRACE |
appels = backtrace_symbols((*element_courant).pile, |
appels = backtrace_symbols((*element_courant).pile, |
(*element_courant).profondeur); |
(*element_courant).profondeur); |
Line 3828 debug_memoire_verification()
|
Line 3932 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 3835 debug_memoire_verification()
|
Line 3940 debug_memoire_verification()
|
return; |
return; |
} |
} |
|
|
|
pid_t |
|
debug_fork() |
|
{ |
|
pid_t pid; |
|
|
|
pthread_mutex_lock(&mutex_allocation); |
|
pid = fork(); |
|
|
|
# ifdef OS2 |
|
if (pid == 0) |
|
{ |
|
sem_init(&semaphore_liste_threads, 0, 1); |
|
sem_init(&semaphore_gestionnaires_signaux, 0, 0); |
|
sem_init(&semaphore_gestionnaires_signaux_atomique, 0, 1); |
|
sem_init(&((*s_etat_processus).semaphore_fork), 0, 0); |
|
} |
|
# endif |
|
|
|
if (pid == 0) |
|
{ |
|
# ifdef _BROKEN_SIGINFO |
|
liberation_fifos_signaux(s_etat_processus); |
|
creation_fifos_signaux(s_etat_processus); |
|
# endif |
|
|
|
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 |
analyse_post_mortem() |
analyse_post_mortem() |
{ |
{ |