2024-04-17 18:49:56 +02:00
/*----------------------------------------------------------------------------*/
/* libshmem.c */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
2024-04-20 10:11:27 +02:00
/* This file is part of LibShMem. */
2024-04-17 18:49:56 +02:00
/* */
/* LibShMem 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. */
/* */
/* LibShMem 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 */
2024-04-20 10:11:27 +02:00
/* License along with LibShMem. If not, see */
2024-04-17 18:49:56 +02:00
/* <https://www.gnu.org/licenses/>. */
/*----------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-18 13:52:43 +02:00
/*----------------------------------------------------------------------------*/
/* Includes */
/*----------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
# define _LIBSHMEM_C_
2000-07-28 16:13:54 +02:00
# include <libshmem.h>
2024-04-17 18:49:56 +02:00
//#ifdef _LIBVER_SUPPORT
//VER_INFO_EXPORT(libshmem,"$Revision: 2.4 $", "$Name: $",__FILE__,"$Author: agibert $")
//#endif
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* FONCTIONS PUBLIQUES */
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* FONCTIONS OPTIMISEES (SM_MODE = 1) */
/*------------------------------------------------------------------------------*/
2024-04-17 18:49:56 +02:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Ouverture d'une instance de la librairie */
/*------------------------------------------------------------------------------*/
/* (I) Instance : num<75> ro de l'instance de la librairie */
/* (I) Context : nom du nouveau contexte */
/* (I) Open_Mode : indicateur cr<63> ation/ouverture + mode d'affichage des erreurs */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-17 18:49:56 +02:00
SMT_Status SM_Library_Open_I ( int Instance , const char * Context , SMT_Flags Open_Mode )
2000-07-28 16:13:54 +02:00
{
2005-01-24 23:57:06 +01:00
SMT_Status rc ;
2024-04-17 18:49:56 +02:00
LGT_Status lg_status ;
2005-01-24 23:57:06 +01:00
int ND_Debug = FALSE ;
int To_Open_Instance ;
NDT_Index_Type index_type = ( NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_TREE | NDD_INDEX_SUBTYPE_BALANCED ) ;
2000-07-28 16:13:54 +02:00
/* D<> finition du mode d'affichage des messages d'erreur */
2005-01-24 23:57:06 +01:00
if ( SMD_DEBUG_MSK ( Open_Mode ) ) SM_stderr = stderr ;
if ( Open_Mode & SMD_DEBUG_ALL ) ND_Debug = TRUE ;
2024-04-19 18:44:32 +02:00
if ( ( lg_status = LG_Library_Open ( LGD_LOG_WRITER_DEFAULT , false ) ) ! = LGS_OK )
2024-04-17 18:49:56 +02:00
{
fprintf ( stderr , " Can't open LibLog library: (%d) \n " , lg_status ) ;
return ( - 1 ) ;
}
2000-07-28 16:13:54 +02:00
/* D<> finition de l'instance <20> ouvrir */
2005-01-24 23:57:06 +01:00
if ( Instance ) To_Open_Instance = Instance ;
2000-07-28 16:13:54 +02:00
else
{
2024-04-19 18:44:32 +02:00
if ( ! getenv ( INSTANCE_ENV_VAR ) | | ( To_Open_Instance = atoi ( getenv ( INSTANCE_ENV_VAR ) ) ) < = 0 )
2005-01-24 23:57:06 +01:00
{
2000-07-28 16:13:54 +02:00
To_Open_Instance = DEFAULT_INSTANCE ;
2005-01-24 23:57:06 +01:00
}
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
if ( Open_Mode & SMD_CREATE ) /* Cr<43> ation d'une nouvelle instance */
2000-07-28 16:13:54 +02:00
{
/* On v<> rifie que le processus courant n'acc<63> de pas d<> j<EFBFBD> <20> une instance */
2005-01-24 23:57:06 +01:00
if ( SM_Open_Counter > 0 )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " SM_Library_Open : the current process has already opened an instance: (%d) of the LIBSHMEM base " , SM_Instance ) ;
2005-01-24 23:57:06 +01:00
return ( SMS_ERRAPI ) ;
2000-07-28 16:13:54 +02:00
}
/* Ouverture de la librairie LIBNODE */
2005-01-24 23:57:06 +01:00
rc = ND_Library_Open ( ND_Debug ) ;
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " SM_Library_Open : unable to open the LIBNODE library " ) ;
2005-01-24 23:57:06 +01:00
return ( rc ) ;
2000-07-28 16:13:54 +02:00
}
/* Ouverture de la liste des heaps ouverts (locale) */
2024-05-25 13:03:36 +02:00
rc = ND_DataStruct_Open ( & Opened_Heap_List , " SM Opened Heap " , 1 , & index_type , " SM_Opened_Heap_List_Manager " , NULL , NULL , TRUE , NULL ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " SM_Library_Open : unable to create the local opened heap cache " ) ;
2000-07-28 16:13:54 +02:00
goto Error1 ;
}
/* Cr<43> ation de la base de m<> moire partag<61> e */
SM_Instance = To_Open_Instance ;
2005-01-24 23:57:06 +01:00
rc = SM_Base_Init ( ) ;
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " SM_Library_Open : unable to initialize the shared memory base " ) ;
2000-07-28 16:13:54 +02:00
goto Error2 ;
}
}
2005-01-24 23:57:06 +01:00
else if ( Open_Mode & SMD_OPEN ) /* Ouverture d'une instance existante */
2000-07-28 16:13:54 +02:00
{
/* On v<> rifie que le processus courant n'a pas d<> j<EFBFBD> ouvert une autre instance */
2005-01-24 23:57:06 +01:00
if ( SM_Open_Counter > 0 & & To_Open_Instance ! = SM_Instance )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_2 ( " SM_Library_Open : the current process cannot open instance: (%d) because it is already accessing instance: (%d) " , To_Open_Instance , SM_Instance ) ;
2005-01-24 23:57:06 +01:00
return ( SMS_ERRAPI ) ;
2000-07-28 16:13:54 +02:00
}
SM_Instance = To_Open_Instance ;
/* Ouverture effective si c'est la premi<6D> re fois */
2005-01-24 23:57:06 +01:00
if ( SM_Open_Counter = = 0 )
2000-07-28 16:13:54 +02:00
{
/* Ouverture de la librairie LIBNODE */
2005-01-24 23:57:06 +01:00
rc = ND_Library_Open ( ND_Debug ) ;
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to open the LIBNODE library " ) ;
2005-01-24 23:57:06 +01:00
return ( rc ) ;
2000-07-28 16:13:54 +02:00
}
/* Ouverture de la liste des heaps ouverts (locale) */
2024-05-25 13:03:36 +02:00
rc = ND_DataStruct_Open ( & Opened_Heap_List , " SM Opened Heap " , 1 , & index_type , " SM_Opened_Heap_List_Manager " , NULL , NULL , TRUE , NULL ) ;
2005-01-24 23:57:06 +01:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to create the local opened heap cache " ) ;
2000-07-28 16:13:54 +02:00
goto Error1 ;
}
/* Ouverture de la base de m<> moire partag<61> e */
2005-01-24 23:57:06 +01:00
rc = SM_Base_Open ( ) ;
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to open the shared memory base " ) ;
2000-07-28 16:13:54 +02:00
goto Error2 ;
}
}
}
/* D<> finition du contexte */
2005-01-24 23:57:06 +01:00
SM_Library_Context_Set_I ( Context ) ;
2000-07-28 16:13:54 +02:00
/* On incr<63> mente le compteur d'ouverture de la librairie */
SM_Open_Counter + + ;
2005-01-24 23:57:06 +01:00
return ( SMS_OK ) ;
2000-07-28 16:13:54 +02:00
/* Gestion d'erreur */
2005-01-24 23:57:06 +01:00
Error2 :
ND_DataStruct_Close ( Opened_Heap_List ) ;
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
Error1 :
ND_Library_Close ( ) ;
return ( rc ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* R<> cup<75> ration du num<75> ro de l'instance utilis<69> e */
/*------------------------------------------------------------------------------*/
/* (O) Instance : adresse du num<75> ro de l'instance utilis<69> e */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
SMT_Status SM_Library_Instance_Get_I ( int * Instance )
2000-07-28 16:13:54 +02:00
{
* Instance = SM_Instance ;
2005-01-24 23:57:06 +01:00
return ( SMS_OK ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* R<> cup<75> ration du nom du contexte utilis<69> */
/*------------------------------------------------------------------------------*/
/* (O) Context : adresse du nom du contexte utilis<69> */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-17 18:49:56 +02:00
SMT_Status SM_Library_Context_Get_I ( char * * Context )
2000-07-28 16:13:54 +02:00
{
* Context = SM_Context ;
2005-01-24 23:57:06 +01:00
return ( SMS_OK ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Changement de contexte d'utilisation de la librairie */
/*------------------------------------------------------------------------------*/
/* (I) Context : nom du nouveau contexte */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
SMT_Status SM_Library_Context_Set_I ( const char * Context )
2000-07-28 16:13:54 +02:00
{
2005-01-24 23:57:06 +01:00
if ( SM_Context ) free ( SM_Context ) ;
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
if ( Context & & strlen ( Context ) )
{
SM_Context = strdup ( Context ) ;
}
2000-07-28 16:13:54 +02:00
else
{
2024-04-19 18:44:32 +02:00
if ( getenv ( CONTEXT_ENV_VAR ) & & strlen ( getenv ( CONTEXT_ENV_VAR ) ) )
2005-01-24 23:57:06 +01:00
{
2024-04-19 18:44:32 +02:00
SM_Context = strdup ( getenv ( CONTEXT_ENV_VAR ) ) ;
2005-01-24 23:57:06 +01:00
}
2000-07-28 16:13:54 +02:00
else
2005-01-24 23:57:06 +01:00
{
2024-04-17 18:49:56 +02:00
SM_Context = strdup ( DEFAULT_CONTEXT ) ;
2005-01-24 23:57:06 +01:00
}
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
return ( SMS_OK ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fermeture de l'instance de la librairie */
/*------------------------------------------------------------------------------*/
/* (I) Close_Mode : mode de fermeture (destruction ou fermeture simple) */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
SMT_Status SM_Library_Close_I ( SMT_Flags Close_Mode )
2000-07-28 16:13:54 +02:00
{
2005-01-24 23:57:06 +01:00
SMT_Status rc ;
2024-04-17 18:49:56 +02:00
LGT_Status lg_status ;
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
if ( Close_Mode & SMD_DESTROY ) /* Destruction de l'instance */
2000-07-28 16:13:54 +02:00
{
/* Destruction de la base de m<> moire partag<61> e */
2005-01-24 23:57:06 +01:00
rc = SM_Base_End ( ) ;
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to destroy the shared memory base " ) ;
2005-01-24 23:57:06 +01:00
return ( rc ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
if ( SM_Context )
2000-07-28 16:13:54 +02:00
{
2005-01-24 23:57:06 +01:00
free ( SM_Context ) ;
2000-07-28 16:13:54 +02:00
SM_Context = NULL ;
}
/* Fermeture de la liste des heaps ouverts */
2005-01-24 23:57:06 +01:00
ND_DataStruct_Close ( Opened_Heap_List ) ;
2000-07-28 16:13:54 +02:00
/* Fermeture de la librairie LIBNODE */
2005-01-24 23:57:06 +01:00
ND_Library_Close ( ) ;
2000-07-28 16:13:54 +02:00
/* R<> initialisation du compteur d'ouverture */
SM_Open_Counter = 0 ;
}
2005-01-24 23:57:06 +01:00
else if ( Close_Mode & SMD_CLOSE ) /* Fermeture de l'instance */
2000-07-28 16:13:54 +02:00
{
/*
2005-01-24 23:57:06 +01:00
La fermeture n ' est effective que si la librairie
n ' a <EFBFBD> t <EFBFBD> ouverte qu ' une seule fois .
2000-07-28 16:13:54 +02:00
*/
2005-01-24 23:57:06 +01:00
if ( SM_Open_Counter = = 1 )
2000-07-28 16:13:54 +02:00
{
/* Fermeture de la base de m<> moire partag<61> e */
2005-01-24 23:57:06 +01:00
rc = SM_Base_Close ( ) ;
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to close the shared memory base " ) ;
2005-01-24 23:57:06 +01:00
return ( rc ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
if ( SM_Context )
2000-07-28 16:13:54 +02:00
{
2005-01-24 23:57:06 +01:00
free ( SM_Context ) ;
2000-07-28 16:13:54 +02:00
SM_Context = NULL ;
}
/* Fermeture de la liste des heaps ouverts */
2005-01-24 23:57:06 +01:00
ND_DataStruct_Close ( Opened_Heap_List ) ;
2000-07-28 16:13:54 +02:00
/* Fermeture de la librairie LIBNODE */
2005-01-24 23:57:06 +01:00
ND_Library_Close ( ) ;
2000-07-28 16:13:54 +02:00
}
/* On met <20> jour le compteur d'ouverture de la librairie */
SM_Open_Counter - - ;
}
2024-04-17 18:49:56 +02:00
2024-04-19 18:44:32 +02:00
if ( ( lg_status = LG_Library_Close ( false ) ) ! = LGS_OK )
2024-04-17 18:49:56 +02:00
{
fprintf ( stderr , " Can't close LibLog library: (%d) \n " , lg_status ) ;
return ( SMS_KO ) ;
}
2005-01-24 23:57:06 +01:00
return ( SMS_OK ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Affichage des informations de la base de m<> moires partag<61> es */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
SMT_Status SM_Library_Dump_I ( FILE * Out )
2000-07-28 16:13:54 +02:00
{
/* Affichage des informations sur la base */
2024-04-18 00:54:07 +02:00
/*
2005-06-27 00:50:49 +02:00
fprintf ( Out , " Base: (%d):[%s] \t Size: (%d) \t Creator PId: (%ld) \t Last write access PId: (%ld) \n Id Mem: (%d):(%d) \t Id Sem: (%d) \t Status: [%s] \n \n " ,
2005-02-24 00:31:06 +01:00
SM_Instance , SM_Context , SM_Base - > Size , SM_Base - > Creator , SM_Base - > Writer , SM_Base - > SysMemId , SM_Base - > DataMemId , SM_Base - > SemId , SM_Lock_Status_Get ( " base " , SM_Base ) ) ;
2024-04-18 00:54:07 +02:00
*/
2000-07-28 16:13:54 +02:00
2024-04-18 00:54:07 +02:00
LG_LOG_INFO_5 ( " Base: (%d):[%s] \t Size: (%d) \t Creator PId: (%ld) \t Last write access PId: (%ld) " ,
SM_Instance , SM_Context , SM_Base - > Size , SM_Base - > Creator , SM_Base - > Writer ) ;
LG_LOG_INFO_4 ( " Id Mem: (%d):(%d) \t Id Sem: (%d) \t Status: [%s] " ,
SM_Base - > SysMemId , SM_Base - > DataMemId , SM_Base - > SemId , SM_Lock_Status_Get ( " base " , SM_Base ) ) ;
LG_LOG_INFO_0 ( " " ) ;
2000-07-28 16:13:54 +02:00
/* Affichage des informations du MHR */
2005-01-24 23:57:06 +01:00
ND_DataStruct_Info_Print ( Out , SM_Base - > MHR , NDD_RECURSIVE_MODE_PARENT_CHILD , 0 , 0 ) ;
2024-04-18 00:54:07 +02:00
// fprintf( Out, "\n");
LG_LOG_INFO_0 ( " " ) ;
2000-07-28 16:13:54 +02:00
/* Affichage des informations de chaque heap */
2005-01-25 00:10:09 +01:00
return ( ND_DataStruct_Value_Print ( Out , SM_Base - > MHR , NDD_RECURSIVE_MODE_PARENT_CHILD , 0 , 0 ) ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Lib<69> ration de tous les verrous (base, heap) */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
SMT_Status SM_Library_Unlock_I ( void )
2000-07-28 16:13:54 +02:00
{
2005-01-24 23:57:06 +01:00
NDT_Node * Node ;
union semun Sem_Ctl ;
2000-07-28 16:13:54 +02:00
/* Lib<69> ration des verrous sur la base */
Sem_Ctl . val = 1 ;
2005-02-24 00:31:06 +01:00
if ( semctl ( SM_Base - > SemId , 0 , SETVAL , Sem_Ctl ) )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to unlock the shared memory base " ) ;
2005-01-24 23:57:06 +01:00
return ( SMS_ERRSEM ) ;
2000-07-28 16:13:54 +02:00
}
/* Lib<69> ration des verrous sur les heaps */
2005-01-25 00:10:09 +01:00
ND_Index_Node_First_Get ( & Node , SM_Base - > MHR , NDD_INDEX_PRIMARY ) ;
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
while ( Node )
2000-07-28 16:13:54 +02:00
{
2005-01-24 23:57:06 +01:00
SMT_MHH * MHH ;
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
MHH = ( SMT_MHH * ) ( Node - > Value ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
if ( semctl ( MHH - > SemId , 0 , SETVAL , Sem_Ctl ) )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to unlock heap: [%s] " , MHH - > Name ) ;
2005-01-24 23:57:06 +01:00
return ( SMS_ERRSEM ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-25 00:10:09 +01:00
ND_Index_Node_Next_Get ( & Node , Node ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-25 00:10:09 +01:00
ND_Index_Node_First_Get ( & Node , Opened_Heap_List , NDD_INDEX_PRIMARY ) ;
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
while ( Node )
2000-07-28 16:13:54 +02:00
{
2005-01-24 23:57:06 +01:00
( ( SMT_Heap * ) ( Node - > Value ) ) - > Lock_Mode = SMD_NO_LOCK ;
2005-01-25 00:10:09 +01:00
ND_Index_Node_Next_Get ( & Node , Node ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
return ( SMS_OK ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* D<> finition de la sortie standard des messages d'erreur de la librairie */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Library_Stderr_Set_I ( FILE * Out )
2000-07-28 16:13:54 +02:00
{
SM_stderr = Out ;
2005-01-24 23:57:06 +01:00
return ( SMS_OK ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Test d'existence d'un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap_Name : Nom du heap */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Exist_I ( const char * Heap_Name )
2000-07-28 16:13:54 +02:00
{
2005-01-24 23:57:06 +01:00
NDT_Node * Node ;
SMT_MHH * MHH ;
2024-04-15 16:54:18 +02:00
char prefixed_name [ SMD_NAME_SIZE ] ;
2005-01-24 23:57:06 +01:00
int Locked = FALSE ;
2000-07-28 16:13:54 +02:00
2024-04-15 16:54:18 +02:00
SM_Name_Prefix ( prefixed_name , Heap_Name ) ;
2005-01-24 23:57:06 +01:00
if ( strcmp ( Heap_Name , HEAP_SYSTEM ) )
2000-07-28 16:13:54 +02:00
{
/* Verrouillage du heap syst<73> me en lecture */
2005-01-24 23:57:06 +01:00
SM_Heap_Lock_I ( System_Heap , SMD_READ , & Locked ) ;
2000-07-28 16:13:54 +02:00
}
/* Recherche dans le MHR */
2005-01-25 00:10:09 +01:00
ND_Index_Node_First_Get ( & Node , SM_Base - > MHR , NDD_INDEX_PRIMARY ) ;
2005-01-24 23:57:06 +01:00
while ( Node )
2000-07-28 16:13:54 +02:00
{
2005-01-24 23:57:06 +01:00
MHH = ( SMT_MHH * ) ( Node - > Value ) ;
2024-04-15 16:54:18 +02:00
if ( ! strcmp ( prefixed_name , MHH - > Name ) )
2005-01-24 23:57:06 +01:00
{
return ( SMS_YES ) ;
}
2005-01-25 00:10:09 +01:00
ND_Index_Node_Next_Get ( & Node , Node ) ;
2000-07-28 16:13:54 +02:00
}
/* D<> verrouillage <20> ventuel du heap syst<73> me */
2005-01-24 23:57:06 +01:00
if ( Locked = = TRUE )
{
SM_Heap_Unlock_I ( System_Heap ) ;
}
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
return ( SMS_NO ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Ouverture/cr<63> ation d'un heap */
/*------------------------------------------------------------------------------*/
2024-04-19 18:44:32 +02:00
/* (I) Heap_Name: nom du heap */
/* (O) Heap_Ptr_Ptr: pointeur sur le heap ouvert / cr<63> <72> */
/* (I) Seg_Size: taille des segments du heap */
/* (I) Open_Mode: mode d'ouverture du heap */
/* (O) Locked: verrou effectif (TRUE ou FALSE) */
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Open_I ( const char * Heap_Name , SMT_Heap * * Heap_Ptr_Ptr , size_t Seg_Size , SMT_Flags Open_Mode , int * Locked )
2000-07-28 16:13:54 +02:00
{
2005-01-24 23:57:06 +01:00
SMT_MHH * MHH ;
2024-04-19 18:44:32 +02:00
NDT_Node * Node_Ptr ;
2005-01-24 23:57:06 +01:00
SMT_DSH * New_DSH ;
2024-04-15 16:54:18 +02:00
char prefixed_name [ SMD_NAME_SIZE ] ;
2005-01-24 23:57:06 +01:00
union semun Sem_Ctl ;
2005-02-24 00:31:06 +01:00
int SemId ;
2005-01-24 23:57:06 +01:00
SMT_Status rc ;
NDT_Index_Type index_type = ( NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_FIFO ) ;
2000-07-28 16:13:54 +02:00
* Locked = FALSE ;
/* On regarde si le heap est d<> j<EFBFBD> ouvert par le processus courant */
2024-04-19 18:44:32 +02:00
if ( SM_Heap_IsOpen_I ( Heap_Name , Heap_Ptr_Ptr ) = = SMS_YES )
2000-07-28 16:13:54 +02:00
{
2005-01-24 23:57:06 +01:00
if ( Open_Mode & SMD_OPEN )
2000-07-28 16:13:54 +02:00
{
/* Verrouillage du heap dans le mode demand<6E> */
2024-04-19 18:44:32 +02:00
rc = SM_Heap_Lock_I ( * Heap_Ptr_Ptr , SMD_LOCK_MSK ( Open_Mode ) , Locked ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_2 ( " Unable to lock heap: [%s] for: [%s] " , Heap_Name , Open_Mode & SMD_READ ? " reading " : " writing " ) ;
2005-01-24 23:57:06 +01:00
return ( rc ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
return ( SMS_OK ) ;
2000-07-28 16:13:54 +02:00
}
else
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " The heap already exists but (Flags & SMD_OPEN) is false " ) ;
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
return ( SMS_ERRAPI ) ;
2000-07-28 16:13:54 +02:00
}
}
2024-04-15 16:54:18 +02:00
SM_Name_Prefix ( prefixed_name , Heap_Name ) ;
2000-07-28 16:13:54 +02:00
/* On regarde si le heap existe d<> j<EFBFBD> dans la base */
2005-01-24 23:57:06 +01:00
if ( SM_Heap_Exist_I ( Heap_Name ) = = SMS_YES )
2000-07-28 16:13:54 +02:00
{
2005-01-24 23:57:06 +01:00
if ( Open_Mode & SMD_OPEN )
2000-07-28 16:13:54 +02:00
{
2005-01-24 23:57:06 +01:00
SMT_MHH To_Find ;
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
/* Ouverture d'un heap existant */
2024-04-15 16:54:18 +02:00
strcpy ( To_Find . Name , prefixed_name ) ;
2024-04-19 18:44:32 +02:00
ND_Index_Node_Find ( & Node_Ptr , SM_Base - > MHR , NDD_INDEX_PRIMARY , & To_Find , NULL ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
MHH = ( SMT_MHH * ) ( Node_Ptr - > Value ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
* Heap_Ptr_Ptr = ( SMT_Heap * ) malloc ( sizeof ( SMT_Heap ) ) ;
if ( ! * Heap_Ptr_Ptr )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to allocate memory for the opened heap: [%s] " , prefixed_name ) ;
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
return ( SMS_ERRMEM ) ;
2000-07-28 16:13:54 +02:00
}
2024-04-19 18:44:32 +02:00
( * Heap_Ptr_Ptr ) - > Name = strdup ( prefixed_name ) ;
( * Heap_Ptr_Ptr ) - > MHH = MHH ;
( * Heap_Ptr_Ptr ) - > Lock_Mode = SMD_NO_LOCK ;
2000-07-28 16:13:54 +02:00
/* On ouvre tous les segments du heap */
2024-04-19 18:44:32 +02:00
ND_Index_Node_First_Get ( & Node_Ptr , ( * Heap_Ptr_Ptr ) - > MHH - > DSR , NDD_INDEX_PRIMARY ) ;
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
while ( Node_Ptr )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
rc = SM_DataSegment_Open ( Node_Ptr - > Value ) ;
2005-01-24 23:57:06 +01:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to open one of the data segments of heap: [%s] " , prefixed_name ) ;
2000-07-28 16:13:54 +02:00
goto Error1 ;
}
2024-04-19 18:44:32 +02:00
ND_Index_Node_Next_Get ( & Node_Ptr , Node_Ptr ) ;
2000-07-28 16:13:54 +02:00
}
2024-04-19 18:44:32 +02:00
( * Heap_Ptr_Ptr ) - > Nb_Seg = ( * Heap_Ptr_Ptr ) - > MHH - > DSR - > Index_Tab [ NDD_INDEX_PRIMARY ] . Node_Number ;
2000-07-28 16:13:54 +02:00
/* Verrouillage du heap dans le mode demand<6E> */
2024-04-19 18:44:32 +02:00
rc = SM_Heap_Lock_I ( * Heap_Ptr_Ptr , SMD_LOCK_MSK ( Open_Mode ) , Locked ) ;
2005-01-24 23:57:06 +01:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_2 ( " Unable to lock heap: [%s] for: [%s] " , prefixed_name , Open_Mode & SMD_READ ? " reading " : " writing " ) ;
2000-07-28 16:13:54 +02:00
goto Error1 ;
}
/* Ajout au cache des heaps ouverts */
2024-04-19 18:44:32 +02:00
rc = ND_DataStruct_Value_Add ( Opened_Heap_List , * Heap_Ptr_Ptr ) ;
2005-01-24 23:57:06 +01:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to add heap: [%s] to the opened heap cache " , prefixed_name ) ;
2000-07-28 16:13:54 +02:00
goto Error2 ;
}
2005-01-24 23:57:06 +01:00
return ( SMS_OK ) ;
2000-07-28 16:13:54 +02:00
}
else
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " The heap already exists but (Open_Mode & SMD_OPEN) is false " ) ;
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
return ( SMS_ERRAPI ) ;
2000-07-28 16:13:54 +02:00
}
}
2024-04-15 16:54:18 +02:00
2005-01-24 23:57:06 +01:00
if ( ! ( Open_Mode & SMD_CREATE ) )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " The heap: [%s] does no exist and (Open_Mode & SMD_CREATE) is false " , prefixed_name ) ;
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
return ( SMS_ERRAPI ) ;
2000-07-28 16:13:54 +02:00
}
2024-04-15 16:54:18 +02:00
2005-06-27 00:50:49 +02:00
/*Alloc du MHH qui fait l'alloccation du premier segment de donnees*/
2024-04-15 16:54:18 +02:00
rc = ND_Value_Alloc ( ( void * * ) & MHH , SM_Base - > MHR , prefixed_name , Seg_Size ) ;
2005-06-27 01:40:14 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to alloc a new MHH structure " ) ;
2005-06-27 00:50:49 +02:00
return ( SMS_ERRAPI ) ;
2000-07-28 16:13:54 +02:00
}
/* Ajout du nouveau heap <20> la structure MHR */
2005-01-25 00:10:09 +01:00
rc = ND_DataStruct_Value_Add ( SM_Base - > MHR , MHH ) ;
2005-01-24 23:57:06 +01:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to add the new heap to the MHR structure " ) ;
2000-07-28 16:13:54 +02:00
goto Error9 ;
}
/* Verrouillage du nouveau MHH dans le mode demand<6E> */
2005-01-24 23:57:06 +01:00
rc = SM_Heap_Lock_Set ( MHH , SMD_LOCK_MSK ( Open_Mode ) ) ;
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_2 ( " Unable to lock heap: [%s] for: [%s] " , prefixed_name , Open_Mode & SMD_READ ? " reading " : " writing " ) ;
2000-07-28 16:13:54 +02:00
goto Error10 ;
}
* Locked = TRUE ;
/* Ajout du nouveau heap au cache des heaps ouverts */
2024-04-19 18:44:32 +02:00
* Heap_Ptr_Ptr = ( SMT_Heap * ) malloc ( sizeof ( SMT_Heap ) ) ;
if ( ! * Heap_Ptr_Ptr )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to allocate memory for a new opened heap: [%s] " , prefixed_name ) ;
2000-07-28 16:13:54 +02:00
rc = SMS_ERRMEM ;
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
goto Error10 ;
}
2024-04-19 18:44:32 +02:00
( * Heap_Ptr_Ptr ) - > Name = strdup ( prefixed_name ) ;
( * Heap_Ptr_Ptr ) - > MHH = MHH ;
( * Heap_Ptr_Ptr ) - > Lock_Mode = SMD_LOCK_MSK ( Open_Mode ) ;
( * Heap_Ptr_Ptr ) - > Nb_Seg = 1 ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
rc = ND_DataStruct_Value_Add ( Opened_Heap_List , * Heap_Ptr_Ptr ) ;
2005-01-24 23:57:06 +01:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to add heap: [%s] to the opened heap cache " , prefixed_name ) ;
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
goto Error11 ;
}
2005-01-24 23:57:06 +01:00
return ( SMS_OK ) ;
2000-07-28 16:13:54 +02:00
/* Gestion d'erreur sur cr<63> ation */
2005-01-24 23:57:06 +01:00
Error11 :
2024-04-19 18:44:32 +02:00
free ( ( * Heap_Ptr_Ptr ) - > Name ) ;
free ( * Heap_Ptr_Ptr ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
* Heap_Ptr_Ptr = NULL ;
2005-01-24 23:57:06 +01:00
Error10 :
2005-01-25 00:10:09 +01:00
ND_DataStruct_Value_Remove ( SM_Base - > MHR , MHH ) ;
2005-01-24 23:57:06 +01:00
Error9 :
2005-01-25 00:10:09 +01:00
ND_DataStruct_Value_Remove ( MHH - > DSR , New_DSH ) ;
2005-01-24 23:57:06 +01:00
Error8 :
2005-06-27 00:50:49 +02:00
ND_Value_Free ( MHH - > DSR , New_DSH ) ;
2005-01-24 23:57:06 +01:00
Error7 :
2024-05-03 00:28:06 +02:00
ND_Deallocator_Exec ( MHH - > FCR , SM_Base - > MHR , SM_Base - > MHR - > Deallocator_Name , SM_Base - > MHR - > Deallocator_Ptr , NULL ) ;
2005-01-24 23:57:06 +01:00
Error6 :
2024-05-03 00:28:06 +02:00
ND_Deallocator_Exec ( MHH - > ACR , SM_Base - > MHR , SM_Base - > MHR - > Deallocator_Name , SM_Base - > MHR - > Deallocator_Ptr , NULL ) ;
2005-01-24 23:57:06 +01:00
Error5 :
2024-05-03 00:28:06 +02:00
ND_Deallocator_Exec ( MHH - > DSR , SM_Base - > MHR , SM_Base - > MHR - > Deallocator_Name , SM_Base - > MHR - > Deallocator_Ptr , NULL ) ;
2005-01-24 23:57:06 +01:00
Error4 :
2024-05-03 00:28:06 +02:00
ND_Deallocator_Exec ( MHH , SM_Base - > MHR , SM_Base - > MHR - > Deallocator_Name , SM_Base - > MHR - > Deallocator_Ptr , NULL ) ;
2005-01-24 23:57:06 +01:00
Error3 :
2005-02-24 00:31:06 +01:00
semctl ( SemId , 0 , IPC_RMID , Sem_Ctl ) ;
2005-01-24 23:57:06 +01:00
return ( rc ) ;
2000-07-28 16:13:54 +02:00
/* Gestion d'erreur sur ouverture */
2005-01-24 23:57:06 +01:00
Error2 :
2024-04-19 18:44:32 +02:00
SM_Heap_Unlock_I ( * Heap_Ptr_Ptr ) ;
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
Error1 :
2024-04-19 18:44:32 +02:00
free ( ( * Heap_Ptr_Ptr ) - > Name ) ;
free ( * Heap_Ptr_Ptr ) ;
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
* Heap_Ptr_Ptr = NULL ;
2005-01-24 23:57:06 +01:00
return ( rc ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Teste si un heap a d<> j<EFBFBD> <20> t<EFBFBD> ouvert par le processus courant */
/*------------------------------------------------------------------------------*/
2024-04-19 18:44:32 +02:00
/* (I) Heap_Name: Nom du heap */
/* (O) Heap_Ptr_Ptr: pointeur sur le heap ouvert */
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_IsOpen_I ( const char * Heap_Name , SMT_Heap * * Heap_Ptr_Ptr )
2000-07-28 16:13:54 +02:00
{
2005-01-25 00:10:09 +01:00
SMT_Status rc ;
2024-04-15 16:54:18 +02:00
char prefixed_name [ SMD_NAME_SIZE ] ;
2005-01-25 00:10:09 +01:00
SMT_Heap To_Find ;
NDT_Node * Node_Ptr ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
* Heap_Ptr_Ptr = NULL ;
2000-07-28 16:13:54 +02:00
2024-04-15 16:54:18 +02:00
To_Find . Name = prefixed_name ;
SM_Name_Prefix ( prefixed_name , Heap_Name ) ;
2000-07-28 16:13:54 +02:00
2005-01-25 00:10:09 +01:00
rc = ND_Index_Node_Find ( & Node_Ptr , Opened_Heap_List , NDD_INDEX_PRIMARY , & To_Find , NULL ) ;
2000-07-28 16:13:54 +02:00
2005-01-25 00:10:09 +01:00
if ( ND_ERROR ( rc ) )
{
return ( SMS_KO ) ;
}
else
{
if ( Node_Ptr = = NULL )
{
2024-04-19 18:44:32 +02:00
* Heap_Ptr_Ptr = NULL ;
2005-01-25 00:10:09 +01:00
return ( SMS_NO ) ;
}
else
{
2024-04-19 18:44:32 +02:00
* Heap_Ptr_Ptr = ( SMT_Heap * ) ( Node_Ptr - > Value ) ;
2005-01-25 00:10:09 +01:00
return ( SMS_YES ) ;
}
}
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Destruction d'un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_End_I ( const char * Heap_Name )
2000-07-28 16:13:54 +02:00
{
SMT_Status rc ;
SMT_Heap * Heap ;
int Locked ;
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
rc = SM_Heap_Exist_I ( Heap_Name ) ;
2024-04-15 16:54:18 +02:00
if ( SM_ERROR ( rc ) ) return rc ;
if ( rc = = SMS_NO )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " SM_Heap_End: heap: [%s] does not exist " , Heap_Name ) ;
2000-07-28 16:13:54 +02:00
return SMS_KO ;
}
2024-04-19 18:44:32 +02:00
rc = SM_Heap_IsOpen_I ( Heap_Name , & Heap ) ;
2024-04-15 16:54:18 +02:00
if ( SM_ERROR ( rc ) ) return rc ;
if ( rc = = SMS_YES )
2000-07-28 16:13:54 +02:00
{
/* Verrouillage en <20> criture */
2024-04-19 18:44:32 +02:00
rc = SM_Heap_Lock_I ( Heap , SMD_WRITE , & Locked ) ;
2000-07-28 16:13:54 +02:00
}
else
{
/* Ouverture du heap en <20> criture */
2024-04-19 18:44:32 +02:00
rc = SM_Heap_Open_I ( Heap_Name , & Heap , 0 , SMD_OPEN | SMD_WRITE , & Locked ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to open the heap to remove for writing " ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
return ( rc ) ;
2000-07-28 16:13:54 +02:00
}
}
/* Suppression du heap */
2005-01-25 00:10:09 +01:00
rc = ND_DataStruct_Value_Remove ( SM_Base - > MHR , Heap - > MHH ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to remove heap: [%s] from the MHR structure " , Heap_Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
return ( rc ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-25 00:10:09 +01:00
rc = ND_Value_Free ( SM_Base - > MHR , Heap - > MHH ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " SM_Heap_End: unable to free heap: [%s] " , Heap_Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
return ( rc ) ;
2000-07-28 16:13:54 +02:00
}
2024-04-19 18:44:32 +02:00
return ( SMS_OK ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fermeture d'un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Close_I ( SMT_Heap * Heap )
2000-07-28 16:13:54 +02:00
{
SMT_Status rc ;
NDT_Node * Node ;
/*
2005-01-24 23:57:06 +01:00
Fermeture des segments de donn <EFBFBD> es composant le heap
en commencant par le dernier ( important pour le heap syst <EFBFBD> me )
2000-07-28 16:13:54 +02:00
*/
2005-01-25 00:10:09 +01:00
ND_Index_Node_Last_Get ( & Node , Heap - > MHH - > DSR , NDD_INDEX_PRIMARY ) ;
2024-04-19 18:44:32 +02:00
while ( Node )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
rc = SM_DataSegment_Close ( Node - > Value ) ;
2024-04-15 16:54:18 +02:00
if ( SM_ERROR ( rc ) ) return rc ;
2000-07-28 16:13:54 +02:00
2005-01-25 00:10:09 +01:00
ND_Index_Node_Previous_Get ( & Node , Node ) ;
2000-07-28 16:13:54 +02:00
}
/* D<> verrouillage du heap */
2024-04-19 18:44:32 +02:00
SM_Heap_Unlock_I ( Heap ) ;
2000-07-28 16:13:54 +02:00
/* Suppression du heap de la liste des heaps ouverts */
2005-01-25 00:10:09 +01:00
rc = ND_DataStruct_Value_Remove ( Opened_Heap_List , Heap ) ;
2024-04-15 16:54:18 +02:00
if ( SM_ERROR ( rc ) ) return rc ;
2000-07-28 16:13:54 +02:00
2005-01-25 00:10:09 +01:00
rc = ND_Value_Free ( Opened_Heap_List , Heap ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Pose d'un verrou sur un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/* (I) Lock_Mode : mode de verrouillage (SMD_READ ou SMD_WRITE) */
/* (O) Locked : verrouillage effectu<74> (TRUE ou FALSE) */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap , SMT_Flags Lock_Mode , int * Locked )
2000-07-28 16:13:54 +02:00
{
SMT_Status rc ;
int Nb_Detected , Nb_Corrected ;
2005-01-24 23:57:06 +01:00
2005-06-27 01:40:14 +02:00
if ( Lock_Mode = = Heap - > Lock_Mode )
2000-07-28 16:13:54 +02:00
{
/* Rien <20> faire : le heap est d<> j<EFBFBD> verrouill<6C> dans ce mode */
2024-04-18 00:54:07 +02:00
/*
2024-04-17 18:49:56 +02:00
fprintf ( stderr , " SM_Heap_Lock: heap [%s] already locked in mode: (%d)! \n " , Heap - > Name , Lock_Mode ) ;
fflush ( stderr ) ;
2024-04-18 00:54:07 +02:00
*/
2024-04-19 18:44:32 +02:00
LG_LOG_WARNING_2 ( " Heap: [%s] already locked in mode: (%d) " , Heap - > Name , Lock_Mode ) ;
// LG_STACK_TRACE( LGD_LOG_LEVEL_DEFAULT);
2024-04-18 00:54:07 +02:00
2000-07-28 16:13:54 +02:00
* Locked = FALSE ;
2024-04-17 18:49:56 +02:00
// *Locked = TRUE;
2000-07-28 16:13:54 +02:00
}
2005-06-27 01:40:14 +02:00
else if ( Heap - > Lock_Mode = = SMD_NO_LOCK )
2000-07-28 16:13:54 +02:00
{
/*
2005-01-24 23:57:06 +01:00
Verrouillage d ' un heap qui ne l ' <EFBFBD> tait pas : le heap ayant pu <EFBFBD> tre modifi <EFBFBD>
depuis la derni <EFBFBD> re fois qu ' on y a acc <EFBFBD> d <EFBFBD> , il faut proc <EFBFBD> der <EFBFBD> un certain
nombre de v <EFBFBD> rifications .
2000-07-28 16:13:54 +02:00
*/
/* V<> rification de l'<27> tat du heap */
2005-06-27 01:40:14 +02:00
if ( Heap - > MHH - > State = = SMD_STATE_CORRUPTED )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Heap: [%s] is flagged as being corrupted " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
return ( SMS_KO ) ;
2000-07-28 16:13:54 +02:00
}
/* Verrouillage du heap dans le mode demand<6E> */
2024-04-15 16:54:18 +02:00
rc = SM_Heap_Lock_Set ( Heap - > MHH , Lock_Mode ) ;
2005-06-27 01:40:14 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_2 ( " Unable to lock heap [%s] for: [%s] " , Heap - > Name , Lock_Mode & SMD_READ ? " reading " : " writing " ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
/* V<> rification de l'<27> tat du heap */
2005-06-27 01:40:14 +02:00
if ( Heap - > MHH - > State = = SMD_STATE_UNVALIDATED )
2000-07-28 16:13:54 +02:00
{
/* Verrouillage du heap en <20> criture pour le v<> rifier */
2024-04-15 16:54:18 +02:00
if ( Lock_Mode = = SMD_READ )
2000-07-28 16:13:54 +02:00
{
2024-04-15 16:54:18 +02:00
rc = SM_Heap_Lock_Change ( Heap - > MHH , SMD_WRITE ) ;
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to lock heap: [%s] for writing before checking " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
SM_Heap_Unlock_I ( Heap ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
}
/* V<> rification du heap */
Nb_Detected = Nb_Corrected = 0 ;
2024-04-19 18:44:32 +02:00
rc = SM_Heap_Check_I ( Heap , & Nb_Detected , & Nb_Corrected , SM_stderr ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to check heap: [%s] " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
SM_Heap_Unlock_I ( Heap ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
/* On reverrouille <20> ventuellement le heap dans le mode demand<6E> */
2005-06-27 01:40:14 +02:00
if ( Lock_Mode = = SMD_READ )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
rc = SM_Heap_Lock_Change ( Heap - > MHH , SMD_READ ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to lock heap: [%s] for reading " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
SM_Heap_Unlock_I ( Heap ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
}
}
2005-06-27 01:40:14 +02:00
/* TEST !!!! */
{
NDT_Node * node_ptr = NULL ;
SMT_Heap * heap_ptr ;
if ( SM_Heap_IsOpen_I ( " system " , & heap_ptr ) ! = SMS_OK )
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Internal Error 1 ! " ) ;
2005-06-27 01:40:14 +02:00
}
else
{
if ( Heap - > Nb_Seg ! = Heap - > MHH - > DSR - > Index_Tab [ NDD_INDEX_PRIMARY ] . Node_Number )
{
ND_Index_Node_First_Get ( & node_ptr , Heap - > MHH - > DSR , NDD_INDEX_PRIMARY ) ;
if ( node_ptr = = NULL )
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Internal Error 2 ! " ) ;
2005-06-27 01:40:14 +02:00
}
else
{
while ( node_ptr )
{
if ( ( rc = SM_DataSegment_Open ( node_ptr - > Value ) ) ! = SMS_OK )
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to open one of the data segments of heap: [%s] " ,
( ( SMT_MHH * ) ( node_ptr - > Value ) ) - > Name ) ;
2005-06-27 01:40:14 +02:00
}
else
{
2024-04-19 18:44:32 +02:00
// LG_LOG_ERROR_1( "SM_Heap_Lock : Opening Segment (%x)", node_ptr->Value);
//
2005-06-27 01:40:14 +02:00
}
ND_Index_Node_Next_Get ( & node_ptr , node_ptr ) ;
}
}
}
}
}
2000-07-28 16:13:54 +02:00
/* On v<> rifie qu'aucun nouveau segment n'a <20> t<EFBFBD> ajout<75> depuis la derni<6E> re ouverture */
2024-04-15 16:54:18 +02:00
if ( Heap - > Nb_Seg ! = Heap - > MHH - > DSR - > Index_Tab [ NDD_INDEX_PRIMARY ] . Node_Number )
2000-07-28 16:13:54 +02:00
{
NDT_Node * Node ;
/* On ouvre tous les segments du heap */
2005-01-25 00:10:09 +01:00
ND_Index_Node_First_Get ( & Node , Heap - > MHH - > DSR , NDD_INDEX_PRIMARY ) ;
2024-04-19 18:44:32 +02:00
while ( Node )
2000-07-28 16:13:54 +02:00
{
rc = SM_DataSegment_Open ( Node - > Value ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2005-01-24 23:57:06 +01:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to open one of the data segments of heap: [%s] " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
SM_Heap_Unlock_I ( Heap ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
2005-01-25 00:10:09 +01:00
ND_Index_Node_Next_Get ( & Node , Node ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
Heap - > Nb_Seg = Heap - > MHH - > DSR - > Index_Tab [ NDD_INDEX_PRIMARY ] . Node_Number ;
2000-07-28 16:13:54 +02:00
}
Heap - > Lock_Mode = Lock_Mode ;
* Locked = TRUE ;
}
else
{
/* Verrouillage du heap qui est d<> j<EFBFBD> verrouill<6C> dans un autre mode */
2024-04-19 18:44:32 +02:00
rc = SM_Heap_Lock_Change ( Heap - > MHH , Lock_Mode ) ;
2005-06-27 01:40:14 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_2 ( " Unable to change lock of heap: [%s] for [%s] " , Heap - > Name , Lock_Mode & SMD_READ ? " reading " : " writing " ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
Heap - > Lock_Mode = Lock_Mode ;
* Locked = TRUE ;
}
2024-04-19 18:44:32 +02:00
LG_LOG_TRACE_2 ( LGD_LOG_LEVEL_DEFAULT , " Locked: heap: [%s] lock_mode: (%d) " , Heap - > Name , Heap - > Lock_Mode ) ;
2024-04-18 00:54:07 +02:00
2024-04-15 16:54:18 +02:00
return ( SMS_OK ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Lib<69> ration d'un verrou sur un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur unheap ouvert */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Unlock_I ( SMT_Heap * Heap )
2000-07-28 16:13:54 +02:00
{
SMT_Status rc ;
2024-04-17 18:49:56 +02:00
2024-04-19 18:44:32 +02:00
rc = SM_Heap_Lock_Release ( Heap - > MHH , Heap - > Lock_Mode ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_2 ( " Unable to unlock heap: [%s] for: [%s] " ,
2005-01-24 23:57:06 +01:00
Heap - > Name , Heap - > Lock_Mode & SMD_READ ? " reading " : " writing " ) ;
2024-04-19 18:44:32 +02:00
2000-07-28 16:13:54 +02:00
2024-04-17 18:49:56 +02:00
return ( rc ) ;
2000-07-28 16:13:54 +02:00
}
Heap - > Lock_Mode = SMD_NO_LOCK ;
2024-04-19 18:44:32 +02:00
LG_LOG_TRACE_2 ( LGD_LOG_LEVEL_DEFAULT , " Unlocked: heap: [%s] lock_mode: (%d) " , Heap - > Name , Heap - > Lock_Mode ) ;
2024-04-18 00:54:07 +02:00
2024-04-17 18:49:56 +02:00
return ( SMS_OK ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Configuration d'un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/* (I) Tag : type de configuration */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Config_I ( SMT_Heap * Heap , SMT_Config Tag , . . . )
2000-07-28 16:13:54 +02:00
{
va_list Arguments ;
size_t Size , Current_Size ;
SMT_Status rc ;
va_start ( Arguments , Tag ) ;
2024-04-19 18:44:32 +02:00
switch ( Tag )
2000-07-28 16:13:54 +02:00
{
case SMD_AUTO_COMPRESS :
2024-04-19 18:44:32 +02:00
{
2000-07-28 16:13:54 +02:00
Size = va_arg ( Arguments , size_t ) ;
Heap - > MHH - > Auto_Compress = Size ;
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case SMD_SEGMENT_SIZE :
2024-04-19 18:44:32 +02:00
{
2000-07-28 16:13:54 +02:00
Size = va_arg ( Arguments , size_t ) ;
Heap - > MHH - > Segment_Size = Size ;
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case SMD_HEAP_LIMIT :
2024-04-19 18:44:32 +02:00
{
2000-07-28 16:13:54 +02:00
Size = va_arg ( Arguments , size_t ) ;
Current_Size = 0 ;
2024-04-15 16:54:18 +02:00
if ( Size ! = SMD_UNLIMITED )
2000-07-28 16:13:54 +02:00
{
/* On contr<74> le que la limite fix<69> e est inf<6E> rieure <20> la taille actuelle du heap */
2024-04-19 18:44:32 +02:00
rc = ND_DataStruct_Traverse ( Heap - > MHH - > DSR , NDD_CMD_VALUE_SUM , ( void * ) & Current_Size ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK ) return rc ;
2000-07-28 16:13:54 +02:00
2024-04-15 16:54:18 +02:00
if ( Current_Size > Size )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " The heap has already exceeded the limit size: (%d) bytes " , Current_Size ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
va_end ( Arguments ) ;
2000-07-28 16:13:54 +02:00
return SMS_ERRAPI ;
}
}
Heap - > MHH - > Limit_Size = Size ;
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
default :
{
LG_LOG_ERROR_1 ( " Unknown config tag: (%d) " , Tag ) ;
va_end ( Arguments ) ;
2000-07-28 16:13:54 +02:00
return SMS_ERRAPI ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
}
2024-04-19 18:44:32 +02:00
va_end ( Arguments ) ;
2000-07-28 16:13:54 +02:00
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Compression d'un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/* (O) Compress : pointeur sur la taille m<> moire gagn<67> e */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2005-06-27 00:50:49 +02:00
SMT_Status SM_Heap_Compress_I ( SMT_Heap * Heap , size_t * Compress )
2000-07-28 16:13:54 +02:00
{
2005-06-27 00:50:49 +02:00
SMT_Status rc ;
NDT_Node * Node ;
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
* Compress = 0 ;
/*
2005-01-24 23:57:06 +01:00
Pour permettre la compression , il faut que les
chunks libres soient tri <EFBFBD> s par adresse .
2000-07-28 16:13:54 +02:00
*/
rc = ND_DataStruct_Reorg ( Heap - > MHH - > FCR ) ;
2005-06-27 00:50:49 +02:00
if ( rc ! = NDS_OK ) return ( rc ) ;
2000-07-28 16:13:54 +02:00
/* Compression de chaque segment de donn<6E> es du heap */
2005-01-25 00:10:09 +01:00
ND_Index_Node_First_Get ( & Node , Heap - > MHH - > DSR , NDD_INDEX_PRIMARY ) ;
2005-06-27 00:50:49 +02:00
while ( Node )
2000-07-28 16:13:54 +02:00
{
2005-06-27 00:50:49 +02:00
* Compress + = SM_DataSegment_Compress ( ( SMT_DSH * ) ( Node - > Value ) , Heap - > MHH - > FCR ) ;
2005-01-25 00:10:09 +01:00
ND_Index_Node_Next_Get ( & Node , Node ) ;
2000-07-28 16:13:54 +02:00
}
2005-06-27 00:50:49 +02:00
Heap - > MHH - > Compress_Nb + + ;
return ( SMS_OK ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* V<> rification/correction des structures d'un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/* (O) Nb_Detected : pointeur sur le nombre d'erreurs d<> tect<63> es */
/* (O) Nb_Corrected : pointeur sur le nombre d'erreurs corrig<69> es */
/* (I) Out : pointeur sur le flux de sortie du rapport */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap , int * Nb_Detected , int * Nb_Corrected , FILE * Out )
2000-07-28 16:13:54 +02:00
{
SMT_Status rc ;
NDT_Node * Node ;
2024-04-19 18:44:32 +02:00
LG_LOG_INFO_1 ( " Checking heap: [%s] " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-15 16:54:18 +02:00
if ( Heap - > MHH - > DSR - > Index_Tab [ NDD_INDEX_PRIMARY ] . Node_Number = = 0 )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to check heap: [%s] which has no data segment " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
( * Nb_Detected ) + + ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
LG_LOG_INFO_2 ( " (%d) error(s) could not be corrected in heap: [%s] which will be declared as corrupted " , * Nb_Detected - * Nb_Corrected , Heap - > Name ) ;
LG_LOG_INFO_0 ( " Please contact an administrator about it " ) ;
2000-07-28 16:13:54 +02:00
Heap - > MHH - > State = SMD_STATE_CORRUPTED ;
return SMS_ERRAPI ;
}
else
{
/* V<> rification de la structure DSR du heap */
2024-04-19 18:44:32 +02:00
LG_LOG_INFO_0 ( " Checking the DSR node structure " ) ;
2000-07-28 16:13:54 +02:00
rc = ND_DataStruct_Check ( Heap - > MHH - > DSR , Nb_Detected , Nb_Corrected , Out ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to check the DSR structure " ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
LG_LOG_INFO_2 ( " (%d) error(s) could not be corrected in heap: [%s] which will be declared as corrupted " , * Nb_Detected - * Nb_Corrected , Heap - > Name ) ;
LG_LOG_INFO_0 ( " Please contact an administrator about it " ) ;
2000-07-28 16:13:54 +02:00
Heap - > MHH - > State = SMD_STATE_CORRUPTED ;
return rc ;
}
}
2024-04-19 18:44:32 +02:00
LG_LOG_INFO_0 ( " Trying to open every data segment of the heap " ) ;
2000-07-28 16:13:54 +02:00
/* Ouverture des segments du heap au cas <20> a n'aurait pas <20> t<EFBFBD> fait */
2005-01-25 00:10:09 +01:00
ND_Index_Node_First_Get ( & Node , Heap - > MHH - > DSR , NDD_INDEX_PRIMARY ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
while ( Node )
2000-07-28 16:13:54 +02:00
{
rc = SM_DataSegment_Open ( Node - > Value ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to open one of the data segments of heap: [%s] " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
( * Nb_Detected ) + + ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
LG_LOG_INFO_2 ( " (%d) error(s) could not be corrected in heap: [%s] which will be declared as corrupted. " ,
* Nb_Detected - * Nb_Corrected , Heap - > Name ) ;
LG_LOG_INFO_0 ( " Please contact an administrator about it " ) ;
2000-07-28 16:13:54 +02:00
Heap - > MHH - > State = SMD_STATE_CORRUPTED ;
return rc ;
}
2005-01-25 00:10:09 +01:00
ND_Index_Node_Next_Get ( & Node , Node ) ;
2000-07-28 16:13:54 +02:00
}
2024-04-19 18:44:32 +02:00
2000-07-28 16:13:54 +02:00
/* V<> rification de la structure ACR du heap */
2024-04-19 18:44:32 +02:00
LG_LOG_INFO_0 ( " Checking the ACR node structure " ) ;
2000-07-28 16:13:54 +02:00
rc = ND_DataStruct_Check ( Heap - > MHH - > ACR , Nb_Detected , Nb_Corrected , Out ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " SM_Heap_Check : unable to check the ACR node structure " ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
LG_LOG_INFO_2 ( " (%d) error(s) could not be corrected in heap: [%s] which will be declared as corrupted. " ,
* Nb_Detected - * Nb_Corrected , Heap - > Name ) ;
LG_LOG_INFO_0 ( " Please contact an administrator about it " ) ;
2000-07-28 16:13:54 +02:00
Heap - > MHH - > State = SMD_STATE_CORRUPTED ;
return rc ;
}
/* V<> rification de la structure FCR du heap */
2024-04-19 18:44:32 +02:00
LG_LOG_INFO_0 ( " Checking the FCR node structure " ) ;
2000-07-28 16:13:54 +02:00
rc = ND_DataStruct_Check ( Heap - > MHH - > FCR , Nb_Detected , Nb_Corrected , Out ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to check the ACR node structure " ) ;
LG_LOG_INFO_2 ( " (%d) error(s) could not be corrected in heap: [%s] which will be declared as corrupted " , * Nb_Detected - * Nb_Corrected , Heap - > Name ) ;
LG_LOG_INFO_0 ( " Please contact an administrator about it " ) ;
2000-07-28 16:13:54 +02:00
Heap - > MHH - > State = SMD_STATE_CORRUPTED ;
return rc ;
}
/* Conclusion de la proc<6F> dure de v<> rification */
2024-04-15 16:54:18 +02:00
if ( * Nb_Detected > * Nb_Corrected )
2000-07-28 16:13:54 +02:00
{
/* On d<> clare le heap corrompu afin que plus personne n'y acc<63> de */
2024-04-19 18:44:32 +02:00
LG_LOG_INFO_2 ( " (%d) error(s) could not be corrected in heap: [%s] which will be declared as corrupted " ,
* Nb_Detected - * Nb_Corrected , Heap - > Name ) ;
LG_LOG_INFO_0 ( " Please contact an administrator about it " ) ;
2000-07-28 16:13:54 +02:00
Heap - > MHH - > State = SMD_STATE_CORRUPTED ;
return SMS_KO ;
}
/* On rend le heap valide */
2024-04-15 16:54:18 +02:00
if ( * Nb_Detected = = 0 )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_INFO_1 ( " No error detected on heap: [%s] which will be declared as a valid heap " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
}
else
{
2024-04-19 18:44:32 +02:00
LG_LOG_WARNING_2 ( " Every (%d) error(s) have beeen corrected on heap: [%s] which will be declared as a valid heap " , * Nb_Corrected , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
}
Heap - > MHH - > State = SMD_STATE_VALID ;
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Allocation d'un chunk dans un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/* (I) Size : taille du chunk */
/* (O) Ptr : adresse d'un pointeur sur la zone de donn<6E> es allou<6F> e */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap , size_t Alloc_Size , void * * Ptr )
2000-07-28 16:13:54 +02:00
{
NDT_Node * Node ;
SMT_Chunk * Chunk ;
SMT_DSH * DSH ;
int Found ;
size_t Round_Size ;
SMT_Status rc ;
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
* Ptr = NULL ;
/*
2005-01-24 23:57:06 +01:00
On invalide le heap jusqu ' <EFBFBD> ce que la proc <EFBFBD> dure d ' allocation soit enti <EFBFBD> rement termin <EFBFBD> e .
Ainsi , si celle - ci est interrompue , le heap restera invalide jusqu ' <EFBFBD> ce qu ' il soit
" r<EFBFBD> par<EFBFBD> " ( appel de la fonction SM_Heap_Check par la fonction SM_Heap_Open ) .
2000-07-28 16:13:54 +02:00
*/
Heap - > MHH - > State = SMD_STATE_UNVALIDATED ;
/*
2005-01-24 23:57:06 +01:00
Pour le heap syst <EFBFBD> me , tous les chunks allou <EFBFBD> s ont la m <EFBFBD> me taille ( DEFAULT_CHUNK_SIZE ) .
Ceci facilite notamment la r <EFBFBD> cup <EFBFBD> ration des errors ( Recovery ) dans le heap syst <EFBFBD> me .
Ceci a aussi pour but de simplifier ( et donc d ' optimiser ) l ' allocation de nouveaux chunks
dans ce heap syst <EFBFBD> me dont la m <EFBFBD> moire n ' a pas besoin d ' <EFBFBD> tre optimis <EFBFBD> e .
2000-07-28 16:13:54 +02:00
*/
2024-04-15 16:54:18 +02:00
if ( Heap = = System_Heap ) Alloc_Size = DEFAULT_CHUNK_SIZE ;
2000-07-28 16:13:54 +02:00
/*
2005-01-24 23:57:06 +01:00
Attention : pour les autres heaps , la taille allou <EFBFBD> e doit <EFBFBD> tre arrondie <EFBFBD> un multiple
de 4 octets ( en 32 bits ) afin que les adresses des chunks soient align <EFBFBD> es ( sinon SIGBUS ! ) .
2000-07-28 16:13:54 +02:00
*/
Round_Size = Alloc_Size % sizeof ( void * ) ;
2024-04-15 16:54:18 +02:00
if ( Round_Size ) Alloc_Size + = sizeof ( void * ) - Round_Size ;
2000-07-28 16:13:54 +02:00
/* Recherche d'un chunk suffisamment grand dans la liste des chunks libres */
Found = FALSE ;
2005-01-25 00:10:09 +01:00
ND_Index_Node_First_Get ( & Node , Heap - > MHH - > FCR , NDD_INDEX_PRIMARY ) ;
2024-04-19 18:44:32 +02:00
while ( Found = = FALSE & & Node )
2000-07-28 16:13:54 +02:00
{
Chunk = ( SMT_Chunk * ) ( Node - > Value ) ;
2024-04-15 16:54:18 +02:00
if ( Chunk - > Size > = Alloc_Size ) Found = TRUE ;
2005-01-25 00:10:09 +01:00
else ND_Index_Node_Next_Get ( & Node , Node ) ;
2000-07-28 16:13:54 +02:00
}
2024-04-15 16:54:18 +02:00
if ( Found = = FALSE )
2000-07-28 16:13:54 +02:00
{
/*
2005-01-24 23:57:06 +01:00
Si aucun chunk libre suffisamment grand n ' a <EFBFBD> t <EFBFBD> trouv <EFBFBD> ,
alors on cr <EFBFBD> e un nouveau segment de donn <EFBFBD> es .
2000-07-28 16:13:54 +02:00
*/
size_t Seg_Size ;
2024-04-15 16:54:18 +02:00
if ( Alloc_Size + sizeof ( NDT_Node ) + sizeof ( SMT_Chunk ) > Heap - > MHH - > Segment_Size )
2000-07-28 16:13:54 +02:00
Seg_Size = Alloc_Size + sizeof ( NDT_Node ) + sizeof ( SMT_Chunk ) ;
else
Seg_Size = Heap - > MHH - > Segment_Size ;
2005-06-27 00:50:49 +02:00
2024-04-14 20:00:25 +02:00
rc = ND_Value_Alloc ( ( void * * ) & DSH , Heap - > MHH - > DSR , Heap - > MHH , Seg_Size ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to create a new data segment for heap: [%s] " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
return SMS_ERRSHM ;
}
2005-01-25 00:10:09 +01:00
rc = ND_DataStruct_Value_Add ( Heap - > MHH - > DSR , DSH ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to add a data segment to the DSR structure of heap: [%s] " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
ND_Value_Free ( Heap - > MHH - > DSR , DSH ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
/*
2005-01-24 23:57:06 +01:00
Maintenant que l ' on a ajout <EFBFBD> un segment de donn <EFBFBD> es , il existe
un chunk libre suffisamment grand au d <EFBFBD> but de ce segment .
2000-07-28 16:13:54 +02:00
*/
Node = ( NDT_Node * ) DSH - > Start ;
Chunk = ( SMT_Chunk * ) ( Node - > Value ) ;
}
/* Suppression du chunk de la liste des chunks libres */
2024-04-19 18:44:32 +02:00
rc = ND_Index_Node_Remove ( Node ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to remove a chunk from the FCR structure of heap: [%s] " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
/* Ajout du chunk <20> la liste des chunks allou<6F> s */
2005-01-25 00:10:09 +01:00
rc = ND_Index_Node_Add ( Heap - > MHH - > ACR , NDD_INDEX_PRIMARY , Node ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to add a chunk to the ACR structure of heap: [%s] " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
/* On tente de revenir en arri<72> re */
2005-01-25 00:10:09 +01:00
ND_Index_Node_Add ( Heap - > MHH - > FCR , NDD_INDEX_PRIMARY , Node ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
/*
2005-01-24 23:57:06 +01:00
Si le chunk trouv <EFBFBD> est plus grand que ce dont on a besoin , alors
on peut cr <EFBFBD> er un nouveau chunk libre avec le reliquat de m <EFBFBD> moire .
2000-07-28 16:13:54 +02:00
*/
2024-04-15 16:54:18 +02:00
if ( Chunk - > Size - Alloc_Size > 0 )
2000-07-28 16:13:54 +02:00
{
size_t Remaining_Size = Chunk - > Size - Alloc_Size ;
/*
2005-01-24 23:57:06 +01:00
La cr <EFBFBD> ation d ' un nouveau chunk libre requiert de la place pour les
donn <EFBFBD> es syst <EFBFBD> me ( SMT_Chunk + NDT_Node ) : on ne cr <EFBFBD> e donc un nouveau
chunk libre que si le reliquat est suffisamment important .
2000-07-28 16:13:54 +02:00
*/
2024-04-15 16:54:18 +02:00
if ( Remaining_Size > sizeof ( SMT_Chunk ) + sizeof ( NDT_Node ) )
2000-07-28 16:13:54 +02:00
{
NDT_Node * New_Node ;
SMT_Chunk * New_Chunk ;
size_t New_Chunk_Size ;
/* Cr<43> ation d'un nouveau chunk libre (noeud puis valeur) juste derri<72> re le chunk trouv<75> */
2024-04-19 18:44:32 +02:00
New_Node = ( NDT_Node * ) ( ( size_t ) ( Chunk - > Data ) + Alloc_Size ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
New_Chunk = ( SMT_Chunk * ) ( ( size_t ) New_Node + sizeof ( NDT_Node ) ) ;
2000-07-28 16:13:54 +02:00
New_Chunk_Size = Remaining_Size - sizeof ( SMT_Chunk ) - sizeof ( NDT_Node ) ;
New_Chunk - > Size = New_Chunk_Size ;
2024-04-19 18:44:32 +02:00
New_Chunk - > Data = ( void * ) ( ( size_t ) ( New_Chunk ) + sizeof ( SMT_Chunk ) ) ;
2000-07-28 16:13:54 +02:00
New_Node - > Root = NULL ;
New_Node - > Parent = NULL ;
New_Node - > Left = NULL ;
New_Node - > Right = NULL ;
New_Node - > Value = New_Chunk ;
2005-01-25 00:10:09 +01:00
rc = ND_Index_Node_Add ( Heap - > MHH - > FCR , NDD_INDEX_PRIMARY , New_Node ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to add a chunk to the FCR structure of heap: [%s] " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
/* Ajustement du chunk allou<6F> */
Chunk - > Size = Alloc_Size ;
}
}
/*
2005-01-24 23:57:06 +01:00
Pour une allocation dans le heap syst <EFBFBD> me , on anticipe l ' ajout
d ' un nouveau segment pour <EFBFBD> viter de se retrouver bloqu <EFBFBD> .
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
Bien entendu , cette op <EFBFBD> ration n ' est faite que si l ' on n ' est
pas d <EFBFBD> j <EFBFBD> en train d ' <EFBFBD> tendre le heap syst <EFBFBD> me ( Adding_Segment = TRUE ) .
2000-07-28 16:13:54 +02:00
*/
2024-04-15 16:54:18 +02:00
if ( Heap = = System_Heap & & Adding_Segment = = FALSE )
2000-07-28 16:13:54 +02:00
{
SMT_Chunk * Free_Chunk ;
unsigned int Free_Usable_Chunk = 0 ;
size_t Free_Usable_Size = 0 ;
int New_Seg_Needed = FALSE ;
/* On compte le nombre de chunks libres "utilisables" dans la structure FCR */
2005-01-25 00:10:09 +01:00
ND_Index_Node_First_Get ( & Node , Heap - > MHH - > FCR , NDD_INDEX_PRIMARY ) ;
2024-04-19 18:44:32 +02:00
while ( Node )
2000-07-28 16:13:54 +02:00
{
Free_Chunk = Node - > Value ;
2024-04-15 16:54:18 +02:00
if ( Free_Chunk - > Size > = DEFAULT_CHUNK_SIZE )
2000-07-28 16:13:54 +02:00
{
Free_Usable_Chunk + + ;
Free_Usable_Size + = Free_Chunk - > Size ;
}
2005-01-25 00:10:09 +01:00
ND_Index_Node_Next_Get ( & Node , Node ) ;
2000-07-28 16:13:54 +02:00
}
/*
2005-01-24 23:57:06 +01:00
S ' il reste au moins FREE_CHUNK_LIMIT chunks libres " utilisables "
ou bien si ces chunks libres " utilisables " repr <EFBFBD> sentent suffisament de
place pour allouer FREE_CHUNK_LIMIT nouveaux chunks , alors tout est OK .
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
Dans le cas contraire , il est urgent d ' <EFBFBD> tendre le heap syst <EFBFBD> me .
2000-07-28 16:13:54 +02:00
*/
2024-04-15 16:54:18 +02:00
if ( Free_Usable_Chunk < FREE_CHUNK_LIMIT )
2000-07-28 16:13:54 +02:00
{
size_t Needed_Size ;
Needed_Size = ( size_t ) ( FREE_CHUNK_LIMIT * DEFAULT_CHUNK_SIZE ) + ( size_t ) ( FREE_CHUNK_LIMIT - Free_Usable_Chunk ) * ( sizeof ( NDT_Node ) + sizeof ( SMT_Chunk ) ) ;
2024-04-15 16:54:18 +02:00
if ( Free_Usable_Size < Needed_Size ) New_Seg_Needed = TRUE ;
2000-07-28 16:13:54 +02:00
}
2024-04-15 16:54:18 +02:00
if ( New_Seg_Needed = = TRUE )
2000-07-28 16:13:54 +02:00
{
NDT_Node * New_Node ;
/*
2005-01-24 23:57:06 +01:00
Puisque l ' ajout d ' un nouveau segment va appeler cette m <EFBFBD> me fonction ,
on positionne une variable globale pour ne pas recommencer cette op <EFBFBD> ration .
2000-07-28 16:13:54 +02:00
*/
Adding_Segment = TRUE ;
/*
2005-01-24 23:57:06 +01:00
On alloue le noeud du nouveau segment avant de faire appel <EFBFBD> la fonction
2005-06-27 00:50:49 +02:00
ND_Value_Alloc pour <EFBFBD> viter que ce noeud soit allou <EFBFBD> dans le nouveau segment .
2000-07-28 16:13:54 +02:00
*/
2024-05-03 00:28:06 +02:00
SM_System_Alloc ( ( void * * ) ( & New_Node ) , NULL , sizeof ( NDT_Node ) , NULL ) ;
2000-07-28 16:13:54 +02:00
New_Node - > Root = NULL ;
New_Node - > Parent = NULL ;
New_Node - > Left = NULL ;
New_Node - > Right = NULL ;
/* On cr<63> e le nouveau segment */
2024-04-14 20:00:25 +02:00
rc = ND_Value_Alloc ( ( void * * ) & DSH , Heap - > MHH - > DSR , Heap - > MHH , Heap - > MHH - > Segment_Size ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to create un new data segment for the system heap (anticipation) " ) ;
2000-07-28 16:13:54 +02:00
return SMS_ERRSHM ;
}
New_Node - > Value = DSH ;
/* On ajoute le nouveau segment au heap syst<73> me */
2005-01-25 00:10:09 +01:00
rc = ND_Index_Node_Add ( Heap - > MHH - > DSR , NDD_INDEX_PRIMARY , New_Node ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to add a data segment to the DSR structure of the system heap (anticipation) " ) ;
2000-07-28 16:13:54 +02:00
2024-04-14 20:00:25 +02:00
ND_Value_Free ( Heap - > MHH - > DSR , DSH ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
Adding_Segment = FALSE ;
}
}
/*
2005-01-24 23:57:06 +01:00
Puisque la proc <EFBFBD> dure d ' allocation d ' un chunk s ' est correctement
termin <EFBFBD> e , on peut rendre le heap <EFBFBD> nouveau valide .
2000-07-28 16:13:54 +02:00
*/
Heap - > MHH - > State = SMD_STATE_VALID ;
* Ptr = Chunk - > Data ;
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* D<> sallocation d'un chunk */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/* (I) Ptr : pointeur sur la zone de donn<6E> es du chunk <20> d<> sallouer */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap , void * Ptr )
2000-07-28 16:13:54 +02:00
{
NDT_Node * Node ;
SMT_Chunk * Chunk ;
SMT_Status rc ;
/*
2005-01-24 23:57:06 +01:00
On invalide le heap jusqu ' <EFBFBD> ce que la proc <EFBFBD> dure de d <EFBFBD> sallocation soit enti <EFBFBD> rement termin <EFBFBD> e .
Ainsi , si celle - ci est interrompue , le heap restera invalide jusqu ' <EFBFBD> ce qu ' il soit
" r<EFBFBD> par<EFBFBD> " ( appel de la fonction SM_Heap_Check par la fonction SM_Heap_Open ) .
2000-07-28 16:13:54 +02:00
*/
Heap - > MHH - > State = SMD_STATE_UNVALIDATED ;
/*
2005-01-24 23:57:06 +01:00
Le noeud du chunk <EFBFBD> tant adjoint <EFBFBD> celui - ci , on n ' a pas besoin
de le rechercher dans la liste des chunks allou <EFBFBD> s .
*/
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
Node = ( NDT_Node * ) ( ( size_t ) Ptr - sizeof ( SMT_Chunk ) - sizeof ( NDT_Node ) ) ;
2000-07-28 16:13:54 +02:00
Chunk = Node - > Value ;
/* Suppression du chunk de la liste des chunks allou<6F> s */
2024-04-19 18:44:32 +02:00
rc = ND_Index_Node_Remove ( Node ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to remove the allocated chunk from the ACR structure of heap: [%s] " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
/* Ajout du chunk <20> la liste des chunks libres */
2005-01-25 00:10:09 +01:00
rc = ND_Index_Node_Add ( Heap - > MHH - > FCR , NDD_INDEX_PRIMARY , Node ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to add the free chunk to the FCR structure of heap: [%s] " , Heap - > Name ) ;
2000-07-28 16:13:54 +02:00
/* Retour arri<72> re */
2005-01-25 00:10:09 +01:00
ND_Index_Node_Add ( Heap - > MHH - > ACR , NDD_INDEX_PRIMARY , Node ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
/*
2005-01-24 23:57:06 +01:00
Puisque la proc <EFBFBD> dure de d <EFBFBD> sallocation d ' un chunk s ' est correctement
termin <EFBFBD> , on peut rendre le heap <EFBFBD> nouveau valide .
2000-07-28 16:13:54 +02:00
*/
Heap - > MHH - > State = SMD_STATE_VALID ;
/* Activation de la compression automatique */
2024-04-15 16:54:18 +02:00
if ( Heap - > MHH - > Auto_Compress ! = SMD_NO_AUTO_COMPRESS & &
2005-01-24 23:57:06 +01:00
Heap - > MHH - > FCR - > Index_Tab [ NDD_INDEX_PRIMARY ] . Node_Number > Heap - > MHH - > Auto_Compress )
2000-07-28 16:13:54 +02:00
{
size_t Compress_Size ;
rc = SM_Heap_Compress ( Heap , & Compress_Size ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_2 ( " Unable to compress FCR structure of heap: [%s] which contains: (%ld) free chunks " , Heap - > Name , Heap - > MHH - > FCR - > Index_Tab [ NDD_INDEX_PRIMARY ] . Node_Number ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
}
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* FONCTIONS SECURISEES (SM_MODE = 0) */
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* Ouverture d'une instance de la librairie */
/*------------------------------------------------------------------------------*/
/* (I) Instance : instance de la librairie */
/* (I) Context : nom du nouveau contexte */
/* (I) Open_Mode : indicateur cr<63> ation/ouverture + mode d'affichage des erreurs */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Library_Open_C ( int Instance , const char * Context , SMT_Flags Open_Mode )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
return SM_Library_Open_I ( Instance , Context , Open_Mode ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* R<> cup<75> ration du num<75> ro de l'instance utilis<69> e */
/*------------------------------------------------------------------------------*/
/* (O) Instance : adresse du num<75> ro de l'instance utilis<69> e */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Library_Instance_Get_C ( int * Instance )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
return SM_Library_Instance_Get_I ( Instance ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* R<> cup<75> ration du nom du contexte utilis<69> */
/*------------------------------------------------------------------------------*/
/* (O) Context : adresse du nom du contexte utilis<69> */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Library_Context_Get_C ( char * * Context )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
return SM_Library_Context_Get_I ( Context ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Changement de contexte d'utilisation de la librairie */
/*------------------------------------------------------------------------------*/
/* (I) Context : nom du nouveau contexte */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Library_Context_Set_C ( const char * Context )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
return SM_Library_Context_Set_I ( Context ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fermeture de l'instance de la librairie */
/*------------------------------------------------------------------------------*/
/* (I) Close_Mode : mode de fermeture (destruction ou fermeture simple) */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Library_Close_C ( SMT_Flags Close_Mode )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
return SM_Library_Close_I ( Close_Mode ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Affichage des informations de la base de m<> moires partag<61> es */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Library_Dump_C ( FILE * Out )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
return SM_Library_Dump_I ( Out ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Lib<69> ration de tous les verrous (base, heap) */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Library_Unlock_C ( void )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
return SM_Library_Unlock_I ( ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* D<> finition de la sortie standard des messages d'erreur de la librairie */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Library_Stderr_Set_C ( FILE * Out )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
return SM_Library_Stderr_Set_I ( Out ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Test d'existence d'un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap_Name : Nom du heap */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Exist_C ( const char * Heap_Name )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
SM_HEAP_NAME_CHECK ( Heap_Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
return SM_Heap_Exist_I ( Heap_Name ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Ouverture/cr<63> ation d'un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap_Name : nom du heap */
/* (O) Heap : pointeur sur le heap ouvert / cr<63> <72> */
/* (I) Seg_Size : taille des segments du heap */
/* (I) Open_Mode : mode d'ouverture du heap */
/* (O) Locked : verrou effectif (TRUE ou FALSE) */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Open_C ( const char * Heap_Name , SMT_Heap * * Heap_Ptr_Ptr , size_t Seg_Size , SMT_Flags Open_Mode , int * Locked )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
SM_HEAP_NAME_CHECK ( Heap_Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
return SM_Heap_Open_I ( Heap_Name , Heap_Ptr_Ptr , Seg_Size , Open_Mode , Locked ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Teste si un heap a d<> j<EFBFBD> <20> t<EFBFBD> ouvert par le processus courant */
/*------------------------------------------------------------------------------*/
/* (I) Heap_Name : Nom du heap */
/* (O) Heap : pointeur sur le heap ouvert */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_IsOpen_C ( const char * Heap_Name , SMT_Heap * * Heap )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
SM_HEAP_NAME_CHECK ( Heap_Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
return SM_Heap_IsOpen_I ( Heap_Name , Heap ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Destruction d'un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_End_C ( const char * Heap_Name )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
SM_HEAP_NAME_CHECK ( Heap_Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
return SM_Heap_End_I ( Heap_Name ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fermeture d'un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap_Ptr )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
SM_HEAP_CHECK ( Heap_Ptr ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
return SM_Heap_Close_I ( Heap_Ptr ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Pose d'un verrou sur un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/* (I) Lock_Mode : mode de verrouillage (SMD_READ ou SMD_WRITE) */
/* (O) Locked : verrouillage effectu<74> (TRUE ou FALSE) */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Lock_C ( SMT_Heap * Heap_Ptr , SMT_Flags Lock_Mode , int * Locked )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
SM_HEAP_CHECK ( Heap_Ptr ) ;
return SM_Heap_Lock_I ( Heap_Ptr , Lock_Mode , Locked ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Lib<69> ration d'un verrou sur un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur unheap ouvert */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Unlock_C ( SMT_Heap * Heap_Ptr )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
SM_HEAP_CHECK ( Heap_Ptr ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
return SM_Heap_Unlock_I ( Heap_Ptr ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Configuration d'un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/* (I) Tag : type de configuration */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap_Ptr , SMT_Config Tag , . . . )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
va_list Arguments ;
size_t Segment_Size , Limit_Size , Current_Size ;
SMT_Status rc ;
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
SM_HEAP_CHECK ( Heap_Ptr ) ;
2000-07-28 16:13:54 +02:00
va_start ( Arguments , Tag ) ;
2024-04-19 18:44:32 +02:00
switch ( Tag )
2000-07-28 16:13:54 +02:00
{
case SMD_SEGMENT_SIZE :
2024-04-19 18:44:32 +02:00
{
2000-07-28 16:13:54 +02:00
Segment_Size = va_arg ( Arguments , size_t ) ;
2024-04-19 18:44:32 +02:00
Heap_Ptr - > MHH - > Segment_Size = Segment_Size ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case SMD_HEAP_LIMIT :
2024-04-19 18:44:32 +02:00
{
2000-07-28 16:13:54 +02:00
Limit_Size = va_arg ( Arguments , size_t ) ;
Current_Size = 0 ;
2024-04-15 16:54:18 +02:00
if ( Limit_Size ! = SMD_UNLIMITED )
2000-07-28 16:13:54 +02:00
{
/* On contr<74> le que la limite fix<69> e est inf<6E> rieure <20> la taille actuelle du heap */
2024-04-19 18:44:32 +02:00
rc = ND_DataStruct_Traverse ( Heap_Ptr - > MHH - > DSR , NDD_CMD_VALUE_SUM , ( void * ) & Current_Size ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK ) return rc ;
2000-07-28 16:13:54 +02:00
2024-04-15 16:54:18 +02:00
if ( Current_Size > Limit_Size )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " The heap has already exceeded the limit size: (%d) bytes " , Current_Size ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
va_end ( Arguments ) ;
2000-07-28 16:13:54 +02:00
return SMS_ERRAPI ;
}
}
2024-04-19 18:44:32 +02:00
Heap_Ptr - > MHH - > Limit_Size = Limit_Size ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
default :
{
LG_LOG_ERROR_1 ( " Unknown config tag: (%d) " , Tag ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
va_end ( Arguments ) ;
2000-07-28 16:13:54 +02:00
return SMS_ERRAPI ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
}
2024-04-19 18:44:32 +02:00
va_end ( Arguments ) ;
2000-07-28 16:13:54 +02:00
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Compression d'un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/* (O) Compress : pointeur sur la taille m<> moire gagn<67> e */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap_Ptr , size_t * Compress )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
SM_HEAP_CHECK ( Heap_Ptr ) ;
2000-07-28 16:13:54 +02:00
2024-04-15 16:54:18 +02:00
if ( ! Compress )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " The compress size pointer is null " ) ;
2000-07-28 16:13:54 +02:00
return SMS_ERRAPI ;
}
2024-04-19 18:44:32 +02:00
return SM_Heap_Compress_I ( Heap_Ptr , Compress ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* V<> rification/correction des structures d'un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/* (O) Nb_Detected : pointeur sur le nombre d'erreurs d<> tect<63> es */
/* (O) Nb_Corrected : pointeur sur le nombre d'erreurs corrig<69> es */
/* (I) Out : pointeur sur le flux de sortie du rapport */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Check_C ( SMT_Heap * Heap_Ptr , int * Nb_Detected , int * Nb_Corrected , FILE * Out )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
SM_HEAP_CHECK ( Heap_Ptr ) ;
2000-07-28 16:13:54 +02:00
2024-04-15 16:54:18 +02:00
if ( ! Nb_Detected | | ! Nb_Corrected )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " The error number pointer is null " ) ;
2000-07-28 16:13:54 +02:00
return SMS_ERRAPI ;
}
2024-04-15 16:54:18 +02:00
if ( ! Out )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " The out stream is null " ) ;
2000-07-28 16:13:54 +02:00
return SMS_ERRAPI ;
}
2024-04-19 18:44:32 +02:00
return SM_Heap_Check_I ( Heap_Ptr , Nb_Detected , Nb_Corrected , Out ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Allocation d'un chunk dans un heap */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/* (I) Size : taille du chunk */
/* (O) Ptr : adresse d'un pointeur sur la zone de donn<6E> es allou<6F> e */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Chunk_Alloc_C ( SMT_Heap * Heap_Ptr , size_t Alloc_Size , void * * Ptr )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
SM_HEAP_CHECK ( Heap_Ptr ) ;
2000-07-28 16:13:54 +02:00
2024-04-15 16:54:18 +02:00
if ( ! Ptr )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " The chunk address is null " ) ;
2000-07-28 16:13:54 +02:00
return SMS_ERRAPI ;
}
2024-04-19 18:44:32 +02:00
return SM_Chunk_Alloc_I ( Heap_Ptr , Alloc_Size , Ptr ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* D<> sallocation d'un chunk */
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/* (I) Ptr : pointeur sur la zone de donn<6E> es du chunk <20> d<> sallouer */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Chunk_Free_C ( SMT_Heap * Heap_Ptr , void * Ptr )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
SM_HEAP_CHECK ( Heap_Ptr ) ;
2000-07-28 16:13:54 +02:00
2024-04-15 16:54:18 +02:00
if ( ! Ptr )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " The chunk pointer is null " ) ;
2000-07-28 16:13:54 +02:00
return SMS_ERRAPI ;
}
2024-04-19 18:44:32 +02:00
return SM_Chunk_Free_I ( Heap_Ptr , Ptr ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2024-04-17 18:49:56 +02:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* FONCTIONS PRIVEES */
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Allocation de m<> moire dans la base */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-05-03 00:28:06 +02:00
NDT_Status SM_Base_Alloc ( void * * Ptr , NDT_Root * ND_Root_Ptr , size_t Size , void * Data_Ptr )
2000-07-28 16:13:54 +02:00
{
* Ptr = SM_Base - > Free ;
2024-04-19 18:44:32 +02:00
SM_Base - > Free = ( void * ) ( ( size_t ) ( SM_Base - > Free ) + Size ) ;
2000-07-28 16:13:54 +02:00
2005-01-25 00:10:09 +01:00
return ( NDS_OK ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* D<> sallocation de m<> moire dans la base */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-05-03 00:28:06 +02:00
NDT_Status SM_Base_Free ( void * Ptr , NDT_Root * ND_Root_Ptr , void * Data_Ptr )
2000-07-28 16:13:54 +02:00
{
2005-01-25 00:10:09 +01:00
if ( ! Ptr ) return ( SMS_ERRAPI ) ;
2000-07-28 16:13:54 +02:00
2005-01-25 00:10:09 +01:00
return ( NDS_OK ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Allocation de m<> moire dans le heap syst<73> me */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-05-03 00:28:06 +02:00
NDT_Status SM_System_Alloc ( void * * Ptr , NDT_Root * ND_Root_Ptr , size_t Size , void * Data_Ptr )
2000-07-28 16:13:54 +02:00
{
2005-01-25 00:10:09 +01:00
return ( SM_Chunk_Alloc_I ( System_Heap , Size , Ptr ) ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* D<> sallocation de m<> moire dans le heap syst<73> me */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-05-03 00:28:06 +02:00
NDT_Status SM_System_Free ( void * Ptr , NDT_Root * ND_Root_Ptr , void * Data_Ptr )
2000-07-28 16:13:54 +02:00
{
2005-01-25 00:10:09 +01:00
return ( SM_Chunk_Free_I ( System_Heap , Ptr ) ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Initialisation de la base */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
SMT_Status SM_Base_Init ( void )
{
2005-01-24 23:57:06 +01:00
SMT_Status rc ;
2005-02-24 00:31:06 +01:00
int SemId ;
int SysMemId ;
int DataMemId ;
2005-01-24 23:57:06 +01:00
union semun Sem_Ctl ;
size_t Size ;
int Locked ;
NDT_Index_Type index_type = ( NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_FIFO ) ;
2000-07-28 16:13:54 +02:00
/* Cr<43> ation du s<> maphore pour la gestion des verrous sur la base */
2005-02-24 00:31:06 +01:00
SemId = semget ( IPC_PRIVATE , 1 , 0777 | IPC_CREAT | IPC_EXCL ) ;
2024-04-15 16:54:18 +02:00
if ( SemId = = - 1 )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
switch ( errno )
2000-07-28 16:13:54 +02:00
{
case ENOMEM :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_0 ( " The amount of memory is not sufficient to create a new semaphore " ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case ENOSPC :
2024-04-19 18:44:32 +02:00
{
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
default :
{
LG_LOG_ERROR_1 ( " Unknown error: (%d) while creating a semaphore " , errno ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
}
return SMS_ERRSEM ;
}
/* Initialisation du s<> maphore <20> 1 (aucun verrou) */
Sem_Ctl . val = 1 ;
2024-04-19 18:44:32 +02:00
if ( semctl ( SemId , 0 , SETVAL , Sem_Ctl ) )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to initialize the value of semaphore: (%d) " , SemId ) ;
2000-07-28 16:13:54 +02:00
rc = SMS_ERRSEM ;
goto Error1 ;
}
2024-04-19 18:44:32 +02:00
2000-07-28 16:13:54 +02:00
/*
2005-01-24 23:57:06 +01:00
Cr <EFBFBD> ation d ' un segment de m <EFBFBD> moire partag <EFBFBD> e qui contiendra la structure SMT_Base .
Ce segment peut <EFBFBD> tre attach <EFBFBD> <EFBFBD> n ' importe quelle adresse .
2000-07-28 16:13:54 +02:00
*/
2024-04-19 18:44:32 +02:00
SysMemId = shmget ( SM_Instance , ( int ) sizeof ( SMT_Base ) , ( 0777 | IPC_CREAT | IPC_EXCL ) ) ;
2024-04-15 16:54:18 +02:00
if ( SysMemId = = - 1 )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
switch ( errno )
2000-07-28 16:13:54 +02:00
{
case EEXIST :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_1 ( " The shared memory segment identifier: (%d) already exists " , SM_Instance ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case EINVAL :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_1 ( " The size of the shared memory segment: (%d) is out of the system-imposed bounds " , sizeof ( SMT_Base ) ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case ENOMEM :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_0 ( " The amount of memory is not sufficient to create the shared memory segment " ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case ENOSPC :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_0 ( " The number of shared memory segments exceeds the system-imposed limit " ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
default :
{
LG_LOG_ERROR_1 ( " Unknown error: (%d) while creating the shared memory segment " , errno ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
}
rc = SMS_ERRSHM ;
goto Error1 ;
}
2024-04-19 18:44:32 +02:00
2000-07-28 16:13:54 +02:00
/* On attache le segment de m<> moire partag<61> e au processus courant */
errno = 0 ;
2005-06-27 00:50:49 +02:00
SM_Base = shmat ( SysMemId , 0 , 0 ) ;
2024-04-15 16:54:18 +02:00
if ( errno )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to attach the first shared memory segment to the current process, error: (%d) " , errno ) ;
2000-07-28 16:13:54 +02:00
rc = SMS_ERRSHM ;
goto Error2 ;
}
/*
2005-01-24 23:57:06 +01:00
Attention : tant que le heap syst <EFBFBD> me n ' est pas cr <EFBFBD> <EFBFBD> , on est oblig <EFBFBD> d ' allouer de
la m <EFBFBD> moire dans le segment de m <EFBFBD> moire partag <EFBFBD> e de la base ( fonction SM_Base_Alloc ) .
Les ressources <EFBFBD> allouer ( structure MHR + ressources du heap syst <EFBFBD> me ) sont r <EFBFBD> f <EFBFBD> renc <EFBFBD> es
par des pointeurs et doivent par cons <EFBFBD> quent <EFBFBD> tre contenues dans un segment attach <EFBFBD> <EFBFBD>
une adresse commune <EFBFBD> tous les processus .
On cr <EFBFBD> e donc ce segment de m <EFBFBD> moire partag <EFBFBD> sp <EFBFBD> cifique dont l ' adresse d ' attachement
sera m <EFBFBD> moris <EFBFBD> e dans la structure SMT_Base .
Pour ce segment de m <EFBFBD> moire partag <EFBFBD> , on r <EFBFBD> serve de la place pour :
- la structure du MHR ( NDT_Root )
- les ressources du heap syst <EFBFBD> me , i . e :
- son noeud ( NDT_Node )
- sa structure d ' ent <EFBFBD> te ( SMT_MHH )
- sa structure DSR ( NDT_Root )
- sa structure ACR ( NDT_Root )
- sa structure FCR ( NDT_Root )
- son premier segment de donn <EFBFBD> es ( noeud + ent <EFBFBD> te )
2000-07-28 16:13:54 +02:00
*/
Size = sizeof ( NDT_Root ) + sizeof ( NDT_Node ) + sizeof ( SMT_MHH ) + 3 * sizeof ( NDT_Root ) + sizeof ( NDT_Node ) + sizeof ( SMT_DSH ) ;
2024-04-19 18:44:32 +02:00
DataMemId = shmget ( IPC_PRIVATE , Size , ( 0777 | IPC_CREAT | IPC_EXCL ) ) ;
2024-04-15 16:54:18 +02:00
if ( DataMemId = = - 1 )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
switch ( errno )
2000-07-28 16:13:54 +02:00
{
case EINVAL :
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " The size of the shared memory segment: (%d) is out of the system-imposed bounds " , Size ) ;
2000-07-28 16:13:54 +02:00
break ;
case ENOMEM :
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " The amount of memory is not sufficient to create the shared memory segment " ) ;
2000-07-28 16:13:54 +02:00
break ;
case ENOSPC :
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " The number of shared memory segments exceeds the system-imposed limit " ) ;
2000-07-28 16:13:54 +02:00
break ;
default :
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unknown error: (%d) while creating a shared memory segment " , errno ) ;
2000-07-28 16:13:54 +02:00
break ;
}
rc = SMS_ERRSHM ;
goto Error3 ;
}
/* Initialisation des informations rattach<63> es <20> la base */
2005-02-24 00:31:06 +01:00
SM_Base - > SemId = SemId ;
SM_Base - > SysMemId = SysMemId ;
SM_Base - > DataMemId = DataMemId ;
2000-07-28 16:13:54 +02:00
SM_Base - > Size = Size ;
SM_Base - > Creator = getpid ( ) ;
SM_Base - > Writer = SM_Base - > Creator ;
SM_Base - > Attach = ( void * ) MEM_LIMIT ;
SM_Base - > MHR = NULL ;
/*
2005-01-24 23:57:06 +01:00
On attache le segment de m <EFBFBD> moire partag <EFBFBD> e au processus courant
<EFBFBD> une adresse la plus haute possible ( MEM_LIMIT ) afin d ' <EFBFBD> viter
de d <EFBFBD> border sur la plage d ' adressage des symboles .
2000-07-28 16:13:54 +02:00
*/
errno = 0 ;
2005-06-27 00:50:49 +02:00
# ifndef __hpux
2024-04-19 18:44:32 +02:00
SM_Base - > Free = shmat ( DataMemId , ( void * ) ( ( size_t ) ( SM_Base - > Attach ) - Size ) , SHM_RND ) ;
2005-06-27 00:50:49 +02:00
# else
SM_Base - > Free = shmat ( DataMemId , 0 , 0 ) ;
# endif
2024-04-15 16:54:18 +02:00
if ( errno )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to attach the second shared memory segment to the current process: (%d) " , errno ) ;
2000-07-28 16:13:54 +02:00
rc = SMS_ERRSHM ;
goto Error4 ;
}
SM_Base - > Attach = SM_Base - > Free ;
2024-05-25 13:03:36 +02:00
2000-07-28 16:13:54 +02:00
/* Cr<43> ation du MHR dans la base */
2024-05-25 13:03:36 +02:00
// rc = ND_DataStruct_Open( &( SM_Base->MHR), 1, &index_type, "MHR_Manager", NULL, "SM_Base_Alloc", NULL, "SM_Base_Free", NULL, TRUE, NULL);
2024-05-27 23:12:23 +02:00
if ( ( rc = ND_DataStruct_Open ( & ( SM_Base - > MHR ) , " SHM-MHR " , 1 , & index_type , " MHR_Manager " , NULL , SMG_DataStruct_Handlers , TRUE , NULL ) ) ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to create the MHR structure " ) ;
2000-07-28 16:13:54 +02:00
goto Error4 ;
}
/*
2005-01-24 23:57:06 +01:00
Cr <EFBFBD> ation d ' un premier heap qui constituera le heap syst <EFBFBD> me
( l ' allocation du MHN , du MHH et des structures DSR , ACR et FCR
sont effectu <EFBFBD> es dans la base )
2000-07-28 16:13:54 +02:00
*/
2024-04-19 18:44:32 +02:00
rc = SM_Heap_Open_I ( HEAP_SYSTEM , & System_Heap , 0 , SMD_CREATE , & Locked ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to create the system heap " ) ;
2000-07-28 16:13:54 +02:00
goto Error5 ;
}
/*
2005-01-24 23:57:06 +01:00
On change les fonctions d ' allocation et de d <EFBFBD> sallocation du MHR afin que d <EFBFBD> sormais ,
les allocations des nouveaux heaps soient faites dans le heap syst <EFBFBD> me .
2000-07-28 16:13:54 +02:00
*/
2005-01-24 23:57:06 +01:00
strcpy ( SM_Base - > MHR - > Allocator_Name , " SM_System_Alloc " ) ;
2024-04-14 20:00:25 +02:00
strcpy ( SM_Base - > MHR - > Deallocator_Name , " SM_System_Free " ) ;
2000-07-28 16:13:54 +02:00
/*
2024-04-14 20:00:25 +02:00
On change les fonctions Allocator et Deallocator du DSR , ACR
2005-01-24 23:57:06 +01:00
et FCR du heap syst <EFBFBD> me afin que d <EFBFBD> sormais , les allocations des
nouveaux segments et chunks soient faites dans le segment de
donn <EFBFBD> es du heap syst <EFBFBD> me .
2000-07-28 16:13:54 +02:00
*/
2005-01-24 23:57:06 +01:00
strcpy ( System_Heap - > MHH - > DSR - > Allocator_Name , " SM_System_Alloc " ) ;
2024-04-14 20:00:25 +02:00
strcpy ( System_Heap - > MHH - > DSR - > Deallocator_Name , " SM_System_Free " ) ;
2005-01-24 23:57:06 +01:00
strcpy ( System_Heap - > MHH - > ACR - > Allocator_Name , " SM_System_Alloc " ) ;
2024-04-14 20:00:25 +02:00
strcpy ( System_Heap - > MHH - > ACR - > Deallocator_Name , " SM_System_Free " ) ;
2005-01-24 23:57:06 +01:00
strcpy ( System_Heap - > MHH - > FCR - > Allocator_Name , " SM_System_Alloc " ) ;
2024-04-14 20:00:25 +02:00
strcpy ( System_Heap - > MHH - > FCR - > Deallocator_Name , " SM_System_Free " ) ;
2000-07-28 16:13:54 +02:00
/* Verrouillage de la base en lecture */
2024-04-19 18:44:32 +02:00
rc = SM_Base_Lock ( SMD_READ ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to lock the shared memory base for reading " ) ;
2000-07-28 16:13:54 +02:00
goto Error5 ;
}
return SMS_OK ;
/* Gestion d'erreur */
2005-01-24 23:57:06 +01:00
Error5 :
2024-04-19 18:44:32 +02:00
ND_DataStruct_Close ( SM_Base - > MHR ) ;
2005-01-24 23:57:06 +01:00
Error4 :
2024-04-19 18:44:32 +02:00
shmdt ( ( void * ) ( SM_Base - > Free ) ) ;
2005-01-24 23:57:06 +01:00
Error3 :
2005-02-24 00:31:06 +01:00
shmctl ( DataMemId , IPC_RMID , 0 ) ;
2024-04-19 18:44:32 +02:00
2005-01-24 23:57:06 +01:00
Error2 :
2024-04-19 18:44:32 +02:00
shmdt ( ( void * ) SM_Base ) ;
2005-02-24 00:31:06 +01:00
shmctl ( SysMemId , IPC_RMID , 0 ) ;
2005-01-24 23:57:06 +01:00
SM_Base = NULL ;
2024-04-19 18:44:32 +02:00
2005-01-24 23:57:06 +01:00
Error1 :
2024-04-19 18:44:32 +02:00
semctl ( SemId , 0 , IPC_RMID , Sem_Ctl ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Destruction de la base */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
SMT_Status SM_Base_End ( void )
{
2005-02-24 00:31:06 +01:00
int SemId ;
int SysMemId , DataMemId ;
2000-07-28 16:13:54 +02:00
SMT_Status rc ;
union semun Sem_Ctl ;
NDT_Node * Node , * Previous_Node ;
/* Retrait du verrou en lecture sur la base */
2024-04-19 18:44:32 +02:00
rc = SM_Base_Unlock ( SMD_READ ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to unlock the shared memory base " ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
/* Verrouillage de la base en <20> criture */
2024-04-19 18:44:32 +02:00
rc = SM_Base_Lock ( SMD_WRITE ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to lock the shared memory base for writing " ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
SM_Base_Lock ( SMD_READ ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
/*
2005-01-24 23:57:06 +01:00
Destruction de tous les heaps ( parcours du MHR en
sens inverse pour d <EFBFBD> truire le heap syst <EFBFBD> me en dernier ) .
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
NB : <EFBFBD> chaque destruction de heap , la base est verrouill <EFBFBD> e en <EFBFBD> criture
2000-07-28 16:13:54 +02:00
*/
2005-01-25 00:10:09 +01:00
ND_Index_Node_Last_Get ( & Node , SM_Base - > MHR , NDD_INDEX_PRIMARY ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
while ( Node )
2000-07-28 16:13:54 +02:00
{
SMT_MHH * MHH = ( SMT_MHH * ) ( Node - > Value ) ;
2005-01-25 00:10:09 +01:00
ND_Index_Node_Previous_Get ( & Previous_Node , Node ) ;
2000-07-28 16:13:54 +02:00
/*
2005-01-24 23:57:06 +01:00
Pour la suppression du heap syst <EFBFBD> me , il faut red <EFBFBD> finir la fonction de
d <EFBFBD> sallocation du MHR , car il a <EFBFBD> t <EFBFBD> allou <EFBFBD> dans la base ( voir SM_Base_Init )
2000-07-28 16:13:54 +02:00
*/
2005-01-24 23:57:06 +01:00
if ( ! Previous_Node )
{
2024-04-14 20:00:25 +02:00
strcpy ( SM_Base - > MHR - > Deallocator_Name , " SM_Base_Free " ) ;
2005-01-24 23:57:06 +01:00
}
2000-07-28 16:13:54 +02:00
/* Retrait du heap de la structure du MHR */
2005-01-25 00:10:09 +01:00
rc = ND_DataStruct_Value_Remove ( SM_Base - > MHR , MHH ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to remove heap: [%s] from the MHR " , MHH - > Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
SM_Base_Unlock ( SMD_WRITE ) ;
SM_Base_Lock ( SMD_READ ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
/* Suppression du heap */
2024-04-19 18:44:32 +02:00
rc = ND_Value_Free ( SM_Base - > MHR , MHH ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to free heap: [%s] " , MHH - > Name ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
SM_Base_Unlock ( SMD_WRITE ) ;
SM_Base_Lock ( SMD_READ ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
Node = Previous_Node ;
}
2005-02-24 00:31:06 +01:00
SemId = SM_Base - > SemId ;
SysMemId = SM_Base - > SysMemId ;
DataMemId = SM_Base - > DataMemId ;
2000-07-28 16:13:54 +02:00
/* Destruction des segments de m<> moire partag<61> e de la base */
2024-04-19 18:44:32 +02:00
if ( shmctl ( DataMemId , IPC_RMID , 0 ) = = - 1 | | shmctl ( SysMemId , IPC_RMID , 0 ) = = - 1 )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
switch ( errno )
2000-07-28 16:13:54 +02:00
{
case EPERM :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_3 ( " Current process: (%d) is not allowed to destroy the shared memory segment: (%d) or (%d) " , ( int ) getpid ( ) , SysMemId , DataMemId ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case EINVAL :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_2 ( " No shared memory segment exists for identifier: (%d) or (%d) " , SysMemId , DataMemId ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
default :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_3 ( " Unknown error: (%d) while destroying the shared memory segment: (%d) or (%d) " , errno , SysMemId , DataMemId ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
}
SM_Base = NULL ;
return SMS_ERRSHM ;
}
SM_Base = NULL ;
2024-04-19 18:44:32 +02:00
2000-07-28 16:13:54 +02:00
/* Destruction du s<> maphore de gestion des verrous sur la base */
2024-04-19 18:44:32 +02:00
if ( semctl ( SemId , 0 , IPC_RMID , Sem_Ctl ) = = - 1 )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
switch ( errno )
2000-07-28 16:13:54 +02:00
{
case EPERM :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_2 ( " Current process: (%d) is not allowed to destroy semaphore: (%d) " , ( int ) getpid ( ) , SemId ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case EINVAL :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_1 ( " No semaphore corresponds to the identifier: (%d) " , SemId ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
default :
{
LG_LOG_ERROR_2 ( " Unknown error: (%d) while destroying semaphore: (%d) " , errno , SemId ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
}
return SMS_ERRSEM ;
}
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Ouverture de la base */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
SMT_Status SM_Base_Open ( void )
{
SMT_Status rc ;
void * Ptr ;
2005-02-24 00:31:06 +01:00
int MemId ;
2000-07-28 16:13:54 +02:00
int Locked ;
2005-01-24 23:57:06 +01:00
2024-04-15 16:54:18 +02:00
if ( SM_Base ) return SMS_OK ;
2000-07-28 16:13:54 +02:00
/* R<> cup<75> ration de l'identifiant du segment de m<> moire partag<61> e de la base */
2024-04-19 18:44:32 +02:00
MemId = shmget ( SM_Instance , 0 , 0 ) ;
2024-04-15 16:54:18 +02:00
if ( MemId = = - 1 )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
switch ( errno )
2000-07-28 16:13:54 +02:00
{
case EACCES :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_1 ( " The shared memory segment: (%d) is not accessible to the current process " , SM_Instance ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case EIDRM :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_1 ( " The shared memory segment: (%d) has been deleted " , SM_Instance ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case ENOENT :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_1 ( " No shared memory segment corresponds to the identifier: (%d) " , SM_Instance ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
default :
{
LG_LOG_ERROR_1 ( " Unknown error: (%d) while retrieving a shared memory segment " , errno ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
}
return SMS_ERRSHM ;
}
2024-04-19 18:44:32 +02:00
2000-07-28 16:13:54 +02:00
/* On attache les segments de m<> moire partag<61> e de la base */
errno = 0 ;
2005-06-27 00:50:49 +02:00
SM_Base = shmat ( MemId , 0 , 0 ) ;
2024-04-19 18:44:32 +02:00
2024-04-15 16:54:18 +02:00
if ( errno )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to attach the shared memory segment to the current process, error: (%d) " , errno ) ;
2000-07-28 16:13:54 +02:00
SM_Base = NULL ;
return SMS_ERRSHM ;
}
errno = 0 ;
2005-02-24 00:31:06 +01:00
Ptr = shmat ( SM_Base - > DataMemId , SM_Base - > MHR , 0 ) ;
2024-04-15 16:54:18 +02:00
if ( errno )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_2 ( " Unable to attach the shared memory segment to the current process at the specified address: (%p) error: (%d) " , SM_Base - > MHR , errno ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
shmdt ( ( void * ) SM_Base ) ;
2000-07-28 16:13:54 +02:00
SM_Base = NULL ;
return SMS_ERRSHM ;
}
2024-04-19 18:44:32 +02:00
2000-07-28 16:13:54 +02:00
/* Verrouillage de la base en lecture */
2024-04-19 18:44:32 +02:00
rc = SM_Base_Lock ( SMD_READ ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to lock the shared memory base for reading " ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
shmdt ( ( void * ) SM_Base ) ;
2000-07-28 16:13:54 +02:00
SM_Base = NULL ;
return rc ;
}
2024-04-19 18:44:32 +02:00
2000-07-28 16:13:54 +02:00
/* Ouverture du heap syst<73> me (sans le verrouiller) */
2024-04-19 18:44:32 +02:00
rc = SM_Heap_Open_I ( HEAP_SYSTEM , & System_Heap , 0 , SMD_OPEN , & Locked ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to open the system heap " ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
shmdt ( ( void * ) SM_Base ) ;
2000-07-28 16:13:54 +02:00
SM_Base = NULL ;
return rc ;
}
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fermeture de la base */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Base_Close ( void )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
NDT_Node * Node ;
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SM_LIBSHMEM_OPEN_CHECK ( ) ;
2000-07-28 16:13:54 +02:00
/*
2005-01-24 23:57:06 +01:00
Fermeture de tous les heaps ( sans d <EFBFBD> verrouillage ) ouverts .
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
Attention : il faut fermer le heap syst <EFBFBD> me en dernier .
2000-07-28 16:13:54 +02:00
*/
2005-01-25 00:10:09 +01:00
ND_Index_Node_First_Get ( & Node , Opened_Heap_List , NDD_INDEX_PRIMARY ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
while ( Node )
2000-07-28 16:13:54 +02:00
{
NDT_Node * Next_Node ;
2005-01-25 00:10:09 +01:00
ND_Index_Node_Next_Get ( & Next_Node , Node ) ;
2024-04-19 18:44:32 +02:00
SM_Heap_Close_I ( ( SMT_Heap * ) ( Node - > Value ) ) ;
Node = Next_Node ;
2000-07-28 16:13:54 +02:00
}
2024-04-19 18:44:32 +02:00
2000-07-28 16:13:54 +02:00
/* D<> verrouillage de la base en lecture */
2024-04-19 18:44:32 +02:00
SM_Base_Unlock ( SMD_READ ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
2000-07-28 16:13:54 +02:00
/* D<> tachement des segments de m<> moire partag<61> e de la base */
2024-04-19 18:44:32 +02:00
shmdt ( ( void * ) SM_Base - > MHR ) ;
shmdt ( ( void * ) SM_Base ) ;
2000-07-28 16:13:54 +02:00
SM_Base = NULL ;
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Pose d'un verrou sur la base */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Base_Lock ( SMT_Flags Lock_Mode )
2000-07-28 16:13:54 +02:00
{
SMT_Status rc ;
2024-04-15 16:54:18 +02:00
if ( Lock_Mode & SMD_READ )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
rc = SM_Semaphore_Operate ( SM_Base - > SemId , SM_SemOp_SSL , 2 ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to lock the library base for reading " ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
}
2024-04-15 16:54:18 +02:00
if ( Lock_Mode & SMD_WRITE )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
rc = SM_Semaphore_Operate ( SM_Base - > SemId , SM_SemOp_SEL , 2 ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to lock the library base for writing " ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
}
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Lib<69> ration d'un verrou sur la base */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Base_Unlock ( SMT_Flags Lock_Mode )
2000-07-28 16:13:54 +02:00
{
SMT_Status rc ;
2024-04-15 16:54:18 +02:00
if ( Lock_Mode & SMD_READ )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
rc = SM_Semaphore_Operate ( SM_Base - > SemId , SM_SemOp_RSL , 2 ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to unlock the library base which had been locked for reading " ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
}
2024-04-15 16:54:18 +02:00
if ( Lock_Mode & SMD_WRITE )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
rc = SM_Semaphore_Operate ( SM_Base - > SemId , SM_SemOp_REL , 2 ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to unlock the library base which had been locked for writing " ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
}
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fonction manager de la liste des heaps ouverts */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-14 20:00:25 +02:00
NDT_Status SM_Opened_Heap_List_Manager ( NDT_Root * Root_Ptr , NDT_Index_Id Index_Id , NDT_Node * Node_Ptr , NDT_Command Command , va_list * Args_Ptr )
2000-07-28 16:13:54 +02:00
{
2005-02-24 00:31:06 +01:00
NDT_Command_Name Command_Name ;
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
2005-02-24 00:31:06 +01:00
switch ( Command )
2000-07-28 16:13:54 +02:00
{
2005-02-24 00:31:06 +01:00
case NDD_CMD_MANAGER_VERSION :
{
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Version_Name_Ptr , * Args_Ptr , NDT_Version_Name * ) ;
2005-02-24 00:31:06 +01:00
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_MANAGER_VERSION " ;
2000-07-28 16:13:54 +02:00
2005-06-27 01:40:14 +02:00
* Version_Name_Ptr = " $Revision: 2.4 $ $Name: $ $Date: 2005/06/26 23:40:14 $ $Author: agibert $ " ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
case NDD_CMD_INDEX_GET :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Reply_Index_Id_Ptr , * Args_Ptr , NDT_Index_Id * ) ;
ND_VA_ARG_GET ( Reply_Command_Ptr , * Args_Ptr , NDT_Command * ) ;
ND_VA_ARG_GET ( Cmd , * Args_Ptr , NDT_Command ) ;
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
2005-02-24 00:31:06 +01:00
*/
2000-07-28 16:13:54 +02:00
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Reply_Index_Id_Ptr , * Args_Ptr , NDT_Index_Id * ) ;
ND_VA_ARG_GET ( Reply_Command_Ptr , * Args_Ptr , NDT_Command * ) ;
ND_VA_ARG_GET ( Cmd , * Args_Ptr , NDT_Command ) ;
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_INDEX_GET " ;
switch ( Cmd )
{
/*
case NDT_CMD_SOME_USER_CMD :
{
* Reply_Index_Id_Ptr = 0 ;
* Reply_Command_Ptr = NDD_CMD_SOME_OTHER_CMD ;
break ;
}
. . .
*/
default :
{
* Reply_Index_Id_Ptr = Index_Id ;
* Reply_Command_Ptr = Cmd ;
break ;
}
}
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_ALLOC :
{
2024-04-14 20:00:25 +02:00
/*
ND_VA_ARG_GET ( Value_Ptr_Ptr , * Args_Ptr , void * * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
2005-02-24 00:31:06 +01:00
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
2005-02-24 00:31:06 +01:00
2024-04-14 20:00:25 +02:00
ND_VA_LIST_CLOSE ( user_args ) ;
*/
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_ALLOC " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_FREE :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Heap_Ptr , * Args_Ptr , SMT_Heap * ) ;
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_FREE " ;
free ( Heap_Ptr - > Name ) ;
free ( Heap_Ptr ) ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_COMP :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value1_Ptr , * Args_Ptr , void * ) ;
ND_VA_ARG_GET ( Value2_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Heap1_Ptr , * Args_Ptr , SMT_Heap * ) ;
ND_VA_ARG_GET ( Heap2_Ptr , * Args_Ptr , SMT_Heap * ) ;
2005-02-24 00:31:06 +01:00
long comp ;
Command_Name = " NDD_CMD_VALUE_COMP " ;
comp = strcmp ( Heap1_Ptr - > Name , Heap2_Ptr - > Name ) ;
if ( comp < 0 ) return ( NDS_LOWER ) ;
if ( comp > 0 ) return ( NDS_GREATER ) ;
return ( NDS_EQUAL ) ;
}
case NDD_CMD_VALUE_ADD :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
Command_Name = " NDD_CMD_VALUE_ADD " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_REMOVE :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
Command_Name = " NDD_CMD_VALUE_REMOVE " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_PRINT :
{
2024-04-14 20:00:25 +02:00
/*
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
ND_VA_LIST_OPEN ( user_args , lib_args ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
ND_VA_LIST_CLOSE ( lib_args ) ;
void * Value_Ptr = Node_Ptr - > Value ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
ND_VA_LIST_CLOSE ( lib_args ) ;
2005-02-24 00:31:06 +01:00
SMT_Heap * Heap_Ptr = ( SMT_Heap * ) ( Node_Ptr - > Value ) ;
Command_Name = " NDD_CMD_VALUE_PRINT " ;
2024-04-18 00:54:07 +02:00
/*
2005-02-24 00:31:06 +01:00
fprintf ( Out , " Heap_Name: [%s]/[%s] Heap_Addr: (%p) MHH_Ptr: (%p) Lock_Mode: (%d) Seg_Nb: (%d) \n " ,
SM_Context , Heap_Ptr - > Name , Heap_Ptr , Heap_Ptr - > MHH , Heap_Ptr - > Lock_Mode , Heap_Ptr - > Nb_Seg ) ;
2024-04-18 00:54:07 +02:00
*/
2005-02-24 00:31:06 +01:00
2024-04-18 00:54:07 +02:00
LG_LOG_INFO_6 ( " Heap_Name: [%s]/[%s] Heap_Addr: (%p) MHH_Ptr: (%p) Lock_Mode: (%d) Seg_Nb: (%d) " ,
SM_Context , Heap_Ptr - > Name , Heap_Ptr , Heap_Ptr - > MHH , Heap_Ptr - > Lock_Mode , Heap_Ptr - > Nb_Seg ) ;
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
case NDD_CMD_INFO_PRINT :
{
2024-04-14 20:00:25 +02:00
/*
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
ND_VA_LIST_OPEN ( user_args , lib_args ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
ND_VA_LIST_CLOSE ( lib_args ) ;
void * Value_Ptr = Node_Ptr - > Value ;
2005-02-24 00:31:06 +01:00
*/
Command_Name = " NDD_CMD_INFO_PRINT " ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
default :
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Manager called with an undefined command: (%d) " , Command ) ;
2005-02-24 00:31:06 +01:00
return ( NDS_ERRAPI ) ;
}
2000-07-28 16:13:54 +02:00
}
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Manager internal error in command: (%d) " , Command ) ;
return ( NDS_ERRAPI ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fonction manager du MHR (Memory Heap Root) */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-14 20:00:25 +02:00
NDT_Status MHR_Manager ( NDT_Root * Root_Ptr , NDT_Index_Id Index_Id , NDT_Node * Node_Ptr , NDT_Command Command , va_list * Args_Ptr )
2000-07-28 16:13:54 +02:00
{
2005-02-24 00:31:06 +01:00
NDT_Command_Name Command_Name ;
switch ( Command )
{
case NDD_CMD_MANAGER_VERSION :
{
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Version_Name_Ptr , * Args_Ptr , NDT_Version_Name * ) ;
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_MANAGER_VERSION " ;
2005-06-27 01:40:14 +02:00
* Version_Name_Ptr = " $Revision: 2.4 $ $Name: $ $Date: 2005/06/26 23:40:14 $ $Author: agibert $ " ;
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
case NDD_CMD_INDEX_GET :
2000-07-28 16:13:54 +02:00
{
2005-02-24 00:31:06 +01:00
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Reply_Index_Id_Ptr , * Args_Ptr , NDT_Index_Id * ) ;
ND_VA_ARG_GET ( Reply_Command_Ptr , * Args_Ptr , NDT_Command * ) ;
ND_VA_ARG_GET ( Cmd , * Args_Ptr , NDT_Command ) ;
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Reply_Index_Id_Ptr , * Args_Ptr , NDT_Index_Id * ) ;
ND_VA_ARG_GET ( Reply_Command_Ptr , * Args_Ptr , NDT_Command * ) ;
ND_VA_ARG_GET ( Cmd , * Args_Ptr , NDT_Command ) ;
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_INDEX_GET " ;
switch ( Cmd )
{
/*
case NDT_CMD_SOME_USER_CMD :
{
* Reply_Index_Id_Ptr = 0 ;
* Reply_Command_Ptr = NDD_CMD_SOME_OTHER_CMD ;
break ;
}
. . .
*/
default :
{
* Reply_Index_Id_Ptr = Index_Id ;
2024-04-14 20:00:25 +02:00
* Reply_Command_Ptr = Cmd ;
2005-02-24 00:31:06 +01:00
break ;
}
}
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
2000-07-28 16:13:54 +02:00
}
2005-02-24 00:31:06 +01:00
case NDD_CMD_VALUE_ALLOC :
2000-07-28 16:13:54 +02:00
{
2024-04-14 20:00:25 +02:00
/*
ND_VA_ARG_GET ( Value_Ptr_Ptr , * Args_Ptr , void * * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
*/
ND_VA_ARG_GET ( MHH_Ptr_Ptr , * Args_Ptr , SMT_MHH * * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Prefixed_Name , user_args , char * ) ;
ND_VA_ARG_GET ( Seg_Size , user_args , size_t ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-06-27 00:50:49 +02:00
union semun Sem_Ctl ;
int SemId ;
NDT_Status rc ;
NDT_Index_Type index_type = ( NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_FIFO ) ;
SMT_DSH * DSH_Ptr ;
Command_Name = " NDD_CMD_VALUE_ALLOC " ;
/* Cr<43> ation du s<> maphore pour g<> rer les verrous sur le nouveau MHH */
SemId = semget ( IPC_PRIVATE , 1 , 0777 | IPC_CREAT | IPC_EXCL ) ;
if ( SemId = = - 1 )
{
switch ( errno )
{
case ENOMEM :
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " The amount of memory is not sufficient to create a new semaphore " ) ;
2005-06-27 00:50:49 +02:00
break ;
}
case ENOSPC :
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " The number of semaphores exceeds the system-imposed limit " ) ;
2005-06-27 00:50:49 +02:00
break ;
}
2024-04-19 18:44:32 +02:00
default :
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unknown error: (%d) while creating a semaphore " , errno ) ;
2005-06-27 00:50:49 +02:00
break ;
}
}
2000-07-28 16:13:54 +02:00
2024-04-14 20:00:25 +02:00
return ( NDS_ERRMEM ) ;
2005-06-27 00:50:49 +02:00
}
2024-04-19 18:44:32 +02:00
2005-06-27 00:50:49 +02:00
/* Initialisation du s<> maphore <20> 1 (<28> quivaut <20> aucun verrou pos<6F> ) */
Sem_Ctl . val = 1 ;
if ( semctl ( SemId , 0 , SETVAL , Sem_Ctl ) )
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to initialize the value of the semaphore: (%d) " , SemId ) ;
2005-06-27 00:50:49 +02:00
rc = SMS_ERRSEM ;
goto Error3 ;
}
/* R<> servation du MHH (dans la base pour le heap syst<73> me, dans le heap syst<73> me pour les autres heaps) */
2024-05-03 00:28:06 +02:00
if ( ND_Allocator_Exec ( ( void * * ) ( MHH_Ptr_Ptr ) , SM_Base - > MHR , sizeof ( SMT_MHH ) , SM_Base - > MHR - > Allocator_Name , SM_Base - > MHR - > Allocator_Ptr , NULL ) ! = NDS_OK )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to allocate memory for the heap header " ) ;
2005-06-27 00:50:49 +02:00
rc = SMS_ERRSHM ;
goto Error3 ;
}
/* Initialisation de la structure du nouveau MHH */
2024-04-19 18:44:32 +02:00
strcpy ( ( * MHH_Ptr_Ptr ) - > Name , Prefixed_Name ) ;
( * MHH_Ptr_Ptr ) - > Writer = getpid ( ) ;
( * MHH_Ptr_Ptr ) - > SemId = SemId ;
( * MHH_Ptr_Ptr ) - > State = SMD_STATE_UNVALIDATED ;
( * MHH_Ptr_Ptr ) - > Segment_Size = ( ( Seg_Size > 0 ) ? Seg_Size : SEGMENT_DEFAULT_SIZE ) ;
( * MHH_Ptr_Ptr ) - > Limit_Size = SMD_UNLIMITED ;
( * MHH_Ptr_Ptr ) - > Auto_Compress = SMD_DEFAULT_COMPRESS ;
( * MHH_Ptr_Ptr ) - > Compress_Nb = 0L ;
2005-06-27 00:50:49 +02:00
/*
Cr <EFBFBD> ation de la structure DSR :
- dans la base pour le heap syst <EFBFBD> me
- dans le heap syst <EFBFBD> me pour les autres heaps
*/
2024-05-25 13:03:36 +02:00
// rc = ND_DataStruct_Open( &( ( *MHH_Ptr_Ptr)->DSR), 1, &index_type, "SM_DSR_Manager", NULL, SM_Base->MHR->Allocator_Name, NULL, SM_Base->MHR->Deallocator_Name, NULL, TRUE, NULL);
2024-05-27 23:12:23 +02:00
if ( ( rc = ND_DataStruct_Open ( & ( ( * MHH_Ptr_Ptr ) - > DSR ) , " SHM-DSR " , 1 , & index_type , " SM_DSR_Manager " , NULL , SMG_DataStruct_Handlers , TRUE , NULL ) ) ! = NDS_OK )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to create the DSR structure " ) ;
2005-06-27 00:50:49 +02:00
goto Error4 ;
}
2005-02-24 00:31:06 +01:00
2005-06-27 00:50:49 +02:00
/*
Cr <EFBFBD> ation de la structure ACR :
- dans la base pour le heap syst <EFBFBD> me
- dans le heap syst <EFBFBD> me pour les autres heaps
*/
2024-05-25 13:03:36 +02:00
// rc = ND_DataStruct_Open( &( ( *MHH_Ptr_Ptr)->ACR), 1, &index_type, "SM_ACR_Manager", NULL, SM_Base->MHR->Allocator_Name, NULL, SM_Base->MHR->Deallocator_Name, NULL, TRUE, NULL);
2024-05-27 23:12:23 +02:00
if ( ( rc = ND_DataStruct_Open ( & ( ( * MHH_Ptr_Ptr ) - > ACR ) , " SHM-ACR " , 1 , & index_type , " SM_ACR_Manager " , NULL , SMG_DataStruct_Handlers , TRUE , NULL ) ) ! = NDS_OK )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to create the ACR structure " ) ;
2005-06-27 00:50:49 +02:00
goto Error5 ;
}
/*
Cr <EFBFBD> ation de la structure FCR :
- dans la base pour le heap syst <EFBFBD> me
- dans le heap syst <EFBFBD> me pour les autres heaps
*/
2024-05-25 13:03:36 +02:00
// rc = ND_DataStruct_Open( &( ( *MHH_Ptr_Ptr)->FCR), 1, &index_type, "SM_FCR_Manager", NULL, SM_Base->MHR->Allocator_Name, NULL, SM_Base->MHR->Deallocator_Name, NULL, TRUE, NULL);
2024-05-27 23:12:23 +02:00
if ( ( rc = ND_DataStruct_Open ( & ( ( * MHH_Ptr_Ptr ) - > FCR ) , " SHM-FCR " , 1 , & index_type , " SM_FCR_Manager " , NULL , SMG_DataStruct_Handlers , TRUE , NULL ) ) ! = NDS_OK )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to create the FCR structure " ) ;
2005-06-27 00:50:49 +02:00
goto Error6 ;
}
/*alloction du premier segement de donnee pour le heap*/
2024-04-19 18:44:32 +02:00
rc = ND_Value_Alloc ( ( void * * ) & DSH_Ptr , ( * MHH_Ptr_Ptr ) - > DSR , * MHH_Ptr_Ptr , ( * MHH_Ptr_Ptr ) - > Segment_Size ) ;
2005-06-27 00:50:49 +02:00
if ( rc ! = NDS_OK )
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to create the DSH structure " ) ;
2005-06-27 00:50:49 +02:00
rc = SMS_ERRSHM ;
goto Error7 ;
}
2024-04-19 18:44:32 +02:00
rc = ND_DataStruct_Value_Add ( ( * MHH_Ptr_Ptr ) - > DSR , DSH_Ptr ) ;
2005-06-27 00:50:49 +02:00
if ( rc ! = NDS_OK )
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to add a data segment to the DSR structure " ) ;
2005-06-27 00:50:49 +02:00
goto Error8 ;
}
2024-04-19 18:44:32 +02:00
( * MHH_Ptr_Ptr ) - > State = SMD_STATE_VALID ;
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
2005-06-27 00:50:49 +02:00
/* Gestion d'erreur sur cr<63> ation */
Error9 :
2024-04-19 18:44:32 +02:00
ND_DataStruct_Value_Remove ( ( * MHH_Ptr_Ptr ) - > DSR , DSH_Ptr ) ;
2005-06-27 00:50:49 +02:00
Error8 :
2024-04-19 18:44:32 +02:00
ND_Value_Free ( ( * MHH_Ptr_Ptr ) - > DSR , DSH_Ptr ) ;
2005-06-27 00:50:49 +02:00
Error7 :
2024-05-03 00:28:06 +02:00
ND_Deallocator_Exec ( ( * MHH_Ptr_Ptr ) - > FCR , SM_Base - > MHR , SM_Base - > MHR - > Deallocator_Name , SM_Base - > MHR - > Deallocator_Ptr , NULL ) ;
2005-06-27 00:50:49 +02:00
Error6 :
2024-05-03 00:28:06 +02:00
ND_Deallocator_Exec ( ( * MHH_Ptr_Ptr ) - > ACR , SM_Base - > MHR , SM_Base - > MHR - > Deallocator_Name , SM_Base - > MHR - > Deallocator_Ptr , NULL ) ;
2005-06-27 00:50:49 +02:00
Error5 :
2024-05-03 00:28:06 +02:00
ND_Deallocator_Exec ( ( * MHH_Ptr_Ptr ) - > DSR , SM_Base - > MHR , SM_Base - > MHR - > Deallocator_Name , SM_Base - > MHR - > Deallocator_Ptr , NULL ) ;
2005-06-27 00:50:49 +02:00
Error4 :
2024-05-03 00:28:06 +02:00
ND_Deallocator_Exec ( * MHH_Ptr_Ptr , SM_Base - > MHR , SM_Base - > MHR - > Deallocator_Name , SM_Base - > MHR - > Deallocator_Ptr , NULL ) ;
2005-06-27 00:50:49 +02:00
Error3 :
semctl ( SemId , 0 , IPC_RMID , Sem_Ctl ) ;
return ( rc ) ;
2000-07-28 16:13:54 +02:00
}
2005-02-24 00:31:06 +01:00
case NDD_CMD_VALUE_FREE :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
2000-07-28 16:13:54 +02:00
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( MHH_Ptr , * Args_Ptr , SMT_MHH * ) ;
2005-06-27 00:50:49 +02:00
SMT_Status rc ;
SMT_Heap To_Find ;
union semun Sem_Ctl ;
SMT_Heap * Opened_Heap ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_FREE " ;
2000-07-28 16:13:54 +02:00
2005-06-27 00:50:49 +02:00
/* Destruction de la structure DSR (et de toutes ses valeurs) */
2024-04-17 18:49:56 +02:00
if ( ! strcmp ( MHH_Ptr - > Name , HEAP_SYSTEM ) )
2005-06-27 00:50:49 +02:00
{
NDT_Node * Node , * Previous_Node ;
SMT_DSH * DSH ;
/*
Pour le heap syst <EFBFBD> me , on doit proc <EFBFBD> der de mani <EFBFBD> re sp <EFBFBD> cifique
car le premier segment contient des r <EFBFBD> f <EFBFBD> rences sur les autres
segments . Il faut donc supprimer celui - ci en dernier .
Par ailleurs , ce premier segment a <EFBFBD> t <EFBFBD> allou <EFBFBD> dans la base .
Il faudra donc aussi red <EFBFBD> finir la fonction de d <EFBFBD> sallocation
du DSR pour celui - ci .
*/
ND_Index_Node_Last_Get ( & Node , MHH_Ptr - > DSR , NDD_INDEX_PRIMARY ) ;
2024-04-19 18:44:32 +02:00
while ( Node )
2005-06-27 00:50:49 +02:00
{
DSH = ( SMT_DSH * ) ( Node - > Value ) ;
ND_Index_Node_Previous_Get ( & Previous_Node , Node ) ;
/* S'agit-il du heap syst<73> me ? */
if ( ! Previous_Node )
{
2024-04-14 20:00:25 +02:00
strcpy ( MHH_Ptr - > DSR - > Deallocator_Name , " SM_Base_Free " ) ;
2005-06-27 00:50:49 +02:00
}
/* Retrait du segment du DSR */
rc = ND_DataStruct_Value_Remove ( MHH_Ptr - > DSR , DSH ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to remove the shared memory segment at address: (%p) from the DSR structure " , DSH - > Start ) ;
2005-06-27 00:50:49 +02:00
2024-04-15 16:54:18 +02:00
if ( SM_ERROR ( rc ) ) return rc ;
2005-06-27 00:50:49 +02:00
}
2000-07-28 16:13:54 +02:00
2005-06-27 00:50:49 +02:00
/* Destruction du segment */
rc = ND_Value_Free ( MHH_Ptr - > DSR , DSH ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to free the shared memory segment at address: (%p) " , DSH - > Start ) ;
2005-06-27 00:50:49 +02:00
2024-04-15 16:54:18 +02:00
if ( SM_ERROR ( rc ) ) return rc ;
2005-06-27 00:50:49 +02:00
}
Node = Previous_Node ;
}
}
else
{
2024-04-19 18:44:32 +02:00
rc = ND_DataStruct_Close ( MHH_Ptr - > DSR ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to destroy the DSR structure of heap: [%s] " , MHH_Ptr - > Name ) ;
2005-06-27 00:50:49 +02:00
}
}
/*
Destruction des structures ACR et FCR .
NB : puisque tous les chunks r <EFBFBD> f <EFBFBD> nrenc <EFBFBD> s par les ACR et FCR <EFBFBD> taient allou <EFBFBD> s
dans les segments qui viennent d ' <EFBFBD> tre supprim <EFBFBD> s , on se contente de d <EFBFBD> tuire
leur racine .
*/
2024-05-03 00:28:06 +02:00
rc = ND_Deallocator_Exec ( MHH_Ptr - > ACR , SM_Base - > MHR , SM_Base - > MHR - > Deallocator_Name , SM_Base - > MHR - > Deallocator_Ptr , NULL ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to free the ACR root of heap: [%s] " , MHH_Ptr - > Name ) ;
2005-06-27 00:50:49 +02:00
}
2024-05-03 00:28:06 +02:00
rc = ND_Deallocator_Exec ( MHH_Ptr - > FCR , SM_Base - > MHR , SM_Base - > MHR - > Deallocator_Name , SM_Base - > MHR - > Deallocator_Ptr , NULL ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to free the FCR root of heap: [%s] " , MHH_Ptr - > Name ) ;
2005-06-27 00:50:49 +02:00
}
/* Suppression du heap de la liste des heaps ouverts */
To_Find . Name = MHH_Ptr - > Name ;
rc = ND_DataStruct_Value_Find ( ( void * * ) & Opened_Heap , Opened_Heap_List , & To_Find ) ;
if ( ( rc = = NDS_OK ) & & ( Opened_Heap ! = NULL ) )
{
rc = ND_DataStruct_Value_Remove ( Opened_Heap_List , Opened_Heap ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2005-06-27 00:50:49 +02:00
{
return ( rc ) ;
}
else
{
rc = ND_Value_Free ( Opened_Heap_List , Opened_Heap ) ;
if ( rc ! = NDS_OK )
{
return ( rc ) ;
}
}
}
/* Destruction du s<> maphore attach<63> au heap */
2024-04-19 18:44:32 +02:00
semctl ( MHH_Ptr - > SemId , 0 , IPC_RMID , Sem_Ctl ) ;
2005-06-27 00:50:49 +02:00
/* D<> sallocation de la structure du MHH */
2024-05-03 00:28:06 +02:00
rc = ND_Deallocator_Exec ( MHH_Ptr , SM_Base - > MHR , SM_Base - > MHR - > Deallocator_Name , SM_Base - > MHR - > Deallocator_Ptr , NULL ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to free the header of heap: [%s] " , MHH_Ptr - > Name ) ;
2005-06-27 00:50:49 +02:00
}
2024-04-14 20:00:25 +02:00
return ( NDS_OK ) ;
2005-02-24 00:31:06 +01:00
}
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
case NDD_CMD_VALUE_COMP :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value1_Ptr , * Args_Ptr , void * ) ;
ND_VA_ARG_GET ( Value2_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
2000-07-28 16:13:54 +02:00
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( MHH1_Ptr , * Args_Ptr , SMT_MHH * ) ;
ND_VA_ARG_GET ( MHH2_Ptr , * Args_Ptr , SMT_MHH * ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
long comp ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_COMP " ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
comp = strcmp ( MHH1_Ptr - > Name , MHH2_Ptr - > Name ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
if ( comp < 0 ) return ( NDS_LOWER ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
if ( comp > 0 ) return ( NDS_GREATER ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
return ( NDS_EQUAL ) ;
}
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
case NDD_CMD_VALUE_ADD :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_ADD " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_REMOVE :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
Command_Name = " NDD_CMD_VALUE_REMOVE " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_PRINT :
{
2024-04-14 20:00:25 +02:00
/*
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
ND_VA_LIST_OPEN ( user_args , lib_args ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
ND_VA_LIST_CLOSE ( lib_args ) ;
void * Value_Ptr = Node_Ptr - > Value ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
ND_VA_LIST_CLOSE ( lib_args ) ;
2005-02-24 00:31:06 +01:00
SMT_MHH * MHH_Ptr = ( SMT_MHH * ) ( Node_Ptr - > Value ) ;
SMT_Status status ;
2005-06-27 00:50:49 +02:00
size_t segment_size = 0 , alloc_size = 0 , free_size = 0 ;
2005-02-24 00:31:06 +01:00
int segment_nb , alloc_chunk_nb , free_chunk_nb ;
SMT_Heap * heap_ptr ;
char * heap_name ;
int locked ;
Command_Name = " NDD_CMD_VALUE_PRINT " ;
/* On n'affiche le heap que s'il fait partie du contexte courant */
if ( ( heap_name = strstr ( MHH_Ptr - > Name , SM_Context ) ) ! = 0 )
{
heap_name + = strlen ( SM_Context ) + 1 ;
}
else
{
if ( strcmp ( HEAP_SYSTEM , MHH_Ptr - > Name ) = = 0 )
{
heap_name = MHH_Ptr - > Name ;
}
else
{
return ( NDS_OK ) ;
}
}
if ( MHH_Ptr - > State = = SMD_STATE_CORRUPTED )
{
2024-04-18 00:54:07 +02:00
/*
2005-02-24 00:31:06 +01:00
fprintf ( Out , " Heap_Name: [%s]/[%s] Heap_Addr: (%lx) *** CORRUPTED *** Checker_PId: (%ld) \n " ,
SM_Context , MHH_Ptr - > Name , MHH_Ptr , MHH_Ptr - > Writer ) ;
2024-04-18 00:54:07 +02:00
*/
LG_LOG_INFO_4 ( " Heap_Name: [%s]/[%s] Heap_Addr: (%lx) *** CORRUPTED *** Checker_PId: (%ld) " ,
SM_Context , MHH_Ptr - > Name , MHH_Ptr , MHH_Ptr - > Writer ) ;
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
if ( status = ( SM_Heap_Open_I ( heap_name , & heap_ptr , 0 , ( SMD_OPEN | SMD_READ ) , & locked ) ) ! = SMS_OK )
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to open Heap_Name: [%s] for reading " , MHH_Ptr - > Name ) ;
2005-02-24 00:31:06 +01:00
return ( status ) ;
}
2005-06-27 01:40:14 +02:00
/* TEST !!! */
if ( locked ! = TRUE )
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to lock Heap_Name: [%s] for reading " , MHH_Ptr - > Name ) ;
2005-06-27 01:40:14 +02:00
2024-04-17 18:49:56 +02:00
// return( SMS_KO);
2005-06-27 01:40:14 +02:00
}
2005-02-24 00:31:06 +01:00
segment_nb = MHH_Ptr - > DSR - > Index_Tab [ NDD_INDEX_PRIMARY ] . Node_Number ;
ND_DataStruct_Traverse ( MHH_Ptr - > DSR , NDD_CMD_VALUE_SUM , ( void * ) & segment_size ) ;
alloc_chunk_nb = MHH_Ptr - > ACR - > Index_Tab [ NDD_INDEX_PRIMARY ] . Node_Number ;
ND_DataStruct_Traverse ( MHH_Ptr - > ACR , NDD_CMD_VALUE_SUM , ( void * ) & alloc_size ) ;
free_chunk_nb = MHH_Ptr - > FCR - > Index_Tab [ NDD_INDEX_PRIMARY ] . Node_Number ;
ND_DataStruct_Traverse ( MHH_Ptr - > FCR , NDD_CMD_VALUE_SUM , ( void * ) & free_size ) ;
2024-04-18 00:54:07 +02:00
/*
2005-06-27 00:50:49 +02:00
fprintf ( Out , " Heap_Name: [%s]/[%s] Heap_Addr: (%p) Sem_Id: (%d) Lock_Status: [%s] \n Writer_PId: (%ld) Seg_Nb: (%d) Heap_Size: (%lu) Size_Limit: (%ld) Auto_Compress: (%d) Compress_Nb: (%ld) \n Alloc_Chunk_Nb: (%d) Alloc_Size: (%lu) Free_Chunk_Nb: (%d) Free_Size: (%lu) \n \n " ,
SM_Context , heap_name , MHH_Ptr , MHH_Ptr - > SemId , SM_Lock_Status_Get ( " heap " , MHH_Ptr ) ,
MHH_Ptr - > Writer , segment_nb , segment_size , MHH_Ptr - > Limit_Size , MHH_Ptr - > Auto_Compress , MHH_Ptr - > Compress_Nb ,
alloc_chunk_nb , alloc_size , free_chunk_nb , free_size ) ;
2024-04-18 00:54:07 +02:00
*/
LG_LOG_INFO_5 ( " Heap_Name: [%s]/[%s] Heap_Addr: (%p) Sem_Id: (%d) Lock_Status: [%s] " ,
SM_Context , heap_name , MHH_Ptr , MHH_Ptr - > SemId , SM_Lock_Status_Get ( " heap " , MHH_Ptr ) ) ;
LG_LOG_INFO_6 ( " Writer_PId: (%ld) Seg_Nb: (%d) Heap_Size: (%lu) Size_Limit: (%ld) Auto_Compress: (%d) Compress_Nb: (%ld) " ,
MHH_Ptr - > Writer , segment_nb , segment_size , MHH_Ptr - > Limit_Size , MHH_Ptr - > Auto_Compress , MHH_Ptr - > Compress_Nb ) ;
LG_LOG_INFO_4 ( " Alloc_Chunk_Nb: (%d) Alloc_Size: (%lu) Free_Chunk_Nb: (%d) Free_Size: (%lu) " ,
alloc_chunk_nb , alloc_size , free_chunk_nb , free_size ) ;
LG_LOG_INFO_0 ( " " ) ;
2005-02-24 00:31:06 +01:00
if ( locked = = TRUE )
{
SM_Heap_Unlock_I ( heap_ptr ) ;
}
return ( NDS_OK ) ;
}
case NDD_CMD_INFO_PRINT :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
ND_VA_LIST_OPEN ( user_args , lib_args ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
ND_VA_LIST_CLOSE ( lib_args ) ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
ND_VA_LIST_CLOSE ( lib_args ) ;
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_INFO_PRINT " ;
return ( NDS_OK ) ;
}
default :
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Manager called with an undefined command: (%d) " , Command ) ;
2005-02-24 00:31:06 +01:00
return ( NDS_ERRAPI ) ;
}
2000-07-28 16:13:54 +02:00
}
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Manager internal error in command: (%d) " , Command ) ;
return ( NDS_ERRAPI ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Destruction d'un MHH (Memory Heap Header) */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2005-02-24 00:31:06 +01:00
SMT_Status SM_MHH_End ( SMT_MHH * MHH )
2000-07-28 16:13:54 +02:00
{
SMT_Status rc ;
SMT_Heap To_Find ;
union semun Sem_Ctl ;
SMT_Heap * Opened_Heap ;
2005-02-24 00:31:06 +01:00
2000-07-28 16:13:54 +02:00
/* Destruction de la structure DSR (et de toutes ses valeurs) */
2024-04-17 18:49:56 +02:00
if ( ! strcmp ( MHH - > Name , HEAP_SYSTEM ) )
2000-07-28 16:13:54 +02:00
{
NDT_Node * Node , * Previous_Node ;
SMT_DSH * DSH ;
/*
2005-01-24 23:57:06 +01:00
Pour le heap syst <EFBFBD> me , on doit proc <EFBFBD> der de mani <EFBFBD> re sp <EFBFBD> cifique
car le premier segment contient des r <EFBFBD> f <EFBFBD> rences sur les autres
segments . Il faut donc supprimer celui - ci en dernier .
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
Par ailleurs , ce premier segment a <EFBFBD> t <EFBFBD> allou <EFBFBD> dans la base .
Il faudra donc aussi red <EFBFBD> finir la fonction de d <EFBFBD> sallocation
du DSR pour celui - ci .
2000-07-28 16:13:54 +02:00
*/
2005-01-25 00:10:09 +01:00
ND_Index_Node_Last_Get ( & Node , MHH - > DSR , NDD_INDEX_PRIMARY ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
while ( Node )
2000-07-28 16:13:54 +02:00
{
DSH = ( SMT_DSH * ) ( Node - > Value ) ;
2005-01-25 00:10:09 +01:00
ND_Index_Node_Previous_Get ( & Previous_Node , Node ) ;
2000-07-28 16:13:54 +02:00
/* S'agit-il du heap syst<73> me ? */
2005-01-24 23:57:06 +01:00
if ( ! Previous_Node )
{
2024-04-14 20:00:25 +02:00
strcpy ( MHH - > DSR - > Deallocator_Name , " SM_Base_Free " ) ;
2005-01-24 23:57:06 +01:00
}
2000-07-28 16:13:54 +02:00
/* Retrait du segment du DSR */
2005-01-25 00:10:09 +01:00
rc = ND_DataStruct_Value_Remove ( MHH - > DSR , DSH ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to remove the shared memory segment at address: (%p) from the DSR structure " , DSH - > Start ) ;
2000-07-28 16:13:54 +02:00
2024-04-15 16:54:18 +02:00
if ( SM_ERROR ( rc ) ) return rc ;
2000-07-28 16:13:54 +02:00
}
/* Destruction du segment */
2005-01-25 00:10:09 +01:00
rc = ND_Value_Free ( MHH - > DSR , DSH ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to free the shared memory segment at address: (%p) " , DSH - > Start ) ;
2000-07-28 16:13:54 +02:00
2024-04-15 16:54:18 +02:00
if ( SM_ERROR ( rc ) ) return rc ;
2000-07-28 16:13:54 +02:00
}
Node = Previous_Node ;
}
}
else
{
2024-04-19 18:44:32 +02:00
rc = ND_DataStruct_Close ( MHH - > DSR ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to destroy the DSR structure of heap: [%s] " , MHH - > Name ) ;
2000-07-28 16:13:54 +02:00
}
}
/*
2005-01-24 23:57:06 +01:00
Destruction des structures ACR et FCR .
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
NB : puisque tous les chunks r <EFBFBD> f <EFBFBD> nrenc <EFBFBD> s par les ACR et FCR <EFBFBD> taient allou <EFBFBD> s
dans les segments qui viennent d ' <EFBFBD> tre supprim <EFBFBD> s , on se contente de d <EFBFBD> tuire
leur racine .
2000-07-28 16:13:54 +02:00
*/
2024-05-03 00:28:06 +02:00
rc = ND_Deallocator_Exec ( MHH - > ACR , SM_Base - > MHR , SM_Base - > MHR - > Deallocator_Name , SM_Base - > MHR - > Deallocator_Ptr , NULL ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to free the ACR root of heap: [%s] " , MHH - > Name ) ;
2000-07-28 16:13:54 +02:00
}
2024-05-03 00:28:06 +02:00
rc = ND_Deallocator_Exec ( MHH - > FCR , SM_Base - > MHR , SM_Base - > MHR - > Deallocator_Name , SM_Base - > MHR - > Deallocator_Ptr , NULL ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to free the FCR root of heap: [%s] " , MHH - > Name ) ;
2000-07-28 16:13:54 +02:00
}
/* Suppression du heap de la liste des heaps ouverts */
To_Find . Name = MHH - > Name ;
2005-01-25 00:10:09 +01:00
rc = ND_DataStruct_Value_Find ( ( void * * ) & Opened_Heap , Opened_Heap_List , & To_Find ) ;
if ( ( rc = = NDS_OK ) & & ( Opened_Heap ! = NULL ) )
2000-07-28 16:13:54 +02:00
{
2005-01-25 00:10:09 +01:00
rc = ND_DataStruct_Value_Remove ( Opened_Heap_List , Opened_Heap ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2005-01-25 00:10:09 +01:00
{
return ( rc ) ;
}
else
{
rc = ND_Value_Free ( Opened_Heap_List , Opened_Heap ) ;
if ( rc ! = NDS_OK )
{
return ( rc ) ;
}
}
2000-07-28 16:13:54 +02:00
}
/* Destruction du s<> maphore attach<63> au heap */
2024-04-19 18:44:32 +02:00
semctl ( MHH - > SemId , 0 , IPC_RMID , Sem_Ctl ) ;
2000-07-28 16:13:54 +02:00
/* D<> sallocation de la structure du MHH */
2024-05-03 00:28:06 +02:00
rc = ND_Deallocator_Exec ( MHH , SM_Base - > MHR , SM_Base - > MHR - > Deallocator_Name , SM_Base - > MHR - > Deallocator_Ptr , NULL ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to free the header of heap: [%s] " , MHH - > Name ) ;
2000-07-28 16:13:54 +02:00
}
return rc ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* Gestion des segments de donn<6E> es */
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fonction manager pour un DSR (Data Segment Root) */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-14 20:00:25 +02:00
NDT_Status SM_DSR_Manager ( NDT_Root * Root_Ptr , NDT_Index_Id Index_Id , NDT_Node * Node_Ptr , NDT_Command Command , va_list * Args_Ptr )
2000-07-28 16:13:54 +02:00
{
2005-02-24 00:31:06 +01:00
NDT_Command_Name Command_Name ;
2005-06-27 00:50:49 +02:00
NDT_Node * Chunk_Node ;
SMT_Chunk * Chunk ;
2005-02-24 00:31:06 +01:00
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
switch ( Command )
2000-07-28 16:13:54 +02:00
{
2005-02-24 00:31:06 +01:00
case NDD_CMD_MANAGER_VERSION :
{
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Version_Name_Ptr , * Args_Ptr , NDT_Version_Name * ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_MANAGER_VERSION " ;
2000-07-28 16:13:54 +02:00
2005-06-27 01:40:14 +02:00
* Version_Name_Ptr = " $Revision: 2.4 $ $Name: $ $Date: 2005/06/26 23:40:14 $ $Author: agibert $ " ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
case NDD_CMD_INDEX_GET :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Reply_Index_Id_Ptr , * Args_Ptr , NDT_Index_Id * ) ;
ND_VA_ARG_GET ( Reply_Command_Ptr , * Args_Ptr , NDT_Command * ) ;
ND_VA_ARG_GET ( Cmd , * Args_Ptr , NDT_Command ) ;
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
2005-02-24 00:31:06 +01:00
*/
2000-07-28 16:13:54 +02:00
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Reply_Index_Id_Ptr , * Args_Ptr , NDT_Index_Id * ) ;
ND_VA_ARG_GET ( Reply_Command_Ptr , * Args_Ptr , NDT_Command * ) ;
ND_VA_ARG_GET ( Cmd , * Args_Ptr , NDT_Command ) ;
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_INDEX_GET " ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
switch ( Cmd )
{
/*
case NDT_CMD_SOME_USER_CMD :
{
* Reply_Index_Id_Ptr = 0 ;
* Reply_Command_Ptr = NDD_CMD_SOME_OTHER_CMD ;
break ;
}
. . .
*/
default :
{
* Reply_Index_Id_Ptr = Index_Id ;
* Reply_Command_Ptr = Cmd ;
break ;
}
}
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
case NDD_CMD_VALUE_ALLOC :
{
2024-04-14 20:00:25 +02:00
/*
ND_VA_ARG_GET ( Value_Ptr_Ptr , * Args_Ptr , void * * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
*/
ND_VA_ARG_GET ( DSH_Ptr_Ptr , * Args_Ptr , SMT_DSH * * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( MHH_Ptr , user_args , SMT_MHH * ) ;
ND_VA_ARG_GET ( Segment_Size , user_args , size_t ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_ALLOC " ;
2000-07-28 16:13:54 +02:00
2005-06-27 00:50:49 +02:00
/* On v<> rifie que le heap n'atteint pas sa limite */
2024-04-15 16:54:18 +02:00
if ( MHH_Ptr - > Limit_Size ! = SMD_UNLIMITED )
2005-06-27 00:50:49 +02:00
{
size_t Current_Size ;
2024-04-19 18:44:32 +02:00
ND_DataStruct_Traverse ( MHH_Ptr - > DSR , NDD_CMD_VALUE_SUM , ( void * ) & Current_Size ) ;
2005-06-27 00:50:49 +02:00
2024-04-15 16:54:18 +02:00
if ( Current_Size + Segment_Size > MHH_Ptr - > Limit_Size )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " The heap limit size would be exceeded " ) ;
2005-06-27 00:50:49 +02:00
2024-04-14 20:00:25 +02:00
* DSH_Ptr_Ptr = NULL ;
return ( NDS_KO ) ;
2005-06-27 00:50:49 +02:00
}
}
/* Cr<43> ation de l'ent<6E> te */
2024-05-03 00:28:06 +02:00
if ( ND_Allocator_Exec ( ( void * * ) DSH_Ptr_Ptr , MHH_Ptr - > DSR , sizeof ( SMT_DSH ) , MHH_Ptr - > DSR - > Allocator_Name , MHH_Ptr - > DSR - > Allocator_Ptr , NULL ) ! = NDS_OK )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " Unable to allocate memory for the new data segment header " ) ;
2024-04-14 20:00:25 +02:00
return ( NDS_KO ) ;
2005-06-27 00:50:49 +02:00
}
2024-04-19 18:44:32 +02:00
2005-06-27 00:50:49 +02:00
/* Cr<43> ation d'un segment de m<> moire partag<61> e */
2024-04-19 18:44:32 +02:00
if ( ( ( * DSH_Ptr_Ptr ) - > MemId = shmget ( IPC_PRIVATE , Segment_Size , 0777 | IPC_CREAT | IPC_EXCL ) ) = = - 1 )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
switch ( errno )
2005-06-27 00:50:49 +02:00
{
case EINVAL :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_1 ( " The size of the shared memory segment: (%d) is out of the system-imposed bounds " , Segment_Size ) ;
2005-06-27 00:50:49 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2005-06-27 00:50:49 +02:00
case ENOMEM :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_0 ( " The amount of memory is not sufficient to create the shared memory segment " ) ;
2005-06-27 00:50:49 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2005-06-27 00:50:49 +02:00
case ENOSPC :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_0 ( " The number of shared memory segments exceeds the system-imposed limit " ) ;
2005-06-27 00:50:49 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2005-06-27 00:50:49 +02:00
2024-04-19 18:44:32 +02:00
default :
{
LG_LOG_ERROR_1 ( " Unknown error: (%d) while creating a shared memory segment " , errno ) ;
2005-06-27 00:50:49 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2005-06-27 00:50:49 +02:00
}
2024-05-03 00:28:06 +02:00
ND_Deallocator_Exec ( ( * DSH_Ptr_Ptr ) , MHH_Ptr - > DSR , MHH_Ptr - > DSR - > Deallocator_Name , MHH_Ptr - > DSR - > Deallocator_Ptr , NULL ) ;
2024-04-19 18:44:32 +02:00
2024-04-14 20:00:25 +02:00
return ( NDS_KO ) ;
}
2005-06-27 00:50:49 +02:00
/* On attache le segment de m<> moire partag<61> e au processus courant */
errno = 0 ;
# ifndef __hpux
2024-04-19 18:44:32 +02:00
( * DSH_Ptr_Ptr ) - > Start = shmat ( ( * DSH_Ptr_Ptr ) - > MemId , ( void * ) ( ( size_t ) ( SM_Base - > Attach ) - Segment_Size ) , SHM_RND ) ;
2005-06-27 00:50:49 +02:00
# else
2024-04-19 18:44:32 +02:00
( * DSH_Ptr_Ptr ) - > Start = shmat ( ( * DSH_Ptr_Ptr ) - > MemId , 0 , 0 ) ;
2005-06-27 00:50:49 +02:00
# endif
2024-04-15 16:54:18 +02:00
if ( errno )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to attach the shared memory segment to the current process, error: (%d) " , errno ) ;
2005-06-27 00:50:49 +02:00
2024-04-19 18:44:32 +02:00
shmctl ( ( * DSH_Ptr_Ptr ) - > MemId , IPC_RMID , 0 ) ;
2005-06-27 00:50:49 +02:00
2024-05-03 00:28:06 +02:00
ND_Deallocator_Exec ( * DSH_Ptr_Ptr , MHH_Ptr - > DSR , MHH_Ptr - > DSR - > Deallocator_Name , MHH_Ptr - > DSR - > Deallocator_Ptr , NULL ) ;
2005-06-27 00:50:49 +02:00
2024-04-14 20:00:25 +02:00
return ( NDS_KO ) ;
2005-06-27 00:50:49 +02:00
}
2024-04-19 18:44:32 +02:00
SM_Base - > Attach = ( * DSH_Ptr_Ptr ) - > Start ;
2005-06-27 00:50:49 +02:00
/* Initialisation des informations de l'ent<6E> te */
2024-04-19 18:44:32 +02:00
( * DSH_Ptr_Ptr ) - > Size = Segment_Size ;
2005-06-27 00:50:49 +02:00
/* Cr<43> ation d'un chunk libre au d<> but du segment de donn<6E> es */
2024-04-19 18:44:32 +02:00
Chunk_Node = ( NDT_Node * ) ( * DSH_Ptr_Ptr ) - > Start ;
2005-06-27 00:50:49 +02:00
2024-04-19 18:44:32 +02:00
Chunk = ( SMT_Chunk * ) ( ( size_t ) Chunk_Node + sizeof ( NDT_Node ) ) ;
2005-06-27 00:50:49 +02:00
Chunk_Node - > Value = Chunk ;
2024-04-19 18:44:32 +02:00
Chunk - > Data = ( void * ) ( ( size_t ) Chunk + sizeof ( SMT_Chunk ) ) ;
2005-06-27 00:50:49 +02:00
2024-04-19 18:44:32 +02:00
Chunk - > Size = ( * DSH_Ptr_Ptr ) - > Size - sizeof ( NDT_Node ) - sizeof ( SMT_Chunk ) ;
2005-06-27 00:50:49 +02:00
/* Ajout du chunk libre <20> la liste des chunks libres du heap */
2024-04-15 16:54:18 +02:00
if ( ND_Index_Node_Add ( MHH_Ptr - > FCR , NDD_INDEX_PRIMARY , Chunk_Node ) ! = NDS_OK )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to add a first chunk to the FCR structure of heap: [%s] " , MHH_Ptr - > Name ) ;
2005-06-27 00:50:49 +02:00
2024-04-19 18:44:32 +02:00
shmctl ( ( * DSH_Ptr_Ptr ) - > MemId , IPC_RMID , 0 ) ;
2005-06-27 00:50:49 +02:00
2024-05-03 00:28:06 +02:00
ND_Deallocator_Exec ( ( * DSH_Ptr_Ptr ) , MHH_Ptr - > DSR , MHH_Ptr - > DSR - > Deallocator_Name , MHH_Ptr - > DSR - > Deallocator_Ptr , NULL ) ;
2005-06-27 00:50:49 +02:00
2024-04-14 20:00:25 +02:00
return ( NDS_KO ) ;
2005-06-27 00:50:49 +02:00
}
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
case NDD_CMD_VALUE_FREE :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
2000-07-28 16:13:54 +02:00
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( DSH_Ptr , * Args_Ptr , SMT_DSH * ) ;
2005-06-27 00:50:49 +02:00
SMT_Status rc ;
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_FREE " ;
2005-06-27 00:50:49 +02:00
/* Destruction du segment de m<> moire partag<61> e du segment de donn<6E> es */
2024-04-15 16:54:18 +02:00
if ( shmctl ( DSH_Ptr - > MemId , IPC_RMID , 0 ) = = - 1 )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
switch ( errno )
2005-06-27 00:50:49 +02:00
{
case EPERM :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_2 ( " Current process: (%d) is not allowed to destroy the shared memory segment: (%d) " , ( int ) getpid ( ) , DSH_Ptr - > MemId ) ;
2005-06-27 00:50:49 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2005-06-27 00:50:49 +02:00
case EINVAL :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_1 ( " No shared memory segment exists for identifier: (%d) " , DSH_Ptr - > MemId ) ;
2005-06-27 00:50:49 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2005-06-27 00:50:49 +02:00
2024-04-19 18:44:32 +02:00
default :
{
LG_LOG_ERROR_2 ( " Unknown error: (%d) while destroying the shared memory segment: (%d) " , errno , DSH_Ptr - > MemId ) ;
2005-06-27 00:50:49 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2005-06-27 00:50:49 +02:00
}
return SMS_ERRSHM ;
}
/* D<> sallocation de l'ent<6E> te */
2024-05-03 00:28:06 +02:00
rc = ND_Deallocator_Exec ( DSH_Ptr , Root_Ptr , Root_Ptr - > Deallocator_Name , Root_Ptr - > Deallocator_Ptr , NULL ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = NDS_OK )
2005-06-27 00:50:49 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_0 ( " The data segment header is nul " ) ;
2005-06-27 00:50:49 +02:00
return rc ;
}
2005-02-24 00:31:06 +01:00
2005-06-27 00:50:49 +02:00
return NDS_OK ;
2005-02-24 00:31:06 +01:00
}
case NDD_CMD_VALUE_COMP :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value1_Ptr , * Args_Ptr , void * ) ;
ND_VA_ARG_GET ( Value2_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
2005-02-24 00:31:06 +01:00
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
2005-02-24 00:31:06 +01:00
2024-04-14 20:00:25 +02:00
ND_VA_LIST_CLOSE ( user_args ) ;
*/
ND_VA_ARG_GET ( DSH1_Ptr , * Args_Ptr , SMT_DSH * ) ;
ND_VA_ARG_GET ( DSH2_Ptr , * Args_Ptr , SMT_DSH * ) ;
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_COMP " ;
if ( DSH1_Ptr - > MemId < DSH2_Ptr - > MemId ) return ( NDS_LOWER ) ;
if ( DSH1_Ptr - > MemId > DSH2_Ptr - > MemId ) return ( NDS_GREATER ) ;
return ( NDS_EQUAL ) ;
}
case NDD_CMD_VALUE_ADD :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
Command_Name = " NDD_CMD_VALUE_ADD " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_REMOVE :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
Command_Name = " NDD_CMD_VALUE_REMOVE " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_PRINT :
{
2024-04-14 20:00:25 +02:00
/*
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
ND_VA_LIST_OPEN ( user_args , lib_args ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
ND_VA_LIST_CLOSE ( lib_args ) ;
void * Value_Ptr = Node_Ptr - > Value ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
ND_VA_LIST_CLOSE ( lib_args ) ;
2005-02-24 00:31:06 +01:00
2024-04-14 20:00:25 +02:00
SMT_DSH * DSH_Ptr = ( SMT_DSH * ) ( Node_Ptr - > Value ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_PRINT " ;
2024-04-18 00:54:07 +02:00
/*
2005-02-24 00:31:06 +01:00
fprintf ( Out , " Data Segment Header: Mem_Id: (%d) Start: (%p) Size: (%ld) \n " ,
DSH_Ptr - > MemId , DSH_Ptr - > Start , DSH_Ptr - > Size ) ;
2024-04-18 00:54:07 +02:00
*/
2005-02-24 00:31:06 +01:00
2024-04-18 00:54:07 +02:00
LG_LOG_INFO_3 ( " Data Segment Header: Mem_Id: (%d) Start: (%p) Size: (%ld) " ,
DSH_Ptr - > MemId , DSH_Ptr - > Start , DSH_Ptr - > Size ) ;
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
case NDD_CMD_INFO_PRINT :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
ND_VA_LIST_OPEN ( user_args , lib_args ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
ND_VA_LIST_CLOSE ( lib_args ) ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
ND_VA_LIST_CLOSE ( lib_args ) ;
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_INFO_PRINT " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_SUM :
{
2024-04-14 20:00:25 +02:00
/*
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
void * Value_Ptr = Node_Ptr - > Value ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Total_Size , user_args , size_t * ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
2024-04-14 20:00:25 +02:00
SMT_DSH * DSH_Ptr = ( SMT_DSH * ) ( Node_Ptr - > Value ) ;
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_SUM " ;
* Total_Size + = DSH_Ptr - > Size ;
return ( NDS_OK ) ;
}
default :
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Manager called with an undefined command: (%d) " , Command ) ;
2005-02-24 00:31:06 +01:00
return ( NDS_ERRAPI ) ;
}
2000-07-28 16:13:54 +02:00
}
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Manager internal error in command: (%d) " , Command ) ;
return ( NDS_ERRAPI ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2024-04-14 20:00:25 +02:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Ouverture d'un segment de donn<6E> es */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
SMT_Status SM_DataSegment_Open ( SMT_DSH * DSH )
{
void * Ptr ;
/*
2005-01-24 23:57:06 +01:00
On attache le segment de m <EFBFBD> moire partag <EFBFBD> e au processus courant .
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
Attention : il faut que ce segment soit attach <EFBFBD> <EFBFBD> la m <EFBFBD> me adresse
que lorsqu ' il a <EFBFBD> t <EFBFBD> cr <EFBFBD> <EFBFBD> afin que les pointeurs qui pointent dans
ce segment soient valides .
2000-07-28 16:13:54 +02:00
*/
2024-04-19 18:44:32 +02:00
shmdt ( ( void * ) DSH - > Start ) ;
2000-07-28 16:13:54 +02:00
errno = 0 ;
2005-06-27 00:50:49 +02:00
Ptr = shmat ( DSH - > MemId , DSH - > Start , 0 ) ;
2024-04-15 16:54:18 +02:00
if ( errno )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_2 ( " Unable to attach the shared memory segment at the specified address: (%p) error: (%d) " , DSH - > Start , errno ) ;
2000-07-28 16:13:54 +02:00
return SMS_ERRSHM ;
}
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fermeture d'un segment de donn<6E> es */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_DataSegment_Close ( SMT_DSH * DSH )
2000-07-28 16:13:54 +02:00
{
/* On d<> tache le segment de m<> moire partag<61> e du processus courant */
2024-04-19 18:44:32 +02:00
shmdt ( ( void * ) DSH - > Start ) ;
2000-07-28 16:13:54 +02:00
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Compression d'un segment de donn<6E> es */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
size_t SM_DataSegment_Compress ( SMT_DSH * DSH , NDT_Root * FCR )
{
size_t Total_Compress = 0 ;
size_t Compress ;
SMT_Chunk * Chunk , * Next_Chunk ;
NDT_Node * Node , * Next_Node ;
void * DSH_End ;
int Found = FALSE ;
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
DSH_End = ( void * ) ( ( size_t ) ( DSH - > Start ) + DSH - > Size ) ;
2000-07-28 16:13:54 +02:00
/* Recherche du premier chunk libre contenu dans le segment courant */
2005-01-25 00:10:09 +01:00
ND_Index_Node_First_Get ( & Node , FCR , NDD_INDEX_PRIMARY ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
while ( Found = = FALSE & & Node )
2000-07-28 16:13:54 +02:00
{
2024-04-15 16:54:18 +02:00
if ( Node > ( NDT_Node * ) DSH_End ) Node = NULL ;
2000-07-28 16:13:54 +02:00
else
{
2024-04-15 16:54:18 +02:00
if ( Node > = ( NDT_Node * ) ( DSH - > Start ) ) Found = TRUE ;
2005-01-25 00:10:09 +01:00
else ND_Index_Node_Next_Get ( & Node , Node ) ;
2000-07-28 16:13:54 +02:00
}
}
2024-04-15 16:54:18 +02:00
if ( ! Node ) return 0 ;
2000-07-28 16:13:54 +02:00
/* Parcours de tous les chunks libres du segment courant */
2005-01-25 00:10:09 +01:00
ND_Index_Node_Next_Get ( & Next_Node , Node ) ;
2000-07-28 16:13:54 +02:00
2024-04-19 18:44:32 +02:00
while ( Next_Node & & ( void * ) Next_Node < DSH_End )
2000-07-28 16:13:54 +02:00
{
Chunk = ( SMT_Chunk * ) ( Node - > Value ) ;
Next_Chunk = ( SMT_Chunk * ) ( Next_Node - > Value ) ;
/* Si le chunk suivant est "coll<6C> " au chunk courant, alors on les fusionne */
2024-04-19 18:44:32 +02:00
if ( Next_Node = = ( NDT_Node * ) ( ( size_t ) ( Chunk - > Data ) + Chunk - > Size ) )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
ND_Index_Node_Remove ( Next_Node ) ;
2000-07-28 16:13:54 +02:00
Compress = sizeof ( SMT_Chunk ) + sizeof ( NDT_Node ) ;
Chunk - > Size + = Next_Chunk - > Size + Compress ;
Total_Compress + = Compress ;
2005-01-25 00:10:09 +01:00
ND_Index_Node_Next_Get ( & Next_Node , Node ) ;
2000-07-28 16:13:54 +02:00
}
else
{
Node = Next_Node ;
2005-01-25 00:10:09 +01:00
ND_Index_Node_Next_Get ( & Next_Node , Next_Node ) ;
2000-07-28 16:13:54 +02:00
}
}
return Total_Compress ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* Fonction de gestion de chunks */
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fonction manager pour un ACR (Allocated Chunk Root) */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-14 20:00:25 +02:00
NDT_Status SM_ACR_Manager ( NDT_Root * Root_Ptr , NDT_Index_Id Index_Id , NDT_Node * Node_Ptr , NDT_Command Command , va_list * Args_Ptr )
2000-07-28 16:13:54 +02:00
{
2005-02-24 00:31:06 +01:00
NDT_Command_Name Command_Name ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
switch ( Command )
2000-07-28 16:13:54 +02:00
{
2005-02-24 00:31:06 +01:00
case NDD_CMD_MANAGER_VERSION :
{
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Version_Name_Ptr , * Args_Ptr , NDT_Version_Name * ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_MANAGER_VERSION " ;
2000-07-28 16:13:54 +02:00
2005-06-27 01:40:14 +02:00
* Version_Name_Ptr = " $Revision: 2.4 $ $Name: $ $Date: 2005/06/26 23:40:14 $ $Author: agibert $ " ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
case NDD_CMD_INDEX_GET :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Reply_Index_Id_Ptr , * Args_Ptr , NDT_Index_Id * ) ;
ND_VA_ARG_GET ( Reply_Command_Ptr , * Args_Ptr , NDT_Command * ) ;
ND_VA_ARG_GET ( Cmd , * Args_Ptr , NDT_Command ) ;
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
2005-02-24 00:31:06 +01:00
*/
2000-07-28 16:13:54 +02:00
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Reply_Index_Id_Ptr , * Args_Ptr , NDT_Index_Id * ) ;
ND_VA_ARG_GET ( Reply_Command_Ptr , * Args_Ptr , NDT_Command * ) ;
ND_VA_ARG_GET ( Cmd , * Args_Ptr , NDT_Command ) ;
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_INDEX_GET " ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
switch ( Cmd )
{
/*
case NDT_CMD_SOME_USER_CMD :
{
* Reply_Index_Id_Ptr = 0 ;
* Reply_Command_Ptr = NDD_CMD_SOME_OTHER_CMD ;
break ;
}
. . .
*/
default :
{
* Reply_Index_Id_Ptr = Index_Id ;
* Reply_Command_Ptr = Cmd ;
break ;
}
}
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_ALLOC :
{
2024-04-14 20:00:25 +02:00
/*
ND_VA_ARG_GET ( Value_Ptr_Ptr , * Args_Ptr , void * * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
*/
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_ALLOC " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_FREE :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
Command_Name = " NDD_CMD_VALUE_FREE " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_COMP :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value1_Ptr , * Args_Ptr , void * ) ;
ND_VA_ARG_GET ( Value2_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Chunk1_Ptr , * Args_Ptr , SMT_Chunk * ) ;
ND_VA_ARG_GET ( Chunk2_Ptr , * Args_Ptr , SMT_Chunk * ) ;
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_COMP " ;
/* Les chunks allou<6F> s sont tri<72> s sur le champ <Data> (adresse d'allocation) */
if ( Chunk1_Ptr - > Data < Chunk1_Ptr - > Data ) return ( NDS_LOWER ) ;
if ( Chunk1_Ptr - > Data > Chunk2_Ptr - > Data ) return ( NDS_GREATER ) ;
return ( NDS_EQUAL ) ;
}
case NDD_CMD_VALUE_ADD :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
Command_Name = " NDD_CMD_VALUE_ADD " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_REMOVE :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
Command_Name = " NDD_CMD_VALUE_REMOVE " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_PRINT :
{
2024-04-14 20:00:25 +02:00
/*
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
ND_VA_LIST_OPEN ( user_args , lib_args ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
ND_VA_LIST_CLOSE ( lib_args ) ;
void * Value_Ptr = Node_Ptr - > Value ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
2000-07-28 16:13:54 +02:00
2024-04-14 20:00:25 +02:00
SMT_Chunk * Chunk_Ptr = ( SMT_Chunk * ) ( Node_Ptr - > Value ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_PRINT " ;
2024-04-18 00:54:07 +02:00
/*
2005-02-24 00:31:06 +01:00
fprintf ( Out , " Allocated Chunk: Chunk_Addr: (%p) Data_Addr: (%p) Data_Size: (%ld) \n " ,
Chunk_Ptr , Chunk_Ptr - > Data , Chunk_Ptr - > Size ) ;
2024-04-18 00:54:07 +02:00
*/
2005-02-24 00:31:06 +01:00
2024-04-18 00:54:07 +02:00
LG_LOG_INFO_3 ( " Allocated Chunk: Chunk_Addr: (%p) Data_Addr: (%p) Data_Size: (%ld) " ,
Chunk_Ptr , Chunk_Ptr - > Data , Chunk_Ptr - > Size ) ;
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
case NDD_CMD_INFO_PRINT :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
2005-02-24 00:31:06 +01:00
2024-04-14 20:00:25 +02:00
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
2005-02-24 00:31:06 +01:00
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
2005-02-24 00:31:06 +01:00
2024-04-14 20:00:25 +02:00
ND_VA_LIST_OPEN ( user_args , lib_args ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
ND_VA_LIST_CLOSE ( lib_args ) ;
*/
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_INFO_PRINT " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_SUM :
{
2024-04-14 20:00:25 +02:00
/*
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
void * Value_Ptr = Node_Ptr - > Value ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
2005-02-24 00:31:06 +01:00
2024-04-14 20:00:25 +02:00
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Total_Size_Ptr , user_args , size_t * ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
SMT_Chunk * Chunk_Ptr = ( SMT_Chunk * ) ( Node_Ptr - > Value ) ;
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_SUM " ;
2024-04-14 20:00:25 +02:00
* Total_Size_Ptr + = Chunk_Ptr - > Size ;
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
default :
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Manager called with an undefined command: (%d) " , Command ) ;
2005-02-24 00:31:06 +01:00
return ( NDS_ERRAPI ) ;
}
2000-07-28 16:13:54 +02:00
}
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Manager internal error in command: (%d) " , Command ) ;
return ( NDS_ERRAPI ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fonction manager pour un FCR (Free Chunk Root) */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-14 20:00:25 +02:00
NDT_Status SM_FCR_Manager ( NDT_Root * Root_Ptr , NDT_Index_Id Index_Id , NDT_Node * Node_Ptr , NDT_Command Command , va_list * Args_Ptr )
2000-07-28 16:13:54 +02:00
{
2005-02-24 00:31:06 +01:00
NDT_Command_Name Command_Name ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
switch ( Command )
2000-07-28 16:13:54 +02:00
{
2005-02-24 00:31:06 +01:00
case NDD_CMD_MANAGER_VERSION :
{
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Version_Name_Ptr , * Args_Ptr , NDT_Version_Name * ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_MANAGER_VERSION " ;
2000-07-28 16:13:54 +02:00
2005-06-27 01:40:14 +02:00
* Version_Name_Ptr = " $Revision: 2.4 $ $Name: $ $Date: 2005/06/26 23:40:14 $ $Author: agibert $ " ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
case NDD_CMD_INDEX_GET :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Reply_Index_Id_Ptr , * Args_Ptr , NDT_Index_Id * ) ;
ND_VA_ARG_GET ( Reply_Command_Ptr , * Args_Ptr , NDT_Command * ) ;
ND_VA_ARG_GET ( Cmd , * Args_Ptr , NDT_Command ) ;
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
2005-02-24 00:31:06 +01:00
*/
2000-07-28 16:13:54 +02:00
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Reply_Index_Id_Ptr , * Args_Ptr , NDT_Index_Id * ) ;
ND_VA_ARG_GET ( Reply_Command_Ptr , * Args_Ptr , NDT_Command * ) ;
ND_VA_ARG_GET ( Cmd , * Args_Ptr , NDT_Command ) ;
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_INDEX_GET " ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
switch ( Cmd )
{
/*
case NDT_CMD_SOME_USER_CMD :
{
* Reply_Index_Id_Ptr = 0 ;
* Reply_Command_Ptr = NDD_CMD_SOME_OTHER_CMD ;
break ;
}
. . .
*/
default :
{
* Reply_Index_Id_Ptr = Index_Id ;
* Reply_Command_Ptr = Cmd ;
break ;
}
}
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_ALLOC :
{
2024-04-14 20:00:25 +02:00
/*
ND_VA_ARG_GET ( Value_Ptr_Ptr , * Args_Ptr , void * * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
*/
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_ALLOC " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_FREE :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_FREE " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_COMP :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value1_Ptr , * Args_Ptr , void * ) ;
ND_VA_ARG_GET ( Value2_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Chunk1_Ptr , * Args_Ptr , SMT_Chunk * ) ;
ND_VA_ARG_GET ( Chunk2_Ptr , * Args_Ptr , SMT_Chunk * ) ;
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_COMP " ;
/*
La comparaison des chunks libres porte sur le champ < Data >
pour faciliter la compression des heaps .
*/
if ( Chunk1_Ptr - > Data < Chunk1_Ptr - > Data ) return ( NDS_LOWER ) ;
if ( Chunk1_Ptr - > Data > Chunk2_Ptr - > Data ) return ( NDS_GREATER ) ;
return ( NDS_EQUAL ) ;
}
case NDD_CMD_VALUE_ADD :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
Command_Name = " NDD_CMD_VALUE_ADD " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_REMOVE :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Value_Ptr , * Args_Ptr , void * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
*/
Command_Name = " NDD_CMD_VALUE_REMOVE " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_PRINT :
{
2024-04-14 20:00:25 +02:00
/*
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
ND_VA_LIST_OPEN ( user_args , lib_args ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
ND_VA_LIST_CLOSE ( lib_args ) ;
void * Value_Ptr = Node_Ptr - > Value ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
2005-02-24 00:31:06 +01:00
2024-04-14 20:00:25 +02:00
SMT_Chunk * Chunk_Ptr = ( SMT_Chunk * ) ( Node_Ptr - > Value ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_VALUE_PRINT " ;
2000-07-28 16:13:54 +02:00
2024-04-18 00:54:07 +02:00
// fprintf( Out, "Free Chunk: Chunk_Addr: (%p) Data_Ptr: (%p) Size: (%ld)\n", Chunk_Ptr, Chunk_Ptr->Data, Chunk_Ptr->Size);
2005-02-24 00:31:06 +01:00
2024-04-18 00:54:07 +02:00
LG_LOG_INFO_3 ( " Free Chunk: Chunk_Addr: (%p) Data_Ptr: (%p) Size: (%ld) " , Chunk_Ptr , Chunk_Ptr - > Data , Chunk_Ptr - > Size ) ;
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
case NDD_CMD_INFO_PRINT :
{
/*
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
ND_VA_LIST_OPEN ( user_args , lib_args ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
ND_VA_LIST_CLOSE ( lib_args ) ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
2005-02-24 00:31:06 +01:00
2024-04-14 20:00:25 +02:00
ND_VA_LIST_OPEN ( lib_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Out , lib_args , FILE * ) ;
ND_VA_ARG_GET ( Recursive_Mode , lib_args , NDT_Recursive_Mode ) ;
ND_VA_ARG_GET ( Recursive_Depth , lib_args , NDT_Recursive_Depth ) ;
ND_VA_ARG_GET ( Recursive_Offset , lib_args , NDT_Recursive_Offset ) ;
2005-02-24 00:31:06 +01:00
Command_Name = " NDD_CMD_INFO_PRINT " ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_SUM :
{
2024-04-14 20:00:25 +02:00
/*
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( user_data , user_args , user_type ) ;
ND_VA_ARG_GET ( . . . , user_args , . . . ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
void * Value_Ptr = Node_Ptr - > Value ;
2005-02-24 00:31:06 +01:00
*/
2024-04-14 20:00:25 +02:00
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Total_Size_Ptr , user_args , size_t * ) ;
2005-02-24 00:31:06 +01:00
2024-04-14 20:00:25 +02:00
ND_VA_LIST_CLOSE ( user_args ) ;
2005-02-24 00:31:06 +01:00
SMT_Chunk * Chunk_Ptr = ( SMT_Chunk * ) ( Node_Ptr - > Value ) ;
Command_Name = " NDD_CMD_VALUE_SUM " ;
2024-04-14 20:00:25 +02:00
* Total_Size_Ptr + = Chunk_Ptr - > Size ;
2005-02-24 00:31:06 +01:00
return ( NDS_OK ) ;
}
default :
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Manager called with an undefined command: (%d) " , Command ) ;
2005-02-24 00:31:06 +01:00
return ( NDS_ERRAPI ) ;
}
2000-07-28 16:13:54 +02:00
}
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Manager internal error in command: (%d) " , Command ) ;
return ( NDS_ERRAPI ) ;
2000-07-28 16:13:54 +02:00
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Pose d'un verrou sur un heap */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
SMT_Status SM_Heap_Lock_Set ( SMT_MHH * MHH , SMT_Flags Lock_Mode )
{
SMT_Status rc ;
2024-04-15 16:54:18 +02:00
if ( Lock_Mode & SMD_READ )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
rc = SM_Semaphore_Operate ( MHH - > SemId , SM_SemOp_SSL , 2 ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to lock the heap: [%s] for reading " , MHH - > Name ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
}
2024-04-15 16:54:18 +02:00
if ( Lock_Mode & SMD_WRITE )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
rc = SM_Semaphore_Operate ( MHH - > SemId , SM_SemOp_SEL , 2 ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to lock the heap: [%s] for writing " , MHH - > Name ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
}
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Changement d'un verrou sur un heap */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Lock_Change ( SMT_MHH * MHH , SMT_Flags Lock_Mode )
2000-07-28 16:13:54 +02:00
{
SMT_Status rc ;
2024-04-15 16:54:18 +02:00
if ( Lock_Mode & SMD_WRITE )
2000-07-28 16:13:54 +02:00
{
/*
2005-01-24 23:57:06 +01:00
Attention : il ne faut pas tenter de transformer directement un verrou en lecture en
un verrou en <EFBFBD> criture car cela pourrait aboutir <EFBFBD> un deadlock entre deux processus
qui voudraient r <EFBFBD> aliser cette op <EFBFBD> ration en m <EFBFBD> me temps .
2000-07-28 16:13:54 +02:00
2005-01-24 23:57:06 +01:00
= > On passe donc par un d <EFBFBD> verrouillage interm <EFBFBD> diaire .
2000-07-28 16:13:54 +02:00
*/
2024-04-19 18:44:32 +02:00
if ( ( rc = SM_Semaphore_Operate ( MHH - > SemId , SM_SemOp_RSL , 2 ) ) ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to transform the heap: [%s] lock for writing " , MHH - > Name ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
2024-04-19 18:44:32 +02:00
if ( ( rc = SM_Semaphore_Operate ( MHH - > SemId , SM_SemOp_SEL , 2 ) ) ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to transform the heap: [%s] lock for writing " , MHH - > Name ) ;
2000-07-28 16:13:54 +02:00
/* On tente de revenir <20> l'<27> tat de verrouillage pr<70> c<EFBFBD> dent */
2024-04-19 18:44:32 +02:00
SM_Semaphore_Operate ( MHH - > SemId , SM_SemOp_SSL , 2 ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
}
2024-04-15 16:54:18 +02:00
else if ( Lock_Mode & SMD_READ )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
rc = SM_Semaphore_Operate ( MHH - > SemId , SM_SemOp_TSL , 2 ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to transform the heap: [%s] lock for reading " , MHH - > Name ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
}
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Lib<69> ration d'un verrou sur un heap */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Heap_Lock_Release ( SMT_MHH * MHH , SMT_Flags Lock_Mode )
2000-07-28 16:13:54 +02:00
{
SMT_Status rc ;
2024-04-15 16:54:18 +02:00
if ( Lock_Mode & SMD_READ )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
rc = SM_Semaphore_Operate ( MHH - > SemId , SM_SemOp_RSL , 2 ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to unlock the heap: [%s] which had been locked for reading " , MHH - > Name ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
}
2024-04-15 16:54:18 +02:00
if ( Lock_Mode & SMD_WRITE )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
rc = SM_Semaphore_Operate ( MHH - > SemId , SM_SemOp_REL , 2 ) ;
2024-04-15 16:54:18 +02:00
if ( rc ! = SMS_OK )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
LG_LOG_ERROR_1 ( " Unable to unlock the heap: [%s] which had been locked for writing " , MHH - > Name ) ;
2000-07-28 16:13:54 +02:00
return rc ;
}
}
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Op<4F> ration sur un s<> maphore */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-19 18:44:32 +02:00
SMT_Status SM_Semaphore_Operate ( int SemId , struct sembuf * Operations , unsigned int Nb_Oper )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
if ( semop ( SemId , Operations , Nb_Oper ) = = - 1 )
2000-07-28 16:13:54 +02:00
{
2024-04-19 18:44:32 +02:00
switch ( errno )
2000-07-28 16:13:54 +02:00
{
case EAGAIN :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_0 ( " The operation would result in suspension of the calling process but the operations have been defined in no wait mode " ) ;
2000-07-28 16:13:54 +02:00
return SMS_NO_WAIT ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case EACCES :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_1 ( " Current process is not allowed to operate on semaphore: (%d) " , SemId ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case EIDRM :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_1 ( " Semaphore: (%d) does not exist " , SemId ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case EINTR :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_1 ( " A signal was received while operating on semaphore: (%d) " , SemId ) ;
2000-07-28 16:13:54 +02:00
return SMS_ERRSIG ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case EINVAL :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_1 ( " The semaphore identifier: (%d) is incorrect or the number of operations which can be done in UNDO mode exceeds the system-imposed limit " , SemId ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case ENOSPC :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_1 ( " The maximum number of process which can operate on semaphore: (%d) in UNDO mode has been reached " , SemId ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
case ERANGE :
2024-04-19 18:44:32 +02:00
{
LG_LOG_ERROR_1 ( " The value of semaphore: (%d) has reached the system-imposed limit " , SemId ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
default :
{
LG_LOG_ERROR_2 ( " Unknown error: (%d) while operating on semaphore: (%d) " , errno , SemId ) ;
2000-07-28 16:13:54 +02:00
break ;
2024-04-19 18:44:32 +02:00
}
2000-07-28 16:13:54 +02:00
}
return SMS_ERRSEM ;
}
return SMS_OK ;
}
2005-01-24 23:57:06 +01:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* R<> cup<75> re sous forme explicite l'<27> tat d'un verrou */
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2005-02-24 00:31:06 +01:00
char * SM_Lock_Status_Get ( const char * Type_Name , void * Struct_Ptr )
2000-07-28 16:13:54 +02:00
{
2005-02-24 00:31:06 +01:00
static char status [ 50 ] ;
int i , sem_id ;
pid_t writer ;
union semun sem_ctl ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
if ( ! strcmp ( Type_Name , " base " ) )
2000-07-28 16:13:54 +02:00
{
2005-02-24 00:31:06 +01:00
sem_id = SM_Base - > SemId ;
writer = SM_Base - > Writer ;
2000-07-28 16:13:54 +02:00
}
2005-02-24 00:31:06 +01:00
else
2000-07-28 16:13:54 +02:00
{
2005-02-24 00:31:06 +01:00
if ( ! strcmp ( Type_Name , " heap " ) )
{
SMT_MHH * MHH_Ptr = ( SMT_MHH * ) Struct_Ptr ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
sem_id = MHH_Ptr - > SemId ;
writer = MHH_Ptr - > Writer ;
}
else
{
strcpy ( status , " Unknown " ) ;
2024-04-19 18:44:32 +02:00
2005-02-24 00:31:06 +01:00
return ( status ) ;
}
2000-07-28 16:13:54 +02:00
}
2005-02-24 00:31:06 +01:00
i = semctl ( sem_id , 0 , GETVAL , sem_ctl ) ;
2000-07-28 16:13:54 +02:00
2005-02-24 00:31:06 +01:00
switch ( i )
2000-07-28 16:13:54 +02:00
{
case 0 :
2005-02-24 00:31:06 +01:00
{
sprintf ( status , " Exclusive Lock for PId: (%ld) " , writer ) ;
2024-04-19 18:44:32 +02:00
2000-07-28 16:13:54 +02:00
break ;
2005-02-24 00:31:06 +01:00
}
2000-07-28 16:13:54 +02:00
case 1 :
2005-02-24 00:31:06 +01:00
{
sprintf ( status , " Unlocked " ) ;
2024-04-19 18:44:32 +02:00
2000-07-28 16:13:54 +02:00
break ;
2005-02-24 00:31:06 +01:00
}
2000-07-28 16:13:54 +02:00
default :
2005-02-24 00:31:06 +01:00
{
if ( i < 0 )
{
sprintf ( status , " Abnormal Status: (%d) " , i ) ;
}
2000-07-28 16:13:54 +02:00
else
2005-02-24 00:31:06 +01:00
{
sprintf ( status , " Shared Lock Process_Nb: (%d) " , i - 1 ) ;
}
2024-04-19 18:44:32 +02:00
2000-07-28 16:13:54 +02:00
break ;
2005-02-24 00:31:06 +01:00
}
2000-07-28 16:13:54 +02:00
}
2005-02-24 00:31:06 +01:00
return ( status ) ;
2005-01-24 23:57:06 +01:00
}
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
2024-04-15 16:54:18 +02:00
/* Add context prefix to heap name */
/*------------------------------------------------------------------------------*/
/* (O) Prefixed: Prefixed heap name */
/* (I) Unprefixed: Unprefixed heap name */
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
2005-01-24 23:57:06 +01:00
2024-04-15 16:54:18 +02:00
SMT_Status SM_Name_Prefix ( char * Prefixed , const char * Unprefixed )
2000-07-28 16:13:54 +02:00
{
2024-04-15 16:54:18 +02:00
if ( ! SM_Context | | ! strlen ( SM_Context ) | | ! strcmp ( Unprefixed , HEAP_SYSTEM ) )
{
strcpy ( Prefixed , Unprefixed ) ;
}
2000-07-28 16:13:54 +02:00
else
2024-04-15 16:54:18 +02:00
{
2024-05-03 00:28:06 +02:00
snprintf ( Prefixed , SMD_NAME_SIZE , " %s/%s " , SM_Context , Unprefixed ) ;
2024-04-15 16:54:18 +02:00
}
2000-07-28 16:13:54 +02:00
2024-04-15 16:54:18 +02:00
return ( SMS_OK ) ;
2000-07-28 16:13:54 +02:00
}