diff options
author | Klaus Schmidinger <kls (at) cadsoft (dot) de> | 2004-01-04 18:00:00 +0100 |
---|---|---|
committer | Klaus Schmidinger <kls (at) cadsoft (dot) de> | 2004-01-04 18:00:00 +0100 |
commit | 93a94b18b540fbcb9bcdaaea9abd26cdf23d6ee6 (patch) | |
tree | bede17e6cd329d36ec02bc53dfe567b95ec835a5 /libdtv/liblx/xMemMgt.c | |
parent | c432905dd60630f906ac89f58592ad835a9063ef (diff) | |
download | vdr-patch-lnbsharing-93a94b18b540fbcb9bcdaaea9abd26cdf23d6ee6.tar.gz vdr-patch-lnbsharing-93a94b18b540fbcb9bcdaaea9abd26cdf23d6ee6.tar.bz2 |
Version 1.3.0vdr-1.3.0
- Changed thread handling to make it work with NPTL ("Native Posix Thread Library").
Thanks to Jon Burgess, Andreas Schultz, Werner Fink and Stefan Huelswitt.
- The cThread class now accepts a 'Description' parameter, which is used to log
the beginning and end of the thread, together with its process and thread id.
For descriptions that need additional parameters you can use the function
cThread::SetDescription(), which accepts 'printf()' like arguments.
Existing plugins that use threads should be changed to use this functionality
instead of explicit 'dsyslog()' calls inside their Action() function in order
to support logging the thread ids.
- Added "Slovak Link" and "Czech Link" to 'ca.conf' (thanks to Emil Petersky).
However, 'ca.conf' is now pretty much obsolete due to the automatic CA handling.
- Mutexes are now created with PTHREAD_MUTEX_ERRORCHECK_NP, which makes the
'lockingTid' stuff obsolete (thanks to Stefan Huelswitt).
- Changed font handling to allow language specific character sets.
- Adopted the small font character set from the "Elchi" patch (originally
provided by Alessio Sangalli).
- Greek language texts now use iso8859-7 character set (thanks to Dimitrios
Dimitrakos).
- Rearranged section data handling, so that the actual data handling can be done
separately, even from within plugins.
- The EPG data structures have been moved from eit.[hc] to epg.[hc] and have been
adapted to the general VDR coding style. Plugins that use these data structures
may need to change some function names (which should be obvious).
The name 'subtitle' has been changed to 'shortText' to avoid clashes with actual
subtitles that are part of a movie. The name 'extendedDescription' has been
shortened to 'description'.
- Replaced 'libdtv' with 'libsi' (thanks to Marcel Wiesweg), which is thread
safe and can be used by multiple section filters simultaneously.
- Added 'cRwLock' to 'thread.[hc]'. Note that all plugin Makefiles need to
define _GNU_SOURCE for this to work (see the example plugin Makefiles and
'newplugin').
- Fixed a problem with crc32 in SI handling on 64bit systems (thanks to Pedro
Miguel Sequeira de Justo Teixeira for reporting this one).
- Fixed an alignment problem in CAM access on 64bit systems (thanks to Pedro
Miguel Sequeira de Justo Teixeira for reporting this one).
- Added 'StreamType' setting to CAM communication, which is important for
Aston/SECA CAMs (thanks to Antonino Sergi).
- Now the CA descriptors are sent to the CAM in the 'program' or 'ES level'
sections, depending on where they are found in the PMT (thanks to Hans-Peter
Raschke for reporting this one). This should make SkyCrypt CAMs work.
- Now using the 'version number' of EPG events to avoid unnecessary work.
- Channel data is now automatically derived from the DVB data stream (inspired
by the 'autopid' patch from Andreas Schultz).
- The current channel is now automatically re-tuned if the PIDs or other settings
change. If a recording is going on on a channel that has a change in its
settings, the recording will be stopped and immediately restarted to use the
new channel settings.
- EPG events now use the complete channel ID with NID, TID and SID.
- Channel names in 'channels.conf' can now have a short form, as provided
by some tv stations (see man vdr(5)). Currently channels that provide short
names in addition to long ones are listed in the OSD as "short,long name",
as in "RTL,RTL Television". The short names will be used explicitly later.
- The Ca parameter in 'channels.conf' has been extended and now contains all the
CA system ids for the given channel. When switching to a channel VDR now tests
for a device that provides one of these CA system ids. The devices automatically
get their supported ids from the CI handler.
- The values in 'ca.conf' are currently without any real meaning. Whether or not
a channel with conditional access can be received is now determined automatically
by evaluating its CA descriptors and comparing them to the CA system ids
provided by the installed CAM. Only the special values 1-16 are used to assign
a channel to a particular device.
- Increased the maximum number of possible OSD colors to 256.
- Limited the line length in the EPG bugfix report, which appears to fix a buffer
overflow that caused a crash when cleaning up the EPG data (at 05:00 in the
morning).
Diffstat (limited to 'libdtv/liblx/xMemMgt.c')
-rw-r--r-- | libdtv/liblx/xMemMgt.c | 624 |
1 files changed, 0 insertions, 624 deletions
diff --git a/libdtv/liblx/xMemMgt.c b/libdtv/liblx/xMemMgt.c deleted file mode 100644 index b1b07de..0000000 --- a/libdtv/liblx/xMemMgt.c +++ /dev/null @@ -1,624 +0,0 @@ -/* - * - * xMemMgt.c: memory management functions of liblx - * - * - * $Revision: 1.1 $ - * $Date: 2001/06/25 12:29:47 $ - * $Author: hakenes $ - * - * (C) 1992-2001 Rolf Hakenes <hakenes@hippomi.de>, under the GNU GPL. - * - * liblx is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * liblx 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 General Public License for more details. - * - * You may have received a copy of the GNU General Public License - * along with liblx; see the file COPYING. If not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <malloc.h> - -#include "liblx.h" - -#ifdef DEBUG -void logPrintf(int, char *, ...); -#endif - -static struct MEM_CHUNK *xRememberKey = NULL; - -static struct MEM_CHUNK **xRememberPtr = &xRememberKey; - -unsigned long xAllocatedMemory = 0; - -/************************************************************************* - * * - * function : xMemAlloc * - * * - * parameter : Size - size of the requested memory area * - * * - * DataPointer - pointer to data pointer * - * * - * return : none * - * * - *-----------------------------------------------------------------------* - * * - * xMemAlloc() is a clustered, remembering memory management routine. * - * It uses its own tables for free and used memory blocks on private * - * memory area. With xMemFree(), you can free this memory likewise * - * the C free() routine, with xMemFreeAll() all memory at once. * - * By changing the current remember key with xSetRemember() you can * - * define a local memory area, which can be freed by only one call of * - * xMemFreeAll() (see xSetRemember() / xGetRemember()). * - * * - *************************************************************************/ - -void xMemAllo (Size, DataPointer) - -unsigned long Size; -unsigned char **DataPointer; -{ - struct MEM_CHUNK *MemChunk, *MemChunkPred; - struct MEM_ENTRY *MemEntry, *MemEntryPred; - long int NewSize; - unsigned short FoundFlag; -#ifdef DEBUG - unsigned char *ptr; -#endif - - while (Size % 4) Size++; - - if (Size > (MEM_CHUNK_SIZE - sizeof(struct MEM_CHUNK) - - sizeof(struct MEM_ENTRY))) - { - NewSize = Size + sizeof(struct MEM_CHUNK) + sizeof(struct MEM_ENTRY); - - if (MemChunk = (*xRememberPtr)) - { - do - { - MemChunkPred = MemChunk; - } while (MemChunk = MemChunk->Succ); - } - else MemChunkPred = (struct MEM_CHUNK *) &(*xRememberPtr); - - MemChunk = MemChunkPred->Succ = (struct MEM_CHUNK *) malloc (NewSize); - xAllocatedMemory += NewSize; - -#ifdef DEBUG - for (ptr = (unsigned char *) MemChunk; ptr < (unsigned char *) - (MemChunk) + NewSize; ptr++) - *ptr = (((unsigned long)ptr)&1) ? 0x55 : 0xAA; -#endif - - if (!MemChunk) - { -#ifdef DEBUG - logPrintf (0, "Not enough memory...\r\n"); -#endif - exit (1); - } - - MemChunk->Size = NewSize; - MemChunk->Pred = MemChunkPred; - MemChunk->Succ = NULL; - MemChunk->FirstFreeMemEntry = NULL; - MemChunk->FirstUsedMemEntry = - MemEntry = (struct MEM_ENTRY *) ((unsigned char *)MemChunk + - sizeof(struct MEM_CHUNK)); - - MemEntry->Size = Size; - MemEntry->Pred = (struct MEM_ENTRY *) &MemChunk->FirstUsedMemEntry; - MemEntry->Succ = NULL; - - *DataPointer = (unsigned char *) ((unsigned char *)MemEntry + - sizeof(struct MEM_ENTRY)); -#ifdef DEBUG_CALLS - logPrintf (0, "xMemAlloc: %x, %d bytes\r\n", *DataPointer, Size); -#endif - return; - } - - MemEntry = NULL; - FoundFlag = 0; - - if (MemChunk = (*xRememberPtr)) - { - do - { - if (MemEntry = MemChunk->FirstFreeMemEntry) - do - { - if (Size <= MemEntry->Size) FoundFlag = 1; - } while ((FoundFlag == 0) && (MemEntry = MemEntry->Succ)); - MemChunkPred = MemChunk; - } while ((FoundFlag == 0) && (MemChunk = MemChunk->Succ)); - } - else MemChunkPred = (struct MEM_CHUNK *) &(*xRememberPtr); - - if (!MemEntry) - { - MemChunk = MemChunkPred->Succ = - (struct MEM_CHUNK *) malloc (MEM_CHUNK_SIZE); - xAllocatedMemory += MEM_CHUNK_SIZE; - -#ifdef DEBUG - for (ptr = (unsigned char *) MemChunk; ptr < (unsigned char *) - (MemChunk) + MEM_CHUNK_SIZE; ptr++) - *ptr = (((unsigned long)ptr)&1) ? 0x55 : 0xAA; -#endif - - if (!MemChunk) - { -#ifdef DEBUG - logPrintf (0, "Not enough memory...\r\n"); -#endif - exit (1); - } - - MemChunk->Size = MEM_CHUNK_SIZE; - MemChunk->Pred = MemChunkPred; - MemChunk->Succ = NULL; - MemChunk->FirstUsedMemEntry = NULL; - MemChunk->FirstFreeMemEntry = - MemEntry = (struct MEM_ENTRY *) - ((unsigned char *)MemChunk + sizeof(struct MEM_CHUNK)); - - MemEntry->Size = MEM_CHUNK_SIZE - sizeof(struct MEM_CHUNK) - - sizeof(struct MEM_ENTRY); - MemEntry->Pred = (struct MEM_ENTRY *) &MemChunk->FirstFreeMemEntry; - MemEntry->Succ = NULL; - } - - NewSize = MemEntry->Size - sizeof(struct MEM_ENTRY) - Size; - - MemEntry->Size = Size; - *DataPointer = (unsigned char *) - ((unsigned char *)MemEntry + sizeof(struct MEM_ENTRY)); - -#ifdef DEBUG - for (ptr = *DataPointer; ptr < (unsigned char *) - (*DataPointer) + Size; ptr++) - { - if (((unsigned long )ptr)&1) - { if (*ptr != 0x55) - logPrintf (0, "freed memory was used\r\n"); } - else { if (*ptr != 0xAA) - logPrintf (0, "freed memory was used\r\n"); } - } -#endif - - if (MemEntry->Succ) - ((struct MEM_ENTRY *)MemEntry->Succ)->Pred = MemEntry->Pred; - ((struct MEM_ENTRY *)MemEntry->Pred)->Succ = MemEntry->Succ; - - if (MemChunk->FirstUsedMemEntry) - MemChunk->FirstUsedMemEntry->Pred = MemEntry; - MemEntry->Succ = MemChunk->FirstUsedMemEntry; - MemChunk->FirstUsedMemEntry = MemEntry; - MemEntry->Pred = (struct MEM_ENTRY *) &MemChunk->FirstUsedMemEntry; - - if (NewSize > 0) - { - MemEntry = (struct MEM_ENTRY *) - ((unsigned char *)MemEntry + sizeof(struct MEM_ENTRY) + Size); - MemEntry->Size = NewSize; - - if (MemChunk->FirstFreeMemEntry) - MemChunk->FirstFreeMemEntry->Pred = MemEntry; - MemEntry->Succ = MemChunk->FirstFreeMemEntry; - MemChunk->FirstFreeMemEntry = MemEntry; - MemEntry->Pred = (struct MEM_ENTRY *) &MemChunk->FirstFreeMemEntry; - } -#ifdef DEBUG_CALLS - logPrintf (0, "xMemAlloc: %x, %d bytes\r\n", *DataPointer, Size); -#endif - return; -} - - - -/************************************************************************* - * * - * function : xMemFree * - * * - * parameter : DataPointer - data pointer * - * * - * return : none * - * * - *-----------------------------------------------------------------------* - * * - * xMemFree() frees with xMemAlloc() allocated memory. * - * * - *************************************************************************/ - -void xMemFre (DataPointer) - -unsigned char *DataPointer; -{ - struct MEM_CHUNK *MemChunk, *MemChunkPred; - struct MEM_ENTRY *MemEntry, *TempEntry, *PredEntry, *SuccEntry; - unsigned short FoundFlag; -#ifdef DEBUG - unsigned char *ptr; -#endif - - if (!DataPointer) - { - return; - } - else - { - MemEntry = NULL; - FoundFlag = 0; - - if (MemChunk = (*xRememberPtr)) - do - { - if (MemEntry = MemChunk->FirstUsedMemEntry) - do - { - if (DataPointer == (unsigned char *) ((unsigned char *) MemEntry + - sizeof(struct MEM_ENTRY))) FoundFlag = 1; - } while ((FoundFlag == 0) && (MemEntry = MemEntry->Succ)); - } while ((FoundFlag == 0) && (MemChunk = MemChunk->Succ)); - - if (FoundFlag == 1) - { -#ifdef DEBUG_CALLS - logPrintf (0, "xMemFree: %x, %d bytes\r\n", DataPointer, MemEntry->Size); -#endif - if (MemEntry->Succ) - ((struct MEM_ENTRY *)MemEntry->Succ)->Pred = MemEntry->Pred; - ((struct MEM_ENTRY *)MemEntry->Pred)->Succ = MemEntry->Succ; - - if (!MemChunk->FirstUsedMemEntry) - { - if (MemChunk->Succ) - ((struct MEM_CHUNK *)MemChunk->Succ)->Pred = MemChunk->Pred; - ((struct MEM_CHUNK *)MemChunk->Pred)->Succ = MemChunk->Succ; - if (xAllocatedMemory > 0) xAllocatedMemory -= MemChunk->Size; - free (MemChunk); - return; - } - - FoundFlag = 0; - PredEntry = NULL; - SuccEntry = NULL; - if (TempEntry = MemChunk->FirstFreeMemEntry) - do - { - if ((struct MEM_ENTRY *)((unsigned char *)TempEntry + - TempEntry->Size + sizeof(struct MEM_ENTRY)) == MemEntry) - { - FoundFlag ++; - PredEntry = TempEntry; - } - if ((struct MEM_ENTRY *)((unsigned char *)MemEntry + - MemEntry->Size + sizeof(struct MEM_ENTRY)) == TempEntry) - { - FoundFlag ++; - SuccEntry = TempEntry; - } - } while ((FoundFlag != 2) && (TempEntry = TempEntry->Succ)); - - if (PredEntry) - { - if (SuccEntry) - { - /* Vorgdnger + Nachfolger */ - - if (SuccEntry->Succ) - ((struct MEM_ENTRY *)SuccEntry->Succ)->Pred = SuccEntry->Pred; - ((struct MEM_ENTRY *)SuccEntry->Pred)->Succ = SuccEntry->Succ; - - PredEntry->Size += MemEntry->Size + sizeof(struct MEM_ENTRY) + - SuccEntry->Size + sizeof(struct MEM_ENTRY); - } - else - { - /* nur Vorgaenger */ - - PredEntry->Size += MemEntry->Size + sizeof(struct MEM_ENTRY); - } -#ifdef DEBUG - for (ptr = (unsigned char *) (PredEntry) + sizeof(struct MEM_ENTRY); - ptr < (unsigned char *) (PredEntry) + sizeof(struct MEM_ENTRY) + - PredEntry->Size; ptr++) - *ptr = (((unsigned long)ptr)&1) ? 0x55 : 0xAA; -#endif - } - else - { - if (SuccEntry) - { - /* nur Nachfolger */ - - if (SuccEntry->Succ) - ((struct MEM_ENTRY *)SuccEntry->Succ)->Pred = SuccEntry->Pred; - ((struct MEM_ENTRY *)SuccEntry->Pred)->Succ = SuccEntry->Succ; - - MemEntry->Size += SuccEntry->Size + sizeof(struct MEM_ENTRY); - } - - if (MemChunk->FirstFreeMemEntry) - MemChunk->FirstFreeMemEntry->Pred = MemEntry; - MemEntry->Succ = MemChunk->FirstFreeMemEntry; - MemChunk->FirstFreeMemEntry = MemEntry; - MemEntry->Pred = (struct MEM_ENTRY *) &MemChunk->FirstFreeMemEntry; -#ifdef DEBUG - for (ptr = (unsigned char *) (MemEntry) + sizeof(struct MEM_ENTRY); - ptr < (unsigned char *) (MemEntry) + sizeof(struct MEM_ENTRY) + - MemEntry->Size; ptr++) - *ptr = (((unsigned long)ptr)&1) ? 0x55 : 0xAA; -#endif - } - } -#ifdef DEBUG_CALLS - else - logPrintf (0, "xMemFree: tried to free unallocated data %x\r\n", DataPointer); -#endif - } - return; -} - - - -/************************************************************************* - * * - * function : xMemFreeAll * - * * - * parameter : RememberPtr * - * * - * return : none * - * * - *-----------------------------------------------------------------------* - * * - * xMemFreeAll() frees all with xMemAlloc() allocated memory. If Re- * - * memberPtr is not NULL, the MEM_CHUNK structure from the specified * - * Address is freed, otherwise the natural MEM_CHUNK will be done. * - * * - *************************************************************************/ - - -void xMemFreeAll (RememberPtr) - -struct MEM_CHUNK **RememberPtr; -{ - struct MEM_CHUNK *MemChunk, *MemChunkPred; - - if (RememberPtr) - { - if (MemChunkPred = (*RememberPtr)) - do - { - MemChunk = MemChunkPred->Succ; - if (xAllocatedMemory > 0) xAllocatedMemory -= MemChunkPred->Size; - free (MemChunkPred); - } while (MemChunkPred = MemChunk); - *RememberPtr = NULL; - } - else - { - if (MemChunkPred = (*xRememberPtr)) - do - { - MemChunk = MemChunkPred->Succ; - if (xAllocatedMemory > 0) xAllocatedMemory -= MemChunkPred->Size; - free (MemChunkPred); - } while (MemChunkPred = MemChunk); - *xRememberPtr = NULL; - } -} - - -/************************************************************************* - * * - * function : xMemMerge * - * * - * parameter : RememberPtr * - * * - * return : none * - * * - *-----------------------------------------------------------------------* - * * - * xMemMerge() merges the memory area pointed to by RememberKey with * - * the currently used in xRememberPtr. * - * * - *************************************************************************/ - -void xMemMerge (RememberPtr) - -struct MEM_CHUNK **RememberPtr; -{ - struct MEM_CHUNK *MemChunk, *MemChunkPred; - - if (RememberPtr) - { - if (MemChunk = (*xRememberPtr)) - { - while (MemChunk->Succ) MemChunk = MemChunk->Succ; - MemChunk->Succ = (*RememberPtr); - *RememberPtr = NULL; - } - else (*xRememberPtr = *RememberPtr); - } - return; -} - -/************************************************************************* - * * - * function : xGetRemember * - * * - * parameter : none * - * * - * return : pointer to a MEM_CHUNK tree * - * * - *-----------------------------------------------------------------------* - * * - * xGetRemember() returns the currently used MEM_CHUNK tree. * - * * - *************************************************************************/ - - -struct MEM_CHUNK **xGetRemember () -{ - return (xRememberPtr); -} - - -/************************************************************************* - * * - * function : xSetRemember * - * * - * parameter : pointer to a MEM_CHUNK tree * - * * - * return : none * - * * - *-----------------------------------------------------------------------* - * * - * xSetRemember() redefines the currently used MEM_CHUNK pointer. If * - * RememberPtr is NULL, the natural MEM_CHUNK is reloaded. * - * * - *************************************************************************/ - - -void xSetRemember (RememberPtr) - -struct MEM_CHUNK **RememberPtr; -{ - if (RememberPtr) - xRememberPtr = RememberPtr; - else - xRememberPtr = &xRememberKey; -} - -/************************************************************************* - * * - * function : xPrintMemList * - * * - * parameter : pointer to a MEM_CHUNK tree * - * * - * return : none * - * * - *-----------------------------------------------------------------------* - * * - * xPrintMemList() prints the currently allocated memory blocks of * - * the specified RememberPtr. * - * * - *************************************************************************/ - - -void xPrintMemList (Remember) - -struct MEM_CHUNK **Remember; -{ - struct MEM_CHUNK *MemChunk; - struct MEM_ENTRY *MemEntry; - - fprintf (stderr, "MemChunkPtr = %x\n", (int) Remember); - - if (MemChunk = *Remember) - do - { - fprintf (stderr, "\tMemChunk at %x with Size %d\n", (int) MemChunk, - (int) MemChunk->Size); - - if (MemEntry = MemChunk->FirstFreeMemEntry) - do - { - fprintf (stderr, "\t\tFree MemEntry at %x (%x) with Size %d\n", - (int) MemEntry, (int)((unsigned char *)MemEntry + - sizeof(struct MEM_ENTRY)), (int) MemEntry->Size); - - } while (MemEntry = MemEntry->Succ); - - if (MemEntry = MemChunk->FirstUsedMemEntry) - do - { - fprintf (stderr, "\t\tUsed MemEntry at %x (%x) with Size %d\n", - (int) MemEntry, (int)((unsigned char *)MemEntry + - sizeof(struct MEM_ENTRY)), (int) MemEntry->Size); - - } while (MemEntry = MemEntry->Succ); - - } while (MemChunk = MemChunk->Succ); - else fprintf (stderr, "\tNo current MemChunk\n"); -} - - -/************************************************************************* - * * - * function : xGetMemSize * - * * - * parameter : pointer to a MEM_CHUNK tree * - * * - * return : none * - * * - *-----------------------------------------------------------------------* - * * - * xGetMemSize() gets the size of the currently allocated memory * - * blocks of the specified (or natural if NULL) RememberPtr * - * * - *************************************************************************/ - - -unsigned long xGetMemSize (RememberPtr) - -struct MEM_CHUNK **RememberPtr; -{ - struct MEM_CHUNK *MemChunk; - struct MEM_ENTRY *MemEntry; - unsigned long Result = 0; - - if (RememberPtr) MemChunk = *RememberPtr; - else MemChunk = xRememberKey; - - if (MemChunk) - do { Result += (unsigned long) MemChunk->Size; } - while (MemChunk = MemChunk->Succ); - - return (Result); -} - - -/************************************************************************* - * * - * function : xSetText * - * * - * arguments : xText - pointer to a string * - * * - * return : pointer to an new allocated string * - * * - *-----------------------------------------------------------------------* - * * - * xSetText() allocates memory for the string pointed to by 'xText' * - * and duplicates it. * - * * - *************************************************************************/ - -char *xSetText (xText) - -char *xText; -{ - char *NewText; - - if (!xText) return (NULL); - - xMemAlloc (strlen(xText) + 1, &NewText); - strcpy (NewText, xText); - - return (NewText); -} |