-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2144 from ghaerr/debugmalloc
[libc] Enhance debugging output for amalloc and dmalloc
- Loading branch information
Showing
6 changed files
with
122 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,53 @@ | ||
#include <malloc.h> | ||
#include <unistd.h> | ||
#include <errno.h> | ||
#include <sys/sysctl.h> | ||
/* fmemalloc/fmemfree - allocate/free from main memory */ | ||
|
||
#define _MK_FP(seg,off) ((void __far *)((((unsigned long)(seg)) << 16) | (off))) | ||
#define DEBUG 1 /* =1 use sysctl, =2 debug output */ | ||
|
||
#if DEBUG | ||
#define debug(...) do { if (debug_level > 1) __dprintf(__VA_ARGS__); } while (0) | ||
static int debug_level = DEBUG; | ||
static unsigned long total; | ||
static unsigned long maxsize; | ||
#else | ||
#define debug(...) | ||
#endif | ||
|
||
#define FP_SEG(fp) ((unsigned)((unsigned long)(void __far *)(fp) >> 16)) | ||
#define FP_OFF(fp) ((unsigned)(unsigned long)(void __far *)(fp)) | ||
#define MK_FP(seg,off) ((void __far *)((((unsigned long)(seg)) << 16) | \ | ||
((unsigned int)(off)))) | ||
|
||
/* alloc from main memory */ | ||
void __far *fmemalloc(unsigned long size) | ||
{ | ||
unsigned short seg; | ||
unsigned int paras = (unsigned int)((size + 15) >> 4); | ||
|
||
if (_fmemalloc(paras, &seg)) | ||
#if DEBUG == 1 | ||
sysctl(CTL_GET, "malloc.debug", &debug_level); | ||
#endif | ||
debug("(%d)FMEMALLOC(%5lu) ", getpid(), size); | ||
if (_fmemalloc(paras, &seg)) { | ||
debug("= FAIL\n"); | ||
return 0; | ||
return _MK_FP(seg, 0); | ||
} | ||
#if DEBUG | ||
total += size; | ||
if (size > maxsize) maxsize = size; | ||
debug("total %lu, maxsize %lu\n", total, maxsize); | ||
#endif | ||
return MK_FP(seg, 0); | ||
} | ||
|
||
int fmemfree(void __far *ptr) | ||
{ | ||
debug("(%d) fmemfree()\n", getpid()); // FIXME get size of allocation | ||
if (FP_OFF(ptr)) { | ||
debug(" FAIL (bad pointer)\n"); // FIXME convert to ASSERT | ||
errno = EINVAL; | ||
return -1; | ||
} | ||
return _fmemfree(FP_SEG(ptr)); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.