/***
*dbgheap.c - Debug CRT Heap Functions
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* Defines debug versions of heap functions.
*
*******************************************************************************/
#ifdef _DEBUG
#include <windows.h>
#include <winheap.h>
#include <ctype.h>
#include <dbgint.h>
#include <crtdbg.h>
#include <rtcsup.h>
#include <internal.h>
#include <limits.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <locale.h>
#include <mtdll.h>
#include <setlocal.h>
#pragma warning(disable:4390)
extern "C" void * __cdecl _heap_alloc_base (size_t size);
extern "C" static void * __cdecl _heap_alloc_dbg_impl(size_t nSize, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp);
/*---------------------------------------------------------------------------
*
* Heap management
*
--------------------------------------------------------------------------*/
#define IGNORE_REQ 0L /* Request number for ignore block */
#define IGNORE_LINE 0xFEDCBABC /* Line number for ignore block */
#define _ALLOCATION_FILE_LINENUM "\nMemory allocated at %hs(%d).\n"
/*
* Bitfield flag that controls CRT heap behavior --
* default is to record all allocations (_CRTDBG_ALLOC_MEM_DF)
* AND check heap consistency on every alloc/dealloc (_CRTDBG_CHECK_ALWAYS_DF)
*/
extern "C" int _crtDbgFlag = _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_DEFAULT_DF;
/*
* Size threshold for filling behavior. See _CrtSetDebugFillThreshold.
*/
extern "C" size_t __crtDebugFillThreshold = SIZE_MAX;
extern "C" int __crtDebugCheckCount = FALSE;
/*
* struct used by _aligned routines as block header.
*/
#define nAlignGapSize sizeof(void *)
typedef struct _AlignMemBlockHdr
{
void *pHead;
unsigned char Gap[nAlignGapSize];
} _AlignMemBlockHdr;
#define IS_2_POW_N(x) (((x)&(x-1)) == 0)
/*
* Statics governing how often _CrtCheckMemory is called.
*/
static unsigned check_frequency = _CRTDBG_CHECK_DEFAULT_DF >> 16;
static unsigned check_counter;
static long _lRequestCurr = 1; /* Current request number */
extern "C" _CRTIMP long _crtBreakAlloc = -1L; /* Break on allocation by request number */
static size_t _lTotalAlloc; /* Grand total - sum of all allocations */
static size_t _lCurAlloc; /* Total amount currently allocated */
static size_t _lMaxAlloc; /* Largest ever allocated at once */
/*
* The following values are non-zero, constant, odd, large, and atypical
* Non-zero values help find bugs assuming zero filled data.
* Constant values are good so that memory filling is deterministic
* (to help make bugs reproducable). Of course it is bad if
* the constant filling of weird values masks a bug.
* Mathematically odd numbers are good for finding bugs assuming a cleared
* lower bit.
* Large numbers (byte values at least) are less typical, and are good
* at finding bad addresses.
* Atypical values (i.e. not too often) are good since they typically
* cause early detection in code.
* For the case of no-man's land and free blocks, if you store to any
* of these locations, the memory integrity checker will detect it.
*
* _bAlignLandFill has been changed from 0xBD to 0xED, to ensure that
* 4 bytes of that (0xEDEDEDED) would give an inaccessible address under 3gb.
*/
static unsigned char _bNoMansLandFill = 0xFD; /* fill no-man's land with this */
static unsigned char _bAlignLandFill = 0xED; /* fill no-man's land for aligned routines */
static unsigned char _bDeadLandFill = 0xDD; /* fill free objects with this */
static unsigned char _bCleanLandFill = 0xCD; /* fill new objects with this */
static _CrtMemBlockHeader * _pFirstBlock;
static _CrtMemBlockHeader * _pLastBlock;
_CRT_DUMP_CLIENT _pfnDumpClient;
#if _FREE_BLOCK != 0 || _NORMAL_BLOCK != 1 || _CRT_BLOCK != 2 || _IGNORE_BLOCK != 3 || _CLIENT_BLOCK != 4
#error Block numbers have changed !
#endif /* _FREE_BLOCK != 0 || _NORMAL_BLOCK != 1 || _CRT_BLOCK != 2 || _IGNORE_BLOCK != 3 || _CLIENT_BLOCK != 4 */
static const char * const szBlockUseName[_MAX_BLOCKS] = {
"Free",
"Normal",
"CRT",
"Ignore",
"Client",
};
extern "C" int __cdecl CheckBytes(unsigned char *, unsigned char, size_t);
/***
*void * _malloc_dbg() - Get a block of memory from the debug heap
*
*Purpose:
* Allocate of block of memory of at least size bytes from the heap and
* return a pointer to it.
*
* Allocates any type of supported memory block.
*
*Entry:
* size_t nSize - size of block requested
* int nBlockUse - block type
* char * szFileName - file name
* int nLine - line number
*
*Exit:
* Success: Pointer to memory block
* Failure: NULL (or some error value)
*
*Exceptions:
*
*******************************************************************************/
extern "C" _CRTIMP void * __cdecl _malloc_dbg (
size_t nSize,
int nBlockUse,
const char * szFileName,
int nLine
)
{
void *res = _nh_malloc_dbg(nSize, _newmode, nBlockUse, szFileName, nLine);
RTCCALLBACK(_RTC_Allocate_hook, (res, nSize, 0));
return res;
}
/***
*void * _nh_malloc() - Get a block of memory from the debug heap
*
*Purpose:
* Allocate of block of memory of at least size bytes from the debug
* heap and return a pointer to it. Assumes heap already locked.
*
* If no blocks available, call new handler.
*
* Allocates 'normal' memory block.
*
*Entry:
* size_t nSize - size of block requested
* int nhFlag - TRUE if new handler function
*
*Exit:
* Success: Pointer to (user portion of) memory block
* Failure: NULL
*
*Exceptions:
*
*******************************************************************************/
extern "C" void * __cdecl _nh_malloc (
size_t nSize,
int nhFlag
)
{
return _nh_malloc_dbg(nSize, nhFlag, _NORMAL_BLOCK, NULL, 0);
}
/***
*void * _nh_malloc_dbg_impl() - Get a block of memory from the debug heap
*
*Purpose:
* Allocate of block of memory of at least size bytes from the debug
* heap and return a pointer to it. Assumes heap already locked.
*
* If no blocks available, call new handler.
*
* Allocates any type of supported memory block.
*
*Entry:
* size_t nSize - size of block requested
* int nhFlag - TRUE if new handler function
* int nBlockUse - block type
* char * szFileName - file name
* int nLine - line number
* int * errno_tmp - pointer of the temporary errno
*
*Exit:
* Success: Pointer to (user portion of) memory block
* Failure: NULL
*
*Exceptions:
*
*******************************************************************************/
extern "C" static void * __cdecl _nh_malloc_dbg_impl (
size_t nSize,
int nhFlag,
int nBlockUse,
const char * szFileName,
int nLine,
int * errno_tmp
)
{
void * pvBlk;
for (;;)
{
/* do the allocation
*/
pvBlk = _heap_alloc_dbg_impl(nSize, nBlockUse, szFileName, nLine, errno_tmp);
if (pvBlk)
{
return pvBlk;
}
if (nhFlag == 0)
{
if (errno_tmp)
{
*errno_tmp = ENOMEM;
}
return
没有合适的资源?快使用搜索试试~ 我知道了~
C/C++标准库源代码
共1304个文件
c:706个
h:169个
cpp:155个
5星 · 超过95%的资源 需积分: 49 1.3k 下载量 13 浏览量
2015-08-16
10:10:31
上传
评论 21
收藏 3.2MB ZIP 举报
温馨提示
C/C++标准库源代码,从Microsoft Visual Studio 10.0即Visual Studio 2010中提取出来的,希望对大家的学习和工作有所帮助。
资源推荐
资源详情
资源评论
收起资源包目录
C/C++标准库源代码 (1304个子文件)
8859_1 3KB
8859_10 5KB
8859_13 5KB
8859_14 5KB
8859_15 4KB
8859_16 5KB
8859_2 5KB
8859_3 5KB
8859_4 5KB
8859_5 6KB
8859_6 5KB
8859_7 6KB
8859_8 5KB
8859_9 4KB
adapter 33KB
algorithm 161KB
algorithm 121KB
allocators 21KB
array 14KB
memcpy.asm 22KB
lldvrm.asm 8KB
strncpy.asm 8KB
strncat.asm 7KB
strspn.asm 7KB
llrem.asm 7KB
strcat.asm 7KB
lldiv.asm 7KB
ulldvrm.asm 6KB
strchr.asm 6KB
ullrem.asm 5KB
ulldiv.asm 5KB
memchr.asm 5KB
strstr.asm 5KB
memset.asm 4KB
memccpy.asm 4KB
_strnicm.asm 4KB
strcmp.asm 4KB
_memicmp.asm 4KB
chkstk.asm 3KB
strrev.asm 3KB
strlen.asm 3KB
strrchr.asm 3KB
llmul.asm 3KB
strnset.asm 2KB
alloca16.asm 2KB
strset.asm 2KB
amdsecgs.asm 2KB
llshr.asm 2KB
ullshr.asm 2KB
llshl.asm 1KB
outp.asm 1KB
inp.asm 1KB
enable.asm 967B
dllsupp.asm 950B
strcspn.asm 477B
memmove.asm 475B
strpbrk.asm 447B
baltic 4KB
big5 449KB
bitset 16KB
dbgheap.c 103KB
output.c 89KB
input.c 53KB
strftime.c 41KB
wcsftime.c 39KB
setlocal.c 36KB
mbctype.c 35KB
getqloc.c 33KB
open.c 33KB
ctype.c 28KB
crt0dat.c 28KB
read.c 23KB
tzset.c 23KB
winsig.c 22KB
getch.c 22KB
dbgrptt.c 22KB
write.c 20KB
crtexe.c 20KB
crtdll.c 19KB
popen.c 19KB
tidtable.c 18KB
inittime.c 17KB
crtlib.c 16KB
tmpfile.c 16KB
align.c 15KB
osfinfo.c 15KB
winxfltr.c 14KB
qsort.c 14KB
setenv.c 14KB
xtoa.c 13KB
vswprint.c 13KB
tombbmbc.c 13KB
wild.c 13KB
stat.c 13KB
fcvt.c 13KB
xmbtowc.c 13KB
cenvarg.c 12KB
ioinit.c 12KB
dllcrt0.c 12KB
wcstombs.c 12KB
共 1304 条
- 1
- 2
- 3
- 4
- 5
- 6
- 14
lovelyanimal
- 粉丝: 1
- 资源: 37
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页