/***
*sbheap.c - Small-block heap code
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* Core code for small-block heap.
*
*******************************************************************************/
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <winheap.h>
#include <windows.h>
#include <internal.h>
#include <malloc.h>
#include <limits.h>
#ifndef _WIN64
/* Current (VC++ 6.0) small-block heap code and data */
size_t __sbh_threshold;
int __sbh_initialized;
PHEADER __sbh_pHeaderList; // pointer to list start
PHEADER __sbh_pHeaderScan; // pointer to list rover
int __sbh_sizeHeaderList; // allocated size of list
int __sbh_cntHeaderList; // count of entries defined
PHEADER __sbh_pHeaderDefer=NULL;
int __sbh_indGroupDefer;
/* Prototypes for user functions */
size_t __cdecl _get_sbh_threshold(void);
int __cdecl _set_sbh_threshold(size_t);
void DumpEntry(char *, int *);
#endif /* _WIN64 */
/***
*size_t _get_sbh_threshold() - return small-block threshold
*
*Purpose:
* Return the current value of __sbh_threshold
*
*Entry:
* None.
*
*Exit:
* See above.
*
*Exceptions:
*
*******************************************************************************/
size_t __cdecl _get_sbh_threshold (void)
{
/* Ensure already initialised */
_ASSERTE(_crtheap);
if(!_crtheap)
{
return 0;
}
#ifndef _WIN64
if ( __active_heap == __V6_HEAP )
{
return __sbh_threshold;
}
#ifdef CRTDLL
if ( __active_heap == __V5_HEAP )
{
return __old_sbh_threshold;
}
#endif /* CRTDLL */
#endif /* _WIN64 */
return 0;
}
/***
*int _set_sbh_threshold(threshold) - set small-block heap threshold
*
*Purpose:
* Set the upper limit for the size of an allocation which will be
* supported from the small-block heap.
*
*Entry:
* size_t threshold - proposed new value for __sbh_theshold
*
*Exit:
* Returns 1 if successful. Returns 0 if threshold was invalid.
*
*Exceptions:
* Input parameters are validated. Refer to the validation section of the function.
*
*******************************************************************************/
int __cdecl _set_sbh_threshold (size_t threshold)
{
_ASSERTE(_crtheap);
if(!_crtheap)
{
return 0;
}
#ifndef _WIN64
if ( __active_heap == __V6_HEAP )
{
// test against maximum value - if too large, return error
_VALIDATE_RETURN(threshold <= MAX_ALLOC_DATA_SIZE, EINVAL, 0);
__sbh_threshold = threshold;
return 1;
}
#ifdef CRTDLL
if ( __active_heap == __V5_HEAP )
{
// Round up the proposed new value to the nearest paragraph
threshold = (threshold + _OLD_PARASIZE - 1) & ~(_OLD_PARASIZE - 1);
// Require that at least two allocations be can be made within a
// page.
_VALIDATE_RETURN(
threshold <= (_OLD_PARASIZE * (_OLD_PARAS_PER_PAGE / 2)),
EINVAL,
0);
__old_sbh_threshold = threshold;
return 1;
}
// if threshold is 0, we just return
if (threshold == 0)
{
return 1;
}
// if necessary, initialize a small-block heap
if (__active_heap == __SYSTEM_HEAP)
{
LinkerVersion lv;
_GetLinkerVersion(&lv);
if (lv.bverMajor >= 6)
{
// Initialize the VC++ 6.0 small-block heap
_VALIDATE_RETURN(
(threshold <= MAX_ALLOC_DATA_SIZE) && __sbh_heap_init(threshold),
EINVAL,
0);
__sbh_threshold = threshold;
__active_heap = __V6_HEAP;
return 1;
}
else
{
// Initialize the old (VC++ 5.0) small-block heap
threshold = (threshold + _OLD_PARASIZE - 1) &
~(_OLD_PARASIZE - 1);
_VALIDATE_RETURN(
(threshold <= (_OLD_PARASIZE * (_OLD_PARAS_PER_PAGE / 2))) &&
(__old_sbh_new_region() != NULL),
EINVAL,
0);
__old_sbh_threshold = threshold;
__active_heap = __V5_HEAP;
return 1;
}
}
#else /* CRTDLL */
// if threshold is 0, we just return
if (threshold == 0)
{
return 1;
}
// if necessary, initialize a small-block heap
if (__active_heap == __SYSTEM_HEAP)
{
// Initialize the VC++ 6.0 small-block heap
_VALIDATE_RETURN(
(threshold <= MAX_ALLOC_DATA_SIZE) && __sbh_heap_init(threshold),
EINVAL,
0);
__sbh_threshold = threshold;
__active_heap = __V6_HEAP;
return 1;
}
#endif /* CRTDLL */
#endif /* _WIN64 */
errno = EINVAL;
return 0;
}
/***
*_set_amblksiz(size) - Set the value of _amblksiz
*
*Purpose:
* Set the value of _amblksiz
*
*Entry:
* size_t size, needs to be > 0
*Exit:
* Returns 0 if everything is ok, else return the errno_t
*
*Exceptions:
* Input parameters are validated. Refer to the validation section of the function.
*
*******************************************************************************/
errno_t __cdecl _set_amblksiz(size_t size)
{
/* validation section */
_VALIDATE_RETURN_ERRCODE(0 < size && size <= UINT_MAX, EINVAL);
_VALIDATE_RETURN_ERRCODE(_crtheap, EINVAL);
_BEGIN_SECURE_CRT_DEPRECATION_DISABLE
_amblksiz = (unsigned int)size;
_END_SECURE_CRT_DEPRECATION_DISABLE
return 0;
}
/***
*_get_amblksiz(pSize) - Get the value of _amblksiz
*
*Purpose:
* Get the value of _amblksiz
*
*Entry:
* size_t *pSize
*Exit:
* Returns 0 if everything is ok, else return the errno_t
*
*Exceptions:
* Input parameters are validated. Refer to the validation section of the function.
*
*******************************************************************************/
errno_t __cdecl _get_amblksiz(size_t *pSize)
{
/* validation section */
_VALIDATE_RETURN_ERRCODE(pSize != NULL, EINVAL);
_VALIDATE_RETURN_ERRCODE(_crtheap, EINVAL);
_BEGIN_SECURE_CRT_DEPRECATION_DISABLE
*pSize = _amblksiz;
_END_SECURE_CRT_DEPRECATION_DISABLE
return 0;
}
#ifndef _WIN64
/***
*int __sbh_heap_init() - set small-block heap threshold
*
*Purpose:
* Allocate space for initial header list and init variables.
*
*Entry:
* None.
*
*Exit:
* Returns 1 if successful. Returns 0 if initialization failed.
*
*Exceptions:
*
*******************************************************************************/
int __cdecl __sbh_heap_init (size_t threshold)
{
if (!(__sbh_pHeaderList = HeapAlloc(_crtheap, 0, 16 * sizeof(HEADER))))
return FALSE;
__sbh_threshold = threshold;
__sbh_pHeaderScan = __sbh_pHeaderList;
__sbh_pHeaderDefer = NULL;
__sbh_cntHeaderList = 0;
__sbh_sizeHeaderList = 16;
return TRUE;
}
/***
*PHEADER *__sbh_find_block(pvAlloc) - find block in small-block heap
*
*Purpose:
* Determine if the specified allocation block lies in the small-block
* heap and, if so, return the header to be used for the block.
*
*Entry:
* void * pvBlock - pointer to block to be freed
*
*Exit:
* If successful, a pointer to the header
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Linux下的C库函数源代码 (2000个子文件)
algorithm 144KB
algorithm 144KB
memcpy.asm 22KB
memcpy.asm 22KB
lldvrm.asm 8KB
lldvrm.asm 8KB
strncpy.asm 8KB
strncpy.asm 8KB
strncat.asm 7KB
strncat.asm 7KB
strspn.asm 7KB
strspn.asm 7KB
llrem.asm 7KB
llrem.asm 7KB
strcat.asm 7KB
strcat.asm 7KB
lldiv.asm 6KB
lldiv.asm 6KB
ulldvrm.asm 6KB
ulldvrm.asm 6KB
strchr.asm 6KB
strchr.asm 6KB
ullrem.asm 5KB
ullrem.asm 5KB
ulldiv.asm 5KB
ulldiv.asm 5KB
memchr.asm 5KB
memchr.asm 5KB
strstr.asm 5KB
strstr.asm 5KB
memset.asm 4KB
memset.asm 4KB
memccpy.asm 4KB
memccpy.asm 4KB
_strnicm.asm 4KB
_strnicm.asm 4KB
strcmp.asm 4KB
strcmp.asm 4KB
_memicmp.asm 4KB
_memicmp.asm 4KB
chkstk.asm 3KB
chkstk.asm 3KB
strrev.asm 3KB
strrev.asm 3KB
strlen.asm 3KB
strlen.asm 3KB
strrchr.asm 3KB
strrchr.asm 3KB
llmul.asm 2KB
llmul.asm 2KB
strnset.asm 2KB
strnset.asm 2KB
alloca16.asm 2KB
alloca16.asm 2KB
strset.asm 2KB
strset.asm 2KB
llshr.asm 2KB
llshr.asm 2KB
ullshr.asm 1KB
ullshr.asm 1KB
outp.asm 1KB
outp.asm 1KB
llshl.asm 1KB
llshl.asm 1KB
inp.asm 1KB
inp.asm 1KB
dllsupp.asm 1KB
dllsupp.asm 1KB
enable.asm 967B
enable.asm 967B
strcspn.asm 477B
strcspn.asm 477B
memmove.asm 475B
memmove.asm 475B
strpbrk.asm 447B
strpbrk.asm 447B
bldwin9x.bat 1KB
bldwin9x.bat 1KB
bitset 14KB
bitset 14KB
sbheap.c 106KB
sbheap.c 106KB
dbgheap.c 95KB
dbgheap.c 95KB
output.c 90KB
output.c 90KB
input.c 53KB
input.c 53KB
setlocal.c 44KB
setlocal.c 44KB
strftime.c 42KB
strftime.c 42KB
mbctype.c 35KB
mbctype.c 35KB
getqloc.c 33KB
getqloc.c 33KB
crt0dat.c 31KB
crt0dat.c 31KB
open.c 29KB
open.c 29KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
huangling123456
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页