Debian Codegraph @

cuneiform_src/Kern/rimage/sources/main/crimemory.cpp

raw
1 /*
2 Copyright (c) 1993-2008, Cognitive Technologies
3 All rights reserved.
4
5 Разрешается повторное распространение и использование как в виде исходного кода,
6 так и в двоичной форме, с изменениями или без, при соблюдении следующих условий:
7
8 * При повторном распространении исходного кода должны оставаться указанное
9 выше уведомление об авторском праве, этот список условий и последующий
10 отказ от гарантий.
11 * При повторном распространении двоичного кода в документации и/или в
12 других материалах, поставляемых при распространении, должны сохраняться
13 указанная выше информация об авторском праве, этот список условий и
14 последующий отказ от гарантий.
15 * Ни название Cognitive Technologies, ни имена ее сотрудников не могут
16 быть использованы в качестве средства поддержки и/или продвижения
17 продуктов, основанных на этом ПО, без предварительного письменного
18 разрешения.
19
20 ЭТА ПРОГРАММА ПРЕДОСТАВЛЕНА ВЛАДЕЛЬЦАМИ АВТОРСКИХ ПРАВ И/ИЛИ ДРУГИМИ ЛИЦАМИ "КАК
21 ОНА ЕСТЬ" БЕЗ КАКОГО-ЛИБО ВИДА ГАРАНТИЙ, ВЫРАЖЕННЫХ ЯВНО ИЛИ ПОДРАЗУМЕВАЕМЫХ,
22 ВКЛЮЧАЯ ГАРАНТИИ КОММЕРЧЕСКОЙ ЦЕННОСТИ И ПРИГОДНОСТИ ДЛЯ КОНКРЕТНОЙ ЦЕЛИ, НО НЕ
23 ОГРАНИЧИВАЯСЬ ИМИ. НИ ВЛАДЕЛЕЦ АВТОРСКИХ ПРАВ И НИ ОДНО ДРУГОЕ ЛИЦО, КОТОРОЕ
24 МОЖЕТ ИЗМЕНЯТЬ И/ИЛИ ПОВТОРНО РАСПРОСТРАНЯТЬ ПРОГРАММУ, НИ В КОЕМ СЛУЧАЕ НЕ
25 НЕСЁТ ОТВЕТСТВЕННОСТИ, ВКЛЮЧАЯ ЛЮБЫЕ ОБЩИЕ, СЛУЧАЙНЫЕ, СПЕЦИАЛЬНЫЕ ИЛИ
26 ПОСЛЕДОВАВШИЕ УБЫТКИ, СВЯЗАННЫЕ С ИСПОЛЬЗОВАНИЕМ ИЛИ ПОНЕСЕННЫЕ ВСЛЕДСТВИЕ
27 НЕВОЗМОЖНОСТИ ИСПОЛЬЗОВАНИЯ ПРОГРАММЫ (ВКЛЮЧАЯ ПОТЕРИ ДАННЫХ, ИЛИ ДАННЫЕ,
28 СТАВШИЕ НЕГОДНЫМИ, ИЛИ УБЫТКИ И/ИЛИ ПОТЕРИ ДОХОДОВ, ПОНЕСЕННЫЕ ИЗ-ЗА ДЕЙСТВИЙ
29 ТРЕТЬИХ ЛИЦ И/ИЛИ ОТКАЗА ПРОГРАММЫ РАБОТАТЬ СОВМЕСТНО С ДРУГИМИ ПРОГРАММАМИ,
30 НО НЕ ОГРАНИЧИВАЯСЬ ЭТИМИ СЛУЧАЯМИ), НО НЕ ОГРАНИЧИВАЯСЬ ИМИ, ДАЖЕ ЕСЛИ ТАКОЙ
31 ВЛАДЕЛЕЦ ИЛИ ДРУГОЕ ЛИЦО БЫЛИ ИЗВЕЩЕНЫ О ВОЗМОЖНОСТИ ТАКИХ УБЫТКОВ И ПОТЕРЬ.
32
33 Redistribution and use in source and binary forms, with or without modification,
34 are permitted provided that the following conditions are met:
35
36 * Redistributions of source code must retain the above copyright notice,
37 this list of conditions and the following disclaimer.
38 * Redistributions in binary form must reproduce the above copyright notice,
39 this list of conditions and the following disclaimer in the documentation
40 and/or other materials provided with the distribution.
41 * Neither the name of the Cognitive Technologies nor the names of its
42 contributors may be used to endorse or promote products derived from this
43 software without specific prior written permission.
44
45 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
46 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
49 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 */
56
57 // Для использования без CFIO.DLL
58 #ifdef _NO_CFIO
59 #undef _NO_CFIO
60 //#define _NO_CFIO
61 #endif
62 /////////////////////////////////////////////////////////////////////////////////////////////////////
63 //
64 //#define RIMAGE_USE_GLOBAL_MEM
65 /////////////////////////////////////////////////////////////////////////////////////////////////////
66 //
67 #ifdef RIMAGE_USE_GLOBAL_MEM
68 #include <windows.h>
69 #endif
70 #include <stdlib.h>
71 /////////////////////////////////////////////////////////////////////////////////////////////////////
72 //
73 #include "resource.h"
74 #include "cridefines.h"
75 #include "criimage.h"
76 #include "crimemory.h"
77 /////////////////////////////////////////////////////////////////////////////////////////////////////
78 //
79 #ifndef _NO_CFIO
80 #include "cfio.h"
81 #else
82 #define CFIO_MAX_COMMENT 48
83 #endif
84 // extern functions
85 //void SetReturnCode_rimage(uint16_t rc);
86 //uint16_t GetReturnCode_rimage();
87 /////////////////////////////////////////////////////////////////////////////////////////////////////
88 //CFIO Entries
89 static void* (*pDAlloc)(uint32_t, uint32_t, puchar, puchar) = NULL;
90 static void* (*pAlloc)(uint32_t, uint32_t) = NULL;
91 static void (*pFree)(void *) = NULL;
92 static void* (*pLock)(void *) = NULL;
93 static void (*pUnlock)(void *) = NULL;
94 /////////////////////////////////////////////////////////////////////////////////////////////////////
95 //
96 #define TAKE_ENTRIE(Name,Pointer,Out) if ( !CFIO_GetExportData(Name, (void*)(&Pointer)) ) Out= FALSE;
97 Bool32 InitCFIOInterface(Bool32 Status)
98 {
99 Bool32 bRet = TRUE;
100
101 if ( Status == TRUE )
102 {
103 CFIO_Init(NULL, NULL);
104
105 TAKE_ENTRIE(CFIO_FNDAllocMemory, pDAlloc, bRet)
106 TAKE_ENTRIE(CFIO_FNAllocMemory, pAlloc, bRet)
107 TAKE_ENTRIE(CFIO_FNFreeMemory, pFree, bRet)
108 TAKE_ENTRIE(CFIO_FNLockMemory, pLock, bRet)
109 TAKE_ENTRIE(CFIO_FNUnlockMemory, pUnlock, bRet)
110 }
111 else
112 {
113 bRet = CFIO_Done();
114 }
115
116 return bRet;
117 }
118
119 /////////////////////////////////////////////////////////////////////////////////////////////////////
120 //
121 #define RIMAGE
122 char cCommentBuffer[CFIO_MAX_COMMENT];
123
124 void RIMAGEComment(const char *Comment)
125 {
126 uint32_t Len = strlen(Comment);
127 Len = Len < CFIO_MAX_COMMENT ? Len : CFIO_MAX_COMMENT - 1 ;
128 strncpy(cCommentBuffer, Comment, Len );
129 cCommentBuffer[Len] = 0x0;
130 }
131
132 void * RIMAGEDAlloc(uint32_t stAllocateBlock, const char *Comment)
133 {
134 RIMAGEComment(Comment);
135 return RIMAGEAlloc(stAllocateBlock);
136 }
137
138 void * RIMAGEAlloc(uint32_t stAllocateBlock) {
139 return malloc(stAllocateBlock);
140 }
141 //////////////////////////////////////////////////////////////////////////////////////////////////
142 //
143 void RIMAGEFree(void * mem) {
144 free(mem);
145 }
146 //////////////////////////////////////////////////////////////////////////////////////////////////
147 //
148 void * RIMAGELock( void * mem ) {
149 return mem;
150 }
151 //////////////////////////////////////////////////////////////////////////////////////////////////
152 //
153 void RIMAGEUnlock( void * mem ) {
154 }
155 /////////////////////////////////////////////////////////////////////////////////////////////////////////
156 //
157 Handle RIMAGEOpenSave(char * lpName)
158 {
159 Handle rc = NULL;
160 #ifdef _NO_CFIO
161 rc = (Handle)fopen(lpName,"wb");
162 #endif
163 return rc;
164 }
165 /////////////////////////////////////////////////////////////////////////////////////////
166 //
167 Handle RIMAGEOpenRestore(char * lpName)
168 {
169 Handle rc = NULL;
170 #ifdef _NO_CFIO
171 rc = (Handle)fopen(lpName,"rb");
172 #endif
173 return rc;
174 }
175 /////////////////////////////////////////////////////////////////////////////////////////
176 //
177 unsigned int RIMAGEWrite(Handle h,void * lpdata,unsigned int size)
178 {
179 uint32_t rc = 0;
180 #ifdef _NO_CFIO
181 rc = fwrite(lpdata,1,size,(FILE*)h);
182 #endif
183 return rc;
184 }
185 /////////////////////////////////////////////////////////////////////////////////////////
186 //
187 unsigned int RIMAGERead(Handle h,void * lpdata,unsigned int size)
188 {
189 uint32_t rc = 0;
190 #ifdef _NO_CFIO
191 rc = fread(lpdata,1,size,(FILE *)h);
192 #endif
193 return rc;
194 }
195 /////////////////////////////////////////////////////////////////////////////////////////
196 //
197 void RIMAGEClose(Handle h)
198 {
199 #ifdef _NO_CFIO
200 fclose((FILE*)h);
201 #endif
202 }
203 /////////////////////////////////////////////////////////////////////////////////////////
204 // end of file