<commit_before>#include "image.h"

/*
  Find starting and ending addresses of the data segment
*/
extern "C" char *sbrk( int );
#if defined(ULTRIX42) || defined(ULTRIX43)
	// Data starts at well known value USRDATA
	// Data ends at sbrk(0)
#	undef NULL
#	include <sys/param.h>
#	include <sys/vmparam.h>
	int data_start_addr() { return USRDATA; }
	int data_end_addr() { return (int)sbrk(0); }
#elif defined(SUNOS41)
	// Data starts at first DATA_ALIGN boundary after end of text
	// Data ends at sbrk(0)
#	include <sys/param.h>
	extern int etext;
	int
	data_start_addr()
	{
		return ((long)&etext + DATA_ALIGN - 1) / DATA_ALIGN * DATA_ALIGN;
	}
	int data_end_addr() { return (int)sbrk(0); }
#else
	// Unknown platforms fall through to here, generating compile time error
#	error
#endif


/*
  Stuff to manipulate the stack pointer using setjmp() and longjmp().
*/
#if defined(ULTRIX42) || defined(ULTRIX43)
	const int StkPtrIdx = 32;
	const int StackGrowsDown = 1;
#elif defined(SUNOS41)
	const int StkPtrIdx = 2;
	const int StackGrowsDown = 1;
#else
	// Unknown platforms fall through to here, generating compile time error
#	error
#endif

/*
  Find starting address of stack segment.

  Portability: A single method works on all the platforms we have tried
  so far, but this will not be true for all platforms.
*/
int
stack_start_addr()
{
#if defined(ULTRIX42) || defined(ULTRIX43) || defined(SUNOS41)
	jmp_buf env;
	(void)SETJMP( env );
	return env[StkPtrIdx] / 1024 * 1024; // Curr sp, rounded down - 1K boundary
#else
	// Unknown platforms fall through to here, generating compile time error
#	error
#endif
}

/*
  Find ending address of stack segment.

  Portability: A single method works on all the platforms we have tried
  so far, but this will not be true for all platforms.
*/
int
stack_end_addr()
{
#if defined(ULTRIX42) || defined(ULTRIX43) || defined(SUNOS41)
	return USRSTACK; // Well known value
#else
	// Unknown platforms fall through to here, generating compile time error
#	error
#endif
}


/*
  Switch to a temporary stack area in the DATA segment, then execute the
  given function.

  Portability: Given the above machine dependent definitions of SETJMP,
  LONGJMP, and StkPtrIdx, it is likely that this code won't have to
  vary for different platforms.
*/
const int	TmpStackSize = 4096;
static char	TmpStack[ TmpStackSize ];
void
ExecuteOnTmpStk( void (*func)() )
{
	jmp_buf	env;

	if( SETJMP(env) == 0 ) {
			// First time through - move SP
		if( StackGrowsDown ) {
			env[StkPtrIdx] = (int)TmpStack + TmpStackSize;
		} else {
			env[StkPtrIdx] = (int)TmpStack;
		}
		LONGJMP( env, 1 );
	} else {
			// Second time through - call the function
		func();
	}
}<commit_msg>A function is passed to ExecuteOnTmpStk(), but this function will move the stack pointer into the data area.  It is therefore necessary to save the function pointer in the global area as a reference to a local variable after the SP has been moved results in an error on the SUNS - as well it should.<commit_after>#include "image.h"

/*
  Find starting and ending addresses of the data segment
*/
extern "C" char *sbrk( int );
#if defined(ULTRIX42) || defined(ULTRIX43)
	// Data starts at well known value USRDATA
	// Data ends at sbrk(0)
#	undef NULL
	int data_start_addr() { return USRDATA; }
	int data_end_addr() { return (int)sbrk(0); }
#elif defined(SUNOS41)
	// Data starts at first DATA_ALIGN boundary after end of text
	// Data ends at sbrk(0)
	extern int etext;
	int
	data_start_addr()
	{
		return ((long)&etext + DATA_ALIGN - 1) / DATA_ALIGN * DATA_ALIGN;
	}
	int data_end_addr() { return (int)sbrk(0); }
#else
	// Unknown platforms fall through to here, generating compile time error
#	error
#endif


/*
  Stuff to manipulate the stack pointer using setjmp() and longjmp().
*/
#if defined(ULTRIX42) || defined(ULTRIX43)
	const int StkPtrIdx = 32;
	const int StackGrowsDown = 1;
#elif defined(SUNOS41)
	const int StkPtrIdx = 2;
	const int StackGrowsDown = 1;
#else
	// Unknown platforms fall through to here, generating compile time error
#	error
#endif

/*
  Find starting address of stack segment.

  Portability: A single method works on all the platforms we have tried
  so far, but this will not be true for all platforms.
*/
int
stack_start_addr()
{
#if defined(ULTRIX42) || defined(ULTRIX43) || defined(SUNOS41)
	jmp_buf env;
	(void)SETJMP( env );
	return env[StkPtrIdx] / 1024 * 1024; // Curr sp, rounded down - 1K boundary
#else
	// Unknown platforms fall through to here, generating compile time error
#	error
#endif
}

/*
  Find ending address of stack segment.

  Portability: A single method works on all the platforms we have tried
  so far, but this will not be true for all platforms.
*/
int
stack_end_addr()
{
#if defined(ULTRIX42) || defined(ULTRIX43) || defined(SUNOS41)
	return USRSTACK; // Well known value
#else
	// Unknown platforms fall through to here, generating compile time error
#	error
#endif
}


/*
  Switch to a temporary stack area in the DATA segment, then execute the
  given function.  Note: we save the address of the function in a
  global data location - referencing a value on the stack after the SP
  is moved would be an error.

  Portability: Given the above machine dependent definitions of SETJMP,
  LONGJMP, and StkPtrIdx, it is likely that this code won't have to
  vary for different platforms.
*/
static void (*SaveFunc)();

const int	TmpStackSize = 4096;
static char	TmpStack[ TmpStackSize ];
void
ExecuteOnTmpStk( void (*func)() )
{
	jmp_buf	env;
	SaveFunc = func;

	if( SETJMP(env) == 0 ) {
			// First time through - move SP
		if( StackGrowsDown ) {
			env[StkPtrIdx] = (int)TmpStack + TmpStackSize;
		} else {
			env[StkPtrIdx] = (int)TmpStack;
		}
		LONGJMP( env, 1 );
	} else {
			// Second time through - call the function
		SaveFunc();
	}
}
{'fraction_non_alphanumeric': 0.09581251077029122, 'fraction_numerical': 0.016887816646562123, 'mean_word_length': 3.84070058381985, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '891694', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1935, 'n_words': 741}