/************************************************************************* MODULE : $RCSfile: targcust.c $ PART OF : CTC/LIBRARY Host-Target support VERSION : $Revision: 1.5 $, $Date: 2016/10/17 13:43:23 $ AUTHOR : $Author: olavi $ LAST EDITED : 17.10.2016/op DESCRIPTION : targcust.c implements the target side functions that the user may customize. These functions are called from targdata.c file. This file may (sometimes must!) be customized by the user. Copyright (c) 2003-2013 Testwell Oy Copyright (c) 2013-2016 Verifysoft Technology GmbH **************************************************************************/ /* Revision history $Log: targcust.c $ Revision 1.5 2016/10/17 13:43:23 olavi - #ifdef __CTC__ #error ... #endif guard on file's instrumentation changed to #pragma CTC SKIP ... #pragma CTC ENDSKIP (works better...) Revision 1.4 2011/07/23 11:26:35 seppo - Added #ifdef __CTC__ guard to prevent compilation with CTC++ Revision 1.3 2009/11/18 14:04:24 seppo - Now, in default compilation, #include is used and ctc_alloc() is mapped to malloc() and ctc_exit() is mapped to exit() - With -DNO_STDLIB, the default implementation is not used, and an #error directive is used to abort the compilation thus requiring the user to provide a reasonable implementation. - In default build (regardless of -DNO_STDLIB), ctc_error() is always null-behaving (just returns). The user can provide an implementation when finding it useful. Revision 1.2 2007/05/17 14:15:19 olavi - added some clarifying header commenting to the file - changed ctc_alloc() default behavior to "silently hanging"!!! Is a precaution if ctc_alloc() anyway gets called, and if it has not been implemented by the user... Revision 1.1 2003/11/28 11:54:14 seppo Initial revision */ /* even if attempted, do not instrument this file */ #ifdef __CTC__ #pragma CTC SKIP #endif /*********************** STANDARD LIBRARY INCLUDES ***********************/ #ifndef NO_STDLIB /* for the sake of seeing and using malloc() and exit()... */ #include #endif /************************* APPLICATION INCLUDES **************************/ #include "ctctypes.h" #include "targdata.h" /********************** GLOBAL VARIABLE DEFINITIONS **********************/ /**************************** PRIVATE DEFINES ****************************/ /***************************** PRIVATE TYPES *****************************/ /*************************** PRIVATE VARIABLES ***************************/ /********************* PRIVATE FUNCTION DECLARATIONS *********************/ /*************************** PUBLIC FUNCTIONS ****************************/ /************************************************************************* FUNCTION : ctc_alloc PURPOSE : Allocates block of memory from heap, i.e. a local 'malloc' implementation. Note 1: If you can't use malloc() from , i.e. you have to compile this file with -DNO_STDLIB, or if malloc() is not implemented in that C library, you have to implement this function by yourself. Note 2: This function can get called only if at least one source file of the code under test is instrumented so that the CTC++ counter arrays are allocated from heap. See the CTC++ User's Guide, the CTC++ configuration file (ctc.ini) and ctc.h for possible use and description of the macros CTC_STATIC_COUNTERS and CTC_HEAP_COUNTERS. ARGUMENTS : - size: bytes to allocate RETURNS : a void pointer to the allocated space, or 0 if there is insufficient memory available *************************************************************************/ void* ctc_alloc(unsigned int size) { #ifndef NO_STDLIB return malloc(size); #else #error Please give a working implementation of ctc_alloc()! /* if you can't invent anything, use */ return 0; /* As if heap allocation had failed => headache moves to ctc_error()! And ensure that no files are instrumented under -DCTC_HEAP_COUNTERS */ #endif } /************************************************************************* FUNCTION : ctc_exit PURPOSE : This function terminates the instrumented program, i.e. a local 'exit' implementation. This function is called if a fatal error is encountered (like ctc_alloc() has failed or some other internal sanity check has failed), or the user has ordered the program to end by inserting #pragma CTC QUIT in the source file (hardly ever used). THIS FUNCTION MUST NOT RETURN, because the caller side assumes this! ARGUMENTS : - status : exit status RETURNS : Does not return! *************************************************************************/ void ctc_exit(int status) { #ifndef NO_STDLIB exit(status); #else #error Please give a working implementation of ctc_exit()! /* if you can't invent anything, use */ for (;;) ; /* HANGS!!!!! Does not return! */ #endif } /************************************************************************* FUNCTION : ctc_show_error PURPOSE : Shows an error message. The default implementation of this function does nothing. The implementation of this function may be written by the user if there is available some proper way to report errors. See readme.txt for further information. ARGUMENTS : - status_code : error code (enum) according to which a message can be selected RETURNS : Nothing *************************************************************************/ void ctc_show_error(CTC_STATUS status_code) { return; /* Does nothing! */ /* If is available at the target environment, a natural implementation could be... #include fprintf(stderr, "\n*** CTC++ Host-Target run-time error code %i\n", status_code); */ } #ifdef __CTC__ #pragma CTC ENDSKIP #endif /* EOF $RCSfile: targcust.c $ */