some speedups in mcount;
better recovery in the face of running out of tos[] space.
SCCS-vsn: lib/libc/gmon/gmon.c 1.6
-static char *sccsid = "@(#)gmon.c 1.5 (Berkeley) %G%";
+static char *sccsid = "@(#)gmon.c 1.6 (Berkeley) %G%";
static unsigned short tolimit = 0;
static char *s_lowpc = 0;
static char *s_highpc = 0;
static unsigned short tolimit = 0;
static char *s_lowpc = 0;
static char *s_highpc = 0;
+static unsigned long s_textsize = 0;
static int ssiz;
static int *sbuf;
static int ssiz;
static int *sbuf;
char *lowpc;
char *highpc;
{
char *lowpc;
char *highpc;
{
- int monsize;
- char *buffer;
- int textsize;
- char *sbrk();
+ int monsize;
+ char *buffer;
+ char *sbrk();
+ unsigned long limit;
s_lowpc = lowpc;
s_highpc = highpc;
s_lowpc = lowpc;
s_highpc = highpc;
- textsize = ( (char *) highpc - (char *) lowpc );
- monsize = textsize + sizeof(struct phdr);
+ s_textsize = highpc - lowpc;
+ monsize = s_textsize + sizeof(struct phdr);
buffer = sbrk( monsize );
if ( buffer == (char *) -1 ) {
write( 2 , MSG , sizeof(MSG) );
return;
}
buffer = sbrk( monsize );
if ( buffer == (char *) -1 ) {
write( 2 , MSG , sizeof(MSG) );
return;
}
- froms = (unsigned short *) sbrk( textsize );
+ froms = (unsigned short *) sbrk( s_textsize );
if ( froms == (unsigned short *) -1 ) {
write( 2 , MSG , sizeof(MSG) );
froms = 0;
return;
}
if ( froms == (unsigned short *) -1 ) {
write( 2 , MSG , sizeof(MSG) );
froms = 0;
return;
}
- tos = (struct tostruct *) sbrk(textsize);
+ tos = (struct tostruct *) sbrk(s_textsize);
if ( tos == (struct tostruct *) -1 ) {
write( 2 , MSG , sizeof(MSG) );
froms = 0;
tos = 0;
return;
}
if ( tos == (struct tostruct *) -1 ) {
write( 2 , MSG , sizeof(MSG) );
froms = 0;
tos = 0;
return;
}
- tolimit = textsize / sizeof(struct tostruct);
+ limit = s_textsize / sizeof(struct tostruct);
+ /*
+ * tolimit is what mcount checks to see if
+ * all the data structures are ready!!!
+ * make sure it won't overflow.
+ */
+ tolimit = limit > 65534 ? 65534 : limit;
monitor( lowpc , highpc , buffer , monsize );
}
monitor( lowpc , highpc , buffer , monsize );
}
int fromindex;
char *frompc;
int toindex;
int fromindex;
char *frompc;
int toindex;
monitor( (int (*)()) 0 );
fd = fopen( "gmon.out" , "w" );
monitor( (int (*)()) 0 );
fd = fopen( "gmon.out" , "w" );
fprintf( stderr , "[mcleanup] sbuf 0x%x ssiz %d\n" , sbuf , ssiz );
# endif DEBUG
fwrite( sbuf , 1 , ssiz , fd );
fprintf( stderr , "[mcleanup] sbuf 0x%x ssiz %d\n" , sbuf , ssiz );
# endif DEBUG
fwrite( sbuf , 1 , ssiz , fd );
- textsize = s_highpc - s_lowpc;
- for ( fromindex = 0 ; fromindex < textsize>>1 ; fromindex++ ) {
+ for ( fromindex = 0 ; fromindex < s_textsize>>1 ; fromindex++ ) {
if ( froms[fromindex] == 0 ) {
continue;
}
if ( froms[fromindex] == 0 ) {
continue;
}
* check that we are profiling
* and that we aren't recursively invoked.
*/
* check that we are profiling
* and that we aren't recursively invoked.
*/
goto out;
}
if ( profiling ) {
goto out;
}
if ( profiling ) {
* for example: signal catchers get called from the stack,
* not from text space. too bad.
*/
* for example: signal catchers get called from the stack,
* not from text space. too bad.
*/
- if ( (char *) frompcindex < s_lowpc || (char *) frompcindex > s_highpc ) {
+ frompcindex = (unsigned short *) ( (long) frompcindex - (long) s_lowpc );
+ if ( (unsigned long) frompcindex > s_textsize ) {
- frompcindex = &froms[ ( (long) frompcindex - (long) s_lowpc ) >> 1 ];
+ frompcindex = &froms[ ( (long) frompcindex ) >> 1 ];
if ( *frompcindex == 0 ) {
*frompcindex = ++tos[0].link;
if ( *frompcindex >= tolimit ) {
if ( *frompcindex == 0 ) {
*frompcindex = ++tos[0].link;
if ( *frompcindex >= tolimit ) {
asm( "#undef _mcount");
overflow:
asm( "#undef _mcount");
overflow:
# define TOLIMIT "mcount: tos overflow\n"
write( 2 , TOLIMIT , sizeof( TOLIMIT ) );
# define TOLIMIT "mcount: tos overflow\n"
write( 2 , TOLIMIT , sizeof( TOLIMIT ) );