# HG changeset patch # User Michael Spacefalcon # Date 1402620936 0 # Node ID c82d093a2b89abab5b31c046e9b9b474be2467f8 # Parent 8891c3d0c68ac722ff437700ba9183a87e1e3b32 os_mem_fl.c: os_AllocateMemory() and os_DeallocateMemory() diff -r 8891c3d0c68a -r c82d093a2b89 gsm-fw/gpf/osl/os_mem_fl.c --- a/gsm-fw/gpf/osl/os_mem_fl.c Wed Jun 11 17:49:13 2014 +0000 +++ b/gsm-fw/gpf/osl/os_mem_fl.c Fri Jun 13 00:55:36 2014 +0000 @@ -239,3 +239,57 @@ } return(OS_ERROR); } + +GLOBAL LONG +os_DeallocateMemory(OS_HANDLE TaskHandle, T_VOID_STRUCT *Buffer) +{ + if (NU_Deallocate_Memory(Buffer) == NU_SUCCESS) + return(OS_OK); + else + return(OS_ERROR); +} + +GLOBAL LONG +os_AllocateMemory(OS_HANDLE TaskHandle, T_VOID_STRUCT **Buffer, ULONG Size, + ULONG Suspend, OS_HANDLE PoolHandle) +{ + int ret, sts; + + if (Suspend == 0xFFFFFFFF) + Suspend = 1; + ret = OS_OK; + for (;;) { + sts = NU_Allocate_Memory(MemPoolTable[PoolHandle].pcb, Buffer, + Size, Suspend); + switch (sts) { + case NU_SUCCESS: + return(ret); + case NU_INVALID_SUSPEND: + Suspend = 0; + continue; + case NU_NO_MEMORY: + case NU_TIMEOUT: + if (Suspend == 1) { + Suspend = 0xFFFFFFFF; + ret = OS_WAITED; + continue; + } else { + *Buffer = 0; + return(OS_TIMEOUT); + } + default: + /* + * Disassembly reveals that the original code + * has an endless loop here, the equivalent + * of continue. My guess is that they simply + * forgot the default case, and so control + * falls onto the closing brace of the switch + * and then onto the closing brace of the for + * loop. But I prefer better error handling, + * hence the present addition. - Space Falcon + */ + *Buffer = 0; + return(OS_ERROR); + } + } +}