![]() ![]() |
![]() |
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 krisbash 1.2 #define WIN32_FROM_HRESULT(hr) (HRESULT_FACILITY(hr) == FACILITY_WIN32 ? HRESULT_CODE(hr) : hr) 36 #endif | ||
37 krisbash 1.1 #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 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 krisbash 1.1 #define MAX_PATH 0x00000104 59 typedef unsigned long long uint64; 60 #endif 61 62 /* 63 **============================================================================== 64 ** 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 krisbash 1.1 ** 80 **============================================================================== 81 */ 82 83 #if !defined(CONFIG_HAVE_FUNCTION_MACRO) 84 # if !defined(_MSC_VER) && !defined(__FUNCTION__) 85 # 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 krisbash 1.1 # 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 # 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 krisbash 1.1 #endif 122 123 /* 124 **============================================================================== 125 ** 126 ** PAL_CALL macro 127 ** 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 krisbash 1.1 */ 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 # define PAL_EXPORT_API __attribute__((visibility("default"))) 149 # define PAL_IMPORT_API /* empty */ 150 #elif defined(sun) | ||
151 krisbash 1.2 # define PAL_EXPORT_API __global | ||
152 krisbash 1.1 # 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 # define PAL_END_EXTERNC } 170 #else 171 # define PAL_BEGIN_EXTERNC 172 # define PAL_END_EXTERNC 173 krisbash 1.1 #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 ** 191 ** PAL_INLINE macro 192 ** 193 **============================================================================== 194 krisbash 1.1 */ 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 krisbash 1.2 | ||
208 krisbash 1.1 /* 209 **============================================================================== 210 ** 211 ** 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 krisbash 1.1 **============================================================================== 230 */ 231 232 #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 krisbash 1.1 **============================================================================== 251 ** 252 ** PAL_HAVE_POSIX 253 ** 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 krisbash 1.1 #endif 272 273 /* 274 **============================================================================== 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 krisbash 1.1 #define PAL_SINT16_MIN (SHRT_MIN) 293 #define PAL_SINT16_MAX (SHRT_MAX) 294 295 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 krisbash 1.1 314 typedef unsigned char PAL_Boolean; 315 316 #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 krisbash 1.1 335 /* 336 **============================================================================== 337 ** 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 krisbash 1.2 | ||
353 krisbash 1.1 # ifndef _Inout_ 354 # define _Inout_ 355 # endif 356 357 # ifndef _Return_type_success_ 358 # 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 krisbash 1.1 # define _Post_z_ 375 # endif 376 377 # ifndef _Out_writes_ 378 # define _Out_writes_(size) 379 # 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 krisbash 1.1 # endif 396 397 # ifndef _Deref_post_z_ 398 # define _Deref_post_z_ 399 # endif 400 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 krisbash 1.1 417 # ifndef _In_opt_z_ 418 # define _In_opt_z_ 419 # endif 420 421 # 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 krisbash 1.1 # ifndef _Frees_ptr_ 438 # define _Frees_ptr_ 439 # endif 440 441 # ifndef _Const_ 442 # 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 krisbash 1.1 # define _Outptr_ 459 # endif 460 461 # ifndef _Outptr_result_buffer_ 462 # define _Outptr_result_buffer_(size) 463 # endif 464 | ||
465 krisbash 1.2 # ifndef _Outptr_result_nullonfailure_ | ||
466 krisbash 1.1 # 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 krisbash 1.2 # ifndef _Analysis_noreturn_ | ||
482 krisbash 1.1 # define _Analysis_noreturn_ 483 # endif 484 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 krisbash 1.1 # endif 504 505 # 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 krisbash 1.1 525 # ifndef _Writable_elements_ 526 # 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 krisbash 1.1 # ifndef _In_bytecount_ 546 # define _In_bytecount_(size) 547 # 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 krisbash 1.1 ** 567 ** PAL_MAX_PATH_SIZE 568 ** 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 krisbash 1.1 588 /* 589 **============================================================================== 590 ** 591 ** PAL_Timestamp (equivalent to MI_Timestamp) 592 ** | ||
593 krisbash 1.2 ** Represents a timestamp as described in the CIM Infrastructure | ||
594 krisbash 1.1 ** 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 PAL_Uint32 microseconds; 611 PAL_Sint32 utc; 612 } 613 PAL_Timestamp; 614 615 krisbash 1.1 /* 616 **============================================================================== 617 ** 618 ** struct PAL_Interval (equivalent to MI_Interval) 619 ** | ||
620 krisbash 1.2 ** Represents an interval as described in the CIM Infrastructure | ||
621 krisbash 1.1 ** 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 /* 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 krisbash 1.1 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 */ 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 krisbash 1.1 } 664 PAL_Datetime; 665 666 /* 667 **============================================================================== 668 ** 669 ** PAL_PREFETCH 670 ** 671 **============================================================================== 672 */ 673 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 krisbash 1.1 ** 685 ** PAL_STATIC_ASSERT 686 ** 687 ** Example usage: 688 ** PAL_STATIC_ASSERT(sizeof(MI_CompositeDisposable) == sizeof(CompositeDisposable)) | ||
689 krisbash 1.2 ** (ensures that size of a public struct (with 3 reserved ptrdiff_t fields) | ||
690 krisbash 1.1 ** is the same as size of an internal struct) 691 **============================================================================== 692 */ 693 694 #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 krisbash 1.1 712 /* 713 **============================================================================== 714 ** 715 ** 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 krisbash 1.1 733 PAL_END_EXTERNC 734 735 /* 736 **============================================================================== 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 krisbash 1.1 return malloc(size); 754 } 755 756 PAL_INLINE void* SystemCalloc( 757 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 krisbash 1.1 } 775 776 PAL_INLINE char* SystemStrdup( 777 const char* str) 778 { 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 krisbash 1.1 return wcsdup(str); 796 # else 797 size_t len = wcslen(str); 798 wchar_t* ptr = (wchar_t*)malloc((len + 1) * sizeof(wchar_t)); 799 if(ptr) 800 memcpy(ptr, str, (len + 1) * sizeof(wchar_t)); 801 return ptr; 802 # endif 803 # endif 804 } 805 806 PAL_END_EXTERNC 807 808 /* 809 **============================================================================== 810 ** 811 ** USE_ALLOCATOR 812 ** USE_PAL_ATEXIT 813 ** 814 **============================================================================== 815 */ 816 krisbash 1.1 817 #if defined(CONFIG_ENABLE_DEBUG) && defined(CONFIG_OS_LINUX) 818 # define USE_ALLOCATOR 819 # define USE_PAL_ATEXIT 820 #endif 821 822 /* 823 **============================================================================== 824 ** 825 ** No Allocator: 826 ** 827 **============================================================================== 828 */ 829 830 #if !defined(USE_ALLOCATOR) 831 832 # define PAL_Malloc SystemMalloc 833 # define PAL_Calloc SystemCalloc 834 # define PAL_Realloc SystemRealloc 835 # define PAL_Free SystemFree 836 # define PAL_Strdup SystemStrdup 837 krisbash 1.1 # define PAL_Wcsdup SystemWcsdup 838 839 # if defined(CONFIG_ENABLE_WCHAR) 840 # define PAL_Tcsdup SystemWcsdup 841 # else 842 # define PAL_Tcsdup SystemStrdup 843 # endif 844 845 #endif /* !defined(USE_ALLOCATOR) */ 846 847 /* 848 **============================================================================== 849 ** 850 ** Allocator: 851 ** 852 **============================================================================== 853 */ 854 855 #if defined(USE_ALLOCATOR) 856 857 PAL_BEGIN_EXTERNC 858 krisbash 1.1 859 # define ENABLE_ALLOC_FAULT_INJECTION 860 # define PAL_ALLOC_CALLSITE __FILE__, __LINE__, __FUNCTION__ 861 862 typedef struct _AllocStats 863 { 864 /* Number of bytes currently allocated */ 865 size_t usage; 866 867 /* Peak memory usage (in bytes) */ 868 size_t peakUsage; 869 870 /* Number of times memory was allocated */ 871 size_t numAllocs; 872 873 /* Number of times memory was freed */ 874 size_t numFrees; 875 } 876 AllocStats; 877 878 AllocStats PAL_GetAllocStats(); 879 krisbash 1.1 880 void PAL_DumpAllocStats(); 881 882 void PAL_DumpAllocList(); 883 884 void PAL_DumpAllocInfo(); 885 886 size_t PAL_GetBlocksAllocated(); 887 888 void PAL_CheckBlocksAllocated( 889 size_t oldBlocksAllocated, 890 const char* file, 891 size_t line, 892 const char* function); 893 894 # define PAL_Malloc(size) __PAL_Malloc(PAL_ALLOC_CALLSITE, size) 895 void* __PAL_Malloc( 896 const char* file, 897 size_t line, 898 const char* func, 899 size_t size); 900 krisbash 1.1 901 # define PAL_Calloc(count, size) __PAL_Calloc(PAL_ALLOC_CALLSITE, count, size) 902 void* __PAL_Calloc( 903 const char* file, 904 size_t line, 905 const char* func, 906 size_t count, 907 size_t size); 908 909 # define PAL_Realloc(ptr, size) __PAL_Realloc(PAL_ALLOC_CALLSITE, ptr, size) 910 void* __PAL_Realloc( 911 const char* file, 912 size_t line, 913 const char* func, 914 void* ptr, 915 size_t size); 916 917 # define PAL_Free(ptr) __PAL_Free(PAL_ALLOC_CALLSITE, ptr) 918 void __PAL_Free( 919 const char* file, 920 size_t line, 921 krisbash 1.1 const char* func, 922 void* ptr); 923 924 #define PAL_Strdup(str) __PAL_Strdup(PAL_ALLOC_CALLSITE, str) 925 char* __PAL_Strdup( 926 const char* file, 927 size_t line, 928 const char* func, 929 const char* str); 930 931 #define PAL_Wcsdup(str) __PAL_Wcsdup(PAL_ALLOC_CALLSITE, str) 932 wchar_t* __PAL_Wcsdup( 933 const char* file, 934 size_t line, 935 const char* func, 936 const wchar_t* str); 937 938 #define PAL_Tcsdup(str) __PAL_Tcsdup(PAL_ALLOC_CALLSITE, str) 939 PAL_Char* __PAL_Tcsdup( 940 const char* file, 941 size_t line, 942 krisbash 1.1 const char* func, 943 const PAL_Char* str); 944 945 PAL_END_EXTERNC 946 947 #endif /* defined(USE_ALLOCATOR) */ 948 949 #if 0 950 # define malloc __malloc_undefined__ 951 # define calloc __calloc_undefined__ 952 # define realloc __realloc_undefined__ 953 # define free __free_undefined__ 954 # define strdup __strdup_undefined__ 955 # define wcsdup __wcsdup_undefined__ 956 #endif 957 958 /* 959 **============================================================================== 960 ** 961 ** PAL_Atexit() 962 ** PAL_AtexitCall() 963 krisbash 1.1 ** 964 **============================================================================== 965 */ 966 967 #if defined(USE_PAL_ATEXIT) 968 969 # define PAL_ATEXIT_MAX 32 970 971 PAL_BEGIN_EXTERNC 972 973 /* Install an at-exit function (to be called on exit() */ 974 int PAL_Atexit(void (*func)()); 975 976 /* Call all the at-exit funcs now */ 977 int PAL_AtexitCall(); 978 979 PAL_END_EXTERNC 980 981 #else /* defined(USE_PAL_ATEXIT) */ 982 # define PAL_Atexit atexit 983 #endif /* defined(USE_PAL_ATEXIT) */ 984 krisbash 1.1 985 #endif /* _pal_palcommon_h */ |
ViewCVS 0.9.2 |