[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / utils / hlos / knl / osal / Qnx / MemoryOS.c
diff --git a/qnx/src/ipc3x_dev/ti/syslink/utils/hlos/knl/osal/Qnx/MemoryOS.c b/qnx/src/ipc3x_dev/ti/syslink/utils/hlos/knl/osal/Qnx/MemoryOS.c
index 76041da3bc04383fb43e7b3e07c67ff7f73fcdc2..b7c08e2d448a220b9f94201b78b0901b7ae48d7b 100644 (file)
*
* ============================================================================
*
- * Copyright (c) 20010-2011, Texas Instruments Incorporated
+ * Copyright (c) 2010-2015, Texas Instruments Incorporated
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
/*!
* @brief Object containing state of the Memory OS module.
*/
-#if !defined(SYSLINK_BUILD_DEBUG)
+#if !defined(IPC_BUILD_DEBUG)
static
-#endif /* if !defined(SYSLINK_BUILD_DEBUG) */
+#endif /* if !defined(IPC_BUILD_DEBUG) */
MemoryOS_ModuleObject MemoryOS_state;
/* Create the Gate handle */
MemoryOS_state.gateHandle = (IGateProvider_Handle)
GateMutex_create ((GateMutex_Params *) NULL, &eb);
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
if (MemoryOS_state.gateHandle == NULL) {
Atomic_set (&MemoryOS_state.refCount, MEMORYOS_MAKE_MAGICSTAMP(0));
/*! @retval MEMORYOS_E_FAIL Failed to create the local gate */
"Failed to create the local gate");
}
else {
-#endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* if !defined(IPC_BUILD_OPTIMIZE) */
List_Params_init (&listparams);
/* Construct the map table.Not passing gate as MemoryOs module
* takes care of protection over list operations
*/
List_construct (&MemoryOS_state.mapTable, &listparams);
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
}
#endif
GT_0trace (curTrace, GT_ENTER, "MemoryOS_destroy");
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
if ( Atomic_cmpmask_and_lt (&(MemoryOS_state.refCount),
MEMORYOS_MAKE_MAGICSTAMP(0),
MEMORYOS_MAKE_MAGICSTAMP(1))
"Module was not initialized!");
}
else {
-#endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* if !defined(IPC_BUILD_OPTIMIZE) */
if ( Atomic_dec_return (&MemoryOS_state.refCount)
== MEMORYOS_MAKE_MAGICSTAMP(0)) {
/* Free any remaining regions */
&MemoryOS_state.gateHandle);
if ((status >= 0) && (tmpStatus < 0)) {
status = tmpStatus;
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
GT_setFailureReason (curTrace,
GT_4CLASS,
"MemoryOS_destroy",
status,
"GateMutex_delete failed!");
-#endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* if !defined(IPC_BUILD_OPTIMIZE) */
}
}
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
}
-#endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* if !defined(IPC_BUILD_OPTIMIZE) */
GT_1trace (curTrace, GT_LEAVE, "MemoryOS_destroy", status);
/* check whether the right paramaters are passed or not.*/
GT_assert (curTrace, (size > 0));
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
if ( Atomic_cmpmask_and_lt (&(MemoryOS_state.refCount),
MEMORYOS_MAKE_MAGICSTAMP(0),
MEMORYOS_MAKE_MAGICSTAMP(1))
"Module was not initialized!");
}
else {
-#endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* if !defined(IPC_BUILD_OPTIMIZE) */
if (flags == MemoryOS_MemTypeFlags_Default) {
/* Call the kernel API for memory allocation */
MEMORYOS_E_MEMORY,
"Memory allocation type is invalid");
}
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
if (NULL == ptr) {
/*! @retval NULL Memory allocation failed */
GT_setFailureReason (curTrace,
"Could not allocate memory");
}
}
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
GT_1trace (curTrace, GT_LEAVE, "MemoryOS_alloc", ptr);
GT_3trace (curTrace, GT_ENTER, "MemoryOS_calloc", size, align, flags);
ptr = MemoryOS_alloc (size, align, flags);
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
if (NULL == ptr) {
/*! @retval NULL Memory allocation failed */
GT_setFailureReason (curTrace,
"Could not allocate memory");
}
else {
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
memset (ptr, 0, size);
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
}
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
GT_1trace (curTrace, GT_LEAVE, "MemoryOS_calloc", ptr);
GT_assert (GT_1CLASS, (ptr != NULL));
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
if (NULL == ptr) {
GT_setFailureReason (curTrace,
GT_4CLASS,
"Pointer NULL for free");
}
else {
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
if (flags == MemoryOS_MemTypeFlags_Default) {
/*! free the memory pointed by ptr */
free (ptr);
MEMORYOS_E_MEMORY,
"Memory free type is invalid");
}
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
}
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
GT_0trace (curTrace, GT_LEAVE, "MemoryOS_free");
}
GT_assert (curTrace, (NULL != mapInfo));
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
if ( Atomic_cmpmask_and_lt (&(MemoryOS_state.refCount),
MEMORYOS_MAKE_MAGICSTAMP(0),
MEMORYOS_MAKE_MAGICSTAMP(1))
"NULL provided for argument mapInfo->src");
}
else {
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
/* Enter the critical section */
key = IGateProvider_enter (MemoryOS_state.gateHandle);
mapInfo->size);
}
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
if (mapInfo->dst == (UInt32)MAP_FAILED) {
/*! @retval MEMORYOS_E_MAP Failed to map to host address space. */
status = MEMORYOS_E_MAP;
"Failed to map to host address space!");
}
else {
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
info = MemoryOS_alloc (sizeof (MemoryOS_MapTableInfo), 0, 0);
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
if (info == NULL) {
/*! @retval MEMORYOS_E_MEMORY Failed to allocate memory. */
status = MEMORYOS_E_MEMORY;
"Failed to allocate memory!");
}
else {
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
/* Initialize the list element */
List_elemClear ((List_Elem *) info);
/* Populate the info */
/* Put the info into the list */
List_putHead ((List_Handle) &MemoryOS_state.mapTable,
(List_Elem *) info);
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
}
}
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
}
/* Leave the crtical section */
IGateProvider_leave (MemoryOS_state.gateHandle, key);
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
}
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
GT_1trace (curTrace, GT_LEAVE, "MemoryOS_map", status);
GT_assert (curTrace, (NULL != unmapInfo));
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
if ( Atomic_cmpmask_and_lt (&(MemoryOS_state.refCount),
MEMORYOS_MAKE_MAGICSTAMP(0),
MEMORYOS_MAKE_MAGICSTAMP(1))
"NULL provided for argument unmapInfo->addr");
}
else {
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
key = IGateProvider_enter (MemoryOS_state.gateHandle);
/* Find the node in the map table */
}
}
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
if (!found) {
status = MEMORYOS_E_UNMAP;
GT_setFailureReason (curTrace,
"Could not find specified entry to unmap!");
}
else {
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
/* Unmap if refCount is 0. */
if (((MemoryOS_MapTableInfo *) info)->refCount == 0) {
List_remove ((List_Handle) &MemoryOS_state.mapTable,
MemoryOS_free (info, sizeof (MemoryOS_MapTableInfo), 0);
munmap ((unsigned int *) unmapInfo->addr, unmapInfo->size);
}
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
}
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
IGateProvider_leave (MemoryOS_state.gateHandle, key);
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
}
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
GT_1trace (curTrace, GT_LEAVE, "MemoryOS_unmap", status);
GT_assert (curTrace, ((NULL != dst) && (NULL != src)));
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
if ( Atomic_cmpmask_and_lt (&(MemoryOS_state.refCount),
MEMORYOS_MAKE_MAGICSTAMP(0),
MEMORYOS_MAKE_MAGICSTAMP(1))
"Invalid argument");
}
else {
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
dst = memcpy (dst, src, len);
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
}
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
GT_1trace (curTrace, GT_LEAVE, "MemoryOS_copy", dst);
GT_assert (curTrace, (NULL != buf) && (len > 0));
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
if ( Atomic_cmpmask_and_lt (&(MemoryOS_state.refCount),
MEMORYOS_MAKE_MAGICSTAMP(0),
MEMORYOS_MAKE_MAGICSTAMP(1))
"Invalid argument");
}
else {
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
buf = memset (buf, value, len);
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
}
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
GT_1trace (curTrace, GT_LEAVE, "MemoryOS_set", buf);
GT_2trace (curTrace, GT_ENTER, "MemoryOS_translate", srcAddr, flags);
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
if ( Atomic_cmpmask_and_lt (&(MemoryOS_state.refCount),
MEMORYOS_MAKE_MAGICSTAMP(0),
MEMORYOS_MAKE_MAGICSTAMP(1))
"Module was not initialized!");
}
else {
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
key = IGateProvider_enter (MemoryOS_state.gateHandle);
/* Traverse to the node in the map table */
IGateProvider_leave (MemoryOS_state.gateHandle, key);
-#if !defined(SYSLINK_BUILD_OPTIMIZE)
+#if !defined(IPC_BUILD_OPTIMIZE)
}
-#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
+#endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
GT_1trace (curTrace, GT_LEAVE, "MemoryOS_translate", buf);