(file) Return to palcommon.h CVS log (file) (dir) Up to [OMI] / omi / pal

  1 krisbash 1.1 #ifndef _pal_palcommon_h
  2              #define _pal_palcommon_h
  3              
  4              #include <stdarg.h>
  5              #include <stddef.h>
  6              #include <stdlib.h>
  7              #include <string.h>
  8              #include <wchar.h>
  9              
 10              #if defined(_MSC_VER)
 11              #    include <windows.h>
 12              #    include <windef.h>
 13              #    include <windows.h>
 14              #    include <strsafe.h>
 15              #else
 16              #    include "../../common/linux/sal.h"
 17              #endif
 18              
 19              #include <limits.h>
 20              
 21              #ifndef NAME_MAX
 22 krisbash 1.1 #  define NAME_MAX 255
 23              #endif
 24              
 25              /*
 26              **==============================================================================
 27              **
 28              **  Windows-specific types.  Defined here for PAL on Non-Windows platforms.
 29              **
 30              **==============================================================================
 31              */
 32              
 33              #ifdef _MSC_VER
 34                  #ifndef WIN32_FROM_HRESULT
 35                      #define WIN32_FROM_HRESULT(hr) (HRESULT_FACILITY(hr) == FACILITY_WIN32 ? HRESULT_CODE(hr) : hr) 
 36                  #endif    
 37              #else
 38                  #define WIN32_FROM_HRESULT(hr) hr
 39                  #define HRESULT_FROM_WIN32(error) error
 40                  typedef unsigned long DWORD, *LPDWORD;
 41                  typedef int BOOL;
 42                  typedef unsigned long HRESULT;
 43 krisbash 1.1     typedef const wchar_t *PCWSTR;
 44                  typedef wchar_t *PWSTR;
 45                  typedef const char *PCSTR;
 46                  typedef char *PSTR;
 47                  typedef void *PVOID;
 48                  typedef PVOID HANDLE;
 49                  #define NO_ERROR 0
 50                  #define INFINITE 0xFFFFFFFF
 51                  #define WINAPI
 52                  #define S_OK 0
 53                  #define ERROR_GEN_FAILURE 31
 54                  #define TRUE 1
 55                  #define FALSE 0
 56                  #define ERROR_INVALID_PARAMETER 87
 57                  #define ERROR_OUTOFMEMORY 14
 58                  #define MAX_PATH 0x00000104
 59                  typedef unsigned long long uint64;
 60              #endif
 61              
 62              /*
 63              **==============================================================================
 64 krisbash 1.1 **
 65              ** Including config.h
 66              **
 67              **==============================================================================
 68              */
 69              #if defined(_MSC_VER)
 70              #    include <pal/config.h>
 71              #else
 72              #    include "config.h"
 73              #endif
 74              
 75              /*
 76              **==============================================================================
 77              **
 78              **  __FUNCTION__
 79              **
 80              **==============================================================================
 81              */
 82              
 83              #if !defined(CONFIG_HAVE_FUNCTION_MACRO)
 84              # if !defined(_MSC_VER) && !defined(__FUNCTION__)
 85 krisbash 1.1 #  define __FUNCTION__ "<unknown>"
 86              # endif
 87              #endif
 88              
 89              /*
 90              **==============================================================================
 91              **
 92              ** PAL_32BIT
 93              ** PAL_64BIT
 94              **
 95              **==============================================================================
 96              */
 97              #if defined(__GNUC__)
 98              # if defined(__i386__)
 99              # define PAL_32BIT
100              # elif defined(__x86_64__)
101              # define PAL_64BIT
102              # elif defined(__ppc__)
103              # define PAL_32BIT
104              # elif defined(__ppc64__)
105              # define PAL_64BIT
106 krisbash 1.1 # elif ((ULONG_MAX) == (UINT_MAX) && (ULONG_MAX == 0xFFFFFFFF))
107              # define PAL_32BIT
108              # else
109              # define PAL_64BIT
110              # endif
111              #elif defined(_MSC_VER)
112              # if defined(_WIN64)
113              # define PAL_64BIT
114              # else
115              # define PAL_32BIT
116              # endif
117              #elif ((ULONG_MAX) == (UINT_MAX) && (ULONG_MAX == 0xFFFFFFFF))
118              # define PAL_32BIT
119              #else
120              # define PAL_64BIT
121              #endif
122              
123              /*
124              **==============================================================================
125              **
126              ** PAL_CALL macro
127 krisbash 1.1 **
128              **==============================================================================
129              */
130              #ifdef _MSC_VER
131              # define PAL_CALL __stdcall
132              #else
133              # define PAL_CALL
134              #endif
135              
136              /*
137              **==============================================================================
138              **
139              ** PAL_EXPORT_API, PAL_IMPORT_API macros
140              **
141              **==============================================================================
142              */
143              
144              #if defined(_MSC_VER)
145              # define PAL_EXPORT_API __declspec(dllexport)
146              # define PAL_IMPORT_API __declspec(dllimport)
147              #elif defined(__GNUC__)
148 krisbash 1.1 # define PAL_EXPORT_API __attribute__((visibility("default")))
149              # define PAL_IMPORT_API /* empty */
150              #elif defined(sun)
151              # define PAL_EXPORT_API __global 
152              # define PAL_IMPORT_API /* empty */
153              #else
154              # define PAL_EXPORT_API /* empty */
155              # define PAL_IMPORT_API /* empty */
156              #endif
157              
158              /*
159              **==============================================================================
160              **
161              ** PAL_BEGIN_EXTERNC
162              ** PAL_END_EXTERNC
163              **
164              **==============================================================================
165              */
166              
167              #if defined(__cplusplus)
168              # define PAL_BEGIN_EXTERNC extern "C" {
169 krisbash 1.1 # define PAL_END_EXTERNC }
170              #else
171              # define PAL_BEGIN_EXTERNC
172              # define PAL_END_EXTERNC
173              #endif
174              
175              /*
176              **==============================================================================
177              **
178              ** PAL_EXTERN_C
179              **
180              **==============================================================================
181              */
182              #ifdef __cplusplus
183              # define PAL_EXTERN_C extern "C"
184              #else
185              # define PAL_EXTERN_C extern
186              #endif /* __cplusplus */
187              
188              /*
189              **==============================================================================
190 krisbash 1.1 **
191              ** PAL_INLINE macro
192              **
193              **==============================================================================
194              */
195              
196              #if defined(_MSC_VER)
197              # define PAL_INLINE static __inline
198              #elif defined(__GNUC__)
199              # define PAL_INLINE static __inline
200              #elif defined(sun)
201              # define PAL_INLINE static inline
202              #elif defined(__PPC)
203              # define PAL_INLINE __inline__
204              #else
205              # define PAL_INLINE static __inline
206              #endif
207                 
208              /*
209              **==============================================================================
210              **
211 krisbash 1.1 ** PAL string
212              **
213              **==============================================================================
214              */
215              
216              #if defined(CONFIG_ENABLE_WCHAR)
217              typedef wchar_t PAL_Char;
218              #else
219              typedef char PAL_Char;
220              #endif
221              
222              typedef PAL_Char TChar;
223              
224              /*
225              **==============================================================================
226              **
227              ** PAL_T()
228              **
229              **==============================================================================
230              */
231              
232 krisbash 1.1 #if defined(CONFIG_ENABLE_WCHAR)
233              # define __PAL_T(STR) L ## STR
234              # define PAL_T(STR) __PAL_T(STR)
235              #else
236              # define PAL_T(STR) STR
237              #endif
238              
239              /*
240              **==============================================================================
241              **
242              ** PAL_UNUSED
243              **
244              **==============================================================================
245              */
246              
247              #define PAL_UNUSED(X) ((void)X)
248              
249              /*
250              **==============================================================================
251              **
252              ** PAL_HAVE_POSIX
253 krisbash 1.1 **
254              **==============================================================================
255              */
256              
257              #if defined(linux) || defined(sun) || defined(hpux) || defined(aix)
258              # define PAL_HAVE_POSIX
259              #endif
260              
261              /*
262              **==============================================================================
263              **
264              ** PAL_HAVE_PTHREADS
265              **
266              **==============================================================================
267              */
268              
269              #if defined(linux) | defined(sun) | defined(hpux) | defined(aix)
270              # define PAL_HAVE_PTHREADS
271              #endif
272              
273              /*
274 krisbash 1.1 **==============================================================================
275              **
276              ** Basic types
277              **
278              **==============================================================================
279              */
280              
281              typedef unsigned char PAL_Uint8;
282              #define PAL_UINT8_MAX (UCHAR_MAX)
283              
284              typedef signed char PAL_Sint8;
285              #define PAL_SINT8_MIN (SCHAR_MIN)
286              #define PAL_SINT8_MAX (SCHAR_MAX)
287              
288              typedef unsigned short PAL_Uint16;
289              #define PAL_UINT16_MAX (USHRT_MAX)
290              
291              typedef signed short PAL_Sint16;
292              #define PAL_SINT16_MIN (SHRT_MIN)
293              #define PAL_SINT16_MAX (SHRT_MAX)
294              
295 krisbash 1.1 typedef unsigned int PAL_Uint32;
296              #define PAL_UINT32_MAX (UINT_MAX)
297              
298              typedef signed int PAL_Sint32;
299              #define PAL_SINT32_MIN (INT_MIN)
300              #define PAL_SINT32_MAX (INT_MAX)
301              
302              #if defined(_MSC_VER)
303              typedef unsigned __int64 PAL_Uint64;
304              typedef signed __int64 PAL_Sint64;
305              #else
306              typedef unsigned long long PAL_Uint64;
307              typedef signed long long PAL_Sint64;
308              #endif
309              #define PAL_UINT64_MIN ((PAL_Uint64)                    0ULL)
310              #define PAL_UINT64_MAX ((PAL_Uint64) 18446744073709551615ULL)
311              #define PAL_SINT64_MIN ((PAL_Sint64) (-9223372036854775807LL - 1LL))
312              #define PAL_SINT64_MAX ((PAL_Sint64)   9223372036854775807LL      )
313              
314              typedef unsigned char PAL_Boolean;
315              
316 krisbash 1.1 #define PAL_TRUE ((PAL_Boolean)1)
317              #define PAL_FALSE ((PAL_Boolean)0)
318              
319              /*
320              **==============================================================================
321              **
322              ** Function calling conventions
323              **
324              **==============================================================================
325              */
326              
327              #ifdef _MSC_VER
328              # define PAL_CDECLAPI __cdecl
329              #else
330              # define PAL_CDECLAPI
331              #endif
332              
333              #define ATEXIT_API PAL_CDECLAPI
334              
335              /*
336              **==============================================================================
337 krisbash 1.1 **
338              ** SAL Notation for non-Windows platforms
339              **
340              **==============================================================================
341              */
342              
343              #if !defined(_MSC_VER)
344              
345              # ifndef _In_
346              #  define _In_
347              # endif
348              
349              # ifndef _Out_
350              #  define _Out_
351              # endif
352               
353              # ifndef _Inout_
354              #  define _Inout_
355              # endif
356              
357              # ifndef _Return_type_success_
358 krisbash 1.1 #  define _Return_type_success_(x)
359              # endif
360              
361              # ifndef _Acquires_lock_
362              #  define _Acquires_lock_(x)
363              # endif
364              
365              # ifndef _Releases_lock_
366              #  define _Releases_lock_(x)
367              # endif
368              
369              # ifndef _In_z_
370              #  define _In_z_
371              # endif
372              
373              # ifndef _Post_z_
374              #  define _Post_z_
375              # endif
376              
377              # ifndef _Out_writes_
378              #  define _Out_writes_(size)
379 krisbash 1.1 # endif
380              
381              # ifndef _Out_writes_z_
382              #  define _Out_writes_z_(size)
383              # endif
384              
385              # ifndef _Null_terminated_
386              #  define _Null_terminated_
387              # endif
388              
389              # ifndef _Use_decl_annotations_
390              #  define _Use_decl_annotations_
391              # endif
392              
393              # ifndef _Out_opt_
394              #  define _Out_opt_
395              # endif
396              
397              # ifndef _Deref_post_z_
398              #  define _Deref_post_z_
399              # endif
400 krisbash 1.1 
401              # ifndef _Inout_updates_z_
402              #  define _Inout_updates_z_(count)
403              # endif
404              
405              # ifndef _Inout_opt_z_
406              #  define _Inout_opt_z_
407              # endif
408              
409              # ifndef _Deref_prepost_opt_z_
410              #  define _Deref_prepost_opt_z_
411              # endif
412              
413              # ifndef _In_opt_
414              #  define _In_opt_
415              # endif
416              
417              # ifndef _In_opt_z_
418              #  define _In_opt_z_
419              # endif
420              
421 krisbash 1.1 # ifndef _Ret_maybenull_
422              #  define _Ret_maybenull_
423              # endif
424              
425              # ifndef _Check_return_
426              #  define _Check_return_
427              # endif
428              
429              # ifndef _Must_inspect_result_
430              #  define _Must_inspect_result_
431              # endif
432              
433              # ifndef _Frees_ptr_opt_
434              #  define _Frees_ptr_opt_
435              # endif
436              
437              # ifndef _Frees_ptr_
438              #  define _Frees_ptr_
439              # endif
440              
441              # ifndef _Const_
442 krisbash 1.1 #  define _Const_
443              # endif
444              
445              # ifndef _Post_writable_byte_size
446              #  define _Post_writable_byte_size(size)
447              # endif
448              
449              # ifndef _Analysis_assume_
450              #  define _Analysis_assume_(expr)
451              # endif
452              
453              # ifndef _Always_
454              #  define _Always_(expr)
455              # endif
456              
457              # ifndef _Outptr_
458              #  define _Outptr_
459              # endif
460              
461              # ifndef _Outptr_result_buffer_
462              #  define _Outptr_result_buffer_(size)
463 krisbash 1.1 # endif
464              
465              # ifndef _Outptr_result_nullonfailure_ 
466              #  define _Outptr_result_nullonfailure_
467              # endif
468              
469              # ifndef  _Maybenull_
470              #  define _Maybenull_
471              # endif
472              
473              # ifndef _Notnull_
474              #  define _Notnull_
475              # endif
476              
477              # ifndef _Valid_
478              #  define _Valid_
479              # endif
480              
481              # ifndef _Analysis_noreturn_ 
482              #  define _Analysis_noreturn_
483              # endif
484 krisbash 1.1 
485              # ifndef _Ret_writes_maybenull_z_
486              #  define _Ret_writes_maybenull_z_(count)
487              # endif
488              
489              # ifndef _String_length_
490              #  define _String_length_(str)
491              # endif
492              
493              # ifndef _Success_
494              #  define _Success_
495              # endif
496              
497              # ifndef _Field_range_
498              #  define _Field_range_(min, max)
499              # endif
500              
501              # ifndef _In_range_
502              #  define _In_range_(min, max)
503              # endif
504              
505 krisbash 1.1 # ifndef _Field_size_
506              #  define _Field_size_(count)
507              # endif
508              
509              # ifndef _Field_size_opt_
510              #  define _Field_size_opt_(count)
511              # endif
512              
513              # ifndef _Field_size_full_opt_
514              #  define _Field_size_full_opt_(count)
515              # endif
516              
517              # ifndef _Field_size_bytes_opt_
518              #  define _Field_size_bytes_opt_(size)
519              # endif
520              
521              # ifndef _Readable_elements_
522              #  define _Readable_elements_(count)
523              # endif
524              
525              # ifndef _Writable_elements_
526 krisbash 1.1 #  define _Writable_elements_(count)
527              # endif
528              
529              # ifndef _Struct_size_bytes_
530              #  define _Struct_size_bytes_(size)
531              # endif
532              
533              # ifndef _At_
534              #  define _At_(target, annotation)
535              # endif
536              
537              # ifndef _Pre_satisfies_
538              #  define _Pre_satisfies_(expr)
539              # endif
540              
541              # ifndef _On_failure_
542              #  define _On_failure_(expr)
543              # endif
544              
545              # ifndef _In_bytecount_
546              #  define _In_bytecount_(size)
547 krisbash 1.1 # endif
548              
549              # ifndef _Out_writes_bytes_to_opt_
550              #  define _Out_writes_bytes_to_opt_(buffLen, bufferNeeded)
551              # endif
552              
553              # ifndef _When_
554              #  define _When_(expr, annotation)
555              # endif
556              
557              # ifndef _Analysis_assume_nullterminated_
558              #  define _Analysis_assume_nullterminated_(expr)
559              # endif
560              
561              
562              #endif /* !defined(_MSC_VER) */
563              
564              /*
565              **==============================================================================
566              **
567              ** PAL_MAX_PATH_SIZE
568 krisbash 1.1 **
569              **==============================================================================
570              */
571              
572              #define PAL_MAX_PATH_SIZE 1024
573              
574              /*
575              **==============================================================================
576              **
577              ** PAL_COUNT
578              **
579              **==============================================================================
580              */
581              
582              #ifdef _MSC_VER
583              # define PAL_COUNT(ARR) _countof(ARR)
584              #else
585              # define PAL_COUNT(ARR) (sizeof(ARR) / sizeof(ARR[0]))
586              #endif
587              
588              /*
589 krisbash 1.1 **==============================================================================
590              **
591              ** PAL_Timestamp (equivalent to MI_Timestamp)
592              **
593              **     Represents a timestamp as described in the CIM Infrastructure 
594              **     specification
595              **
596              **     [1] MI_ee DSP0004 (http://www.dmtf.org/standards/published_documents)
597              **
598              **==============================================================================
599              */
600              
601              typedef struct _PAL_Timestamp
602              {
603                  /* YYYYMMDDHHMMSS.MMMMMMSUTC */
604                  PAL_Uint32 year;
605                  PAL_Uint32 month;
606                  PAL_Uint32 day;
607                  PAL_Uint32 hour;
608                  PAL_Uint32 minute;
609                  PAL_Uint32 second;
610 krisbash 1.1     PAL_Uint32 microseconds;
611                  PAL_Sint32 utc;
612              }
613              PAL_Timestamp;
614              
615              /*
616              **==============================================================================
617              **
618              ** struct PAL_Interval (equivalent to MI_Interval)
619              **
620              **     Represents an interval as described in the CIM Infrastructure 
621              **     specification. This structure is padded to have the same length
622              **     as a MI_Timestamp structure.
623              **
624              **     [1] MI_ee DSP0004 (http://www.dmtf.org/standards/published_documents)
625              **
626              **==============================================================================
627              */
628              
629              typedef struct _PAL_Interval
630              {
631 krisbash 1.1     /* DDDDDDDDHHMMSS.MMMMMM:000 */
632                  PAL_Uint32 days;
633                  PAL_Uint32 hours;
634                  PAL_Uint32 minutes;
635                  PAL_Uint32 seconds;
636                  PAL_Uint32 microseconds;
637                  PAL_Uint32 __padding1;
638                  PAL_Uint32 __padding2;
639                  PAL_Uint32 __padding3;
640              }
641              PAL_Interval;
642              
643              /*
644              **==============================================================================
645              **
646              ** struct PAL_Datetime (equivalent to MI_Datetime)
647              **
648              **     Represents a CIM datetime type as described in the CIM Infrastructure
649              **     specification. It contains a union of PAL_Timestamp and PAL_Interval.
650              **
651              **==============================================================================
652 krisbash 1.1 */
653              
654              typedef struct _PAL_Datetime
655              {
656                  PAL_Uint32 isTimestamp;
657                  union
658                  {
659                      PAL_Timestamp timestamp;
660                      PAL_Interval interval;
661                  }
662                  u;
663              }
664              PAL_Datetime;
665              
666              /*
667              **==============================================================================
668              **
669              ** PAL_PREFETCH
670              **
671              **==============================================================================
672              */
673 krisbash 1.1 
674              #if defined(_MSC_VER)
675              # define PAL_PREFETCH(p) ReadForWriteAccess(p)
676              #elif defined(CONFIG_HAVE_BUILTIN_PREFETCH)
677              # define PAL_PREFETCH(p) (__builtin_prefetch((const void*)p),*(p))
678              #else
679              # define PAL_PREFETCH(p) (*p)
680              #endif
681              
682              /*
683              **==============================================================================
684              **
685              ** PAL_STATIC_ASSERT
686              **
687              ** Example usage:
688              **   PAL_STATIC_ASSERT(sizeof(MI_CompositeDisposable) == sizeof(CompositeDisposable))
689              **   (ensures that size of a public struct (with 3 reserved ptrdiff_t fields) 
690              **    is the same as size of an internal struct)
691              **==============================================================================
692              */
693              
694 krisbash 1.1 #define PAL_STATIC_ASSERT(condition) \
695                  typedef char _static_assert ## __LINE__ [(condition) ? 1 : -1]
696              
697              /*
698              **==============================================================================
699              **
700              ** PAL_tolower (same as tolower from C89's <ctype.h>, but operating on PAL_Char)
701              **
702              **==============================================================================
703              */
704              
705              PAL_INLINE PAL_Char PAL_tolower(PAL_Char c)
706              {
707                  if ((PAL_T('A') <= c) && (c <= PAL_T('Z')))
708                      c = (PAL_Char) ((int) (unsigned char) c + (PAL_T('a') - PAL_T('A')));
709                  return c;
710              }
711              
712              /*
713              **==============================================================================
714              **
715 krisbash 1.1 ** va_copy and other non-C89 helpers for vararg handling
716              **
717              **==============================================================================
718              */
719              
720              #if defined(CONFIG_HAVE_VA_COPY)
721                  #define PAL_va_copy(dest, source) va_copy(dest, source)
722              #else
723                  #define PAL_va_copy(dest, source) ((dest) = (source))
724              #endif
725              
726              PAL_BEGIN_EXTERNC
727              
728              #if defined(_MSC_VER)
729              extern SECURITY_DESCRIPTOR g_SecurityDescriptor;
730              extern SECURITY_ATTRIBUTES g_SecurityAttributes;
731              #endif
732              
733              PAL_END_EXTERNC
734              
735              /*
736 krisbash 1.1 **==============================================================================
737              **
738              ** SystemMalloc()
739              ** SystemCalloc()
740              ** SystemRealloc()
741              ** SystemFree()
742              ** SystemStrdup()
743              ** SystemWcsdup()
744              **
745              **==============================================================================
746              */
747              
748              PAL_BEGIN_EXTERNC
749              
750              PAL_INLINE void* SystemMalloc(
751                  size_t size)
752              {
753                  return malloc(size);
754              }
755              
756              PAL_INLINE void* SystemCalloc(
757 krisbash 1.1     size_t count,
758                  size_t size)
759              {
760                  return calloc(count, size);
761              }
762              
763              PAL_INLINE void* SystemRealloc(
764                  void* ptr,
765                  size_t size)
766              {
767                  return realloc(ptr, size);
768              }
769              
770              PAL_INLINE void SystemFree(
771                  void* ptr)
772              {
773                  free(ptr);
774              }
775              
776              PAL_INLINE char* SystemStrdup(
777                  const char* str)
778 krisbash 1.1 {
779              # if defined(_MSC_VER)
780                  return _strdup(str);
781              # else
782                  return strdup(str);
783              # endif
784              }
785              
786              
787              PAL_INLINE wchar_t* SystemWcsdup(
788                  const wchar_t* str)
789              {
790              # if defined(_MSC_VER)
791                  return _wcsdup(str);
792              # else
793              #  if defined(CONFIG_HAVE_WCSDUP)
794                  extern wchar_t* wcsdup(const wchar_t* str);
795                  return wcsdup(str);
796              #  else
797                  size_t len = wcslen(str);
798                  wchar_t* ptr = (wchar_t*)malloc((len + 1) * sizeof(wchar_t));
799 krisbash 1.1     if(ptr)
800                      memcpy(ptr, str, (len + 1) * sizeof(wchar_t));
801                  return ptr;
802              #  endif
803              # endif
804              }
805              
806              
807              PAL_END_EXTERNC
808              
809              /*
810              **==============================================================================
811              **
812              ** USE_ALLOCATOR
813              ** USE_PAL_ATEXIT
814              **
815              **==============================================================================
816              */
817              
818              #if defined(CONFIG_ENABLE_DEBUG) && defined(CONFIG_OS_LINUX)
819              # define USE_ALLOCATOR
820 krisbash 1.1 # define USE_PAL_ATEXIT
821              #endif
822              
823              /*
824              **==============================================================================
825              **
826              ** No Allocator:
827              **
828              **==============================================================================
829              */
830              
831              #if !defined(USE_ALLOCATOR)
832              
833              # define PAL_Malloc SystemMalloc
834              # define PAL_Calloc SystemCalloc
835              # define PAL_Realloc SystemRealloc
836              # define PAL_Free SystemFree
837              # define PAL_Strdup SystemStrdup
838              # define PAL_Wcsdup SystemWcsdup
839              
840              # if defined(CONFIG_ENABLE_WCHAR)
841 krisbash 1.1 #  define PAL_Tcsdup SystemWcsdup
842              # else
843              #  define PAL_Tcsdup SystemStrdup
844              # endif
845              
846              #endif /* !defined(USE_ALLOCATOR) */
847              
848              /*
849              **==============================================================================
850              **
851              ** Allocator:
852              **
853              **==============================================================================
854              */
855              
856              #if defined(USE_ALLOCATOR)
857              
858              PAL_BEGIN_EXTERNC
859              
860              # define ENABLE_ALLOC_FAULT_INJECTION
861              # define PAL_ALLOC_CALLSITE __FILE__, __LINE__, __FUNCTION__
862 krisbash 1.1 
863              typedef struct _AllocStats
864              {
865                  /* Number of bytes currently allocated */
866                  size_t usage;
867              
868                  /* Peak memory usage (in bytes) */
869                  size_t peakUsage;
870              
871                  /* Number of times memory was allocated */
872                  size_t numAllocs;
873              
874                  /* Number of times memory was freed */
875                  size_t numFrees;
876              }
877              AllocStats;
878              
879              AllocStats PAL_GetAllocStats();
880              
881              void PAL_DumpAllocStats();
882              
883 krisbash 1.1 void PAL_DumpAllocList();
884              
885              void PAL_DumpAllocInfo();
886              
887              size_t PAL_GetBlocksAllocated();
888              
889              void PAL_CheckBlocksAllocated(
890                  size_t oldBlocksAllocated,
891                  const char* file,
892                  size_t line,
893                  const char* function);
894              
895              # define PAL_Malloc(size) __PAL_Malloc(PAL_ALLOC_CALLSITE, size)
896              void* __PAL_Malloc(
897                  const char* file,
898                  size_t line,
899                  const char* func,
900                  size_t size);
901              
902              # define PAL_Calloc(count, size) __PAL_Calloc(PAL_ALLOC_CALLSITE, count, size)
903              void* __PAL_Calloc(
904 krisbash 1.1     const char* file,
905                  size_t line,
906                  const char* func,
907                  size_t count,
908                  size_t size);
909              
910              # define PAL_Realloc(ptr, size) __PAL_Realloc(PAL_ALLOC_CALLSITE, ptr, size)
911              void* __PAL_Realloc(
912                  const char* file,
913                  size_t line,
914                  const char* func,
915                  void* ptr,
916                  size_t size);
917              
918              # define PAL_Free(ptr) __PAL_Free(PAL_ALLOC_CALLSITE, ptr)
919              void __PAL_Free(
920                  const char* file,
921                  size_t line,
922                  const char* func,
923                  void* ptr);
924              
925 krisbash 1.1 #define PAL_Strdup(str) __PAL_Strdup(PAL_ALLOC_CALLSITE, str)
926              char* __PAL_Strdup(
927                  const char* file,
928                  size_t line,
929                  const char* func,
930                  const char* str);
931              
932              #define PAL_Wcsdup(str) __PAL_Wcsdup(PAL_ALLOC_CALLSITE, str)
933              wchar_t* __PAL_Wcsdup(
934                  const char* file,
935                  size_t line,
936                  const char* func,
937                  const wchar_t* str);
938              
939              #define PAL_Tcsdup(str) __PAL_Tcsdup(PAL_ALLOC_CALLSITE, str)
940              PAL_Char* __PAL_Tcsdup(
941                  const char* file,
942                  size_t line,
943                  const char* func,
944                  const PAL_Char* str);
945              
946 krisbash 1.1 PAL_END_EXTERNC
947              
948              #endif /* defined(USE_ALLOCATOR) */
949              
950              #if 0
951              # define malloc __malloc_undefined__
952              # define calloc __calloc_undefined__
953              # define realloc __realloc_undefined__
954              # define free __free_undefined__
955              # define strdup __strdup_undefined__
956              # define wcsdup __wcsdup_undefined__
957              #endif
958              
959              /*
960              **==============================================================================
961              **
962              ** PAL_Atexit()
963              ** PAL_AtexitCall()
964              **
965              **==============================================================================
966              */
967 krisbash 1.1 
968              #if defined(USE_PAL_ATEXIT)
969              
970              # define PAL_ATEXIT_MAX 32
971              
972              PAL_BEGIN_EXTERNC
973              
974              /* Install an at-exit function (to be called on exit() */
975              int PAL_Atexit(void (*func)());
976              
977              /* Call all the at-exit funcs now */
978              int PAL_AtexitCall();
979              
980              PAL_END_EXTERNC
981              
982              #else /* defined(USE_PAL_ATEXIT) */
983              # define PAL_Atexit atexit
984              #endif /* defined(USE_PAL_ATEXIT) */
985              
986              #endif /* _pal_palcommon_h */

ViewCVS 0.9.2