Initial revision
This commit is contained in:
80
src/ca/posix_depen.c
Normal file
80
src/ca/posix_depen.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* $Id$
|
||||
* Author: Jeffrey O. Hill
|
||||
* hill@luke.lanl.gov
|
||||
* (505) 665 1831
|
||||
* Date: 9-93
|
||||
*
|
||||
* Experimental Physics and Industrial Control System (EPICS)
|
||||
*
|
||||
* Copyright 1991, the Regents of the University of California,
|
||||
* and the University of Chicago Board of Governors.
|
||||
*
|
||||
* This software was produced under U.S. Government contracts:
|
||||
* (W-7405-ENG-36) at the Los Alamos National Laboratory,
|
||||
* and (W-31-109-ENG-38) at Argonne National Laboratory.
|
||||
*
|
||||
* Initial development by:
|
||||
* The Controls and Automation Group (AT-8)
|
||||
* Ground Test Accelerator
|
||||
* Accelerator Technology Division
|
||||
* Los Alamos National Laboratory
|
||||
*
|
||||
* Co-developed with
|
||||
* The Controls and Computing Group
|
||||
* Accelerator Systems Division
|
||||
* Advanced Photon Source
|
||||
* Argonne National Laboratory
|
||||
*
|
||||
* Modification Log:
|
||||
* -----------------
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* ANSI includes
|
||||
*/
|
||||
#include "assert.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#include "unistd.h"
|
||||
#include "pwd.h"
|
||||
#include "sys/param.h"
|
||||
|
||||
#include "iocinf.h"
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* This should work on any POSIX compliant OS
|
||||
*
|
||||
* o Indicates failure by setting ptr to nill
|
||||
*/
|
||||
char *localUserName()
|
||||
{
|
||||
int length;
|
||||
char *pName;
|
||||
char *pTmp;
|
||||
|
||||
pName = getlogin();
|
||||
if(!pName){
|
||||
pName = getpwuid(getuid())->pw_name;
|
||||
if(!pName){
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
length = strlen(pName)+1;
|
||||
pTmp = malloc(length);
|
||||
if(!pTmp){
|
||||
return pTmp;
|
||||
}
|
||||
strncpy(pTmp, pName, length-1);
|
||||
pTmp[length-1] = '\0';
|
||||
|
||||
return pTmp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
107
src/ca/vms_depen.c
Normal file
107
src/ca/vms_depen.c
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* $Id$
|
||||
* Author: Jeffrey O. Hill
|
||||
* hill@luke.lanl.gov
|
||||
* (505) 665 1831
|
||||
* Date: 9-93
|
||||
*
|
||||
* Experimental Physics and Industrial Control System (EPICS)
|
||||
*
|
||||
* Copyright 1991, the Regents of the University of California,
|
||||
* and the University of Chicago Board of Governors.
|
||||
*
|
||||
* This software was produced under U.S. Government contracts:
|
||||
* (W-7405-ENG-36) at the Los Alamos National Laboratory,
|
||||
* and (W-31-109-ENG-38) at Argonne National Laboratory.
|
||||
*
|
||||
* Initial development by:
|
||||
* The Controls and Automation Group (AT-8)
|
||||
* Ground Test Accelerator
|
||||
* Accelerator Technology Division
|
||||
* Los Alamos National Laboratory
|
||||
*
|
||||
* Co-developed with
|
||||
* The Controls and Computing Group
|
||||
* Accelerator Systems Division
|
||||
* Advanced Photon Source
|
||||
* Argonne National Laboratory
|
||||
*
|
||||
* Modification Log:
|
||||
* -----------------
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* ANSI includes
|
||||
*/
|
||||
#include "assert.h"
|
||||
#include "string.h"
|
||||
#include "stdLib.h"
|
||||
|
||||
#include "stsdef.h"
|
||||
#include "ssdef.h"
|
||||
|
||||
#include "iocinf.h"
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* localUserName() - for VMS
|
||||
*
|
||||
* o Indicates failure by setting ptr to nill
|
||||
*
|
||||
* !! NEEDS TO BE TESTED !!
|
||||
*
|
||||
*/
|
||||
char *localUserName()
|
||||
{
|
||||
struct {
|
||||
short buffer_length;
|
||||
short item_code;
|
||||
void *pBuf;
|
||||
void *pRetSize;
|
||||
unsigned long end_of_list;
|
||||
}item_list;
|
||||
int length;
|
||||
char pName[8]; /* the size of VMS account names */
|
||||
short nameLength;
|
||||
char *psrc;
|
||||
char *pdest;
|
||||
int status;
|
||||
char *pTmp;
|
||||
|
||||
item_list.buffer_length = sizeof(pName);
|
||||
item_list.item_code = JPI$ACCOUNT; /* fetch the account name */
|
||||
item_list.pBuf = pName;
|
||||
item_list.pRetSize = &nameLength;
|
||||
item_list.end_of_list = NULL;
|
||||
|
||||
status = sys$getjpiw(
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
&item_list,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
if(status != SS$_NORMAL){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
psrc = pName;
|
||||
length = 0;
|
||||
while(psrc<&pName[sizeof(pName)] && *psrc != ' '){
|
||||
length++;
|
||||
psrc++;
|
||||
}
|
||||
|
||||
pTmp = (char *)malloc(length+1);
|
||||
if(!pTmp){
|
||||
return pTmp;
|
||||
}
|
||||
strncpy(pTmp, pName, length);
|
||||
pTmp[length] = '\0';
|
||||
|
||||
return pTmp;
|
||||
}
|
||||
|
||||
71
src/ca/vxWorks_depen.c
Normal file
71
src/ca/vxWorks_depen.c
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* $Id$
|
||||
* Author: Jeffrey O. Hill
|
||||
* hill@luke.lanl.gov
|
||||
* (505) 665 1831
|
||||
* Date: 9-93
|
||||
*
|
||||
* Experimental Physics and Industrial Control System (EPICS)
|
||||
*
|
||||
* Copyright 1991, the Regents of the University of California,
|
||||
* and the University of Chicago Board of Governors.
|
||||
*
|
||||
* This software was produced under U.S. Government contracts:
|
||||
* (W-7405-ENG-36) at the Los Alamos National Laboratory,
|
||||
* and (W-31-109-ENG-38) at Argonne National Laboratory.
|
||||
*
|
||||
* Initial development by:
|
||||
* The Controls and Automation Group (AT-8)
|
||||
* Ground Test Accelerator
|
||||
* Accelerator Technology Division
|
||||
* Los Alamos National Laboratory
|
||||
*
|
||||
* Co-developed with
|
||||
* The Controls and Computing Group
|
||||
* Accelerator Systems Division
|
||||
* Advanced Photon Source
|
||||
* Argonne National Laboratory
|
||||
*
|
||||
* Modification Log:
|
||||
* -----------------
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* ANSI includes
|
||||
*/
|
||||
#include "assert.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#include "remLib.h"
|
||||
|
||||
#include "iocinf.h"
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* localUserName() - for vxWorks
|
||||
*
|
||||
* o Indicates failure by setting ptr to nill
|
||||
*/
|
||||
char *localUserName()
|
||||
{
|
||||
char *pTmp;
|
||||
int length;
|
||||
char pName[MAX_IDENTITY_LEN];
|
||||
|
||||
remCurIdGet(pName, NULL);
|
||||
|
||||
length = strlen(pName)+1;
|
||||
pTmp = malloc(length);
|
||||
if(!pTmp){
|
||||
return;
|
||||
}
|
||||
strncpy(pTmp, pName, length-1);
|
||||
pTmp[length-1] = '\0';
|
||||
|
||||
return pTmp;
|
||||
}
|
||||
|
||||
|
||||
275
src/libCom/memDebugLib.c
Normal file
275
src/libCom/memDebugLib.c
Normal file
@@ -0,0 +1,275 @@
|
||||
/* share/src/libCom $Id$
|
||||
* memDebugLib.c
|
||||
* Author: Jeff Hill
|
||||
* Date: 03-29-93
|
||||
*
|
||||
* Experimental Physics and Industrial Control System (EPICS)
|
||||
*
|
||||
* Copyright 1991, the Regents of the University of California,
|
||||
* and the University of Chicago Board of Governors.
|
||||
*
|
||||
* This software was produced under U.S. Government contracts:
|
||||
* (W-7405-ENG-36) at the Los Alamos National Laboratory,
|
||||
* and (W-31-109-ENG-38) at Argonne National Laboratory.
|
||||
*
|
||||
* Initial development by:
|
||||
* The Controls and Automation Group (AT-8)
|
||||
* Ground Test Accelerator
|
||||
* Accelerator Technology Division
|
||||
* Los Alamos National Laboratory
|
||||
*
|
||||
* Co-developed with
|
||||
* The Controls and Computing Group
|
||||
* Accelerator Systems Division
|
||||
* Advanced Photon Source
|
||||
* Argonne National Laboratory
|
||||
*
|
||||
* Modification Log:
|
||||
* -----------------
|
||||
* .01 mm-dd-yy iii Comment
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <ellLib.h>
|
||||
|
||||
#ifdef vxWorks
|
||||
#define LOCKS_REQUIRED
|
||||
#include <tickLib.h>
|
||||
#endif /*vxWorks*/
|
||||
|
||||
#ifdef LOCKS_REQUIRED
|
||||
#include <fast_lock.h>
|
||||
#else /*LOCKS_REQUIRED*/
|
||||
#define FASTLOCK(A)
|
||||
#define FASTUNLOCK(A)
|
||||
#define FASTLOCKINIT(A)
|
||||
#endif /*LOCKS_REQUIRED*/
|
||||
|
||||
unsigned memDebugLevel = 1;
|
||||
|
||||
#define debugMallocMagic 0xaaaaaaaa
|
||||
|
||||
typedef struct debugMallocFooter{
|
||||
unsigned long magic;
|
||||
}DMF;
|
||||
|
||||
typedef struct debugMallocHeader{
|
||||
ELLNODE node;
|
||||
char *pFile;
|
||||
char *pUser;
|
||||
DMF *pFoot;
|
||||
unsigned long line;
|
||||
unsigned long size;
|
||||
unsigned long tick;
|
||||
unsigned long magic;
|
||||
}DMH;
|
||||
|
||||
#include <memDebugLib.h>
|
||||
#undef free
|
||||
#undef malloc
|
||||
#undef calloc
|
||||
|
||||
#define LOCAL static
|
||||
|
||||
#ifdef LOCKS_REQUIRED
|
||||
LOCAL int memDebugInit;
|
||||
LOCAL FAST_LOCK memDebugLock;
|
||||
#endif /*LOCKS_REQUIRED*/
|
||||
|
||||
#ifdef __STDC__
|
||||
LOCAL int memDebugVerify(DMH *pHdr);
|
||||
#else /*__STDC__*/
|
||||
LOCAL int memDebugVerify();
|
||||
#endif /*__STDC__*/
|
||||
|
||||
LOCAL ELLLIST memDebugList;
|
||||
|
||||
|
||||
/*
|
||||
* memDebugMalloc()
|
||||
*/
|
||||
#ifdef __STDC__
|
||||
char *memDebugMalloc(char *pFile, unsigned long line, unsigned long size)
|
||||
#else /*__STDC__*/
|
||||
char *memDebugMalloc(pFile, line, size)
|
||||
char *pFile;
|
||||
unsigned long line;
|
||||
unsigned long size;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
DMH *pHdr;
|
||||
|
||||
pHdr = (DMH *)calloc(1,sizeof(DMH)+sizeof(DMF)+size);
|
||||
if(!pHdr){
|
||||
return NULL;
|
||||
}
|
||||
pHdr->pUser = (char *) (pHdr+1);
|
||||
pHdr->pFoot = (DMF *) (pHdr->pUser+size);
|
||||
pHdr->pFile = pFile;
|
||||
pHdr->line = line;
|
||||
pHdr->size = size;
|
||||
pHdr->magic = debugMallocMagic;
|
||||
#ifdef vxWorks
|
||||
pHdr->tick = tickGet();
|
||||
#else /*vxWorks*/
|
||||
pHdr->tick = 0;
|
||||
#endif /*vxWorks*/
|
||||
pHdr->pFoot->magic = debugMallocMagic;
|
||||
|
||||
#ifdef LOCKS_REQUIRED
|
||||
if(!memDebugInit){
|
||||
memDebugInit = 1;
|
||||
FASTLOCKINIT(&memDebugLock);
|
||||
}
|
||||
#endif /*LOCKS_REQUIRED*/
|
||||
|
||||
FASTLOCK(&memDebugLock);
|
||||
ellAdd(&memDebugList, &pHdr->node);
|
||||
FASTUNLOCK(&memDebugLock);
|
||||
|
||||
if(memDebugLevel>2){
|
||||
fprintf(stderr, "%08x=malloc(%d) %s.%d\n",
|
||||
pHdr->pUser, size, pFile, line);
|
||||
}
|
||||
|
||||
return pHdr->pUser;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* memDebugCalloc()
|
||||
*/
|
||||
#ifdef __STDC__
|
||||
char *memDebugCalloc(char *pFile, unsigned long line,
|
||||
unsigned long nelem, unsigned long elsize)
|
||||
#else /*__STDC__*/
|
||||
char *memDebugCalloc(pFile, line, nelem, elsize)
|
||||
char *pFile;
|
||||
unsigned long line;
|
||||
unsigned long nelem;
|
||||
unsigned long elsize;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
return memDebugMalloc(pFile, line, nelem*elsize);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* memDebugFree()
|
||||
*/
|
||||
#ifdef __STDC__
|
||||
void memDebugFree(char *pFile, unsigned long line, void *ptr)
|
||||
#else /*__STDC__*/
|
||||
void memDebugFree(pFile, line, ptr)
|
||||
char *pFile;
|
||||
unsigned long line;
|
||||
void *ptr;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
DMH *pHdr;
|
||||
int status;
|
||||
|
||||
pHdr = -1 + (DMH *) ptr;
|
||||
FASTLOCK(&memDebugLock);
|
||||
status = ellFind(&memDebugList, &pHdr->node);
|
||||
|
||||
if(status<0 || (pHdr->pUser != ptr)){
|
||||
FASTUNLOCK(&memDebugLock);
|
||||
fprintf(stderr, "%s.%d free(%08x) failed\n", pFile, line, ptr);
|
||||
fprintf(stderr, "malloc occured at %s.%d\n", pHdr->pFile, pHdr->line);
|
||||
assert(0);
|
||||
}
|
||||
ellDelete(&memDebugList, &pHdr->node);
|
||||
FASTUNLOCK(&memDebugLock);
|
||||
|
||||
memDebugVerify(pHdr);
|
||||
|
||||
if(memDebugLevel>2){
|
||||
fprintf(stderr, "free(%08x) %s.%d\n", ptr, pFile, line);
|
||||
fprintf(stderr,
|
||||
"\tmalloc(%d) at %s.%d\n",
|
||||
pHdr->size,
|
||||
pHdr->pFile,
|
||||
pHdr->line);
|
||||
}
|
||||
|
||||
free(pHdr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* memDebugVerify()
|
||||
*/
|
||||
#ifdef __STDC__
|
||||
LOCAL int memDebugVerify(DMH *pHdr)
|
||||
#else /*__STDC__*/
|
||||
LOCAL int memDebugVerify(pHdr)
|
||||
DMH *pHdr;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
if(memDebugLevel==0){
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(pHdr->magic != debugMallocMagic || pHdr->pFoot->magic != debugMallocMagic){
|
||||
fprintf(stderr, "block overwritten %x\n", pHdr->pUser);
|
||||
fprintf(stderr, "malloc occured at %s.%d\n", pHdr->pFile, pHdr->line);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* memDebugVerifyAll()
|
||||
*/
|
||||
int memDebugVerifyAll()
|
||||
{
|
||||
int status;
|
||||
DMH *pHdr;
|
||||
|
||||
FASTLOCK(&memDebugLock);
|
||||
pHdr = (DMH *) ellFirst(&memDebugList);
|
||||
while(pHdr = (DMH *) ellNext(pHdr)){
|
||||
status = memDebugVerify(pHdr);
|
||||
}
|
||||
FASTUNLOCK(&memDebugLock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* memPrintAll()
|
||||
*/
|
||||
#ifdef __STDC__
|
||||
int memDebugPrintAll(unsigned long ignoreBeforeThisTick)
|
||||
#else /*__STDC__*/
|
||||
int memDebugPrintAll(ignoreBeforeThisTick)
|
||||
unsigned long ignoreBeforeThisTick;
|
||||
#endif /*__STDC__*/
|
||||
{
|
||||
int status;
|
||||
DMH *pHdr;
|
||||
|
||||
FASTLOCK(&memDebugLock);
|
||||
pHdr = (DMH *) ellFirst(&memDebugList);
|
||||
while(pHdr = (DMH *) ellNext(pHdr)){
|
||||
if(pHdr->tick<ignoreBeforeThisTick){
|
||||
continue;
|
||||
}
|
||||
fprintf(stderr,
|
||||
"\t%8x = malloc(%d) at %s.%d tick=%d\n",
|
||||
pHdr->pUser,
|
||||
pHdr->size,
|
||||
pHdr->pFile,
|
||||
pHdr->line,
|
||||
pHdr->tick);
|
||||
}
|
||||
FASTUNLOCK(&memDebugLock);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user