Changeset 31157 in vbox
- Timestamp:
- Jul 28, 2010 3:15:35 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/mem.h
r30827 r31157 56 56 #define RTMEM_ALIGNMENT 8 57 57 58 /** 59 * Allocates temporary memory. 58 /** @def RTMEM_TAG 59 * The default allocation tag used by the RTMem allocation APIs. 60 * 61 * When not defined before the inclusion of iprt/mem.h or iprt/memobj.h, this 62 * will default to the pointer to the current file name. The memory API will 63 * make of use of this as pointer to a volatile but read-only string. 64 */ 65 #ifndef RTMEM_TAG 66 # define RTMEM_TAG (__FILE__) 67 #endif 68 69 70 /** @name Allocate temporary memory. 71 * @{ */ 72 /** 73 * Allocates temporary memory with default tag. 60 74 * 61 75 * Temporary memory blocks are used for not too large memory blocks which … … 65 79 * 66 80 * @returns Pointer to the allocated memory. 67 * @returns NULL on failure .81 * @returns NULL on failure, assertion raised in strict builds. 68 82 * @param cb Size in bytes of the memory block to allocated. 69 83 */ 70 RTDECL(void *) RTMemTmpAlloc(size_t cb) RT_NO_THROW; 71 72 /** 73 * Allocates zero'ed temporary memory. 84 #define RTMemTmpAlloc(cb) RTMemTmpAllocTag((cb), RTMEM_TAG) 85 86 /** 87 * Allocates temporary memory with custom tag. 88 * 89 * Temporary memory blocks are used for not too large memory blocks which 90 * are believed not to stick around for too long. Using this API instead 91 * of RTMemAlloc() not only gives the heap manager room for optimization 92 * but makes the code easier to read. 93 * 94 * @returns Pointer to the allocated memory. 95 * @returns NULL on failure, assertion raised in strict builds. 96 * @param cb Size in bytes of the memory block to allocated. 97 * @param pszTag Allocation tag used for statistics and such. 98 */ 99 RTDECL(void *) RTMemTmpAllocTag(size_t cb, const char *pszTag) RT_NO_THROW; 100 101 /** 102 * Allocates zero'ed temporary memory with default tag. 74 103 * 75 104 * Same as RTMemTmpAlloc() but the memory will be zero'ed. 76 105 * 77 106 * @returns Pointer to the allocated memory. 78 * @returns NULL on failure .107 * @returns NULL on failure, assertion raised in strict builds. 79 108 * @param cb Size in bytes of the memory block to allocated. 80 109 */ 81 RTDECL(void *) RTMemTmpAllocZ(size_t cb) RT_NO_THROW; 110 #define RTMemTmpAllocZ(cb) RTMemTmpAllocZTag((cb), RTMEM_TAG) 111 112 /** 113 * Allocates zero'ed temporary memory with custom tag. 114 * 115 * Same as RTMemTmpAlloc() but the memory will be zero'ed. 116 * 117 * @returns Pointer to the allocated memory. 118 * @returns NULL on failure, assertion raised in strict builds. 119 * @param cb Size in bytes of the memory block to allocated. 120 * @param pszTag Allocation tag used for statistics and such. 121 */ 122 RTDECL(void *) RTMemTmpAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW; 82 123 83 124 /** … … 88 129 RTDECL(void) RTMemTmpFree(void *pv) RT_NO_THROW; 89 130 90 91 /** 92 * Allocates memory. 93 * 94 * @returns Pointer to the allocated memory. 95 * @returns NULL on failure. 131 /** @} */ 132 133 134 /** 135 * Allocates memory with default tag. 136 * 137 * @returns Pointer to the allocated memory. 138 * @returns NULL on failure, assertion raised in strict builds. 96 139 * @param cb Size in bytes of the memory block to allocated. 97 */ 98 RTDECL(void *) RTMemAlloc(size_t cb) RT_NO_THROW; 99 100 /** 101 * Allocates zero'ed memory. 140 * @param pszTag Allocation tag used for statistics and such. 141 */ 142 #define RTMemAlloc(cb) RTMemAllocTag((cb), RTMEM_TAG) 143 144 /** 145 * Allocates memory with custom tag. 146 * 147 * @returns Pointer to the allocated memory. 148 * @returns NULL on failure, assertion raised in strict builds. 149 * @param cb Size in bytes of the memory block to allocated. 150 * @param pszTag Allocation tag used for statistics and such. 151 */ 152 RTDECL(void *) RTMemAllocTag(size_t cb, const char *pszTag) RT_NO_THROW; 153 154 /** 155 * Allocates zero'ed memory with default tag. 102 156 * 103 157 * Instead of memset(pv, 0, sizeof()) use this when you want zero'ed … … 109 163 * @param cb Size in bytes of the memory block to allocated. 110 164 */ 111 RTDECL(void *) RTMemAllocZ(size_t cb) RT_NO_THROW; 165 #define RTMemAllocZ(cb) RTMemAllocZTag((cb), RTMEM_TAG) 166 167 /** 168 * Allocates zero'ed memory with custom tag. 169 * 170 * Instead of memset(pv, 0, sizeof()) use this when you want zero'ed 171 * memory. This keeps the code smaller and the heap can skip the memset 172 * in about 0.42% of calls :-). 173 * 174 * @returns Pointer to the allocated memory. 175 * @returns NULL on failure. 176 * @param cb Size in bytes of the memory block to allocated. 177 * @param pszTag Allocation tag used for statistics and such. 178 */ 179 RTDECL(void *) RTMemAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW; 112 180 113 181 /** … … 118 186 * @param cbUnaligned The unaligned size. 119 187 */ 120 RTDECL(void *) RTMemAllocVar(size_t cbUnaligned); 188 #define RTMemAllocVar(cbUnaligned) RTMemAllocVarTag((cbUnaligned), RTMEM_TAG) 189 190 /** 191 * Wrapper around RTMemAllocTag for automatically aligning variable sized 192 * allocations so that the various electric fence heaps works correctly. 193 * 194 * @returns See RTMemAlloc. 195 * @param cbUnaligned The unaligned size. 196 * @param pszTag Allocation tag used for statistics and such. 197 */ 198 RTDECL(void *) RTMemAllocVarTag(size_t cbUnaligned, const char *pszTag) RT_NO_THROW; 121 199 122 200 /** … … 127 205 * @param cbUnaligned The unaligned size. 128 206 */ 129 RTDECL(void *) RTMemAllocZVar(size_t cbUnaligned); 130 131 /** 132 * Duplicates a chunk of memory into a new heap block. 207 #define RTMemAllocZVar(cbUnaligned) RTMemAllocZVarTag((cbUnaligned), RTMEM_TAG) 208 209 /** 210 * Wrapper around RTMemAllocZTag for automatically aligning variable sized 211 * allocations so that the various electric fence heaps works correctly. 212 * 213 * @returns See RTMemAllocZ. 214 * @param cbUnaligned The unaligned size. 215 * @param pszTag Allocation tag used for statistics and such. 216 */ 217 RTDECL(void *) RTMemAllocZVarTag(size_t cbUnaligned, const char *pszTag) RT_NO_THROW; 218 219 /** 220 * Duplicates a chunk of memory into a new heap block (default tag). 133 221 * 134 222 * @returns New heap block with the duplicate data. … … 137 225 * @param cb The amount of memory to duplicate. 138 226 */ 139 RTDECL(void *) RTMemDup(const void *pvSrc, size_t cb) RT_NO_THROW; 140 141 /** 142 * Duplicates a chunk of memory into a new heap block with some 143 * additional zeroed memory. 227 #define RTMemDup(pvSrc, cb) RTMemDupTag((pvSrc), (cb), RTMEM_TAG) 228 229 /** 230 * Duplicates a chunk of memory into a new heap block (custom tag). 231 * 232 * @returns New heap block with the duplicate data. 233 * @returns NULL if we're out of memory. 234 * @param pvSrc The memory to duplicate. 235 * @param cb The amount of memory to duplicate. 236 * @param pszTag Allocation tag used for statistics and such. 237 */ 238 RTDECL(void *) RTMemDupTag(const void *pvSrc, size_t cb, const char *pszTag) RT_NO_THROW; 239 240 /** 241 * Duplicates a chunk of memory into a new heap block with some additional 242 * zeroed memory (default tag). 144 243 * 145 244 * @returns New heap block with the duplicate data. … … 149 248 * @param cbExtra The amount of extra memory to allocate and zero. 150 249 */ 151 RTDECL(void *) RTMemDupEx(const void *pvSrc, size_t cbSrc, size_t cbExtra) RT_NO_THROW; 152 153 /** 154 * Reallocates memory. 250 #define RTMemDupEx(pvSrc, cbSrc, cbExtra) RTMemDupExTag((pvSrc), (cbSrc), (cbExtra), RTMEM_TAG) 251 252 /** 253 * Duplicates a chunk of memory into a new heap block with some additional 254 * zeroed memory (default tag). 255 * 256 * @returns New heap block with the duplicate data. 257 * @returns NULL if we're out of memory. 258 * @param pvSrc The memory to duplicate. 259 * @param cbSrc The amount of memory to duplicate. 260 * @param cbExtra The amount of extra memory to allocate and zero. 261 * @param pszTag Allocation tag used for statistics and such. 262 */ 263 RTDECL(void *) RTMemDupExTag(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag) RT_NO_THROW; 264 265 /** 266 * Reallocates memory with default tag. 155 267 * 156 268 * @returns Pointer to the allocated memory. … … 159 271 * @param cbNew The new block size (in bytes). 160 272 */ 161 RTDECL(void *) RTMemRealloc(void *pvOld, size_t cbNew) RT_NO_THROW; 273 #define RTMemRealloc(pvOld, cbNew) RTMemReallocTag((pvOld), (cbNew), RTMEM_TAG) 274 275 /** 276 * Reallocates memory with custom tag. 277 * 278 * @returns Pointer to the allocated memory. 279 * @returns NULL on failure. 280 * @param pvOld The memory block to reallocate. 281 * @param cbNew The new block size (in bytes). 282 * @param pszTag Allocation tag used for statistics and such. 283 */ 284 RTDECL(void *) RTMemReallocTag(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW; 162 285 163 286 /** … … 168 291 RTDECL(void) RTMemFree(void *pv) RT_NO_THROW; 169 292 170 /** 171 * Allocates memory which may contain code. 293 294 295 /** 296 * Allocates memory which may contain code (default tag). 172 297 * 173 298 * @returns Pointer to the allocated memory. … … 175 300 * @param cb Size in bytes of the memory block to allocate. 176 301 */ 177 RTDECL(void *) RTMemExecAlloc(size_t cb) RT_NO_THROW; 302 #define RTMemExecAlloc(cb) RTMemExecAllocTag((cb), RTMEM_TAG) 303 304 /** 305 * Allocates memory which may contain code (custom tag). 306 * 307 * @returns Pointer to the allocated memory. 308 * @returns NULL on failure. 309 * @param cb Size in bytes of the memory block to allocate. 310 * @param pszTag Allocation tag used for statistics and such. 311 */ 312 RTDECL(void *) RTMemExecAllocTag(size_t cb, const char *pszTag) RT_NO_THROW; 178 313 179 314 /** … … 204 339 205 340 /** 206 * Allocate page aligned memory .341 * Allocate page aligned memory with default tag. 207 342 * 208 343 * @returns Pointer to the allocated memory. … … 210 345 * @param cb Size of the memory block. Will be rounded up to page size. 211 346 */ 212 RTDECL(void *) RTMemPageAlloc(size_t cb) RT_NO_THROW; 213 214 /** 215 * Allocate zero'ed page aligned memory.347 #define RTMemPageAlloc(cb) RTMemPageAllocTag((cb), RTMEM_TAG) 348 349 /** 350 * Allocate page aligned memory with custom tag. 216 351 * 217 352 * @returns Pointer to the allocated memory. 218 353 * @returns NULL if we're out of memory. 219 354 * @param cb Size of the memory block. Will be rounded up to page size. 220 */ 221 RTDECL(void *) RTMemPageAllocZ(size_t cb) RT_NO_THROW; 355 * @param pszTag Allocation tag used for statistics and such. 356 */ 357 RTDECL(void *) RTMemPageAllocTag(size_t cb, const char *pszTag) RT_NO_THROW; 358 359 /** 360 * Allocate zero'ed page aligned memory with default tag. 361 * 362 * @returns Pointer to the allocated memory. 363 * @returns NULL if we're out of memory. 364 * @param cb Size of the memory block. Will be rounded up to page size. 365 */ 366 #define RTMemPageAllocZ(cb) RTMemPageAllocZTag((cb), RTMEM_TAG) 367 368 /** 369 * Allocate zero'ed page aligned memory with custom tag. 370 * 371 * @returns Pointer to the allocated memory. 372 * @returns NULL if we're out of memory. 373 * @param cb Size of the memory block. Will be rounded up to page size. 374 * @param pszTag Allocation tag used for statistics and such. 375 */ 376 RTDECL(void *) RTMemPageAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW; 222 377 223 378 /** … … 360 515 361 516 /** 362 * Same as RTMemTmpAlloc () except that it's fenced.517 * Same as RTMemTmpAllocTag() except that it's fenced. 363 518 * 364 519 * @returns Pointer to the allocated memory. 365 520 * @returns NULL on failure. 366 521 * @param cb Size in bytes of the memory block to allocate. 367 */ 368 RTDECL(void *) RTMemEfTmpAlloc(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW; 369 370 /** 371 * Same as RTMemTmpAllocZ() except that it's fenced. 522 * @param pszTag Allocation tag used for statistics and such. 523 */ 524 RTDECL(void *) RTMemEfTmpAlloc(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW; 525 526 /** 527 * Same as RTMemTmpAllocZTag() except that it's fenced. 372 528 * 373 529 * @returns Pointer to the allocated memory. 374 530 * @returns NULL on failure. 375 531 * @param cb Size in bytes of the memory block to allocate. 376 */ 377 RTDECL(void *) RTMemEfTmpAllocZ(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW; 532 * @param pszTag Allocation tag used for statistics and such. 533 */ 534 RTDECL(void *) RTMemEfTmpAllocZ(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW; 378 535 379 536 /** … … 385 542 386 543 /** 387 * Same as RTMemAlloc () except that it's fenced.544 * Same as RTMemAllocTag() except that it's fenced. 388 545 * 389 546 * @returns Pointer to the allocated memory. Free with RTMemEfFree(). 390 547 * @returns NULL on failure. 391 548 * @param cb Size in bytes of the memory block to allocate. 392 */ 393 RTDECL(void *) RTMemEfAlloc(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW; 394 395 /** 396 * Same as RTMemAllocZ() except that it's fenced. 549 * @param pszTag Allocation tag used for statistics and such. 550 */ 551 RTDECL(void *) RTMemEfAlloc(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW; 552 553 /** 554 * Same as RTMemAllocZTag() except that it's fenced. 397 555 * 398 556 * @returns Pointer to the allocated memory. 399 557 * @returns NULL on failure. 400 558 * @param cb Size in bytes of the memory block to allocate. 401 */ 402 RTDECL(void *) RTMemEfAllocZ(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW; 403 404 /** 405 * Same as RTMemAllocVar() except that it's fenced. 559 * @param pszTag Allocation tag used for statistics and such. 560 */ 561 RTDECL(void *) RTMemEfAllocZ(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW; 562 563 /** 564 * Same as RTMemAllocVarTag() except that it's fenced. 406 565 * 407 566 * @returns Pointer to the allocated memory. Free with RTMemEfFree(). 408 567 * @returns NULL on failure. 409 568 * @param cbUnaligned Size in bytes of the memory block to allocate. 410 */ 411 RTDECL(void *) RTMemEfAllocVar(size_t cbUnaligned, RT_SRC_POS_DECL) RT_NO_THROW; 412 413 /** 414 * Same as RTMemAllocZVar() except that it's fenced. 569 * @param pszTag Allocation tag used for statistics and such. 570 */ 571 RTDECL(void *) RTMemEfAllocVar(size_t cbUnaligned, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW; 572 573 /** 574 * Same as RTMemAllocZVarTag() except that it's fenced. 415 575 * 416 576 * @returns Pointer to the allocated memory. 417 577 * @returns NULL on failure. 418 578 * @param cbUnaligned Size in bytes of the memory block to allocate. 419 */ 420 RTDECL(void *) RTMemEfAllocZVar(size_t cbUnaligned, RT_SRC_POS_DECL) RT_NO_THROW; 421 422 /** 423 * Same as RTMemRealloc() except that it's fenced. 579 * @param pszTag Allocation tag used for statistics and such. 580 */ 581 RTDECL(void *) RTMemEfAllocZVar(size_t cbUnaligned, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW; 582 583 /** 584 * Same as RTMemReallocTag() except that it's fenced. 424 585 * 425 586 * @returns Pointer to the allocated memory. … … 427 588 * @param pvOld The memory block to reallocate. 428 589 * @param cbNew The new block size (in bytes). 429 */ 430 RTDECL(void *) RTMemEfRealloc(void *pvOld, size_t cbNew, RT_SRC_POS_DECL) RT_NO_THROW; 590 * @param pszTag Allocation tag used for statistics and such. 591 */ 592 RTDECL(void *) RTMemEfRealloc(void *pvOld, size_t cbNew, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW; 431 593 432 594 /** … … 438 600 439 601 /** 440 * Same as RTMemDup () except that it's fenced.602 * Same as RTMemDupTag() except that it's fenced. 441 603 * 442 604 * @returns New heap block with the duplicate data. … … 444 606 * @param pvSrc The memory to duplicate. 445 607 * @param cb The amount of memory to duplicate. 446 */ 447 RTDECL(void *) RTMemEfDup(const void *pvSrc, size_t cb, RT_SRC_POS_DECL) RT_NO_THROW; 448 449 /** 450 * Same as RTMemEfDupEx except that it's fenced. 608 * @param pszTag Allocation tag used for statistics and such. 609 */ 610 RTDECL(void *) RTMemEfDup(const void *pvSrc, size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW; 611 612 /** 613 * Same as RTMemEfDupExTag except that it's fenced. 451 614 * 452 615 * @returns New heap block with the duplicate data. … … 455 618 * @param cbSrc The amount of memory to duplicate. 456 619 * @param cbExtra The amount of extra memory to allocate and zero. 457 */ 458 RTDECL(void *) RTMemEfDupEx(const void *pvSrc, size_t cbSrc, size_t cbExtra, RT_SRC_POS_DECL) RT_NO_THROW; 620 * @param pszTag Allocation tag used for statistics and such. 621 */ 622 RTDECL(void *) RTMemEfDupEx(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW; 459 623 460 624 /** @def RTMEM_WRAP_TO_EF_APIS … … 462 626 */ 463 627 #if defined(RTMEM_WRAP_TO_EF_APIS) && defined(IN_RING3) && !defined(RTMEM_NO_WRAP_TO_EF_APIS) 464 # define RTMemTmpAlloc (cb) RTMemEfTmpAlloc((cb), RT_SRC_POS)465 # define RTMemTmpAllocZ (cb) RTMemEfTmpAllocZ((cb), RT_SRC_POS)466 # define RTMemTmpFree(pv) RTMemEfTmpFree((pv), RT_SRC_POS)467 # define RTMemAlloc (cb) RTMemEfAlloc((cb), RT_SRC_POS)468 # define RTMemAllocZ (cb) RTMemEfAllocZ((cb), RT_SRC_POS)469 # define RTMemAllocVar (cbUnaligned) RTMemEfAllocVar((cbUnaligned), RT_SRC_POS)470 # define RTMemAllocZVar (cbUnaligned) RTMemEfAllocZVar((cbUnaligned), RT_SRC_POS)471 # define RTMemRealloc (pvOld, cbNew) RTMemEfRealloc((pvOld), (cbNew), RT_SRC_POS)472 # define RTMemFree(pv) RTMemEfFree((pv), RT_SRC_POS)473 # define RTMemDup (pvSrc, cb) RTMemEfDup((pvSrc), (cb), RT_SRC_POS)474 # define RTMemDupEx (pvSrc, cbSrc, cbExtra) RTMemEfDupEx((pvSrc), (cbSrc), (cbExtra), RT_SRC_POS)628 # define RTMemTmpAllocTag(cb, pszTag) RTMemEfTmpAlloc((cb), (pszTag), RT_SRC_POS) 629 # define RTMemTmpAllocZTag(cb, pszTag) RTMemEfTmpAllocZ((cb), (pszTag), RT_SRC_POS) 630 # define RTMemTmpFree(pv) RTMemEfTmpFree((pv), RT_SRC_POS) 631 # define RTMemAllocTag(cb, pszTag) RTMemEfAlloc((cb), (pszTag), RT_SRC_POS) 632 # define RTMemAllocZTag(cb, pszTag) RTMemEfAllocZ((cb), (pszTag), RT_SRC_POS) 633 # define RTMemAllocVarTag(cbUnaligned, pszTag) RTMemEfAllocVar((cbUnaligned), (pszTag), RT_SRC_POS) 634 # define RTMemAllocZVarTag(cbUnaligned, pszTag) RTMemEfAllocZVar((cbUnaligned), (pszTag), RT_SRC_POS) 635 # define RTMemReallocTag(pvOld, cbNew, pszTag) RTMemEfRealloc((pvOld), (cbNew), (pszTag), RT_SRC_POS) 636 # define RTMemFree(pv) RTMemEfFree((pv), RT_SRC_POS) 637 # define RTMemDupTag(pvSrc, cb, pszTag) RTMemEfDup((pvSrc), (cb), (pszTag), RT_SRC_POS) 638 # define RTMemDupExTag(pvSrc, cbSrc, cbExtra, pszTag) RTMemEfDupEx((pvSrc), (cbSrc), (cbExtra), (pszTag), RT_SRC_POS) 475 639 #endif 476 640 #ifdef DOXYGEN_RUNNING … … 479 643 480 644 /** 481 * Fenced drop-in replacement for RTMemTmpAlloc .482 * @copydoc RTMemTmpAlloc 483 */ 484 RTDECL(void *) RTMemEfTmpAllocNP(size_t cb ) RT_NO_THROW;485 486 /** 487 * Fenced drop-in replacement for RTMemTmpAllocZ .488 * @copydoc RTMemTmpAllocZ 489 */ 490 RTDECL(void *) RTMemEfTmpAllocZNP(size_t cb ) RT_NO_THROW;491 492 /** 493 * Fenced drop-in replacement for RTMemTmpFree .494 * @copydoc RTMemTmpFree 645 * Fenced drop-in replacement for RTMemTmpAllocTag. 646 * @copydoc RTMemTmpAllocTag 647 */ 648 RTDECL(void *) RTMemEfTmpAllocNP(size_t cb, const char *pszTag) RT_NO_THROW; 649 650 /** 651 * Fenced drop-in replacement for RTMemTmpAllocZTag. 652 * @copydoc RTMemTmpAllocZTag 653 */ 654 RTDECL(void *) RTMemEfTmpAllocZNP(size_t cb, const char *pszTag) RT_NO_THROW; 655 656 /** 657 * Fenced drop-in replacement for RTMemTmpFreeTag. 658 * @copydoc RTMemTmpFreeTag 495 659 */ 496 660 RTDECL(void) RTMemEfTmpFreeNP(void *pv) RT_NO_THROW; 497 661 498 662 /** 499 * Fenced drop-in replacement for RTMemAlloc .500 * @copydoc RTMemAlloc 501 */ 502 RTDECL(void *) RTMemEfAllocNP(size_t cb ) RT_NO_THROW;503 504 /** 505 * Fenced drop-in replacement for RTMemAllocZ .506 * @copydoc RTMemAllocZ 507 */ 508 RTDECL(void *) RTMemEfAllocZNP(size_t cb ) RT_NO_THROW;509 510 /** 511 * Fenced drop-in replacement for RTMemAllocVar 512 * @copydoc RTMemAllocVar 513 */ 514 RTDECL(void *) RTMemEfAllocVarNP(size_t cbUnaligned ) RT_NO_THROW;515 516 /** 517 * Fenced drop-in replacement for RTMemAllocZVar .518 * @copydoc RTMemAllocZVar 519 */ 520 RTDECL(void *) RTMemEfAllocZVarNP(size_t cbUnaligned ) RT_NO_THROW;521 522 /** 523 * Fenced drop-in replacement for RTMemRealloc .524 * @copydoc RTMemRealloc 525 */ 526 RTDECL(void *) RTMemEfReallocNP(void *pvOld, size_t cbNew ) RT_NO_THROW;663 * Fenced drop-in replacement for RTMemAllocTag. 664 * @copydoc RTMemAllocTag 665 */ 666 RTDECL(void *) RTMemEfAllocNP(size_t cb, const char *pszTag) RT_NO_THROW; 667 668 /** 669 * Fenced drop-in replacement for RTMemAllocZTag. 670 * @copydoc RTMemAllocZTag 671 */ 672 RTDECL(void *) RTMemEfAllocZNP(size_t cb, const char *pszTag) RT_NO_THROW; 673 674 /** 675 * Fenced drop-in replacement for RTMemAllocVarTag 676 * @copydoc RTMemAllocVarTag 677 */ 678 RTDECL(void *) RTMemEfAllocVarNP(size_t cbUnaligned, const char *pszTag) RT_NO_THROW; 679 680 /** 681 * Fenced drop-in replacement for RTMemAllocZVarTag. 682 * @copydoc RTMemAllocZVarTag 683 */ 684 RTDECL(void *) RTMemEfAllocZVarNP(size_t cbUnaligned, const char *pszTag) RT_NO_THROW; 685 686 /** 687 * Fenced drop-in replacement for RTMemReallocTag. 688 * @copydoc RTMemReallocTag 689 */ 690 RTDECL(void *) RTMemEfReallocNP(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW; 527 691 528 692 /** … … 533 697 534 698 /** 535 * Fenced drop-in replacement for RTMemDupEx .536 * @copydoc RTMemDupEx 537 */ 538 RTDECL(void *) RTMemEfDupNP(const void *pvSrc, size_t cb ) RT_NO_THROW;539 540 /** 541 * Fenced drop-in replacement for RTMemDupEx .542 * @copydoc RTMemDupEx 543 */ 544 RTDECL(void *) RTMemEfDupExNP(const void *pvSrc, size_t cbSrc, size_t cbExtra ) RT_NO_THROW;699 * Fenced drop-in replacement for RTMemDupExTag. 700 * @copydoc RTMemDupExTag 701 */ 702 RTDECL(void *) RTMemEfDupNP(const void *pvSrc, size_t cb, const char *pszTag) RT_NO_THROW; 703 704 /** 705 * Fenced drop-in replacement for RTMemDupExTag. 706 * @copydoc RTMemDupExTag 707 */ 708 RTDECL(void *) RTMemEfDupExNP(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag) RT_NO_THROW; 545 709 546 710 /** @} */ … … 655 819 void Destruct(T *) = RTMemAutoDestructor<T>, 656 820 # ifdef RTMEM_WRAP_TO_EF_APIS 657 void *Allocator(void *, size_t ) = RTMemEfReallocNP821 void *Allocator(void *, size_t, const char *) = RTMemEfReallocNP 658 822 # else 659 void *Allocator(void *, size_t ) = RTMemRealloc823 void *Allocator(void *, size_t, const char *) = RTMemReallocTag 660 824 # endif 661 825 > … … 682 846 */ 683 847 RTMemAutoPtr(size_t a_cElements, bool a_fZeroed = false) 684 : RTAutoRes<T *, Destruct, RTMemAutoNil<T> >((T *)Allocator(NULL, a_cElements * sizeof(T) ))848 : RTAutoRes<T *, Destruct, RTMemAutoNil<T> >((T *)Allocator(NULL, a_cElements * sizeof(T), RTMEM_TAG)) 685 849 { 686 850 if (a_fZeroed && RT_LIKELY(this->get() != NULL)) … … 744 908 { 745 909 this->reset(NULL); 746 T *pNewMem = (T *)Allocator(NULL, a_cElements * sizeof(T) );910 T *pNewMem = (T *)Allocator(NULL, a_cElements * sizeof(T), RTMEM_TAG); 747 911 if (a_fZeroed && RT_LIKELY(pNewMem != NULL)) 748 912 memset(pNewMem, '\0', a_cElements * sizeof(T)); … … 771 935 bool realloc(size_t a_cElements = 1) 772 936 { 773 T *aNewValue = (T *)Allocator(this->get(), a_cElements * sizeof(T) );937 T *aNewValue = (T *)Allocator(this->get(), a_cElements * sizeof(T), RTMEM_TAG); 774 938 if (RT_LIKELY(aNewValue != NULL)) 775 939 this->release(); -
trunk/include/iprt/memobj.h
r29027 r31157 4 4 5 5 /* 6 * Copyright (C) 2006-20 07Oracle Corporation6 * Copyright (C) 2006-2010 Oracle Corporation 7 7 * 8 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 37 37 */ 38 38 39 /** @def RTMEM_TAG 40 * The default allocation tag used by the RTMem allocation APIs. 41 * 42 * When not defined before the inclusion of iprt/memobj.h or iprt/mem.h, this 43 * will default to the pointer to the current file name. The memory API will 44 * make of use of this as pointer to a volatile but read-only string. 45 */ 46 #ifndef RTMEM_TAG 47 # define RTMEM_TAG (__FILE__) 48 #endif 49 39 50 #ifdef IN_RING0 40 51 … … 102 113 103 114 /** 104 * Allocates page aligned virtual kernel memory .115 * Allocates page aligned virtual kernel memory (default tag). 105 116 * 106 117 * The memory is taken from a non paged (= fixed physical memory backing) pool. … … 111 122 * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. 112 123 */ 113 RTR0DECL(int) RTR0MemObjAllocPage(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable); 114 115 /** 116 * Allocates page aligned virtual kernel memory with physical backing below 4GB. 124 #define RTR0MemObjAllocPage(pMemObj, cb, fExecutable) \ 125 RTR0MemObjAllocPageTag((pMemObj), (cb), (fExecutable), RTMEM_TAG) 126 127 /** 128 * Allocates page aligned virtual kernel memory (custom tag). 129 * 130 * The memory is taken from a non paged (= fixed physical memory backing) pool. 131 * 132 * @returns IPRT status code. 133 * @param pMemObj Where to store the ring-0 memory object handle. 134 * @param cb Number of bytes to allocate. This is rounded up to nearest page. 135 * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. 136 * @param pszTag Allocation tag used for statistics and such. 137 */ 138 RTR0DECL(int) RTR0MemObjAllocPageTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag); 139 140 /** 141 * Allocates page aligned virtual kernel memory with physical backing below 4GB 142 * (default tag). 117 143 * 118 144 * The physical memory backing the allocation is fixed. … … 123 149 * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. 124 150 */ 125 RTR0DECL(int) RTR0MemObjAllocLow(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable); 126 127 /** 128 * Allocates page aligned virtual kernel memory with contiguous physical backing below 4GB. 151 #define RTR0MemObjAllocLow(pMemObj, cb, fExecutable) \ 152 RTR0MemObjAllocLowTag((pMemObj), (cb), (fExecutable), RTMEM_TAG) 153 154 /** 155 * Allocates page aligned virtual kernel memory with physical backing below 4GB 156 * (custom tag). 129 157 * 130 158 * The physical memory backing the allocation is fixed. … … 134 162 * @param cb Number of bytes to allocate. This is rounded up to nearest page. 135 163 * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. 136 */ 137 RTR0DECL(int) RTR0MemObjAllocCont(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable); 138 139 /** 140 * Locks a range of user virtual memory. 164 * @param pszTag Allocation tag used for statistics and such. 165 */ 166 RTR0DECL(int) RTR0MemObjAllocLowTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag); 167 168 /** 169 * Allocates page aligned virtual kernel memory with contiguous physical backing 170 * below 4GB (default tag). 171 * 172 * The physical memory backing the allocation is fixed. 173 * 174 * @returns IPRT status code. 175 * @param pMemObj Where to store the ring-0 memory object handle. 176 * @param cb Number of bytes to allocate. This is rounded up to nearest page. 177 * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. 178 */ 179 #define RTR0MemObjAllocCont(pMemObj, cb, fExecutable) \ 180 RTR0MemObjAllocContTag((pMemObj), (cb), (fExecutable), RTMEM_TAG) 181 182 /** 183 * Allocates page aligned virtual kernel memory with contiguous physical backing 184 * below 4GB (custom tag). 185 * 186 * The physical memory backing the allocation is fixed. 187 * 188 * @returns IPRT status code. 189 * @param pMemObj Where to store the ring-0 memory object handle. 190 * @param cb Number of bytes to allocate. This is rounded up to nearest page. 191 * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. 192 * @param pszTag Allocation tag used for statistics and such. 193 */ 194 RTR0DECL(int) RTR0MemObjAllocContTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag); 195 196 /** 197 * Locks a range of user virtual memory (default tag). 141 198 * 142 199 * @returns IPRT status code. … … 159 216 * lifting it. 160 217 */ 161 RTR0DECL(int) RTR0MemObjLockUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess, RTR0PROCESS R0Process); 162 163 /** 164 * Locks a range of kernel virtual memory. 218 #define RTR0MemObjLockUser(pMemObj, R3Ptr, cb, fAccess, R0Process) \ 219 RTR0MemObjLockUserTag((pMemObj), (R3Ptr), (cb), (fAccess), (R0Process), RTMEM_TAG) 220 221 /** 222 * Locks a range of user virtual memory (custom tag). 223 * 224 * @returns IPRT status code. 225 * @param pMemObj Where to store the ring-0 memory object handle. 226 * @param R3Ptr User virtual address. This is rounded down to a page 227 * boundrary. 228 * @param cb Number of bytes to lock. This is rounded up to 229 * nearest page boundrary. 230 * @param fAccess The desired access, a combination of RTMEM_PROT_READ 231 * and RTMEM_PROT_WRITE. 232 * @param R0Process The process to lock pages in. NIL_R0PROCESS is an 233 * alias for the current one. 234 * @param pszTag Allocation tag used for statistics and such. 235 * 236 * @remarks RTR0MemGetAddressR3() and RTR0MemGetAddress() will return therounded 237 * down address. 238 * 239 * @remarks Linux: This API requires that the memory begin locked is in a memory 240 * mapping that is not required in any forked off child process. This 241 * is not intented as permanent restriction, feel free to help out 242 * lifting it. 243 */ 244 RTR0DECL(int) RTR0MemObjLockUserTag(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess, 245 RTR0PROCESS R0Process, const char *pszTag); 246 247 /** 248 * Locks a range of kernel virtual memory (default tag). 165 249 * 166 250 * @returns IPRT status code. … … 173 257 * @remark RTR0MemGetAddress() will return the rounded down address. 174 258 */ 175 RTR0DECL(int) RTR0MemObjLockKernel(PRTR0MEMOBJ pMemObj, void *pv, size_t cb, uint32_t fAccess); 176 177 /** 178 * Allocates contiguous page aligned physical memory without (necessarily) any kernel mapping. 259 #define RTR0MemObjLockKernel(pMemObj, pv, cb, fAccess) \ 260 RTR0MemObjLockKernelTag((pMemObj), (pv), (cb), (fAccess), RTMEM_TAG) 261 262 /** 263 * Locks a range of kernel virtual memory (custom tag). 264 * 265 * @returns IPRT status code. 266 * @param pMemObj Where to store the ring-0 memory object handle. 267 * @param pv Kernel virtual address. This is rounded down to a page boundrary. 268 * @param cb Number of bytes to lock. This is rounded up to nearest page boundrary. 269 * @param fAccess The desired access, a combination of RTMEM_PROT_READ 270 * and RTMEM_PROT_WRITE. 271 * @param pszTag Allocation tag used for statistics and such. 272 * 273 * @remark RTR0MemGetAddress() will return the rounded down address. 274 */ 275 RTR0DECL(int) RTR0MemObjLockKernelTag(PRTR0MEMOBJ pMemObj, void *pv, size_t cb, uint32_t fAccess, const char *pszTag); 276 277 /** 278 * Allocates contiguous page aligned physical memory without (necessarily) any 279 * kernel mapping (default tag). 179 280 * 180 281 * @returns IPRT status code. … … 184 285 * Pass NIL_RTHCPHYS if any address is acceptable. 185 286 */ 186 RTR0DECL(int) RTR0MemObjAllocPhys(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest); 187 188 /** 189 * Allocates contiguous physical memory without (necessarily) any kernel mapping. 287 #define RTR0MemObjAllocPhys(pMemObj, cb, PhysHighest) \ 288 RTR0MemObjAllocPhysTag((pMemObj), (cb), (PhysHighest), RTMEM_TAG) 289 290 /** 291 * Allocates contiguous page aligned physical memory without (necessarily) any 292 * kernel mapping (custom tag). 190 293 * 191 294 * @returns IPRT status code. … … 194 297 * @param PhysHighest The highest permittable address (inclusive). 195 298 * Pass NIL_RTHCPHYS if any address is acceptable. 299 * @param pszTag Allocation tag used for statistics and such. 300 */ 301 RTR0DECL(int) RTR0MemObjAllocPhysTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, const char *pszTag); 302 303 /** 304 * Allocates contiguous physical memory without (necessarily) any kernel mapping 305 * (default tag). 306 * 307 * @returns IPRT status code. 308 * @param pMemObj Where to store the ring-0 memory object handle. 309 * @param cb Number of bytes to allocate. This is rounded up to nearest page. 310 * @param PhysHighest The highest permittable address (inclusive). 311 * Pass NIL_RTHCPHYS if any address is acceptable. 196 312 * @param uAlignment The alignment of the reserved memory. 197 313 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M, _4M and _1G. 198 314 */ 199 RTR0DECL(int) RTR0MemObjAllocPhysEx(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment); 200 201 /** 202 * Allocates non-contiguous page aligned physical memory without (necessarily) any kernel mapping. 315 #define RTR0MemObjAllocPhysEx(pMemObj, cb, PhysHighest, uAlignment) \ 316 RTR0MemObjAllocPhysExTag((pMemObj), (cb), (PhysHighest), (uAlignment), RTMEM_TAG) 317 318 /** 319 * Allocates contiguous physical memory without (necessarily) any kernel mapping 320 * (custom tag). 321 * 322 * @returns IPRT status code. 323 * @param pMemObj Where to store the ring-0 memory object handle. 324 * @param cb Number of bytes to allocate. This is rounded up to nearest page. 325 * @param PhysHighest The highest permittable address (inclusive). 326 * Pass NIL_RTHCPHYS if any address is acceptable. 327 * @param uAlignment The alignment of the reserved memory. 328 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M, _4M and _1G. 329 * @param pszTag Allocation tag used for statistics and such. 330 */ 331 RTR0DECL(int) RTR0MemObjAllocPhysExTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment, const char *pszTag); 332 333 /** 334 * Allocates non-contiguous page aligned physical memory without (necessarily) 335 * any kernel mapping (default tag). 203 336 * 204 337 * This API is for allocating huge amounts of pages and will return … … 216 349 * Pass NIL_RTHCPHYS if any address is acceptable. 217 350 */ 218 RTR0DECL(int) RTR0MemObjAllocPhysNC(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest); 351 #define RTR0MemObjAllocPhysNC(pMemObj, cb, PhysHighest) \ 352 RTR0MemObjAllocPhysNCTag((pMemObj), (cb), (PhysHighest), RTMEM_TAG) 353 354 /** 355 * Allocates non-contiguous page aligned physical memory without (necessarily) 356 * any kernel mapping (custom tag). 357 * 358 * This API is for allocating huge amounts of pages and will return 359 * VERR_NOT_SUPPORTED if this cannot be implemented in a satisfactory 360 * manner. 361 * 362 * @returns IPRT status code. 363 * @retval VERR_NOT_SUPPORTED if it's not possible to allocated unmapped 364 * physical memory on this platform. The caller should expect 365 * this error and have a fallback strategy for it. 366 * 367 * @param pMemObj Where to store the ring-0 memory object handle. 368 * @param cb Number of bytes to allocate. This is rounded up to nearest page. 369 * @param PhysHighest The highest permittable address (inclusive). 370 * Pass NIL_RTHCPHYS if any address is acceptable. 371 * @param pszTag Allocation tag used for statistics and such. 372 */ 373 RTR0DECL(int) RTR0MemObjAllocPhysNCTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, const char *pszTag); 219 374 220 375 /** Memory cache policy for RTR0MemObjEnterPhys. … … 228 383 229 384 /** 230 * Creates a page aligned, contiguous, physical memory object .385 * Creates a page aligned, contiguous, physical memory object (default tag). 231 386 * 232 387 * No physical memory is allocated, we trust you do know what you're doing. … … 239 394 * @param uCachePolicy One of the RTMEM_CACHE_XXX modes. 240 395 */ 241 RTR0DECL(int) RTR0MemObjEnterPhys(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy); 242 243 /** 244 * Reserves kernel virtual address space. 396 #define RTR0MemObjEnterPhys(pMemObj, Phys, cb, uCachePolicy) \ 397 RTR0MemObjEnterPhysTag((pMemObj), (Phys), (cb), (uCachePolicy), RTMEM_TAG) 398 399 /** 400 * Creates a page aligned, contiguous, physical memory object (custom tag). 401 * 402 * No physical memory is allocated, we trust you do know what you're doing. 403 * 404 * @returns IPRT status code. 405 * @param pMemObj Where to store the ring-0 memory object handle. 406 * @param Phys The physical address to start at. This is rounded down to the 407 * nearest page boundrary. 408 * @param cb The size of the object in bytes. This is rounded up to nearest page boundrary. 409 * @param uCachePolicy One of the RTMEM_CACHE_XXX modes. 410 * @param pszTag Allocation tag used for statistics and such. 411 */ 412 RTR0DECL(int) RTR0MemObjEnterPhysTag(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy, const char *pszTag); 413 414 /** 415 * Reserves kernel virtual address space (default tag). 245 416 * 246 417 * If this function fails with VERR_NOT_SUPPORTED, the idea is that you … … 255 426 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. 256 427 */ 257 RTR0DECL(int) RTR0MemObjReserveKernel(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment); 258 259 /** 260 * Reserves user virtual address space in the current process. 428 #define RTR0MemObjReserveKernel(pMemObj, pvFixed, cb, uAlignment) \ 429 RTR0MemObjReserveKernelTag((pMemObj), (pvFixed), (cb), (uAlignment), RTMEM_TAG) 430 431 /** 432 * Reserves kernel virtual address space (custom tag). 433 * 434 * If this function fails with VERR_NOT_SUPPORTED, the idea is that you 435 * can use RTR0MemObjEnterPhys() + RTR0MemObjMapKernel() as a fallback if 436 * you have a safe physical address range to make use of... 437 * 438 * @returns IPRT status code. 439 * @param pMemObj Where to store the ring-0 memory object handle. 440 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment. 441 * @param cb The number of bytes to reserve. This is rounded up to nearest page. 442 * @param uAlignment The alignment of the reserved memory. 443 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. 444 * @param pszTag Allocation tag used for statistics and such. 445 */ 446 RTR0DECL(int) RTR0MemObjReserveKernelTag(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment, const char *pszTag); 447 448 /** 449 * Reserves user virtual address space in the current process (default tag). 261 450 * 262 451 * @returns IPRT status code. … … 268 457 * @param R0Process The process to reserve the memory in. NIL_R0PROCESS is an alias for the current one. 269 458 */ 270 RTR0DECL(int) RTR0MemObjReserveUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process); 271 272 /** 273 * Maps a memory object into kernel virtual address space. 459 #define RTR0MemObjReserveUser(pMemObj, R3PtrFixed, cb, uAlignment, R0Process) \ 460 RTR0MemObjReserveUserTag((pMemObj), (R3PtrFixed), (cb), (uAlignment), (R0Process), RTMEM_TAG) 461 462 /** 463 * Reserves user virtual address space in the current process (custom tag). 464 * 465 * @returns IPRT status code. 466 * @param pMemObj Where to store the ring-0 memory object handle. 467 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment. 468 * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE. 469 * @param uAlignment The alignment of the reserved memory. 470 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. 471 * @param R0Process The process to reserve the memory in. NIL_R0PROCESS is an alias for the current one. 472 * @param pszTag Allocation tag used for statistics and such. 473 */ 474 RTR0DECL(int) RTR0MemObjReserveUserTag(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, 475 RTR0PROCESS R0Process, const char *pszTag); 476 477 /** 478 * Maps a memory object into kernel virtual address space (default tag). 274 479 * 275 480 * This is the same as calling RTR0MemObjMapKernelEx with cbSub and offSub set … … 284 489 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE). 285 490 */ 286 RTR0DECL(int) RTR0MemObjMapKernel(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, unsigned fProt); 287 288 /** 289 * Maps a memory object into kernel virtual address space. 491 #define RTR0MemObjMapKernel(pMemObj, MemObjToMap, pvFixed, uAlignment, fProt) \ 492 RTR0MemObjMapKernelTag((pMemObj), (MemObjToMap), (pvFixed), (uAlignment), (fProt), RTMEM_TAG) 493 494 /** 495 * Maps a memory object into kernel virtual address space (custom tag). 496 * 497 * This is the same as calling RTR0MemObjMapKernelEx with cbSub and offSub set 498 * to zero. 499 * 500 * @returns IPRT status code. 501 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object. 502 * @param MemObjToMap The object to be map. 503 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment. 504 * @param uAlignment The alignment of the reserved memory. 505 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. 506 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE). 507 * @param pszTag Allocation tag used for statistics and such. 508 */ 509 RTR0DECL(int) RTR0MemObjMapKernelTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, 510 size_t uAlignment, unsigned fProt, const char *pszTag); 511 512 /** 513 * Maps a memory object into kernel virtual address space (default tag). 290 514 * 291 515 * The ability to map subsections of the object into kernel space is currently … … 310 534 * page aligned. 311 535 */ 312 RTR0DECL(int) RTR0MemObjMapKernelEx(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, 313 unsigned fProt, size_t offSub, size_t cbSub); 314 315 /** 316 * Maps a memory object into user virtual address space in the current process. 536 #define RTR0MemObjMapKernelEx(pMemObj, MemObjToMap, pvFixed, uAlignment, fProt, offSub, cbSub) \ 537 RTR0MemObjMapKernelExTag((pMemObj), (MemObjToMap), (pvFixed), (uAlignment), (fProt), (offSub), (cbSub), RTMEM_TAG) 538 539 /** 540 * Maps a memory object into kernel virtual address space (custom tag). 541 * 542 * The ability to map subsections of the object into kernel space is currently 543 * not implemented on all platforms. All/Most of platforms supports mapping the 544 * whole object into kernel space. 545 * 546 * @returns IPRT status code. 547 * @retval VERR_NOT_SUPPORTED if it's not possible to map a subsection of a 548 * memory object on this platform. When you hit this, try implement it. 549 * 550 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object. 551 * @param MemObjToMap The object to be map. 552 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment. 553 * @param uAlignment The alignment of the reserved memory. 554 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. 555 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE). 556 * @param offSub Where in the object to start mapping. If non-zero 557 * the value must be page aligned and cbSub must be 558 * non-zero as well. 559 * @param cbSub The size of the part of the object to be mapped. If 560 * zero the entire object is mapped. The value must be 561 * page aligned. 562 * @param pszTag Allocation tag used for statistics and such. 563 */ 564 RTR0DECL(int) RTR0MemObjMapKernelExTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, 565 unsigned fProt, size_t offSub, size_t cbSub, const char *pszTag); 566 567 /** 568 * Maps a memory object into user virtual address space in the current process 569 * (default tag). 317 570 * 318 571 * @returns IPRT status code. … … 325 578 * @param R0Process The process to map the memory into. NIL_R0PROCESS is an alias for the current one. 326 579 */ 327 RTR0DECL(int) RTR0MemObjMapUser(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process); 580 #define RTR0MemObjMapUser(pMemObj, MemObjToMap, R3PtrFixed, uAlignment, fProt, R0Process) \ 581 RTR0MemObjMapUserTag((pMemObj), (MemObjToMap), (R3PtrFixed), (uAlignment), (fProt), (R0Process), RTMEM_TAG) 582 583 /** 584 * Maps a memory object into user virtual address space in the current process 585 * (custom tag). 586 * 587 * @returns IPRT status code. 588 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object. 589 * @param MemObjToMap The object to be map. 590 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment. 591 * @param uAlignment The alignment of the reserved memory. 592 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. 593 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE). 594 * @param R0Process The process to map the memory into. NIL_R0PROCESS is an alias for the current one. 595 * @param pszTag Allocation tag used for statistics and such. 596 */ 597 RTR0DECL(int) RTR0MemObjMapUserTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, 598 size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process, const char *pszTag); 328 599 329 600 /** -
trunk/include/iprt/string.h
r30859 r31157 4 4 5 5 /* 6 * Copyright (C) 2006-20 07Oracle Corporation6 * Copyright (C) 2006-2010 Oracle Corporation 7 7 * 8 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 115 115 116 116 117 /** @def RTMEM_TAG 118 * The default allocation tag used by the RTStr allocation APIs. 119 * 120 * When not defined before the inclusion of iprt/string.h, this will default to 121 * the pointer to the current file name. The string API will make of use of 122 * this as pointer to a volatile but read-only string. 123 */ 124 #ifndef RTSTR_TAG 125 # define RTSTR_TAG (__FILE__) 126 #endif 127 128 117 129 #ifdef IN_RING3 118 130 119 131 /** 120 * Allocates tmp buffer, translates pszString from UTF8 to current codepage. 132 * Allocates tmp buffer with default tag, translates pszString from UTF8 to 133 * current codepage. 121 134 * 122 135 * @returns iprt status code. … … 125 138 * @param pszString UTF-8 string to convert. 126 139 */ 127 RTR3DECL(int) RTStrUtf8ToCurrentCP(char **ppszString, const char *pszString); 140 #define RTStrUtf8ToCurrentCP(ppszString, pszString) RTStrUtf8ToCurrentCPTag((ppszString), (pszString), RTSTR_TAG) 141 142 /** 143 * Allocates tmp buffer with custom tag, translates pszString from UTF8 to 144 * current codepage. 145 * 146 * @returns iprt status code. 147 * @param ppszString Receives pointer of allocated native CP string. 148 * The returned pointer must be freed using 149 * RTStrFree()., const char *pszTag 150 * @param pszString UTF-8 string to convert. 151 * @param pszTag Allocation tag used for statistics and such. 152 */ 153 RTR3DECL(int) RTStrUtf8ToCurrentCPTag(char **ppszString, const char *pszString, const char *pszTag); 128 154 129 155 /** … … 135 161 * @param pszString Native string to convert. 136 162 */ 137 RTR3DECL(int) RTStrCurrentCPToUtf8(char **ppszString, const char *pszString); 138 139 #endif 163 #define RTStrCurrentCPToUtf8(ppszString, pszString) RTStrCurrentCPToUtf8Tag((ppszString), (pszString), RTSTR_TAG) 164 165 /** 166 * Allocates tmp buffer, translates pszString from current codepage to UTF-8. 167 * 168 * @returns iprt status code. 169 * @param ppszString Receives pointer of allocated UTF-8 string. 170 * The returned pointer must be freed using RTStrFree(). 171 * @param pszString Native string to convert. 172 * @param pszTag Allocation tag used for statistics and such. 173 */ 174 RTR3DECL(int) RTStrCurrentCPToUtf8Tag(char **ppszString, const char *pszString, const char *pszTag); 175 176 #endif /* IN_RING3 */ 140 177 141 178 /** … … 149 186 150 187 /** 151 * Allocates a new copy of the given UTF-8 string .188 * Allocates a new copy of the given UTF-8 string (default tag). 152 189 * 153 190 * @returns Pointer to the allocated UTF-8 string. 154 191 * @param pszString UTF-8 string to duplicate. 155 192 */ 156 RTDECL(char *) RTStrDup(const char *pszString); 157 158 /** 159 * Allocates a new copy of the given UTF-8 string. 193 #define RTStrDup(pszString) RTStrDupTag((pszString), RTSTR_TAG) 194 195 /** 196 * Allocates a new copy of the given UTF-8 string (custom tag). 197 * 198 * @returns Pointer to the allocated UTF-8 string. 199 * @param pszString UTF-8 string to duplicate. 200 * @param pszTag Allocation tag used for statistics and such. 201 */ 202 RTDECL(char *) RTStrDupTag(const char *pszString, const char *pszTag); 203 204 /** 205 * Allocates a new copy of the given UTF-8 string (default tag). 160 206 * 161 207 * @returns iprt status code. … … 164 210 * @param pszString UTF-8 string to duplicate. 165 211 */ 166 RTDECL(int) RTStrDupEx(char **ppszString, const char *pszString); 167 168 /** 169 * Allocates a new copy of the given UTF-8 substring. 212 #define RTStrDupEx(ppszString, pszString) RTStrDupExTag((ppszString), (pszString), RTSTR_TAG) 213 214 /** 215 * Allocates a new copy of the given UTF-8 string (custom tag). 216 * 217 * @returns iprt status code. 218 * @param ppszString Receives pointer of the allocated UTF-8 string. 219 * The returned pointer must be freed using RTStrFree(). 220 * @param pszString UTF-8 string to duplicate. 221 * @param pszTag Allocation tag used for statistics and such. 222 */ 223 RTDECL(int) RTStrDupExTag(char **ppszString, const char *pszString, const char *pszTag); 224 225 /** 226 * Allocates a new copy of the given UTF-8 substring (default tag). 170 227 * 171 228 * @returns Pointer to the allocated UTF-8 substring. … … 174 231 * the terminator. 175 232 */ 176 RTDECL(char *) RTStrDupN(const char *pszString, size_t cchMax); 177 178 /** 179 * Appends a string onto an existing IPRT allocated string. 233 #define RTStrDupN(pszString, cchMax) RTStrDupNTag((pszString), (cchMax), RTSTR_TAG) 234 235 /** 236 * Allocates a new copy of the given UTF-8 substring (custom tag). 237 * 238 * @returns Pointer to the allocated UTF-8 substring. 239 * @param pszString UTF-8 string to duplicate. 240 * @param cchMax The max number of chars to duplicate, not counting 241 * the terminator. 242 * @param pszTag Allocation tag used for statistics and such. 243 */ 244 RTDECL(char *) RTStrDupNTag(const char *pszString, size_t cchMax, const char *pszTag); 245 246 /** 247 * Appends a string onto an existing IPRT allocated string (defaul tag). 180 248 * 181 249 * @retval VINF_SUCCESS … … 189 257 * are quietly ignored. 190 258 */ 191 RTDECL(int) RTStrAAppend(char **ppsz, const char *pszAppend); 192 193 /** 194 * Appends N bytes from a strings onto an existing IPRT allocated string. 259 #define RTStrAAppend(ppsz, pszAppend) RTStrAAppendTag((ppsz), (pszAppend), RTSTR_TAG) 260 261 /** 262 * Appends a string onto an existing IPRT allocated string (custom tag). 263 * 264 * @retval VINF_SUCCESS 265 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz 266 * remains unchanged. 267 * 268 * @param ppsz Pointer to the string pointer. The string 269 * pointer must either be NULL or point to a string 270 * returned by an IPRT string API. (In/Out) 271 * @param pszAppend The string to append. NULL and empty strings 272 * are quietly ignored. 273 * @param pszTag Allocation tag used for statistics and such. 274 */ 275 RTDECL(int) RTStrAAppendTag(char **ppsz, const char *pszAppend, const char *pszTag); 276 277 /** 278 * Appends N bytes from a strings onto an existing IPRT allocated string 279 * (default tag). 195 280 * 196 281 * @retval VINF_SUCCESS … … 209 294 * of @a pszAppend without having to strlen it. 210 295 */ 211 RTDECL(int) RTStrAAppendN(char **ppsz, const char *pszAppend, size_t cchAppend); 296 #define RTStrAAppendN(ppsz, pszAppend, cchAppend) RTStrAAppendNTag((ppsz), (pszAppend), (cchAppend), RTSTR_TAG) 297 298 /** 299 * Appends N bytes from a strings onto an existing IPRT allocated string (custom 300 * tag). 301 * 302 * @retval VINF_SUCCESS 303 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz 304 * remains unchanged. 305 * 306 * @param ppsz Pointer to the string pointer. The string 307 * pointer must either be NULL or point to a string 308 * returned by an IPRT string API. (In/Out) 309 * @param pszAppend The string to append. Can be NULL if cchAppend 310 * is NULL. 311 * @param cchAppend The number of chars (not code points) to append 312 * from pszAppend. Must not be more than 313 * @a pszAppend contains, except for the special 314 * value RTSTR_MAX that can be used to indicate all 315 * of @a pszAppend without having to strlen it. 316 * @param pszTag Allocation tag used for statistics and such. 317 */ 318 RTDECL(int) RTStrAAppendNTag(char **ppsz, const char *pszAppend, size_t cchAppend, const char *pszTag); 212 319 213 320 /** … … 230 337 * the string in the first argument. 231 338 */ 232 RTDECL(int) RTStrAAppendExNV(char **ppsz, size_t cPairs, va_list va); 339 #define RTStrAAppendExNV(ppsz, cPairs, va) RTStrAAppendExNVTag((ppsz), (cPairs), (va), RTSTR_TAG) 233 340 234 341 /** 235 342 * Appends one or more strings onto an existing IPRT allocated string. 343 * 344 * This is a very flexible and efficient alternative to using RTStrAPrintf to 345 * combine several strings together. 346 * 347 * @retval VINF_SUCCESS 348 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz 349 * remains unchanged. 350 * 351 * @param ppsz Pointer to the string pointer. The string 352 * pointer must either be NULL or point to a string 353 * returned by an IPRT string API. (In/Out) 354 * @param cPairs The number of string / length pairs in the 355 * @a va. 356 * @param va List of string (const char *) and length 357 * (size_t) pairs. The strings will be appended to 358 * the string in the first argument. 359 * @param pszTag Allocation tag used for statistics and such. 360 */ 361 RTDECL(int) RTStrAAppendExNVTag(char **ppsz, size_t cPairs, va_list va, const char *pszTag); 362 363 /** 364 * Appends one or more strings onto an existing IPRT allocated string 365 * (untagged). 236 366 * 237 367 * This is a very flexible and efficient alternative to using RTStrAPrintf to … … 251 381 * the string in the first argument. 252 382 */ 253 RTDECL(int) RTStrAAppendExN(char **ppsz, size_t cPairs, ...); 254 255 /** 256 * Truncates an IPRT allocated string. 383 DECLINLINE(int) RTStrAAppendExN(char **ppsz, size_t cPairs, ...) 384 { 385 int rc; 386 va_list va; 387 va_start(va, cPairs); 388 rc = RTStrAAppendExNVTag(ppsz, cPairs, va, RTSTR_TAG); 389 va_end(va); 390 return rc; 391 } 392 393 /** 394 * Appends one or more strings onto an existing IPRT allocated string (custom 395 * tag). 396 * 397 * This is a very flexible and efficient alternative to using RTStrAPrintf to 398 * combine several strings together. 399 * 400 * @retval VINF_SUCCESS 401 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz 402 * remains unchanged. 403 * 404 * @param ppsz Pointer to the string pointer. The string 405 * pointer must either be NULL or point to a string 406 * returned by an IPRT string API. (In/Out) 407 * @param pszTag Allocation tag used for statistics and such. 408 * @param cPairs The number of string / length pairs in the 409 * ellipsis. 410 * @param ... List of string (const char *) and length 411 * (size_t) pairs. The strings will be appended to 412 * the string in the first argument. 413 */ 414 DECLINLINE(int) RTStrAAppendExNTag(char **ppsz, const char *pszTag, size_t cPairs, ...) 415 { 416 int rc; 417 va_list va; 418 va_start(va, cPairs); 419 rc = RTStrAAppendExNVTag(ppsz, cPairs, va, pszTag); 420 va_end(va); 421 return rc; 422 } 423 424 /** 425 * Truncates an IPRT allocated string (default tag). 257 426 * 258 427 * @retval VINF_SUCCESS. … … 269 438 * assert on you. 270 439 */ 271 RTDECL(int) RTStrATruncate(char **ppsz, size_t cchNew); 272 273 /** 274 * Allocates memory for string storage. 440 #define RTStrATruncate(ppsz, cchNew) RTStrATruncateTag((ppsz), (cchNew), RTSTR_TAG) 441 442 /** 443 * Truncates an IPRT allocated string. 444 * 445 * @retval VINF_SUCCESS. 446 * @retval VERR_OUT_OF_RANGE if cchNew is too long. Nothing is done. 447 * 448 * @param ppsz Pointer to the string pointer. The string 449 * pointer can be NULL if @a cchNew is 0, no change 450 * is made then. If we actually reallocate the 451 * string, the string pointer might be changed by 452 * this call. (In/Out) 453 * @param cchNew The new string length (excluding the 454 * terminator). The string must be at least this 455 * long or we'll return VERR_OUT_OF_RANGE and 456 * assert on you. 457 * @param pszTag Allocation tag used for statistics and such. 458 */ 459 RTDECL(int) RTStrATruncateTag(char **ppsz, size_t cchNew, const char *pszTag); 460 461 /** 462 * Allocates memory for string storage (default tag). 275 463 * 276 464 * You should normally not use this function, except if there is some very … … 289 477 * will allocate a terminator byte anyway. 290 478 */ 291 RTDECL(char *) RTStrAlloc(size_t cb); 292 293 /** 294 * Allocates memory for string storage, with status code. 479 #define RTStrAlloc(cb) RTStrAllocTag((cb), RTSTR_TAG) 480 481 /** 482 * Allocates memory for string storage (custom tag). 483 * 484 * You should normally not use this function, except if there is some very 485 * custom string handling you need doing that isn't covered by any of the other 486 * APIs. 487 * 488 * @returns Pointer to the allocated string. The first byte is always set 489 * to the string terminator char, the contents of the remainder of the 490 * memory is undefined. The string must be freed by calling RTStrFree. 491 * 492 * NULL is returned if the allocation failed. Please translate this to 493 * VERR_NO_STR_MEMORY and not VERR_NO_MEMORY. Also consider 494 * RTStrAllocEx if an IPRT status code is required. 495 * 496 * @param cb How many bytes to allocate. If this is zero, we 497 * will allocate a terminator byte anyway. 498 * @param pszTag Allocation tag used for statistics and such. 499 */ 500 RTDECL(char *) RTStrAllocTag(size_t cb, const char *pszTag); 501 502 /** 503 * Allocates memory for string storage, with status code (default tag). 295 504 * 296 505 * You should normally not use this function, except if there is some very … … 310 519 * will allocate a terminator byte anyway. 311 520 */ 312 RTDECL(int) RTStrAllocEx(char **ppsz, size_t cb); 313 314 /** 315 * Reallocates the specifed string. 521 #define RTStrAllocEx(ppsz, cb) RTStrAllocExTag((ppsz), (cb), RTSTR_TAG) 522 523 /** 524 * Allocates memory for string storage, with status code (custom tag). 525 * 526 * You should normally not use this function, except if there is some very 527 * custom string handling you need doing that isn't covered by any of the other 528 * APIs. 529 * 530 * @retval VINF_SUCCESS 531 * @retval VERR_NO_STR_MEMORY 532 * 533 * @param ppsz Where to return the allocated string. This will 534 * be set to NULL on failure. On success, the 535 * returned memory will always start with a 536 * terminator char so that it is considered a valid 537 * C string, the contents of rest of the memory is 538 * undefined. 539 * @param cb How many bytes to allocate. If this is zero, we 540 * will allocate a terminator byte anyway. 541 * @param pszTag Allocation tag used for statistics and such. 542 */ 543 RTDECL(int) RTStrAllocExTag(char **ppsz, size_t cb, const char *pszTag); 544 545 /** 546 * Reallocates the specified string (default tag). 316 547 * 317 548 * You should normally not have use this function, except perhaps to truncate a … … 344 575 * terminator char. 345 576 */ 346 RTDECL(int) RTStrRealloc(char **ppsz, size_t cbNew); 577 #define RTStrRealloc(ppsz, cbNew) RTStrReallocTag((ppsz), (cbNew), RTSTR_TAG) 578 579 /** 580 * Reallocates the specified string (custom tag). 581 * 582 * You should normally not have use this function, except perhaps to truncate a 583 * really long string you've got from some IPRT string API, but then you should 584 * use RTStrATruncate. 585 * 586 * @returns VINF_SUCCESS. 587 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz 588 * remains unchanged. 589 * 590 * @param ppsz Pointer to the string variable containing the 591 * input and output string. 592 * 593 * When not freeing the string, the result will 594 * always have the last byte set to the terminator 595 * character so that when used for string 596 * truncation the result will be a valid C string 597 * (your job to keep it a valid UTF-8 string). 598 * 599 * When the input string is NULL and we're supposed 600 * to reallocate, the returned string will also 601 * have the first byte set to the terminator char 602 * so it will be a valid C string. 603 * 604 * @param cbNew When @a cbNew is zero, we'll behave like 605 * RTStrFree and @a *ppsz will be set to NULL. 606 * 607 * When not zero, this will be the new size of the 608 * memory backing the string, i.e. it includes the 609 * terminator char. 610 * @param pszTag Allocation tag used for statistics and such. 611 */ 612 RTDECL(int) RTStrReallocTag(char **ppsz, size_t cbNew, const char *pszTag); 347 613 348 614 /** … … 477 743 478 744 /** 479 * Translate a UTF-8 string into a UTF-16 allocating the result buffer. 745 * Translate a UTF-8 string into a UTF-16 allocating the result buffer (default 746 * tag). 480 747 * 481 748 * @returns iprt status code. … … 484 751 * The returned string must be freed using RTUtf16Free(). 485 752 */ 486 RTDECL(int) RTStrToUtf16(const char *pszString, PRTUTF16 *ppwszString); 753 #define RTStrToUtf16(pszString, ppwszString) RTStrToUtf16Tag((pszString), (ppwszString), RTSTR_TAG) 754 755 /** 756 * Translate a UTF-8 string into a UTF-16 allocating the result buffer (custom 757 * tag). 758 * 759 * @returns iprt status code. 760 * @param pszString UTF-8 string to convert. 761 * @param ppwszString Receives pointer to the allocated UTF-16 string. 762 * The returned string must be freed using RTUtf16Free(). 763 * @param pszTag Allocation tag used for statistics and such. 764 */ 765 RTDECL(int) RTStrToUtf16Tag(const char *pszString, PRTUTF16 *ppwszString, const char *pszTag); 487 766 488 767 /** … … 508 787 * length that can be used to resize the buffer. 509 788 */ 510 RTDECL(int) RTStrToUtf16Ex(const char *pszString, size_t cchString, PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc); 789 #define RTStrToUtf16Ex(pszString, cchString, ppwsz, cwc, pcwc) \ 790 RTStrToUtf16ExTag((pszString), (cchString), (ppwsz), (cwc), (pcwc), RTSTR_TAG) 791 792 /** 793 * Translates pszString from UTF-8 to UTF-16, allocating the result buffer if 794 * requested (custom tag). 795 * 796 * @returns iprt status code. 797 * @param pszString UTF-8 string to convert. 798 * @param cchString The maximum size in chars (the type) to convert. The conversion stop 799 * when it reaches cchString or the string terminator ('\\0'). 800 * Use RTSTR_MAX to translate the entire string. 801 * @param ppwsz If cwc is non-zero, this must either be pointing to pointer to 802 * a buffer of the specified size, or pointer to a NULL pointer. 803 * If *ppwsz is NULL or cwc is zero a buffer of at least cwc items 804 * will be allocated to hold the translated string. 805 * If a buffer was requested it must be freed using RTUtf16Free(). 806 * @param cwc The buffer size in RTUTF16s. This includes the terminator. 807 * @param pcwc Where to store the length of the translated string, 808 * excluding the terminator. (Optional) 809 * 810 * This may be set under some error conditions, 811 * however, only for VERR_BUFFER_OVERFLOW and 812 * VERR_NO_STR_MEMORY will it contain a valid string 813 * length that can be used to resize the buffer. 814 * @param pszTag Allocation tag used for statistics and such. 815 */ 816 RTDECL(int) RTStrToUtf16ExTag(const char *pszString, size_t cchString, PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc, const char *pszTag); 511 817 512 818 … … 948 1254 949 1255 /** 950 * Allocating string printf .1256 * Allocating string printf (default tag). 951 1257 * 952 1258 * @returns The length of the string in the returned *ppszBuffer. … … 958 1264 * @param args The format argument. 959 1265 */ 960 RTDECL(int) RTStrAPrintfV(char **ppszBuffer, const char *pszFormat, va_list args); 1266 #define RTStrAPrintfV(ppszBuffer, pszFormat, args) RTStrAPrintfVTag((ppszBuffer), (pszFormat), (args), RTSTR_TAG) 1267 1268 /** 1269 * Allocating string printf (custom tag). 1270 * 1271 * @returns The length of the string in the returned *ppszBuffer. 1272 * @returns -1 on failure. 1273 * @param ppszBuffer Where to store the pointer to the allocated output buffer. 1274 * The buffer should be freed using RTStrFree(). 1275 * On failure *ppszBuffer will be set to NULL. 1276 * @param pszFormat The format string. 1277 * @param args The format argument. 1278 * @param pszTag Allocation tag used for statistics and such. 1279 */ 1280 RTDECL(int) RTStrAPrintfVTag(char **ppszBuffer, const char *pszFormat, va_list args, const char *pszTag); 961 1281 962 1282 /** … … 971 1291 * @param ... The format argument. 972 1292 */ 973 RTDECL(int) RTStrAPrintf(char **ppszBuffer, const char *pszFormat, ...); 1293 DECLINLINE(int) RTStrAPrintf(char **ppszBuffer, const char *pszFormat, ...) 1294 { 1295 int cbRet; 1296 va_list va; 1297 va_start(va, pszFormat); 1298 cbRet = RTStrAPrintfVTag(ppszBuffer, pszFormat, va, RTSTR_TAG); 1299 va_end(va); 1300 return cbRet; 1301 } 1302 1303 /** 1304 * Allocating string printf (custom tag). 1305 * 1306 * @returns The length of the string in the returned *ppszBuffer. 1307 * @returns -1 on failure. 1308 * @param ppszBuffer Where to store the pointer to the allocated output buffer. 1309 * The buffer should be freed using RTStrFree(). 1310 * On failure *ppszBuffer will be set to NULL. 1311 * @param pszTag Allocation tag used for statistics and such. 1312 * @param pszFormat The format string. 1313 * @param ... The format argument. 1314 */ 1315 DECLINLINE(int) RTStrAPrintfTag(char **ppszBuffer, const char *pszTag, const char *pszFormat, ...) 1316 { 1317 int cbRet; 1318 va_list va; 1319 va_start(va, pszFormat); 1320 cbRet = RTStrAPrintfVTag(ppszBuffer, pszFormat, va, pszTag); 1321 va_end(va); 1322 return cbRet; 1323 } 974 1324 975 1325 /** … … 981 1331 * @param args The format argument. 982 1332 */ 983 RTDECL(char *) RTStrAPrintf2V(const char *pszFormat, va_list args); 984 985 /** 986 * Allocating string printf, version2. 1333 #define RTStrAPrintf2V(pszFormat, args) RTStrAPrintf2VTag((pszFormat), (args), RTSTR_TAG) 1334 1335 /** 1336 * Allocating string printf, version 2. 1337 * 1338 * @returns Formatted string. Use RTStrFree() to free it. NULL when out of 1339 * memory. 1340 * @param pszFormat The format string. 1341 * @param args The format argument. 1342 * @param pszTag Allocation tag used for statistics and such. 1343 */ 1344 RTDECL(char *) RTStrAPrintf2VTag(const char *pszFormat, va_list args, const char *pszTag); 1345 1346 /** 1347 * Allocating string printf, version 2 (default tag). 987 1348 * 988 1349 * @returns Formatted string. Use RTStrFree() to free it. NULL when out of … … 991 1352 * @param ... The format argument. 992 1353 */ 993 RTDECL(char *) RTStrAPrintf2(const char *pszFormat, ...); 1354 DECLINLINE(char *) RTStrAPrintf2(const char *pszFormat, ...) 1355 { 1356 char *pszRet; 1357 va_list va; 1358 va_start(va, pszFormat); 1359 pszRet = RTStrAPrintf2VTag(pszFormat, va, RTSTR_TAG); 1360 va_end(va); 1361 return pszRet; 1362 } 1363 1364 /** 1365 * Allocating string printf, version 2 (custom tag). 1366 * 1367 * @returns Formatted string. Use RTStrFree() to free it. NULL when out of 1368 * memory. 1369 * @param pszTag Allocation tag used for statistics and such. 1370 * @param pszFormat The format string. 1371 * @param ... The format argument. 1372 */ 1373 DECLINLINE(char *) RTStrAPrintf2Tag(const char *pszTag, const char *pszFormat, ...) 1374 { 1375 char *pszRet; 1376 va_list va; 1377 va_start(va, pszFormat); 1378 pszRet = RTStrAPrintf2VTag(pszFormat, va, pszTag); 1379 va_end(va); 1380 return pszRet; 1381 } 994 1382 995 1383 /** … … 1887 2275 1888 2276 /** 1889 * Allocates a new copy of the specified UTF-16 string .2277 * Allocates a new copy of the specified UTF-16 string (default tag). 1890 2278 * 1891 2279 * @returns Pointer to the allocated string copy. Use RTUtf16Free() to free it. … … 1894 2282 * @remark This function will not make any attempt to validate the encoding. 1895 2283 */ 1896 RTDECL(PRTUTF16) RTUtf16Dup(PCRTUTF16 pwszString); 1897 1898 /** 1899 * Allocates a new copy of the specified UTF-16 string. 2284 #define RTUtf16Dup(pwszString) RTUtf16DupTag((pwszString), RTSTR_TAG) 2285 2286 /** 2287 * Allocates a new copy of the specified UTF-16 string (custom tag). 2288 * 2289 * @returns Pointer to the allocated string copy. Use RTUtf16Free() to free it. 2290 * @returns NULL when out of memory. 2291 * @param pwszString UTF-16 string to duplicate. 2292 * @param pszTag Allocation tag used for statistics and such. 2293 * @remark This function will not make any attempt to validate the encoding. 2294 */ 2295 RTDECL(PRTUTF16) RTUtf16DupTag(PCRTUTF16 pwszString, const char *pszTag); 2296 2297 /** 2298 * Allocates a new copy of the specified UTF-16 string (default tag). 1900 2299 * 1901 2300 * @returns iprt status code. … … 1906 2305 * @remark This function will not make any attempt to validate the encoding. 1907 2306 */ 1908 RTDECL(int) RTUtf16DupEx(PRTUTF16 *ppwszString, PCRTUTF16 pwszString, size_t cwcExtra); 2307 #define RTUtf16DupEx(ppwszString, pwszString, cwcExtra) \ 2308 RTUtf16DupExTag((ppwszString), (pwszString), (cwcExtra), RTSTR_TAG) 2309 2310 /** 2311 * Allocates a new copy of the specified UTF-16 string (custom tag). 2312 * 2313 * @returns iprt status code. 2314 * @param ppwszString Receives pointer of the allocated UTF-16 string. 2315 * The returned pointer must be freed using RTUtf16Free(). 2316 * @param pwszString UTF-16 string to duplicate. 2317 * @param cwcExtra Number of extra RTUTF16 items to allocate. 2318 * @param pszTag Allocation tag used for statistics and such. 2319 * @remark This function will not make any attempt to validate the encoding. 2320 */ 2321 RTDECL(int) RTUtf16DupExTag(PRTUTF16 *ppwszString, PCRTUTF16 pwszString, size_t cwcExtra, const char *pszTag); 1909 2322 1910 2323 /** … … 1991 2404 1992 2405 /** 1993 * Translate a UTF-16 string into a UTF-8 allocating the result buffer. 2406 * Translate a UTF-16 string into a UTF-8 allocating the result buffer (default 2407 * tag). 1994 2408 * 1995 2409 * @returns iprt status code. … … 1999 2413 * The returned pointer must be freed using RTStrFree(). 2000 2414 */ 2001 RTDECL(int) RTUtf16ToUtf8(PCRTUTF16 pwszString, char **ppszString); 2002 2003 /** 2004 * Translates UTF-16 to UTF-8 using buffer provided by the caller or 2005 * a fittingly sized buffer allocated by the function. 2415 #define RTUtf16ToUtf8(pwszString, ppszString) RTUtf16ToUtf8Tag((pwszString), (ppszString), RTSTR_TAG) 2416 2417 /** 2418 * Translate a UTF-16 string into a UTF-8 allocating the result buffer. 2419 * 2420 * @returns iprt status code. 2421 * @param pwszString UTF-16 string to convert. 2422 * @param ppszString Receives pointer of allocated UTF-8 string on 2423 * success, and is always set to NULL on failure. 2424 * The returned pointer must be freed using RTStrFree(). 2425 * @param pszTag Allocation tag used for statistics and such. 2426 */ 2427 RTDECL(int) RTUtf16ToUtf8Tag(PCRTUTF16 pwszString, char **ppszString, const char *pszTag); 2428 2429 /** 2430 * Translates UTF-16 to UTF-8 using buffer provided by the caller or a fittingly 2431 * sized buffer allocated by the function (default tag). 2006 2432 * 2007 2433 * @returns iprt status code. … … 2024 2450 * length that can be used to resize the buffer. 2025 2451 */ 2026 RTDECL(int) RTUtf16ToUtf8Ex(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch); 2452 #define RTUtf16ToUtf8Ex(pwszString, cwcString, ppsz, cch, pcch) \ 2453 RTUtf16ToUtf8ExTag((pwszString), (cwcString), (ppsz), (cch), (pcch), RTSTR_TAG) 2454 2455 /** 2456 * Translates UTF-16 to UTF-8 using buffer provided by the caller or a fittingly 2457 * sized buffer allocated by the function (custom tag). 2458 * 2459 * @returns iprt status code. 2460 * @param pwszString The UTF-16 string to convert. 2461 * @param cwcString The number of RTUTF16 items to translate from pwszString. 2462 * The translation will stop when reaching cwcString or the terminator ('\\0'). 2463 * Use RTSTR_MAX to translate the entire string. 2464 * @param ppsz If cch is non-zero, this must either be pointing to a pointer to 2465 * a buffer of the specified size, or pointer to a NULL pointer. 2466 * If *ppsz is NULL or cch is zero a buffer of at least cch chars 2467 * will be allocated to hold the translated string. 2468 * If a buffer was requested it must be freed using RTStrFree(). 2469 * @param cch The buffer size in chars (the type). This includes the terminator. 2470 * @param pcch Where to store the length of the translated string, 2471 * excluding the terminator. (Optional) 2472 * 2473 * This may be set under some error conditions, 2474 * however, only for VERR_BUFFER_OVERFLOW and 2475 * VERR_NO_STR_MEMORY will it contain a valid string 2476 * length that can be used to resize the buffer. 2477 * @param pszTag Allocation tag used for statistics and such. 2478 */ 2479 RTDECL(int) RTUtf16ToUtf8ExTag(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch, const char *pszTag); 2027 2480 2028 2481 /** … … 2056 2509 /** 2057 2510 * Translate a UTF-16 string into a Latin-1 (ISO-8859-1) allocating the result 2058 * buffer .2511 * buffer (default tag). 2059 2512 * 2060 2513 * @returns iprt status code. … … 2064 2517 * The returned pointer must be freed using RTStrFree(). 2065 2518 */ 2066 RTDECL(int) RTUtf16ToLatin1(PCRTUTF16 pwszString, char **ppszString); 2519 #define RTUtf16ToLatin1(pwszString, ppszString) RTUtf16ToLatin1Tag((pwszString), (ppszString), RTSTR_TAG) 2520 2521 /** 2522 * Translate a UTF-16 string into a Latin-1 (ISO-8859-1) allocating the result 2523 * buffer (custom tag). 2524 * 2525 * @returns iprt status code. 2526 * @param pwszString UTF-16 string to convert. 2527 * @param ppszString Receives pointer of allocated Latin1 string on 2528 * success, and is always set to NULL on failure. 2529 * The returned pointer must be freed using RTStrFree(). 2530 * @param pszTag Allocation tag used for statistics and such. 2531 */ 2532 RTDECL(int) RTUtf16ToLatin1Tag(PCRTUTF16 pwszString, char **ppszString, const char *pszTag); 2067 2533 2068 2534 /** 2069 2535 * Translates UTF-16 to Latin-1 (ISO-8859-1) using buffer provided by the caller 2070 * or a fittingly sized buffer allocated by the function .2536 * or a fittingly sized buffer allocated by the function (default tag). 2071 2537 * 2072 2538 * @returns iprt status code. … … 2101 2567 * length that can be used to resize the buffer. 2102 2568 */ 2103 RTDECL(int) RTUtf16ToLatin1Ex(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch); 2569 #define RTUtf16ToLatin1Ex(pwszString, cwcString, ppsz, cch, pcch) \ 2570 RTUtf16ToLatin1ExTag((pwszString), (cwcString), (ppsz), (cch), (pcch), RTSTR_TAG) 2571 2572 /** 2573 * Translates UTF-16 to Latin-1 (ISO-8859-1) using buffer provided by the caller 2574 * or a fittingly sized buffer allocated by the function (custom tag). 2575 * 2576 * @returns iprt status code. 2577 * @param pwszString The UTF-16 string to convert. 2578 * @param cwcString The number of RTUTF16 items to translate from 2579 * pwszString. The translation will stop when reaching 2580 * cwcString or the terminator ('\\0'). Use RTSTR_MAX 2581 * to translate the entire string. 2582 * @param ppsz Pointer to the pointer to the Latin-1 string. The 2583 * buffer can optionally be preallocated by the caller. 2584 * 2585 * If cch is zero, *ppsz is undefined. 2586 * 2587 * If cch is non-zero and *ppsz is not NULL, then this 2588 * will be used as the output buffer. 2589 * VERR_BUFFER_OVERFLOW will be returned if this is 2590 * insufficient. 2591 * 2592 * If cch is zero or *ppsz is NULL, then a buffer of 2593 * sufficent size is allocated. cch can be used to 2594 * specify a minimum size of this buffer. Use 2595 * RTUtf16Free() to free the result. 2596 * 2597 * @param cch The buffer size in chars (the type). This includes 2598 * the terminator. 2599 * @param pcch Where to store the length of the translated string, 2600 * excluding the terminator. (Optional) 2601 * 2602 * This may be set under some error conditions, 2603 * however, only for VERR_BUFFER_OVERFLOW and 2604 * VERR_NO_STR_MEMORY will it contain a valid string 2605 * length that can be used to resize the buffer. 2606 * @param pszTag Allocation tag used for statistics and such. 2607 */ 2608 RTDECL(int) RTUtf16ToLatin1ExTag(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch, const char *pszTag); 2104 2609 2105 2610 /** … … 2338 2843 /** 2339 2844 * Translate a Latin-1 (ISO-8859-1) string into a UTF-16 allocating the result 2340 * buffer .2845 * buffer (default tag). 2341 2846 * 2342 2847 * @returns iprt status code. … … 2345 2850 * returned string must be freed using RTUtf16Free(). 2346 2851 */ 2347 RTDECL(int) RTLatin1ToUtf16(const char *pszString, PRTUTF16 *ppwszString); 2852 #define RTLatin1ToUtf16(pszString, ppwszString) RTLatin1ToUtf16Tag((pszString), (ppwszString), RTSTR_TAG) 2853 2854 /** 2855 * Translate a Latin-1 (ISO-8859-1) string into a UTF-16 allocating the result 2856 * buffer (custom tag). 2857 * 2858 * @returns iprt status code. 2859 * @param pszString The Latin-1 string to convert. 2860 * @param ppwszString Receives pointer to the allocated UTF-16 string. The 2861 * returned string must be freed using RTUtf16Free(). 2862 * @param pszTag Allocation tag used for statistics and such. 2863 */ 2864 RTDECL(int) RTLatin1ToUtf16Tag(const char *pszString, PRTUTF16 *ppwszString, const char *pszTag); 2348 2865 2349 2866 /** 2350 2867 * Translates pszString from Latin-1 (ISO-8859-1) to UTF-16, allocating the 2351 * result buffer if requested .2868 * result buffer if requested (default tag). 2352 2869 * 2353 2870 * @returns iprt status code. … … 2374 2891 * length that can be used to resize the buffer. 2375 2892 */ 2376 RTDECL(int) RTLatin1ToUtf16Ex(const char *pszString, size_t cchString, PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc); 2893 #define RTLatin1ToUtf16Ex(pszString, cchString, ppwsz, cwc, pcwc) \ 2894 RTLatin1ToUtf16ExTag((pszString), (cchString), (ppwsz), (cwc), (pcwc), RTSTR_TAG) 2895 2896 /** 2897 * Translates pszString from Latin-1 (ISO-8859-1) to UTF-16, allocating the 2898 * result buffer if requested. 2899 * 2900 * @returns iprt status code. 2901 * @param pszString The Latin-1 string to convert. 2902 * @param cchString The maximum size in chars (the type) to convert. 2903 * The conversion stops when it reaches cchString or 2904 * the string terminator ('\\0'). 2905 * Use RTSTR_MAX to translate the entire string. 2906 * @param ppwsz If cwc is non-zero, this must either be pointing 2907 * to pointer to a buffer of the specified size, or 2908 * pointer to a NULL pointer. 2909 * If *ppwsz is NULL or cwc is zero a buffer of at 2910 * least cwc items will be allocated to hold the 2911 * translated string. If a buffer was requested it 2912 * must be freed using RTUtf16Free(). 2913 * @param cwc The buffer size in RTUTF16s. This includes the 2914 * terminator. 2915 * @param pcwc Where to store the length of the translated string, 2916 * excluding the terminator. (Optional) 2917 * 2918 * This may be set under some error conditions, 2919 * however, only for VERR_BUFFER_OVERFLOW and 2920 * VERR_NO_STR_MEMORY will it contain a valid string 2921 * length that can be used to resize the buffer. 2922 * @param pszTag Allocation tag used for statistics and such. 2923 */ 2924 RTDECL(int) RTLatin1ToUtf16ExTag(const char *pszString, size_t cchString, 2925 PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc, const char *pszTag); 2377 2926 2378 2927 /** @} */ -
trunk/src/VBox/HostDrivers/Support/SUPDrv.c
r30320 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 09Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 181 181 { "SUPGetGIP", (void *)SUPGetGIP }, 182 182 { "g_pSUPGlobalInfoPage", (void *)&g_pSUPGlobalInfoPage }, 183 { "RTMemAlloc", (void *)RTMemAlloc }, 184 { "RTMemAllocZ", (void *)RTMemAllocZ }, 183 { "RTMemAllocTag", (void *)RTMemAllocTag }, 184 { "RTMemAllocZTag", (void *)RTMemAllocZTag }, 185 { "RTMemAllocVarTag", (void *)RTMemAllocVarTag }, 186 { "RTMemAllocZVarTag", (void *)RTMemAllocZVarTag }, 185 187 { "RTMemFree", (void *)RTMemFree }, 186 /*{ "RTMemDup", (void *)RTMemDup},187 { "RTMemDupEx ", (void *)RTMemDupEx },*/188 { "RTMemRealloc ", (void *)RTMemRealloc},189 { "RTR0MemObjAllocLow ", (void *)RTR0MemObjAllocLow},190 { "RTR0MemObjAllocPage ", (void *)RTR0MemObjAllocPage},191 { "RTR0MemObjAllocPhys ", (void *)RTR0MemObjAllocPhys},192 { "RTR0MemObjAllocPhysEx ", (void *)RTR0MemObjAllocPhysEx},193 { "RTR0MemObjAllocPhysNC ", (void *)RTR0MemObjAllocPhysNC},194 { "RTR0MemObjAllocCont ", (void *)RTR0MemObjAllocCont},195 { "RTR0MemObjEnterPhys ", (void *)RTR0MemObjEnterPhys},196 { "RTR0MemObjLockUser ", (void *)RTR0MemObjLockUser},197 { "RTR0MemObjMapKernel ", (void *)RTR0MemObjMapKernel},198 { "RTR0MemObjMapKernelEx ", (void *)RTR0MemObjMapKernelEx},199 { "RTR0MemObjMapUser ", (void *)RTR0MemObjMapUser},188 { "RTMemDupTag", (void *)RTMemDupTag }, 189 { "RTMemDupExTag", (void *)RTMemDupExTag }, 190 { "RTMemReallocTag", (void *)RTMemReallocTag }, 191 { "RTR0MemObjAllocLowTag", (void *)RTR0MemObjAllocLowTag }, 192 { "RTR0MemObjAllocPageTag", (void *)RTR0MemObjAllocPageTag }, 193 { "RTR0MemObjAllocPhysTag", (void *)RTR0MemObjAllocPhysTag }, 194 { "RTR0MemObjAllocPhysExTag", (void *)RTR0MemObjAllocPhysExTag }, 195 { "RTR0MemObjAllocPhysNCTag", (void *)RTR0MemObjAllocPhysNCTag }, 196 { "RTR0MemObjAllocContTag", (void *)RTR0MemObjAllocContTag }, 197 { "RTR0MemObjEnterPhysTag", (void *)RTR0MemObjEnterPhysTag }, 198 { "RTR0MemObjLockUserTag", (void *)RTR0MemObjLockUserTag }, 199 { "RTR0MemObjMapKernelTag", (void *)RTR0MemObjMapKernelTag }, 200 { "RTR0MemObjMapKernelExTag", (void *)RTR0MemObjMapKernelExTag }, 201 { "RTR0MemObjMapUserTag", (void *)RTR0MemObjMapUserTag }, 200 202 { "RTR0MemObjProtect", (void *)RTR0MemObjProtect }, 201 203 { "RTR0MemObjAddress", (void *)RTR0MemObjAddress }, … … 359 361 (PFNRT)RTUuidCompareStr, 360 362 (PFNRT)RTUuidFromStr, 361 (PFNRT)RTStrDup ,363 (PFNRT)RTStrDupTag, 362 364 (PFNRT)RTStrFree, 363 365 /* VBoxNetAdp */ … … 1256 1258 REQ_CHECK_EXPR_FMT(paSyms[i].offName < pReq->u.In.cbStrTab, 1257 1259 ("SUP_IOCTL_LDR_LOAD: sym #%ld: name off %#lx (max=%#lx)\n", (long)i, (long)paSyms[i].offName, (long)pReq->u.In.cbImageWithTabs)); 1258 REQ_CHECK_EXPR_FMT(RTStrEnd(&pReq->u.In.abImage[pReq->u.In.offStrTab + paSyms[i].offName], pReq->u.In.cbStrTab - paSyms[i].offName), 1260 REQ_CHECK_EXPR_FMT(RTStrEnd((char const *)&pReq->u.In.abImage[pReq->u.In.offStrTab + paSyms[i].offName], 1261 pReq->u.In.cbStrTab - paSyms[i].offName), 1259 1262 ("SUP_IOCTL_LDR_LOAD: sym #%ld: unterminated name! (%#lx / %#lx)\n", (long)i, (long)paSyms[i].offName, (long)pReq->u.In.cbImageWithTabs)); 1260 1263 } -
trunk/src/VBox/HostDrivers/Support/SUPDrvIOC.h
r28800 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 193 193 * - Nothing. 194 194 */ 195 #define SUPDRV_IOC_VERSION 0x001 40001195 #define SUPDRV_IOC_VERSION 0x00150000 196 196 197 197 /** SUP_IOCTL_COOKIE. */ -
trunk/src/VBox/HostDrivers/Support/SUPLib.cpp
r30112 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 268 268 strcpy(CookieReq.u.In.szMagic, SUPCOOKIE_MAGIC); 269 269 CookieReq.u.In.u32ReqVersion = SUPDRV_IOC_VERSION; 270 const uint32_t uMinVersion = (SUPDRV_IOC_VERSION & 0xffff0000) == 0x00140000271 ? 0x001 40001272 : 270 const uint32_t uMinVersion = /*(SUPDRV_IOC_VERSION & 0xffff0000) == 0x00150000 271 ? 0x00150001 272 :*/ SUPDRV_IOC_VERSION & 0xffff0000; 273 273 CookieReq.u.In.u32MinVersion = uMinVersion; 274 274 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_COOKIE, &CookieReq, SUP_IOCTL_COOKIE_SIZE); -
trunk/src/VBox/Runtime/common/alloc/alloc.cpp
r28800 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 36 36 37 37 #undef RTMemDup 38 #undef RTMemDupTag 38 39 #undef RTMemDupEx 40 #undef RTMemDupExTag 39 41 40 42 41 43 42 /** 43 * Duplicates a chunk of memory into a new heap block. 44 * 45 * @returns New heap block with the duplicate data. 46 * @returns NULL if we're out of memory. 47 * @param pvSrc The memory to duplicate. 48 * @param cb The amount of memory to duplicate. 49 */ 50 RTDECL(void *) RTMemDup(const void *pvSrc, size_t cb) RT_NO_THROW 44 RTDECL(void *) RTMemDupTag(const void *pvSrc, size_t cb, const char *pszTag) RT_NO_THROW 51 45 { 52 void *pvDst = RTMemAlloc (cb);46 void *pvDst = RTMemAllocTag(cb, pszTag); 53 47 if (pvDst) 54 48 memcpy(pvDst, pvSrc, cb); 55 49 return pvDst; 56 50 } 57 RT_EXPORT_SYMBOL(RTMemDup );51 RT_EXPORT_SYMBOL(RTMemDupTag); 58 52 59 53 60 /** 61 * Duplicates a chunk of memory into a new heap block with some 62 * additional zeroed memory. 63 * 64 * @returns New heap block with the duplicate data. 65 * @returns NULL if we're out of memory. 66 * @param pvSrc The memory to duplicate. 67 * @param cbSrc The amount of memory to duplicate. 68 * @param cbExtra The amount of extra memory to allocate and zero. 69 */ 70 RTDECL(void *) RTMemDupEx(const void *pvSrc, size_t cbSrc, size_t cbExtra) RT_NO_THROW 54 RTDECL(void *) RTMemDupExTag(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag) RT_NO_THROW 71 55 { 72 void *pvDst = RTMemAlloc (cbSrc + cbExtra);56 void *pvDst = RTMemAllocTag(cbSrc + cbExtra, pszTag); 73 57 if (pvDst) 74 58 { … … 78 62 return pvDst; 79 63 } 80 RT_EXPORT_SYMBOL(RTMemDupEx );64 RT_EXPORT_SYMBOL(RTMemDupExTag); 81 65 -
trunk/src/VBox/Runtime/common/string/straprintf.cpp
r28800 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 43 43 { 44 44 /** Pointer to current buffer position. */ 45 char *psz;45 char *psz; 46 46 /** Number of bytes left in the buffer - not including the trailing zero. */ 47 size_t cch;47 size_t cch; 48 48 /** Pointer to the start of the buffer. */ 49 char *pszBuffer;49 char *pszBuffer; 50 50 /** The number of bytes in the buffer. */ 51 size_t cchBuffer;51 size_t cchBuffer; 52 52 /** Set if the buffer was allocated using RTMemRealloc(). If clear 53 53 * pszBuffer points to the initial stack buffer. */ 54 bool fAllocated; 54 bool fAllocated; 55 /** Allocation tag used for statistics and such. */ 56 const char *pszTag; 55 57 } STRALLOCARG; 56 58 /** Pointer to a strallocoutput() argument structure. */ … … 100 102 if (cbAdded <= _1G) 101 103 { 102 char *pszBuffer = (char *)RTMemRealloc(pArg->fAllocated ? pArg->pszBuffer : NULL, cbAdded + pArg->cchBuffer); 104 char *pszBuffer = (char *)RTMemReallocTag(pArg->fAllocated ? pArg->pszBuffer : NULL, 105 cbAdded + pArg->cchBuffer, pArg->pszTag); 103 106 if (pszBuffer) 104 107 { … … 135 138 136 139 137 RTDECL(int) RTStrAPrintfV (char **ppszBuffer, const char *pszFormat, va_list args)140 RTDECL(int) RTStrAPrintfVTag(char **ppszBuffer, const char *pszFormat, va_list args, const char *pszTag) 138 141 { 139 142 char szBuf[2048]; … … 144 147 Arg.cch = sizeof(szBuf) - 1; 145 148 Arg.psz = szBuf; 149 Arg.pszTag = pszTag; 146 150 szBuf[0] = '\0'; 147 151 int cbRet = (int)RTStrFormatV(strallocoutput, &Arg, NULL, NULL, pszFormat, args); … … 152 156 /* duplicate the string in szBuf */ 153 157 Assert(Arg.pszBuffer == szBuf); 154 char *psz = (char *)RTMemAlloc (cbRet + 1);158 char *psz = (char *)RTMemAllocTag(cbRet + 1, pszTag); 155 159 if (psz) 156 160 memcpy(psz, szBuf, cbRet + 1); … … 160 164 { 161 165 /* adjust the allocated buffer */ 162 char *psz = (char *)RTMemRealloc (Arg.pszBuffer, cbRet + 1);166 char *psz = (char *)RTMemReallocTag(Arg.pszBuffer, cbRet + 1, pszTag); 163 167 *ppszBuffer = psz ? psz : Arg.pszBuffer; 164 168 } … … 177 181 return cbRet; 178 182 } 179 RT_EXPORT_SYMBOL(RTStrAPrintfV );183 RT_EXPORT_SYMBOL(RTStrAPrintfVTag); 180 184 181 185 182 RTDECL(int) RTStrAPrintf(char **ppszBuffer, const char *pszFormat, ...) 183 { 184 va_list args; 185 va_start(args, pszFormat); 186 int cbRet = RTStrAPrintfV(ppszBuffer, pszFormat, args); 187 va_end(args); 188 return cbRet; 189 } 190 RT_EXPORT_SYMBOL(RTStrAPrintf); 191 192 193 RTDECL(char *) RTStrAPrintf2V(const char *pszFormat, va_list args) 186 RTDECL(char *) RTStrAPrintf2VTag(const char *pszFormat, va_list args, const char *pszTag) 194 187 { 195 188 char *pszBuffer; 196 RTStrAPrintfV (&pszBuffer, pszFormat, args);189 RTStrAPrintfVTag(&pszBuffer, pszFormat, args, pszTag); 197 190 return pszBuffer; 198 191 } 199 RT_EXPORT_SYMBOL(RTStrAPrintf2V );192 RT_EXPORT_SYMBOL(RTStrAPrintf2VTag); 200 193 201 202 RTDECL(char *) RTStrAPrintf2(const char *pszFormat, ...)203 {204 va_list va;205 char *pszBuffer;206 207 va_start(va, pszFormat);208 RTStrAPrintfV(&pszBuffer, pszFormat, va);209 va_end(va);210 211 return pszBuffer;212 }213 RT_EXPORT_SYMBOL(RTStrAPrintf2);214 -
trunk/src/VBox/Runtime/common/string/stringalloc.cpp
r30320 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 40 40 41 41 42 RTDECL(char *) RTStrAlloc (size_t cb)43 { 44 char *psz = (char *)RTMemAlloc (RT_MAX(cb, 1));42 RTDECL(char *) RTStrAllocTag(size_t cb, const char *pszTag) 43 { 44 char *psz = (char *)RTMemAllocTag(RT_MAX(cb, 1), pszTag); 45 45 if (psz) 46 46 *psz = '\0'; 47 47 return psz; 48 48 } 49 RT_EXPORT_SYMBOL(RTStrAlloc );50 51 52 RTDECL(int) RTStrAllocEx (char **ppsz, size_t cb)53 { 54 char *psz = *ppsz = (char *)RTMemAlloc (RT_MAX(cb, 1));49 RT_EXPORT_SYMBOL(RTStrAllocTag); 50 51 52 RTDECL(int) RTStrAllocExTag(char **ppsz, size_t cb, const char *pszTag) 53 { 54 char *psz = *ppsz = (char *)RTMemAllocTag(RT_MAX(cb, 1), pszTag); 55 55 if (psz) 56 56 { … … 60 60 return VERR_NO_STR_MEMORY; 61 61 } 62 RT_EXPORT_SYMBOL(RTStrAlloc );63 64 65 RTDECL(int) RTStrRealloc (char **ppsz, size_t cbNew)62 RT_EXPORT_SYMBOL(RTStrAllocTag); 63 64 65 RTDECL(int) RTStrReallocTag(char **ppsz, size_t cbNew, const char *pszTag) 66 66 { 67 67 char *pszOld = *ppsz; … … 73 73 else if (pszOld) 74 74 { 75 char *pszNew = (char *)RTMemRealloc (pszOld, cbNew);75 char *pszNew = (char *)RTMemReallocTag(pszOld, cbNew, pszTag); 76 76 if (!pszNew) 77 77 return VERR_NO_STR_MEMORY; … … 81 81 else 82 82 { 83 char *pszNew = (char *)RTMemAlloc (cbNew);83 char *pszNew = (char *)RTMemAllocTag(cbNew, pszTag); 84 84 if (!pszNew) 85 85 return VERR_NO_STR_MEMORY; … … 90 90 return VINF_SUCCESS; 91 91 } 92 RT_EXPORT_SYMBOL(RTStrReallocTag); 92 93 93 94 RTDECL(void) RTStrFree(char *pszString) … … 99 100 100 101 101 RTDECL(char *) RTStrDup (const char *pszString)102 RTDECL(char *) RTStrDupTag(const char *pszString, const char *pszTag) 102 103 { 103 104 AssertPtr(pszString); 104 105 size_t cch = strlen(pszString) + 1; 105 char *psz = (char *)RTMemAlloc (cch);106 char *psz = (char *)RTMemAllocTag(cch, pszTag); 106 107 if (psz) 107 108 memcpy(psz, pszString, cch); 108 109 return psz; 109 110 } 110 RT_EXPORT_SYMBOL(RTStrDup );111 112 113 RTDECL(int) RTStrDupEx (char **ppszString, const char *pszString)111 RT_EXPORT_SYMBOL(RTStrDupTag); 112 113 114 RTDECL(int) RTStrDupExTag(char **ppszString, const char *pszString, const char *pszTag) 114 115 { 115 116 AssertPtr(ppszString); … … 117 118 118 119 size_t cch = strlen(pszString) + 1; 119 char *psz = (char *)RTMemAlloc (cch);120 char *psz = (char *)RTMemAllocTag(cch, pszTag); 120 121 if (psz) 121 122 { … … 126 127 return VERR_NO_MEMORY; 127 128 } 128 RT_EXPORT_SYMBOL(RTStrDupEx );129 130 131 RTDECL(char *) RTStrDupN (const char *pszString, size_t cchMax)129 RT_EXPORT_SYMBOL(RTStrDupExTag); 130 131 132 RTDECL(char *) RTStrDupNTag(const char *pszString, size_t cchMax, const char *pszTag) 132 133 { 133 134 AssertPtr(pszString); 134 135 char const *pszEnd = RTStrEnd(pszString, cchMax); 135 136 size_t cch = pszEnd ? (uintptr_t)pszEnd - (uintptr_t)pszString : cchMax; 136 char *pszDst = (char *)RTMemAlloc (cch + 1);137 char *pszDst = (char *)RTMemAllocTag(cch + 1, pszTag); 137 138 if (pszDst) 138 139 { … … 142 143 return pszDst; 143 144 } 144 RT_EXPORT_SYMBOL(RTStrDupN );145 146 147 RTDECL(int) RTStrAAppend (char **ppsz, const char *pszAppend)145 RT_EXPORT_SYMBOL(RTStrDupNTag); 146 147 148 RTDECL(int) RTStrAAppendTag(char **ppsz, const char *pszAppend, const char *pszTag) 148 149 { 149 150 if (!pszAppend) 150 151 return VINF_SUCCESS; 151 return RTStrAAppendN (ppsz, pszAppend, RTSTR_MAX);152 } 153 154 155 RTDECL(int) RTStrAAppendN (char **ppsz, const char *pszAppend, size_t cchAppend)152 return RTStrAAppendNTag(ppsz, pszAppend, RTSTR_MAX, pszTag); 153 } 154 155 156 RTDECL(int) RTStrAAppendNTag(char **ppsz, const char *pszAppend, size_t cchAppend, const char *pszTag) 156 157 { 157 158 if (!cchAppend) … … 163 164 164 165 size_t const cchOrg = *ppsz ? strlen(*ppsz) : 0; 165 char *pszNew = (char *)RTMemRealloc (*ppsz, cchOrg + cchAppend + 1);166 char *pszNew = (char *)RTMemReallocTag(*ppsz, cchOrg + cchAppend + 1, pszTag); 166 167 if (!pszNew) 167 168 return VERR_NO_STR_MEMORY; … … 175 176 176 177 177 RTDECL(int) RTStrAAppendExNV (char **ppsz, size_t cPairs, va_list va)178 RTDECL(int) RTStrAAppendExNVTag(char **ppsz, size_t cPairs, va_list va, const char *pszTag) 178 179 { 179 180 AssertPtr(ppsz); … … 212 213 * Try reallocate the string. 213 214 */ 214 char *pszNew = (char *)RTMemRealloc (*ppsz, cchNewTotal);215 char *pszNew = (char *)RTMemReallocTag(*ppsz, cchNewTotal, pszTag); 215 216 if (!pszNew) 216 217 return VERR_NO_STR_MEMORY; … … 232 233 return VINF_SUCCESS; 233 234 } 234 RT_EXPORT_SYMBOL(RTStrAAppendExNV); 235 236 237 RTDECL(int) RTStrAAppendExN(char **ppsz, size_t cPairs, ...) 238 { 239 va_list va; 240 va_start(va, cPairs); 241 int rc = RTStrAAppendExNV(ppsz, cPairs, va); 242 va_end(va); 243 return rc; 244 } 245 RT_EXPORT_SYMBOL(RTStrAAppendExN); 246 247 248 RTDECL(int) RTStrATruncate(char **ppsz, size_t cchNew) 235 RT_EXPORT_SYMBOL(RTStrAAppendExNVTag); 236 237 238 RTDECL(int) RTStrATruncateTag(char **ppsz, size_t cchNew, const char *pszTag) 249 239 { 250 240 char *pszOld = *ppsz; … … 254 244 { 255 245 *pszOld = '\0'; 256 char *pszNew = (char *)RTMemRealloc (pszOld, 1);246 char *pszNew = (char *)RTMemReallocTag(pszOld, 1, pszTag); 257 247 if (pszNew) 258 248 *ppsz = pszNew; … … 268 258 if (!pszZero) 269 259 { 270 char *pszNew = (char *)RTMemRealloc (pszOld, cchNew + 1);260 char *pszNew = (char *)RTMemReallocTag(pszOld, cchNew + 1, pszTag); 271 261 if (pszNew) 272 262 *ppsz = pszNew; … … 275 265 return VINF_SUCCESS; 276 266 } 277 RT_EXPORT_SYMBOL(RTStrATruncate );278 267 RT_EXPORT_SYMBOL(RTStrATruncateTag); 268 -
trunk/src/VBox/Runtime/common/string/utf-16.cpp
r30749 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 48 48 49 49 50 RTDECL(PRTUTF16) RTUtf16Dup (PCRTUTF16 pwszString)50 RTDECL(PRTUTF16) RTUtf16DupTag(PCRTUTF16 pwszString, const char *pszTag) 51 51 { 52 52 Assert(pwszString); 53 53 size_t cb = (RTUtf16Len(pwszString) + 1) * sizeof(RTUTF16); 54 PRTUTF16 pwsz = (PRTUTF16)RTMemAlloc (cb);54 PRTUTF16 pwsz = (PRTUTF16)RTMemAllocTag(cb, pszTag); 55 55 if (pwsz) 56 56 memcpy(pwsz, pwszString, cb); 57 57 return pwsz; 58 58 } 59 RT_EXPORT_SYMBOL(RTUtf16Dup );60 61 62 RTDECL(int) RTUtf16DupEx (PRTUTF16 *ppwszString, PCRTUTF16 pwszString, size_t cwcExtra)59 RT_EXPORT_SYMBOL(RTUtf16DupTag); 60 61 62 RTDECL(int) RTUtf16DupExTag(PRTUTF16 *ppwszString, PCRTUTF16 pwszString, size_t cwcExtra, const char *pszTag) 63 63 { 64 64 Assert(pwszString); 65 65 size_t cb = (RTUtf16Len(pwszString) + 1) * sizeof(RTUTF16); 66 PRTUTF16 pwsz = (PRTUTF16)RTMemAlloc (cb + cwcExtra * sizeof(RTUTF16));66 PRTUTF16 pwsz = (PRTUTF16)RTMemAllocTag(cb + cwcExtra * sizeof(RTUTF16), pszTag); 67 67 if (pwsz) 68 68 { … … 73 73 return VERR_NO_MEMORY; 74 74 } 75 RT_EXPORT_SYMBOL(RTUtf16DupEx );75 RT_EXPORT_SYMBOL(RTUtf16DupExTag); 76 76 77 77 … … 425 425 426 426 427 RTDECL(int) RTUtf16ToUtf8 (PCRTUTF16 pwszString, char **ppszString)427 RTDECL(int) RTUtf16ToUtf8Tag(PCRTUTF16 pwszString, char **ppszString, const char *pszTag) 428 428 { 429 429 /* … … 444 444 * Allocate buffer and recode it. 445 445 */ 446 char *pszResult = (char *)RTMemAlloc (cch + 1);446 char *pszResult = (char *)RTMemAllocTag(cch + 1, pszTag); 447 447 if (pszResult) 448 448 { … … 461 461 return rc; 462 462 } 463 RT_EXPORT_SYMBOL(RTUtf16ToUtf8 );464 465 466 RTDECL(int) RTUtf16ToUtf8Ex (PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch)463 RT_EXPORT_SYMBOL(RTUtf16ToUtf8Tag); 464 465 466 RTDECL(int) RTUtf16ToUtf8ExTag(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch, const char *pszTag) 467 467 { 468 468 /* … … 500 500 fShouldFree = true; 501 501 cch = RT_MAX(cch, cchResult + 1); 502 pszResult = (char *)RTStrAlloc (cch);502 pszResult = (char *)RTStrAllocTag(cch, pszTag); 503 503 } 504 504 if (pszResult) … … 519 519 return rc; 520 520 } 521 RT_EXPORT_SYMBOL(RTUtf16ToUtf8Ex );521 RT_EXPORT_SYMBOL(RTUtf16ToUtf8ExTag); 522 522 523 523 … … 785 785 786 786 787 RTDECL(int) RTUtf16ToLatin1 (PCRTUTF16 pwszString, char **ppszString)787 RTDECL(int) RTUtf16ToLatin1Tag(PCRTUTF16 pwszString, char **ppszString, const char *pszTag) 788 788 { 789 789 /* … … 804 804 * Allocate buffer and recode it. 805 805 */ 806 char *pszResult = (char *)RTMemAlloc (cch + 1);806 char *pszResult = (char *)RTMemAllocTag(cch + 1, pszTag); 807 807 if (pszResult) 808 808 { … … 821 821 return rc; 822 822 } 823 RT_EXPORT_SYMBOL(RTUtf16ToLatin1 );824 825 826 RTDECL(int) RTUtf16ToLatin1Ex (PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch)823 RT_EXPORT_SYMBOL(RTUtf16ToLatin1Tag); 824 825 826 RTDECL(int) RTUtf16ToLatin1ExTag(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch, const char *pszTag) 827 827 { 828 828 /* … … 860 860 fShouldFree = true; 861 861 cch = RT_MAX(cch, cchResult + 1); 862 pszResult = (char *)RTMemAlloc (cch);862 pszResult = (char *)RTMemAllocTag(cch, pszTag); 863 863 } 864 864 if (pszResult) … … 879 879 return rc; 880 880 } 881 RT_EXPORT_SYMBOL(RTUtf16ToLatin1Ex );881 RT_EXPORT_SYMBOL(RTUtf16ToLatin1ExTag); 882 882 883 883 … … 964 964 965 965 966 RTDECL(int) RTLatin1ToUtf16 (const char *pszString, PRTUTF16 *ppwszString)966 RTDECL(int) RTLatin1ToUtf16Tag(const char *pszString, PRTUTF16 *ppwszString, const char *pszTag) 967 967 { 968 968 /* … … 983 983 * Allocate buffer. 984 984 */ 985 PRTUTF16 pwsz = (PRTUTF16)RTMemAlloc ((cwc + 1) * sizeof(RTUTF16));985 PRTUTF16 pwsz = (PRTUTF16)RTMemAllocTag((cwc + 1) * sizeof(RTUTF16), pszTag); 986 986 if (pwsz) 987 987 { … … 1002 1002 return rc; 1003 1003 } 1004 RT_EXPORT_SYMBOL(RTLatin1ToUtf16); 1005 1006 1007 RTDECL(int) RTLatin1ToUtf16Ex(const char *pszString, size_t cchString, PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc) 1004 RT_EXPORT_SYMBOL(RTLatin1ToUtf16Tag); 1005 1006 1007 RTDECL(int) RTLatin1ToUtf16ExTag(const char *pszString, size_t cchString, 1008 PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc, const char *pszTag) 1008 1009 { 1009 1010 /* … … 1041 1042 fShouldFree = true; 1042 1043 cwc = RT_MAX(cwcResult + 1, cwc); 1043 pwszResult = (PRTUTF16)RTMemAlloc (cwc * sizeof(RTUTF16));1044 pwszResult = (PRTUTF16)RTMemAllocTag(cwc * sizeof(RTUTF16), pszTag); 1044 1045 } 1045 1046 if (pwszResult) … … 1062 1063 return rc; 1063 1064 } 1064 RT_EXPORT_SYMBOL(RTLatin1ToUtf16Ex );1065 RT_EXPORT_SYMBOL(RTLatin1ToUtf16ExTag); 1065 1066 1066 1067 -
trunk/src/VBox/Runtime/common/string/utf-8.cpp
r30859 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 09Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 672 672 673 673 674 RTDECL(int) RTStrToUtf16 (const char *pszString, PRTUTF16 *ppwszString)674 RTDECL(int) RTStrToUtf16Tag(const char *pszString, PRTUTF16 *ppwszString, const char *pszTag) 675 675 { 676 676 /* … … 691 691 * Allocate buffer. 692 692 */ 693 PRTUTF16 pwsz = (PRTUTF16)RTMemAlloc ((cwc + 1) * sizeof(RTUTF16));693 PRTUTF16 pwsz = (PRTUTF16)RTMemAllocTag((cwc + 1) * sizeof(RTUTF16), pszTag); 694 694 if (pwsz) 695 695 { … … 710 710 return rc; 711 711 } 712 RT_EXPORT_SYMBOL(RTStrToUtf16); 713 714 715 RTDECL(int) RTStrToUtf16Ex(const char *pszString, size_t cchString, PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc) 712 RT_EXPORT_SYMBOL(RTStrToUtf16Tag); 713 714 715 RTDECL(int) RTStrToUtf16ExTag(const char *pszString, size_t cchString, 716 PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc, const char *pszTag) 716 717 { 717 718 /* … … 749 750 fShouldFree = true; 750 751 cwc = RT_MAX(cwcResult + 1, cwc); 751 pwszResult = (PRTUTF16)RTMemAlloc (cwc * sizeof(RTUTF16));752 pwszResult = (PRTUTF16)RTMemAllocTag(cwc * sizeof(RTUTF16), pszTag); 752 753 } 753 754 if (pwszResult) … … 770 771 return rc; 771 772 } 772 RT_EXPORT_SYMBOL(RTStrToUtf16Ex );773 RT_EXPORT_SYMBOL(RTStrToUtf16ExTag); 773 774 774 775 -
trunk/src/VBox/Runtime/r0drv/alloc-r0drv.cpp
r29250 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 81 81 82 82 83 84 /** 85 * Allocates temporary memory. 86 * 87 * Temporary memory blocks are used for not too large memory blocks which 88 * are believed not to stick around for too long. Using this API instead 89 * of RTMemAlloc() not only gives the heap manager room for optimization 90 * but makes the code easier to read. 91 * 92 * @returns Pointer to the allocated memory. 93 * @returns NULL on failure. 94 * @param cb Size in bytes of the memory block to allocated. 95 */ 96 RTDECL(void *) RTMemTmpAlloc(size_t cb) RT_NO_THROW 97 { 98 return RTMemAlloc(cb); 99 } 100 RT_EXPORT_SYMBOL(RTMemTmpAlloc); 101 102 103 /** 104 * Allocates zero'ed temporary memory. 105 * 106 * Same as RTMemTmpAlloc() but the memory will be zero'ed. 107 * 108 * @returns Pointer to the allocated memory. 109 * @returns NULL on failure. 110 * @param cb Size in bytes of the memory block to allocated. 111 */ 112 RTDECL(void *) RTMemTmpAllocZ(size_t cb) RT_NO_THROW 113 { 114 return RTMemAllocZ(cb); 115 } 116 RT_EXPORT_SYMBOL(RTMemTmpAllocZ); 117 118 119 /** 120 * Free temporary memory. 121 * 122 * @param pv Pointer to memory block. 123 */ 83 #undef RTMemTmpAlloc 84 #undef RTMemTmpAllocTag 85 #undef RTMemTmpAllocZ 86 #undef RTMemTmpAllocZTag 87 #undef RTMemTmpFree 88 #undef RTMemAlloc 89 #undef RTMemAllocTag 90 #undef RTMemAllocZ 91 #undef RTMemAllocZTag 92 #undef RTMemAllocVar 93 #undef RTMemAllocVarTag 94 #undef RTMemAllocZVar 95 #undef RTMemAllocZVarTag 96 #undef RTMemRealloc 97 #undef RTMemReallocTag 98 #undef RTMemFree 99 #undef RTMemDup 100 #undef RTMemDupTag 101 #undef RTMemDupEx 102 #undef RTMemDupExTag 103 104 105 106 RTDECL(void *) RTMemTmpAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 107 { 108 return RTMemAllocTag(cb, pszTag); 109 } 110 RT_EXPORT_SYMBOL(RTMemTmpAllocTag); 111 112 113 RTDECL(void *) RTMemTmpAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW 114 { 115 return RTMemAllocZTag(cb, pszTag); 116 } 117 RT_EXPORT_SYMBOL(RTMemTmpAllocZTag); 118 119 124 120 RTDECL(void) RTMemTmpFree(void *pv) RT_NO_THROW 125 121 { … … 129 125 130 126 131 /** 132 * Allocates memory. 133 * 134 * @returns Pointer to the allocated memory. 135 * @returns NULL on failure. 136 * @param cb Size in bytes of the memory block to allocated. 137 */ 138 RTDECL(void *) RTMemAlloc(size_t cb) RT_NO_THROW 127 128 129 130 RTDECL(void *) RTMemAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 139 131 { 140 132 PRTMEMHDR pHdr; … … 152 144 return NULL; 153 145 } 154 RT_EXPORT_SYMBOL(RTMemAlloc); 155 156 157 /** 158 * Allocates zero'ed memory. 159 * 160 * Instead of memset(pv, 0, sizeof()) use this when you want zero'ed 161 * memory. This keeps the code smaller and the heap can skip the memset 162 * in about 0.42% of calls :-). 163 * 164 * @returns Pointer to the allocated memory. 165 * @returns NULL on failure. 166 * @param cb Size in bytes of the memory block to allocated. 167 */ 168 RTDECL(void *) RTMemAllocZ(size_t cb) RT_NO_THROW 146 RT_EXPORT_SYMBOL(RTMemAllocTag); 147 148 149 RTDECL(void *) RTMemAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW 169 150 { 170 151 PRTMEMHDR pHdr; … … 184 165 return NULL; 185 166 } 186 RT_EXPORT_SYMBOL(RTMemAllocZ); 187 188 189 /** 190 * Wrapper around RTMemAlloc for automatically aligning variable sized 191 * allocations so that the various electric fence heaps works correctly. 192 * 193 * @returns See RTMemAlloc. 194 * @param cbUnaligned The unaligned size. 195 */ 196 RTDECL(void *) RTMemAllocVar(size_t cbUnaligned) 167 RT_EXPORT_SYMBOL(RTMemAllocZTag); 168 169 170 RTDECL(void *) RTMemAllocVarTag(size_t cbUnaligned, const char *pszTag) 197 171 { 198 172 size_t cbAligned; … … 201 175 else 202 176 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 203 return RTMemAlloc(cbAligned); 204 } 205 RT_EXPORT_SYMBOL(RTMemAllocVar); 206 207 208 /** 209 * Wrapper around RTMemAllocZ for automatically aligning variable sized 210 * allocations so that the various electric fence heaps works correctly. 211 * 212 * @returns See RTMemAllocZ. 213 * @param cbUnaligned The unaligned size. 214 */ 215 RTDECL(void *) RTMemAllocZVar(size_t cbUnaligned) 177 return RTMemAllocTag(cbAligned, pszTag); 178 } 179 RT_EXPORT_SYMBOL(RTMemAllocVarTag); 180 181 182 RTDECL(void *) RTMemAllocZVarTag(size_t cbUnaligned, const char *pszTag) 216 183 { 217 184 size_t cbAligned; … … 220 187 else 221 188 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 222 return RTMemAllocZ(cbAligned); 223 } 224 RT_EXPORT_SYMBOL(RTMemAllocZVar); 225 226 227 /** 228 * Reallocates memory. 229 * 230 * @returns Pointer to the allocated memory. 231 * @returns NULL on failure. 232 * @param pvOld The memory block to reallocate. 233 * @param cbNew The new block size (in bytes). 234 */ 235 RTDECL(void *) RTMemRealloc(void *pvOld, size_t cbNew) RT_NO_THROW 189 return RTMemAllocZTag(cbAligned, pszTag); 190 } 191 RT_EXPORT_SYMBOL(RTMemAllocZVarTag); 192 193 194 RTDECL(void *) RTMemReallocTag(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW 236 195 { 237 196 if (!cbNew) 238 197 RTMemFree(pvOld); 239 198 else if (!pvOld) 240 return RTMemAlloc (cbNew);199 return RTMemAllocTag(cbNew, pszTag); 241 200 else 242 201 { … … 275 234 return NULL; 276 235 } 277 RT_EXPORT_SYMBOL(RTMemRealloc); 278 279 280 /** 281 * Free memory related to an virtual machine 282 * 283 * @param pv Pointer to memory block. 284 */ 236 RT_EXPORT_SYMBOL(RTMemReallocTag); 237 238 285 239 RTDECL(void) RTMemFree(void *pv) RT_NO_THROW 286 240 { … … 311 265 312 266 313 /** 314 * Allocates memory which may contain code. 315 * 316 * @returns Pointer to the allocated memory. 317 * @returns NULL on failure. 318 * @param cb Size in bytes of the memory block to allocate. 319 */ 320 RTDECL(void *) RTMemExecAlloc(size_t cb) RT_NO_THROW 267 268 269 270 271 RTDECL(void *) RTMemExecAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 321 272 { 322 273 PRTMEMHDR pHdr; … … 338 289 return NULL; 339 290 } 340 RT_EXPORT_SYMBOL(RTMemExecAlloc); 341 342 343 /** 344 * Free executable/read/write memory allocated by RTMemExecAlloc(). 345 * 346 * @param pv Pointer to memory block. 347 */ 291 RT_EXPORT_SYMBOL(RTMemExecAllocTag); 292 293 348 294 RTDECL(void) RTMemExecFree(void *pv) RT_NO_THROW 349 295 { -
trunk/src/VBox/Runtime/r0drv/memobj-r0drv.cpp
r29027 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 405 405 406 406 407 /** 408 * Allocates page aligned virtual kernel memory. 409 * 410 * The memory is taken from a non paged (= fixed physical memory backing) pool. 411 * 412 * @returns IPRT status code. 413 * @param pMemObj Where to store the ring-0 memory object handle. 414 * @param cb Number of bytes to allocate. This is rounded up to nearest page. 415 * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. 416 */ 417 RTR0DECL(int) RTR0MemObjAllocPage(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable) 407 RTR0DECL(int) RTR0MemObjAllocPageTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag) 418 408 { 419 409 /* sanity checks. */ … … 428 418 return rtR0MemObjNativeAllocPage(pMemObj, cbAligned, fExecutable); 429 419 } 430 RT_EXPORT_SYMBOL(RTR0MemObjAllocPage); 431 432 433 /** 434 * Allocates page aligned virtual kernel memory with physical backing below 4GB. 435 * 436 * The physical memory backing the allocation is fixed. 437 * 438 * @returns IPRT status code. 439 * @param pMemObj Where to store the ring-0 memory object handle. 440 * @param cb Number of bytes to allocate. This is rounded up to nearest page. 441 * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. 442 */ 443 RTR0DECL(int) RTR0MemObjAllocLow(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable) 420 RT_EXPORT_SYMBOL(RTR0MemObjAllocPageTag); 421 422 423 RTR0DECL(int) RTR0MemObjAllocLowTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag) 444 424 { 445 425 /* sanity checks. */ … … 454 434 return rtR0MemObjNativeAllocLow(pMemObj, cbAligned, fExecutable); 455 435 } 456 RT_EXPORT_SYMBOL(RTR0MemObjAllocLow); 457 458 459 /** 460 * Allocates page aligned virtual kernel memory with contiguous physical backing below 4GB. 461 * 462 * The physical memory backing the allocation is fixed. 463 * 464 * @returns IPRT status code. 465 * @param pMemObj Where to store the ring-0 memory object handle. 466 * @param cb Number of bytes to allocate. This is rounded up to nearest page. 467 * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. 468 */ 469 RTR0DECL(int) RTR0MemObjAllocCont(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable) 436 RT_EXPORT_SYMBOL(RTR0MemObjAllocLowTag); 437 438 439 RTR0DECL(int) RTR0MemObjAllocContTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag) 470 440 { 471 441 /* sanity checks. */ … … 480 450 return rtR0MemObjNativeAllocCont(pMemObj, cbAligned, fExecutable); 481 451 } 482 RT_EXPORT_SYMBOL(RTR0MemObjAllocCont); 483 484 485 /** 486 * Locks a range of user virtual memory. 487 * 488 * @returns IPRT status code. 489 * @param pMemObj Where to store the ring-0 memory object handle. 490 * @param R3Ptr User virtual address. This is rounded down to a page 491 * boundrary. 492 * @param cb Number of bytes to lock. This is rounded up to 493 * nearest page boundrary. 494 * @param fAccess The desired access, a combination of RTMEM_PROT_READ 495 * and RTMEM_PROT_WRITE. 496 * @param R0Process The process to lock pages in. NIL_RTR0PROCESS is an 497 * alias for the current one. 498 * 499 * @remarks RTR0MemGetAddressR3() and RTR0MemGetAddress() will return therounded 500 * down address. 501 * 502 * @remarks Linux: This API requires that the memory begin locked is in a memory 503 * mapping that is not required in any forked off child process. This 504 * is not intented as permanent restriction, feel free to help out 505 * lifting it. 506 */ 507 RTR0DECL(int) RTR0MemObjLockUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess, RTR0PROCESS R0Process) 452 RT_EXPORT_SYMBOL(RTR0MemObjAllocContTag); 453 454 455 RTR0DECL(int) RTR0MemObjLockUserTag(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb, 456 uint32_t fAccess, RTR0PROCESS R0Process, const char *pszTag) 508 457 { 509 458 /* sanity checks. */ … … 523 472 return rtR0MemObjNativeLockUser(pMemObj, R3PtrAligned, cbAligned, fAccess, R0Process); 524 473 } 525 RT_EXPORT_SYMBOL(RTR0MemObjLockUser); 526 527 528 /** 529 * Locks a range of kernel virtual memory. 530 * 531 * @returns IPRT status code. 532 * @param pMemObj Where to store the ring-0 memory object handle. 533 * @param pv Kernel virtual address. This is rounded down to a page boundrary. 534 * @param cb Number of bytes to lock. This is rounded up to nearest page boundrary. 535 * @param fAccess The desired access, a combination of RTMEM_PROT_READ 536 * and RTMEM_PROT_WRITE. 537 * 538 * @remark RTR0MemGetAddress() will return the rounded down address. 539 */ 540 RTR0DECL(int) RTR0MemObjLockKernel(PRTR0MEMOBJ pMemObj, void *pv, size_t cb, uint32_t fAccess) 474 RT_EXPORT_SYMBOL(RTR0MemObjLockUserTag); 475 476 477 RTR0DECL(int) RTR0MemObjLockKernelTag(PRTR0MEMOBJ pMemObj, void *pv, size_t cb, uint32_t fAccess, const char *pszTag) 541 478 { 542 479 /* sanity checks. */ … … 555 492 return rtR0MemObjNativeLockKernel(pMemObj, pvAligned, cbAligned, fAccess); 556 493 } 557 RT_EXPORT_SYMBOL(RTR0MemObjLockKernel); 558 559 560 /** 561 * Allocates contiguous page aligned physical memory without (necessarily) any kernel mapping. 562 * 563 * @returns IPRT status code. 564 * @param pMemObj Where to store the ring-0 memory object handle. 565 * @param cb Number of bytes to allocate. This is rounded up to nearest page. 566 * @param PhysHighest The highest permittable address (inclusive). 567 * Pass NIL_RTHCPHYS if any address is acceptable. 568 */ 569 RTR0DECL(int) RTR0MemObjAllocPhys(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest) 494 RT_EXPORT_SYMBOL(RTR0MemObjLockKernelTag); 495 496 497 RTR0DECL(int) RTR0MemObjAllocPhysTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, const char *pszTag) 570 498 { 571 499 /* sanity checks. */ … … 581 509 return rtR0MemObjNativeAllocPhys(pMemObj, cbAligned, PhysHighest, PAGE_SIZE /* page aligned */); 582 510 } 583 RT_EXPORT_SYMBOL(RTR0MemObjAllocPhys); 584 585 586 /** 587 * Allocates contiguous physical memory without (necessarily) any kernel mapping. 588 * 589 * @returns IPRT status code. 590 * @param pMemObj Where to store the ring-0 memory object handle. 591 * @param cb Number of bytes to allocate. This is rounded up to nearest page. 592 * @param PhysHighest The highest permittable address (inclusive). 593 * Pass NIL_RTHCPHYS if any address is acceptable. 594 * @param uAlignment The alignment of the physical memory to allocate. 595 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M, _4M and _1G. 596 */ 597 RTR0DECL(int) RTR0MemObjAllocPhysEx(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment) 511 RT_EXPORT_SYMBOL(RTR0MemObjAllocPhysTag); 512 513 514 RTR0DECL(int) RTR0MemObjAllocPhysExTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment, const char *pszTag) 598 515 { 599 516 /* sanity checks. */ … … 622 539 return rtR0MemObjNativeAllocPhys(pMemObj, cbAligned, PhysHighest, uAlignment); 623 540 } 624 RT_EXPORT_SYMBOL(RTR0MemObjAllocPhysEx); 625 626 627 /** 628 * Allocates non-contiguous page aligned physical memory without (necessarily) any kernel mapping. 629 * 630 * @returns IPRT status code. 631 * @param pMemObj Where to store the ring-0 memory object handle. 632 * @param cb Number of bytes to allocate. This is rounded up to nearest page. 633 * @param PhysHighest The highest permittable address (inclusive). 634 * Pass NIL_RTHCPHYS if any address is acceptable. 635 */ 636 RTR0DECL(int) RTR0MemObjAllocPhysNC(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest) 541 RT_EXPORT_SYMBOL(RTR0MemObjAllocPhysExTag); 542 543 544 RTR0DECL(int) RTR0MemObjAllocPhysNCTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, const char *pszTag) 637 545 { 638 546 /* sanity checks. */ … … 648 556 return rtR0MemObjNativeAllocPhysNC(pMemObj, cbAligned, PhysHighest); 649 557 } 650 RT_EXPORT_SYMBOL(RTR0MemObjAllocPhysNC); 651 652 653 /** 654 * Creates a page aligned, contiguous, physical memory object. 655 * 656 * No physical memory is allocated, we trust you do know what you're doing. 657 * 658 * @returns IPRT status code. 659 * @param pMemObj Where to store the ring-0 memory object handle. 660 * @param Phys The physical address to start at. This is rounded down to the 661 * nearest page boundrary. 662 * @param cb The size of the object in bytes. This is rounded up to nearest page boundrary. 663 * @param uCachePolicy One of the RTMEM_CACHE_XXX modes. 664 */ 665 RTR0DECL(int) RTR0MemObjEnterPhys(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy) 558 RT_EXPORT_SYMBOL(RTR0MemObjAllocPhysNCTag); 559 560 561 RTR0DECL(int) RTR0MemObjEnterPhysTag(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy, const char *pszTag) 666 562 { 667 563 /* sanity checks. */ … … 681 577 return rtR0MemObjNativeEnterPhys(pMemObj, PhysAligned, cbAligned, uCachePolicy); 682 578 } 683 RT_EXPORT_SYMBOL(RTR0MemObjEnterPhys); 684 685 686 /** 687 * Reserves kernel virtual address space. 688 * 689 * @returns IPRT status code. 690 * @param pMemObj Where to store the ring-0 memory object handle. 691 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment. 692 * @param cb The number of bytes to reserve. This is rounded up to nearest page. 693 * @param uAlignment The alignment of the reserved memory. 694 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. 695 */ 696 RTR0DECL(int) RTR0MemObjReserveKernel(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment) 579 RT_EXPORT_SYMBOL(RTR0MemObjEnterPhysTag); 580 581 582 RTR0DECL(int) RTR0MemObjReserveKernelTag(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment, const char *pszTag) 697 583 { 698 584 /* sanity checks. */ … … 712 598 return rtR0MemObjNativeReserveKernel(pMemObj, pvFixed, cbAligned, uAlignment); 713 599 } 714 RT_EXPORT_SYMBOL(RTR0MemObjReserveKernel); 715 716 717 /** 718 * Reserves user virtual address space in the current process. 719 * 720 * @returns IPRT status code. 721 * @param pMemObj Where to store the ring-0 memory object handle. 722 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment. 723 * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE. 724 * @param uAlignment The alignment of the reserved memory. 725 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. 726 * @param R0Process The process to reserve the memory in. NIL_RTR0PROCESS is an alias for the current one. 727 */ 728 RTR0DECL(int) RTR0MemObjReserveUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process) 600 RT_EXPORT_SYMBOL(RTR0MemObjReserveKernelTag); 601 602 603 RTR0DECL(int) RTR0MemObjReserveUserTag(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, 604 size_t uAlignment, RTR0PROCESS R0Process, const char *pszTag) 729 605 { 730 606 /* sanity checks. */ … … 746 622 return rtR0MemObjNativeReserveUser(pMemObj, R3PtrFixed, cbAligned, uAlignment, R0Process); 747 623 } 748 RT_EXPORT_SYMBOL(RTR0MemObjReserveUser); 749 750 751 /** 752 * Maps a memory object into kernel virtual address space. 753 * 754 * @returns IPRT status code. 755 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object. 756 * @param MemObjToMap The object to be map. 757 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment. 758 * @param uAlignment The alignment of the reserved memory. 759 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. 760 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE). 761 */ 762 RTR0DECL(int) RTR0MemObjMapKernel(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, unsigned fProt) 763 { 764 return RTR0MemObjMapKernelEx(pMemObj, MemObjToMap, pvFixed, uAlignment, fProt, 0, 0); 765 } 766 RT_EXPORT_SYMBOL(RTR0MemObjMapKernel); 767 768 769 /** 770 * Maps a memory object into kernel virtual address space. 771 * 772 * The ability to map subsections of the object into kernel space is currently 773 * not implemented on all platforms. All/Most of platforms supports mapping the 774 * whole object into kernel space. 775 * 776 * @returns IPRT status code. 777 * @retval VERR_NOT_SUPPORTED if it's not possible to map a subsection of a 778 * memory object on this platform. When you hit this, try implement it. 779 * 780 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object. 781 * @param MemObjToMap The object to be map. 782 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment. 783 * @param uAlignment The alignment of the reserved memory. 784 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. 785 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE). 786 * @param offSub Where in the object to start mapping. If non-zero 787 * the value must be page aligned and cbSub must be 788 * non-zero as well. 789 * @param cbSub The size of the part of the object to be mapped. If 790 * zero the entire object is mapped. The value must be 791 * page aligned. 792 */ 793 RTR0DECL(int) RTR0MemObjMapKernelEx(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, 794 unsigned fProt, size_t offSub, size_t cbSub) 624 RT_EXPORT_SYMBOL(RTR0MemObjReserveUserTag); 625 626 627 RTR0DECL(int) RTR0MemObjMapKernelTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, 628 size_t uAlignment, unsigned fProt, const char *pszTag) 629 { 630 return RTR0MemObjMapKernelExTag(pMemObj, MemObjToMap, pvFixed, uAlignment, fProt, 0, 0, pszTag); 631 } 632 RT_EXPORT_SYMBOL(RTR0MemObjMapKernelTag); 633 634 635 RTR0DECL(int) RTR0MemObjMapKernelExTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, 636 unsigned fProt, size_t offSub, size_t cbSub, const char *pszTag) 795 637 { 796 638 PRTR0MEMOBJINTERNAL pMemToMap; … … 846 688 return rc; 847 689 } 848 RT_EXPORT_SYMBOL(RTR0MemObjMapKernelEx); 849 850 851 /** 852 * Maps a memory object into user virtual address space in the current process. 853 * 854 * @returns IPRT status code. 855 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object. 856 * @param MemObjToMap The object to be map. 857 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment. 858 * @param uAlignment The alignment of the reserved memory. 859 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. 860 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE). 861 * @param R0Process The process to map the memory into. NIL_RTR0PROCESS is an alias for the current one. 862 */ 863 RTR0DECL(int) RTR0MemObjMapUser(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process) 690 RT_EXPORT_SYMBOL(RTR0MemObjMapKernelExTag); 691 692 693 RTR0DECL(int) RTR0MemObjMapUserTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, 694 size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process, const char *pszTag) 864 695 { 865 696 /* sanity checks. */ … … 907 738 return rc; 908 739 } 909 RT_EXPORT_SYMBOL(RTR0MemObjMapUser );740 RT_EXPORT_SYMBOL(RTR0MemObjMapUserTag); 910 741 911 742 -
trunk/src/VBox/Runtime/r3/alloc-ef-cpp.cpp
r28800 r31157 58 58 void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb) throw(std::bad_alloc) 59 59 { 60 void *pv = rtR3MemAlloc("new", RTMEMTYPE_NEW, cb, cb, ASMReturnAddress(), NULL, 0, NULL);60 void *pv = rtR3MemAlloc("new", RTMEMTYPE_NEW, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL); 61 61 if (!pv) 62 62 throw std::bad_alloc(); … … 67 67 void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb, const std::nothrow_t &) throw() 68 68 { 69 void *pv = rtR3MemAlloc("new nothrow", RTMEMTYPE_NEW, cb, cb, ASMReturnAddress(), NULL, 0, NULL);69 void *pv = rtR3MemAlloc("new nothrow", RTMEMTYPE_NEW, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL); 70 70 return pv; 71 71 } … … 94 94 void *RT_EF_CDECL operator new[](RT_EF_SIZE_T cb) throw(std::bad_alloc) 95 95 { 96 void *pv = rtR3MemAlloc("new[]", RTMEMTYPE_NEW_ARRAY, cb, cb, ASMReturnAddress(), NULL, 0, NULL);96 void *pv = rtR3MemAlloc("new[]", RTMEMTYPE_NEW_ARRAY, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL); 97 97 if (!pv) 98 98 throw std::bad_alloc(); … … 103 103 void * RT_EF_CDECL operator new[](RT_EF_SIZE_T cb, const std::nothrow_t &) throw() 104 104 { 105 void *pv = rtR3MemAlloc("new[] nothrow", RTMEMTYPE_NEW_ARRAY, cb, cb, ASMReturnAddress(), NULL, 0, NULL);105 void *pv = rtR3MemAlloc("new[] nothrow", RTMEMTYPE_NEW_ARRAY, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL); 106 106 return pv; 107 107 } -
trunk/src/VBox/Runtime/r3/alloc-ef.cpp
r28800 r31157 127 127 */ 128 128 DECLINLINE(PRTMEMBLOCK) rtmemBlockCreate(RTMEMTYPE enmType, size_t cbUnaligned, size_t cbAligned, 129 void *pvCaller, RT_SRC_POS_DECL)129 const char *pszTag, void *pvCaller, RT_SRC_POS_DECL) 130 130 { 131 131 PRTMEMBLOCK pBlock = (PRTMEMBLOCK)malloc(sizeof(*pBlock)); … … 135 135 pBlock->cbUnaligned = cbUnaligned; 136 136 pBlock->cbAligned = cbAligned; 137 pBlock->pszTag = pszTag; 137 138 pBlock->pvCaller = pvCaller; 138 139 pBlock->iLine = iLine; … … 273 274 */ 274 275 RTDECL(void *) rtR3MemAlloc(const char *pszOp, RTMEMTYPE enmType, size_t cbUnaligned, size_t cbAligned, 275 void *pvCaller, RT_SRC_POS_DECL)276 const char *pszTag, void *pvCaller, RT_SRC_POS_DECL) 276 277 { 277 278 /* … … 305 306 * Allocate the trace block. 306 307 */ 307 PRTMEMBLOCK pBlock = rtmemBlockCreate(enmType, cbUnaligned, cbAligned, p vCaller, RT_SRC_POS_ARGS);308 PRTMEMBLOCK pBlock = rtmemBlockCreate(enmType, cbUnaligned, cbAligned, pszTag, pvCaller, RT_SRC_POS_ARGS); 308 309 if (!pBlock) 309 310 { … … 503 504 * Internal realloc. 504 505 */ 505 RTDECL(void *) rtR3MemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, void *pvCaller, RT_SRC_POS_DECL) 506 RTDECL(void *) rtR3MemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, 507 const char *pszTag, void *pvCaller, RT_SRC_POS_DECL) 506 508 { 507 509 /* … … 509 511 */ 510 512 if (!pvOld) 511 return rtR3MemAlloc(pszOp, enmType, cbNew, cbNew, p vCaller, RT_SRC_POS_ARGS);513 return rtR3MemAlloc(pszOp, enmType, cbNew, cbNew, pszTag, pvCaller, RT_SRC_POS_ARGS); 512 514 if (!cbNew) 513 515 { … … 524 526 if (pBlock) 525 527 { 526 void *pvRet = rtR3MemAlloc(pszOp, enmType, cbNew, cbNew, p vCaller, RT_SRC_POS_ARGS);528 void *pvRet = rtR3MemAlloc(pszOp, enmType, cbNew, cbNew, pszTag, pvCaller, RT_SRC_POS_ARGS); 527 529 if (pvRet) 528 530 { … … 547 549 548 550 549 RTDECL(void *) RTMemEfTmpAlloc(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW550 { 551 return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), RT_SRC_POS_ARGS);552 } 553 554 555 RTDECL(void *) RTMemEfTmpAllocZ(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW556 { 557 return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), RT_SRC_POS_ARGS);551 RTDECL(void *) RTMemEfTmpAlloc(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW 552 { 553 return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOC, cb, cb, pszTag, ASMReturnAddress(), RT_SRC_POS_ARGS); 554 } 555 556 557 RTDECL(void *) RTMemEfTmpAllocZ(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW 558 { 559 return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOCZ, cb, cb, pszTag, ASMReturnAddress(), RT_SRC_POS_ARGS); 558 560 } 559 561 … … 566 568 567 569 568 RTDECL(void *) RTMemEfAlloc(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW569 { 570 return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), RT_SRC_POS_ARGS);571 } 572 573 574 RTDECL(void *) RTMemEfAllocZ(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW575 { 576 return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), RT_SRC_POS_ARGS);577 } 578 579 580 RTDECL(void *) RTMemEfAllocVar(size_t cbUnaligned, RT_SRC_POS_DECL) RT_NO_THROW570 RTDECL(void *) RTMemEfAlloc(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW 571 { 572 return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, pszTag, ASMReturnAddress(), RT_SRC_POS_ARGS); 573 } 574 575 576 RTDECL(void *) RTMemEfAllocZ(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW 577 { 578 return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, pszTag, ASMReturnAddress(), RT_SRC_POS_ARGS); 579 } 580 581 582 RTDECL(void *) RTMemEfAllocVar(size_t cbUnaligned, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW 581 583 { 582 584 size_t cbAligned; … … 585 587 else 586 588 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 587 return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, ASMReturnAddress(), RT_SRC_POS_ARGS);588 } 589 590 591 RTDECL(void *) RTMemEfAllocZVar(size_t cbUnaligned, RT_SRC_POS_DECL) RT_NO_THROW589 return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), RT_SRC_POS_ARGS); 590 } 591 592 593 RTDECL(void *) RTMemEfAllocZVar(size_t cbUnaligned, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW 592 594 { 593 595 size_t cbAligned; … … 596 598 else 597 599 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 598 return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, ASMReturnAddress(), RT_SRC_POS_ARGS);599 } 600 601 602 RTDECL(void *) RTMemEfRealloc(void *pvOld, size_t cbNew, RT_SRC_POS_DECL) RT_NO_THROW603 { 604 return rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, ASMReturnAddress(), RT_SRC_POS_ARGS);600 return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), RT_SRC_POS_ARGS); 601 } 602 603 604 RTDECL(void *) RTMemEfRealloc(void *pvOld, size_t cbNew, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW 605 { 606 return rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, pszTag, ASMReturnAddress(), RT_SRC_POS_ARGS); 605 607 } 606 608 … … 613 615 614 616 615 RTDECL(void *) RTMemEfDup(const void *pvSrc, size_t cb, RT_SRC_POS_DECL) RT_NO_THROW616 { 617 void *pvDst = RTMemEfAlloc(cb, RT_SRC_POS_ARGS);617 RTDECL(void *) RTMemEfDup(const void *pvSrc, size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW 618 { 619 void *pvDst = RTMemEfAlloc(cb, pszTag, RT_SRC_POS_ARGS); 618 620 if (pvDst) 619 621 memcpy(pvDst, pvSrc, cb); … … 622 624 623 625 624 RTDECL(void *) RTMemEfDupEx(const void *pvSrc, size_t cbSrc, size_t cbExtra, RT_SRC_POS_DECL) RT_NO_THROW625 { 626 void *pvDst = RTMemEfAlloc(cbSrc + cbExtra, RT_SRC_POS_ARGS);626 RTDECL(void *) RTMemEfDupEx(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW 627 { 628 void *pvDst = RTMemEfAlloc(cbSrc + cbExtra, pszTag, RT_SRC_POS_ARGS); 627 629 if (pvDst) 628 630 { … … 644 646 645 647 646 RTDECL(void *) RTMemEfTmpAllocNP(size_t cb ) RT_NO_THROW647 { 648 return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), NULL, 0, NULL);649 } 650 651 652 RTDECL(void *) RTMemEfTmpAllocZNP(size_t cb ) RT_NO_THROW653 { 654 return rtR3MemAlloc("TmpAllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), NULL, 0, NULL);648 RTDECL(void *) RTMemEfTmpAllocNP(size_t cb, const char *pszTag) RT_NO_THROW 649 { 650 return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOC, cb, cb, pszTag, ASMReturnAddress(), NULL, 0, NULL); 651 } 652 653 654 RTDECL(void *) RTMemEfTmpAllocZNP(size_t cb, const char *pszTag) RT_NO_THROW 655 { 656 return rtR3MemAlloc("TmpAllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, pszTag, ASMReturnAddress(), NULL, 0, NULL); 655 657 } 656 658 … … 663 665 664 666 665 RTDECL(void *) RTMemEfAllocNP(size_t cb ) RT_NO_THROW666 { 667 return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), NULL, 0, NULL);668 } 669 670 671 RTDECL(void *) RTMemEfAllocZNP(size_t cb ) RT_NO_THROW672 { 673 return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), NULL, 0, NULL);674 } 675 676 677 RTDECL(void *) RTMemEfAllocVarNP(size_t cbUnaligned ) RT_NO_THROW667 RTDECL(void *) RTMemEfAllocNP(size_t cb, const char *pszTag) RT_NO_THROW 668 { 669 return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, pszTag, ASMReturnAddress(), NULL, 0, NULL); 670 } 671 672 673 RTDECL(void *) RTMemEfAllocZNP(size_t cb, const char *pszTag) RT_NO_THROW 674 { 675 return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, pszTag, ASMReturnAddress(), NULL, 0, NULL); 676 } 677 678 679 RTDECL(void *) RTMemEfAllocVarNP(size_t cbUnaligned, const char *pszTag) RT_NO_THROW 678 680 { 679 681 size_t cbAligned; … … 682 684 else 683 685 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 684 return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, ASMReturnAddress(), NULL, 0, NULL);685 } 686 687 688 RTDECL(void *) RTMemEfAllocZVarNP(size_t cbUnaligned ) RT_NO_THROW686 return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), NULL, 0, NULL); 687 } 688 689 690 RTDECL(void *) RTMemEfAllocZVarNP(size_t cbUnaligned, const char *pszTag) RT_NO_THROW 689 691 { 690 692 size_t cbAligned; … … 693 695 else 694 696 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 695 return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, ASMReturnAddress(), NULL, 0, NULL);696 } 697 698 699 RTDECL(void *) RTMemEfReallocNP(void *pvOld, size_t cbNew ) RT_NO_THROW700 { 701 return rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, ASMReturnAddress(), NULL, 0, NULL);697 return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), NULL, 0, NULL); 698 } 699 700 701 RTDECL(void *) RTMemEfReallocNP(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW 702 { 703 return rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, pszTag, ASMReturnAddress(), NULL, 0, NULL); 702 704 } 703 705 … … 710 712 711 713 712 RTDECL(void *) RTMemEfDupNP(const void *pvSrc, size_t cb ) RT_NO_THROW713 { 714 void *pvDst = RTMemEfAlloc(cb, NULL, 0, NULL);714 RTDECL(void *) RTMemEfDupNP(const void *pvSrc, size_t cb, const char *pszTag) RT_NO_THROW 715 { 716 void *pvDst = RTMemEfAlloc(cb, pszTag, NULL, 0, NULL); 715 717 if (pvDst) 716 718 memcpy(pvDst, pvSrc, cb); … … 719 721 720 722 721 RTDECL(void *) RTMemEfDupExNP(const void *pvSrc, size_t cbSrc, size_t cbExtra ) RT_NO_THROW722 { 723 void *pvDst = RTMemEfAlloc(cbSrc + cbExtra, NULL, 0, NULL);723 RTDECL(void *) RTMemEfDupExNP(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag) RT_NO_THROW 724 { 725 void *pvDst = RTMemEfAlloc(cbSrc + cbExtra, pszTag, NULL, 0, NULL); 724 726 if (pvDst) 725 727 { -
trunk/src/VBox/Runtime/r3/alloc-ef.h
r28800 r31157 166 166 /** The aligned size of the block. */ 167 167 size_t cbAligned; 168 /** The allocation tag (read-only string). */ 169 const char *pszTag; 168 170 /** The return address of the allocator function. */ 169 171 void *pvCaller; … … 184 186 RT_C_DECLS_BEGIN 185 187 RTDECL(void *) rtR3MemAlloc(const char *pszOp, RTMEMTYPE enmType, size_t cbUnaligned, size_t cbAligned, 186 void *pvCaller, RT_SRC_POS_DECL); 187 RTDECL(void *) rtR3MemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, void *pvCaller, RT_SRC_POS_DECL); 188 const char *pszTag, void *pvCaller, RT_SRC_POS_DECL); 189 RTDECL(void *) rtR3MemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, 190 const char *pszTag, void *pvCaller, RT_SRC_POS_DECL); 188 191 RTDECL(void) rtR3MemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, RT_SRC_POS_DECL); 189 192 RT_C_DECLS_END -
trunk/src/VBox/Runtime/r3/alloc.cpp
r28800 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 48 48 49 49 #undef RTMemTmpAlloc 50 #undef RTMemTmpAllocTag 50 51 #undef RTMemTmpAllocZ 52 #undef RTMemTmpAllocZTag 51 53 #undef RTMemTmpFree 52 54 #undef RTMemAlloc 55 #undef RTMemAllocTag 53 56 #undef RTMemAllocZ 57 #undef RTMemAllocZTag 54 58 #undef RTMemAllocVar 59 #undef RTMemAllocVarTag 55 60 #undef RTMemAllocZVar 61 #undef RTMemAllocZVarTag 56 62 #undef RTMemRealloc 63 #undef RTMemReallocTag 57 64 #undef RTMemFree 58 65 #undef RTMemDup 66 #undef RTMemDupTag 59 67 #undef RTMemDupEx 68 #undef RTMemDupExTag 60 69 61 70 62 /** 63 * Allocates temporary memory. 64 * 65 * Temporary memory blocks are used for not too large memory blocks which 66 * are believed not to stick around for too long. Using this API instead 67 * of RTMemAlloc() not only gives the heap manager room for optimization 68 * but makes the code easier to read. 69 * 70 * @returns Pointer to the allocated memory. 71 * @returns NULL on failure. 72 * @param cb Size in bytes of the memory block to allocate. 73 */ 74 RTDECL(void *) RTMemTmpAlloc(size_t cb) RT_NO_THROW 71 RTDECL(void *) RTMemTmpAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 75 72 { 76 return RTMemAlloc (cb);73 return RTMemAllocTag(cb, pszTag); 77 74 } 78 75 79 76 80 /** 81 * Allocates zero'ed temporary memory. 82 * 83 * Same as RTMemTmpAlloc() but the memory will be zero'ed. 84 * 85 * @returns Pointer to the allocated memory. 86 * @returns NULL on failure. 87 * @param cb Size in bytes of the memory block to allocate. 88 */ 89 RTDECL(void *) RTMemTmpAllocZ(size_t cb) RT_NO_THROW 77 RTDECL(void *) RTMemTmpAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW 90 78 { 91 return RTMemAllocZ (cb);79 return RTMemAllocZTag(cb, pszTag); 92 80 } 93 81 94 82 95 /** 96 * Free temporary memory. 97 * 98 * @param pv Pointer to memory block. 99 */ 100 RTDECL(void) RTMemTmpFree(void *pv) RT_NO_THROW 83 RTDECL(void) RTMemTmpFree(void *pv) RT_NO_THROW 101 84 { 102 85 RTMemFree(pv); … … 104 87 105 88 106 /** 107 * Allocates memory. 108 * 109 * @returns Pointer to the allocated memory. 110 * @returns NULL on failure. 111 * @param cb Size in bytes of the memory block to allocate. 112 */ 113 RTDECL(void *) RTMemAlloc(size_t cb) RT_NO_THROW 89 RTDECL(void *) RTMemAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 114 90 { 115 91 #ifdef RTALLOC_USE_EFENCE 116 void *pv = rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), NULL, 0, NULL);92 void *pv = rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, pszTag, ASMReturnAddress(), NULL, 0, NULL); 117 93 118 94 #else /* !RTALLOC_USE_EFENCE */ … … 130 106 131 107 132 /** 133 * Allocates zero'ed memory. 134 * 135 * Instead of memset(pv, 0, sizeof()) use this when you want zero'ed 136 * memory. This keeps the code smaller and the heap can skip the memset 137 * in about 0.42% of the calls :-). 138 * 139 * @returns Pointer to the allocated memory. 140 * @returns NULL on failure. 141 * @param cb Size in bytes of the memory block to allocate. 142 */ 143 RTDECL(void *) RTMemAllocZ(size_t cb) RT_NO_THROW 108 RTDECL(void *) RTMemAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW 144 109 { 145 110 #ifdef RTALLOC_USE_EFENCE 146 void *pv = rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), NULL, 0, NULL);111 void *pv = rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, pszTag, ASMReturnAddress(), NULL, 0, NULL); 147 112 148 113 #else /* !RTALLOC_USE_EFENCE */ … … 161 126 162 127 163 /** 164 * Wrapper around RTMemAlloc for automatically aligning variable sized 165 * allocations so that the various electric fence heaps works correctly. 166 * 167 * @returns See RTMemAlloc. 168 * @param cbUnaligned The unaligned size. 169 */ 170 RTDECL(void *) RTMemAllocVar(size_t cbUnaligned) 128 RTDECL(void *) RTMemAllocVarTag(size_t cbUnaligned, const char *pszTag) RT_NO_THROW 171 129 { 172 130 size_t cbAligned; … … 176 134 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 177 135 #ifdef RTALLOC_USE_EFENCE 178 void *pv = rtR3MemAlloc("AllocVar", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, ASMReturnAddress(), NULL, 0, NULL);136 void *pv = rtR3MemAlloc("AllocVar", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), NULL, 0, NULL); 179 137 #else 180 void *pv = RTMemAlloc (cbAligned);138 void *pv = RTMemAllocTag(cbAligned, pszTag); 181 139 #endif 182 140 return pv; … … 184 142 185 143 186 /** 187 * Wrapper around RTMemAllocZ for automatically aligning variable sized 188 * allocations so that the various electric fence heaps works correctly. 189 * 190 * @returns See RTMemAllocZ. 191 * @param cbUnaligned The unaligned size. 192 */ 193 RTDECL(void *) RTMemAllocZVar(size_t cbUnaligned) 144 RTDECL(void *) RTMemAllocZVarTag(size_t cbUnaligned, const char *pszTag) RT_NO_THROW 194 145 { 195 146 size_t cbAligned; … … 199 150 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 200 151 #ifdef RTALLOC_USE_EFENCE 201 void *pv = rtR3MemAlloc("AllocZVar", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, ASMReturnAddress(), NULL, 0, NULL);152 void *pv = rtR3MemAlloc("AllocZVar", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), NULL, 0, NULL); 202 153 #else 203 void *pv = RTMemAllocZ (cbAligned);154 void *pv = RTMemAllocZTag(cbAligned, pszTag); 204 155 #endif 205 156 return pv; … … 207 158 208 159 209 /** 210 * Reallocates memory. 211 * 212 * @returns Pointer to the allocated memory. 213 * @returns NULL on failure. 214 * @param pvOld The memory block to reallocate. 215 * @param cbNew The new block size (in bytes). 216 */ 217 RTDECL(void *) RTMemRealloc(void *pvOld, size_t cbNew) RT_NO_THROW 160 RTDECL(void *) RTMemReallocTag(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW 218 161 { 219 162 #ifdef RTALLOC_USE_EFENCE 220 void *pv = rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, ASMReturnAddress(), NULL, 0, NULL);163 void *pv = rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, pszTag, ASMReturnAddress(), NULL, 0, NULL); 221 164 222 165 #else /* !RTALLOC_USE_EFENCE */ … … 233 176 234 177 235 /** 236 * Free memory related to a virtual machine 237 * 238 * @param pv Pointer to memory block. 239 */ 240 RTDECL(void) RTMemFree(void *pv) RT_NO_THROW 178 RTDECL(void) RTMemFree(void *pv) RT_NO_THROW 241 179 { 242 180 if (pv) -
trunk/src/VBox/Runtime/r3/darwin/alloc-darwin.cpp
r28800 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 40 40 41 41 42 /** 43 * Allocates memory which may contain code. 44 * 45 * @returns Pointer to the allocated memory. 46 * @returns NULL on failure. 47 * @param cb Size in bytes of the memory block to allocate. 48 */ 49 RTDECL(void *) RTMemExecAlloc(size_t cb) RT_NO_THROW 42 RTDECL(void *) RTMemExecAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 50 43 { 51 44 /* … … 74 67 75 68 76 /**77 * Free executable/read/write memory allocated by RTMemExecAlloc().78 *79 * @param pv Pointer to memory block.80 */81 69 RTDECL(void) RTMemExecFree(void *pv) RT_NO_THROW 82 70 { … … 86 74 87 75 88 /** 89 * Allocate page aligned memory. 90 * 91 * @returns Pointer to the allocated memory. 92 * @returns NULL if we're out of memory. 93 * @param cb Size of the memory block. Will be rounded up to page size. 94 */ 95 RTDECL(void *) RTMemPageAlloc(size_t cb) RT_NO_THROW 76 RTDECL(void *) RTMemPageAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 96 77 { 97 78 return valloc(RT_ALIGN_Z(cb, PAGE_SIZE)); … … 99 80 100 81 101 /** 102 * Allocate zero'ed page aligned memory. 103 * 104 * @returns Pointer to the allocated memory. 105 * @returns NULL if we're out of memory. 106 * @param cb Size of the memory block. Will be rounded up to page size. 107 */ 108 RTDECL(void *) RTMemPageAllocZ(size_t cb) RT_NO_THROW 82 RTDECL(void *) RTMemPageAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW 109 83 { 110 84 cb = RT_ALIGN_Z(cb, PAGE_SIZE); … … 116 90 117 91 118 /**119 * Free a memory block allocated with RTMemPageAlloc() or RTMemPageAllocZ().120 *121 * @param pv Pointer to the block as it was returned by the allocation function.122 * NULL will be ignored.123 */124 92 RTDECL(void) RTMemPageFree(void *pv, size_t cb) RT_NO_THROW 125 93 { … … 129 97 130 98 131 /**132 * Change the page level protection of a memory region.133 *134 * @returns iprt status code.135 * @param pv Start of the region. Will be rounded down to nearest page boundary.136 * @param cb Size of the region. Will be rounded up to the nearest page boundary.137 * @param fProtect The new protection, a combination of the RTMEM_PROT_* defines.138 */139 99 RTDECL(int) RTMemProtect(void *pv, size_t cb, unsigned fProtect) RT_NO_THROW 140 100 { -
trunk/src/VBox/Runtime/r3/posix/utf8-posix.cpp
r30294 r31157 413 413 414 414 415 /** 416 * Allocates tmp buffer, translates pszString from UTF8 to current codepage. 417 * 418 * @returns iprt status code. 419 * @param ppszString Receives pointer of allocated native CP string. 420 * The returned pointer must be freed using RTStrFree(). 421 * @param pszString UTF-8 string to convert. 422 */ 423 RTR3DECL(int) RTStrUtf8ToCurrentCP(char **ppszString, const char *pszString) 415 RTR3DECL(int) RTStrUtf8ToCurrentCPTag(char **ppszString, const char *pszString, const char *pszTag) 424 416 { 425 417 Assert(ppszString); … … 434 426 { 435 427 /* zero length string passed. */ 436 *ppszString = (char *)RTMemTmpAllocZ (sizeof(char));428 *ppszString = (char *)RTMemTmpAllocZTag(sizeof(char), pszTag); 437 429 if (*ppszString) 438 430 return VINF_SUCCESS; … … 443 435 444 436 445 /** 446 * Allocates tmp buffer, translates pszString from current codepage to UTF-8. 447 * 448 * @returns iprt status code. 449 * @param ppszString Receives pointer of allocated UTF-8 string. 450 * The returned pointer must be freed using RTStrFree(). 451 * @param pszString Native string to convert. 452 */ 453 RTR3DECL(int) RTStrCurrentCPToUtf8(char **ppszString, const char *pszString) 437 RTR3DECL(int) RTStrCurrentCPToUtf8Tag(char **ppszString, const char *pszString, const char *pszTag) 454 438 { 455 439 Assert(ppszString); … … 464 448 { 465 449 /* zero length string passed. */ 466 *ppszString = (char *)RTMemTmpAllocZ (sizeof(char));450 *ppszString = (char *)RTMemTmpAllocZTag(sizeof(char), pszTag); 467 451 if (*ppszString) 468 452 return VINF_SUCCESS; -
trunk/src/VBox/Runtime/r3/win/utf8-win.cpp
r28800 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 38 38 39 39 40 /** 41 * Allocates tmp buffer, translates pszString from UTF8 to current codepage. 42 * 43 * @returns iprt status code. 44 * @param ppszString Receives pointer of allocated native CP string. 45 * The returned pointer must be freed using RTStrFree(). 46 * @param pszString UTF-8 string to convert. 47 */ 48 RTR3DECL(int) RTStrUtf8ToCurrentCP(char **ppszString, const char *pszString) 40 RTR3DECL(int) RTStrUtf8ToCurrentCPTag(char **ppszString, const char *pszString, const char *pszTag) 49 41 { 50 42 Assert(ppszString); … … 56 48 if (!*pszString) 57 49 { 58 *ppszString = (char *)RTMemTmpAllocZ (sizeof(char));50 *ppszString = (char *)RTMemTmpAllocZTag(sizeof(char), pszTag); 59 51 if (*ppszString) 60 52 return VINF_SUCCESS; … … 81 73 * Alloc space for result buffer. 82 74 */ 83 LPSTR lpString = (LPSTR)RTMemTmpAlloc (cbResult);75 LPSTR lpString = (LPSTR)RTMemTmpAllocTag(cbResult, pszTag); 84 76 if (lpString) 85 77 { … … 115 107 } 116 108 117 /** 118 * Allocates tmp buffer, translates pszString from current codepage to UTF-8. 119 * 120 * @returns iprt status code. 121 * @param ppszString Receives pointer of allocated UTF-8 string. 122 * The returned pointer must be freed using RTStrFree(). 123 * @param pszString Native string to convert. 124 */ 125 RTR3DECL(int) RTStrCurrentCPToUtf8(char **ppszString, const char *pszString) 109 110 RTR3DECL(int) RTStrCurrentCPToUtf8Tag(char **ppszString, const char *pszString, const char *pszTag) 126 111 { 127 112 Assert(ppszString); … … 135 120 { 136 121 /* zero length string passed. */ 137 *ppszString = (char *)RTMemTmpAllocZ (sizeof(char));122 *ppszString = (char *)RTMemTmpAllocZTag(sizeof(char), pszTag); 138 123 if (*ppszString) 139 124 return VINF_SUCCESS; -
trunk/src/VBox/Runtime/testcase/tstMemAutoPtr.cpp
r28800 r31157 5 5 6 6 /* 7 * Copyright (C) 2008 Oracle Corporation7 * Copyright (C) 2008-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 114 114 115 115 116 void *tstMemAutoPtrAllocatorNoZero(void *pvOld, size_t cbNew )117 { 118 void *pvNew = RTMemRealloc (pvOld, cbNew);116 void *tstMemAutoPtrAllocatorNoZero(void *pvOld, size_t cbNew, const char *pszTag) 117 { 118 void *pvNew = RTMemReallocTag(pvOld, cbNew, pszTag); 119 119 if (pvNew) 120 120 memset(pvNew, 0xfe, cbNew); -
trunk/src/VBox/Runtime/testcase/tstRTMemEf.cpp
r28800 r31157 47 47 * the word after the allocated block and the word before. One of them 48 48 * will crash no matter whether the fence is at the bottom or on top. */ 49 int32_t *p = (int32_t *)RTMemEfAllocNP(sizeof(int32_t) );49 int32_t *p = (int32_t *)RTMemEfAllocNP(sizeof(int32_t), RTMEM_TAG); 50 50 RTPrintf("tstRTMemAllocEfAccess: allocated int32_t at %#p\n", p); 51 51 RTPrintf("tstRTMemAllocEfAccess: triggering buffer overrun...\n");
Note:
See TracChangeset
for help on using the changeset viewer.