All YumaPro SDK C sources files use a common H file to set basic definitions such as malloc and free, bit definitions, and all basic C data types (e.g. uint16, uint32).


The file netconf/src/platform/procdefs.h is included first by all YumaPro SDK C files, before any other YumaPro SDK H files.  The definitions in this file can be changed as needed.


This file almost never changes.  If it does change, only new additions would be made, without changing any existing definitions.


The 16.10 version of procdefs.h is shown below:


  

/*
 * Copyright (c) 2008 - 2012, Andy Bierman, All Rights Reserved.
 * Copyright (c) 2012 - 2016, YumaWorks, Inc., All Rights Reserved.
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
 */
#ifndef _H_procdefs
#define _H_procdefs
#define _INC_PROCDEFS
/*
 *  File: procdefs.h
 *
 *  Contains global constants and types used for portability
 *  defines UNIX/MSDOS variant strings
 *
 */

/* no user source files should include limits.h
 * they should include procdefs.h instead, 
 * and use the defined base types provided below
 */
#include    <limits.h>
#include    <stdlib.h>

#ifdef PTHREADS
#include  <pthread.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 1
#endif

#ifdef SUBSYS_UNIT /* Hack needed to exempt subsystem.c and subsys_util.c
		      from certain thread definitions */
#undef HEAP_CHECKING
#define ENTER_CS
#define EXIT_CS

#else
#undef HEAP_CHECKING
/* For debugging only: enable heap checking (see heapchk.[c,h]): */
//#define HEAP_CHECKING
#endif


#ifdef DEBUG
#define CPP_DEBUG           1
#endif  /* DEBUG */

#ifdef CPP_FULL_DEBUG
#define	    CPP_MTRACE	    1 
#define	    CPP_ICHK	    1
#define	    CPP_CHK_HEAP    1
#define     CPP_FULL_TRACE  1
#endif	/* CPP_FULL_DEBUG */

/* program environment and personality switches
 * SUN is the only supported unix platform at this time
 */
#if defined(SUN) || defined(LINUX) || defined(MACOSX)
#define	    CPV_UNIX		1
#define	    CPV_MSC		0
#define	    CPV_ALLOW_FAR	0
#define	    CPV_DOS		0
#else
/* !!! ASSUME MSC VERSION !!! */
#define	    CPV_UNIX		0
#define	    CPV_MSC		1
#define	    CPV_ALLOW_FAR	0
#define	    CPV_DOS		1
#endif	    /* SUN */


/* #define  CPP_NO_MACROS   0 -- ifdefs still used */
/* CPP_DEBUG assigned at the command line */
/* CPP_CHK_HEAP assigned at the command line */
/* CPP_ICHK assigned at the command line */

#if CPV_UNIX
#define	    NEWLN		0xa
#else
#define	    NEWLN		0xd
#endif	    /* CPV_UNIX */

/* only the module that contains 'main' should define _C_main */
#ifdef _C_main
#define PUBLIC 
#else
#define PUBLIC extern
#endif	    /* _C_main */

/* 16-bit word bit definitions */
#define		bit0	0x0001
#define		bit1	0x0002
#define		bit2	0x0004
#define		bit3	0x0008
#define		bit4	0x0010
#define		bit5	0x0020
#define		bit6	0x0040
#define		bit7	0x0080
#define		bit8	0x0100
#define		bit9	0x0200
#define		bit10	0x0400
#define		bit11	0x0800
#define		bit12	0x1000
#define		bit13	0x2000
#define		bit14	0x4000
#define		bit15	0x8000

/* 32 bit extended bit definitions */
#define		bit16	0x00010000
#define		bit17	0x00020000
#define		bit18	0x00040000
#define		bit19	0x00080000
#define		bit20	0x00100000
#define		bit21	0x00200000
#define		bit22	0x00400000
#define		bit23	0x00800000
#define		bit24	0x01000000
#define		bit25	0x02000000
#define		bit26	0x04000000
#define		bit27	0x08000000
#define		bit28	0x10000000
#define		bit29	0x20000000
#define		bit30	0x40000000
#define		bit31	0x80000000

#define m__setbit(F,B)  F |= (B)

#define m__clrbit(F,B)  F &= ~(B)

#define m__bitset(F,B)  F & B

#if CPV_UNIX
#define	    STATIC  
#define	    CONST
#define	    REG		register
#define	    REGVAR  
#define	    VOLATILE
#define	    FAR
#define	    NEAR
#define	    PASCAL
/* #define	    signed */
#define	    cdecl
#define	    memicmp	memcmp
#define	    strcmpi	strcasecmp
#define	    _strcmpi	strcasecmp
#define	    _strdup	strdup		
#define	    _chdir	chdir
#define     _getcwd	getcwd

#else
/*** CPV_DOS ***/
#define	    STATIC	static
#define	    CONST	const
#define	    REG		register
#define	    REGVAR	register
#define	    VOLATILE	volatile

#ifdef __STDC__
#ifndef WINDOWS
#define	    strcmpi	_strcmpi
#endif
#endif

#if CPV_ALLOW_FAR
#define	    FAR		far
#else
#define	    FAR 
#endif	    /* CPV_ALLOW_FAR */

#endif	    /* CPV_UNIX */

#ifndef __cplusplus
#ifndef min
#define	    min(A,B)	((A<B)?A:B)
#endif

#ifndef max
#define	    max(A,B)	((A>B)?A:B)
#endif
#endif

#ifdef CHAR_BIT
#define	    BITS_PER_BYTE	CHAR_BIT
#else
#define	    BITS_PER_BYTE	8
#endif	    /* CHAR_BIT */


/* assign debug flag */
#ifdef CPP_DEBUG
#define		DBG_STAMP	"DEBUG"
#else
#define		DBG_STAMP	"NODEBUG"
#endif	    /* CPP_DEBUG */

#if !CPV_UNIX
#ifndef WINDOWS
typedef		unsigned int		uint; 
#endif
#else
#include <sys/types.h>
#endif	    /* !CPV_UNIX */

#ifdef MACOSX
  typedef       unsigned int          uint;
#endif

#include <inttypes.h>
#include <stdbool.h>

typedef         uint8_t             uchar;
typedef		uint8_t             uint8;
typedef		uint16_t            uint16;
typedef		uint32_t            uint32;
typedef		uint64_t            uint64;
typedef		int8_t              int8;
typedef		int16_t             int16;
typedef		int32_t		    int32;
typedef		int64_t  	    int64;
typedef		uint8_t      	    byte;
typedef		bool		    boolean;

#ifdef SUN413_GNU
typedef         unsigned long           ulong;
#endif


#if !CPV_UNIX
#ifndef __STDC__
#ifndef _WCHAR_T_DEFINED	/** MSC 7.0 **/
#define _WCHAR_T_DEFINED
typedef	unsigned short		wchar_t;
#endif	/* WCHAR_T_DEFINED */
#endif	/* __STDC__ */
#endif  /* !CPV_UNIX */

#ifndef WCHAR_MAX
#define		WCHAR_MAX		0xffff
#endif	    /* WCHAR_MAX */

#if CPV_UNIX	
typedef		double			LDBL;
#else
typedef		long double		LDBL;
#endif	    /* CPV_UNIX */

/* MSC symbolic constants have to be faked in unix */
#if CPV_UNIX
#define SEEK_SET    0
#define SEEK_CUR    1
#define SEEK_END    2
#endif	    /* CPV_UNIX */

/* c-portability adjustment ...(avoid lint error)--version for runtine code */
#if !defined(FALSE) && !defined(TRUE)
#define		FALSE	 false
#define		TRUE	 true
#endif	    /* FALSE | TRUE */


/* Move the following def to build variable ??? */ /***** MOVE ME *****/
//#undef  CS_MULTICORE
//#define CS_MULTICORE /* Comment out if not building for multi-core CPU */

/*
 * Define basic critical section support globally here. However, note
 * well the restrictions below.
 *
 * The below critical section primitives are used primarily by dlq
 * primitives. However, they MAY be used elsewhere WITH EXTREME CAUTION.
 * (For example, see the defs using malloc() and free() below.)
 */

#ifndef PTHREADS

#define ENTER_FAST_CS
#define EXIT_FAST_CS
#define ENTER_CS
#define EXIT_CS

#else  //#ifndef PTHREADS

#ifdef SUBSYS_UNIT
#define ENTER_FAST_CS
#define EXIT_FAST_CS
#define ENTER_CS
#define EXIT_CS

#else // not SUBSYS_UNIT

/*
 * ENTER/EXIT_FAST_CS
 *
 * Specialized "fast" critical section enforcement mechanism. Uses a
 * spin lock initially, then reverts to wait on a mutex if necessary.
 * NOTE WELL that it's only "fast" if used for minimal computation sections,
 * such as queue manipulation (see dlq.c). Do not call directly ... use
 * the macros below.
 *
 * Note: Definition of "fast" section:
 *
 *       - see dlq.c
 *       - ENTER_FAST_CS;malloc_cnt++;cntA++;cntB--;cntC += cntD;EXIT_FAST_CS;
 *
 * Note: Definition of "slow" section:
 *
 *       - everything else !!!
 *
 * For extended computational sections (everything else) use ENTER/EXIT_CS.
 * These are general purpose in that they do not employ a spin lock and
 * may be called recursively (by the owning thread). See heapchk.c for
 * an example.
 */

extern int thd_lock_cs_fast_mutex (void);
extern int thd_unlock_cs_fast_mutex (void);

#define ENTER_FAST_CS  if (netconfd_running && thd_init_successful) {      \
                           if (thd_lock_cs_fast_mutex())                   \
                           {                                               \
			       SET_ERROR(ERR_MUTEX_ERR);                   \
                           }                                               \
                       }


#define EXIT_FAST_CS  if (netconfd_running && thd_init_successful) {       \
                          if (thd_unlock_cs_fast_mutex())                  \
                          {                                                \
			       SET_ERROR(ERR_MUTEX_ERR);                   \
                          }                                                \
                      }

extern int thd_lock_cs_recursive_mutex (void);
extern int thd_unlock_cs_recursive_mutex (void);

#define ENTER_CS     if (netconfd_running) {                               \
                         if (thd_lock_recursive_cs_mutex())                \
                         {                                                 \
			     SET_ERROR(ERR_MUTEX_ERR);                     \
                         }                                                 \
                     }

#define EXIT_CS      if (netconfd_running) {                               \
                         if (thd_unlock_recursive_cs_mutex())              \
                         {                                                 \
			     SET_ERROR(ERR_MUTEX_ERR);                     \
                         }                                                 \
                     }

#endif //#ifdef SUBSYS_UNIT
#endif //#ifndef PTHREADS

/* memory for these vars in ncx/ncx.c */
extern uint32  malloc_cnt;
extern uint32  free_cnt;

/*
 * Note that addition of -lpthread to PTHREAD link does choose thread-safe
 * versions of malloc() and free()
 *
 * However, malloc_cnt++ and free_cnt++ are NOT thread-safe and thus must
 * be protected in a critical section. ENTER_CS and EXIT_CS provide this
 * capability, but evaluate to null if PTHREADS is not defined.
 *
 */

#ifndef HEAP_CHECKING /* This is the default ... no special checking */

#ifndef m__getMem
#define   m__getMem(X)    malloc(X);ENTER_FAST_CS;malloc_cnt++;EXIT_FAST_CS
#endif /* m__getMem */

#ifndef m__free
#define   m__free(X)  do {if (X) {free(X);                                    \
                          ENTER_FAST_CS;free_cnt++;EXIT_FAST_CS; } } while(0)
#endif /* m__free */

#ifndef m__getObj
#define m__getObj(OBJ) (OBJ *)malloc(sizeof(OBJ));                            \
                       ENTER_FAST_CS;malloc_cnt++;EXIT_FAST_CS
#endif /* m__getObj */

#else

/* This is for debugging only. Do custom checking (see heapchk.[c,h]) */

extern boolean free_hold;
extern void *malloc_checker ( size_t size );
extern void free_checker ( void *memP );

#ifndef m__getMem
#define m__getMem(X)  malloc_checker(X)
#endif		/* m__getMem */

#ifndef m__free
#define m__free(X) do { if ( X ) { free_checker( X ); } } while (0)
#endif		/* m__free */

#ifndef m__getObj
#define m__getObj(OBJ)	(OBJ *)malloc_checker(sizeof(OBJ))
#endif		/* m__getObj */

#endif //#ifndef HEAP_CHECKING

/* Use m__strdup() instead of strdup(), then use m__free() to return dup mem */

#ifndef m__strdup
#define m__strdup(s, str) s=strdup(str);                                    \
                          if (s) {ENTER_FAST_CS;malloc_cnt++;EXIT_FAST_CS}
#endif /* m__strdup */


#ifdef __cplusplus
}  /* end extern 'C' */
#endif

#endif		/* _H_procdefs */