solarisHeaders.h

Go to the documentation of this file.
00001 /*
00002  * See the dyninst/COPYRIGHT file for copyright information.
00003  * 
00004  * We provide the Paradyn Tools (below described as "Paradyn")
00005  * on an AS IS basis, and do not warrant its validity or performance.
00006  * We reserve the right to update, modify, or discontinue this
00007  * software at any time.  We shall have no obligation to supply such
00008  * updates or modifications or any other form of support to you.
00009  * 
00010  * By your use of Paradyn, you understand and agree that we (or any
00011  * other person or entity with proprietary rights in Paradyn) are
00012  * under no obligation to provide either maintenance services,
00013  * update services, notices of latent defects, or correction of
00014  * defects for Paradyn.
00015  * 
00016  * This library is free software; you can redistribute it and/or
00017  * modify it under the terms of the GNU Lesser General Public
00018  * License as published by the Free Software Foundation; either
00019  * version 2.1 of the License, or (at your option) any later version.
00020  * 
00021  * This library is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024  * Lesser General Public License for more details.
00025  * 
00026  * You should have received a copy of the GNU Lesser General Public
00027  * License along with this library; if not, write to the Free Software
00028  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00029  */
00030 
00031 
00032 #if !defined(_solaris_headers_h)
00033 #define _solaris_headers_h
00034 
00035 #include <assert.h>
00036 #include <stdio.h>
00037 #include <string.h>
00038 #include <stdlib.h>
00039 #include <errno.h>
00040 #include <assert.h>
00041 #include <fcntl.h>
00042 #include <netinet/in.h>
00043 #include <netdb.h>
00044 #include <sys/types.h>
00045 #include <sys/mman.h>
00046 #include <sys/time.h>
00047 #include <unistd.h>
00048 #include <sys/file.h>
00049 #include <sys/socket.h>
00050 #include <sys/errno.h>
00051 #include <sys/wait.h>
00052 #include <signal.h>
00053 #include <sys/resource.h>
00054 #include <stdarg.h>
00055 #include <time.h>
00056 #include <sys/utsname.h>
00057 #include <sys/stat.h>
00058 #include <sys/un.h>
00059 
00060 #include <rpc/types.h>
00061 #include <rpc/xdr.h>
00062 
00063 #define PDSOCKET_ERROR (-1)
00064 typedef int PDSOCKET;
00065 typedef int (*P_xdrproc_t)(XDR*, ...);
00066 extern const char *sys_errlist[];
00067 
00068 extern int (*P_native_demangle)(const char *, char *, size_t);
00069 
00070 extern "C" int rexec(char **, unsigned short, const char *,
00071              const char *, const char *, int *);
00072 
00073 /* POSIX */
00074 inline int P_getopt(int argc, char *argv[], const char *optstring) { return getopt(argc, argv, optstring);}
00075 inline void P_abort (void) { abort();}
00076 inline int P_close (int FILEDES) { return (close(FILEDES));}
00077 inline int P_dup2 (int OLD, int NEW) { return (dup2(OLD, NEW));}
00078 inline int P_execvp (const char *FILENAME, char *const ARGV[]) {
00079   return (execvp(FILENAME, ARGV));}
00080 inline int P_execve (const char* FILENAME,
00081              char* const ARGV[], char* const ENVP[]) {
00082     return (execve(FILENAME, ARGV, ENVP));
00083 }
00084 inline void P__exit (int STATUS) { _exit(STATUS);}
00085 inline int P_fcntl (int FILEDES, int COMMAND, int ARG2) {
00086   return (fcntl(FILEDES, COMMAND, ARG2));}
00087 inline FILE * P_fdopen (int FILEDES, const char *OPENTYPE) {
00088   return (fdopen(FILEDES, OPENTYPE));}
00089 inline FILE * P_fopen (const char *FILENAME, const char *OPENTYPE) {
00090   return (fopen(FILENAME, OPENTYPE));}
00091 inline int P_fstat (int FILEDES, struct stat *BUF) { return (fstat(FILEDES, BUF));}
00092 inline pid_t P_getpid () { return (getpid());}
00093 inline int P_kill(pid_t PID, int SIGNUM) { return (kill(PID, SIGNUM));}
00094 inline off_t P_lseek (int FILEDES, off_t OFFSET, int WHENCE) {
00095   return (lseek(FILEDES, OFFSET, WHENCE));}
00096 inline int P_open(const char *FILENAME, int FLAGS, mode_t MODE) {
00097   return (open(FILENAME, FLAGS, MODE));}
00098 inline int P_pclose (FILE *STREAM) { return (pclose(STREAM));}
00099 inline FILE *P_popen (const char *COMMAND, const char *MODE) {
00100   return (popen(COMMAND, MODE));}
00101 inline size_t P_read (int FILEDES, void *BUFFER, size_t SIZE) {
00102   return (read(FILEDES, BUFFER, SIZE));}
00103 inline int P_uname(struct utsname *un) { return (uname(un));}
00104 inline pid_t P_wait(int *status_ptr) { return (wait(status_ptr));}
00105 inline int P_waitpid(pid_t pid, int *statusp, int options) {
00106   return (waitpid(pid, statusp, options));}
00107 inline size_t P_write (int FILEDES, const void *BUFFER, size_t SIZE) {
00108   return (write(FILEDES, BUFFER, SIZE));}
00109 inline int P_chdir(const char *path) { return (chdir(path)); }
00110 inline int P_putenv(char *str) { return putenv(str); }
00111 
00112 /* SYSTEM-V shared memory */
00113 #include <sys/ipc.h>
00114 #include <sys/shm.h> /* shmid_ds */
00115 inline int P_shmget(key_t theKey, int size, int flags) {
00116    return shmget(theKey, size, flags);
00117 }
00118 inline void *P_shmat(int shmid, void *addr, int flags) {
00119    return shmat(shmid, (char *)addr, flags);
00120 }
00121 inline int P_shmdt(void *addr) {return shmdt((char*)addr);}
00122 inline int P_shmctl(int shmid, int cmd, struct shmid_ds *buf) {
00123    return shmctl(shmid, cmd, buf);
00124 }
00125 
00126 /* ANSI */
00127 inline void P_exit (int STATUS) { exit(STATUS);}
00128 inline int P_fflush(FILE *stream) { return (fflush(stream));}
00129 inline char * P_fgets (char *S, int COUNT, FILE *STREAM) {
00130   return (fgets(S, COUNT, STREAM));}
00131 inline void * P_malloc (size_t SIZE) { return (malloc(SIZE));}
00132 extern void * P_memcpy (void *A1, const void *A2, size_t SIZE);
00133 inline void * P_memset (void *BLOCK, int C, size_t SIZE) {
00134   return (memset(BLOCK, C, SIZE));}
00135 inline void P_perror (const char *MESSAGE) { perror(MESSAGE);}
00136 extern "C" {
00137 typedef void (*P_sig_handler)(int);
00138 }
00139 inline P_sig_handler P_signal (int SIGNUM, P_sig_handler ACTION) {
00140   return (signal(SIGNUM, ACTION));}
00141 inline char * P_strcat (char *TO, const char *FROM) {
00142   return (strcat(TO, FROM));}
00143 
00144 inline const char * P_strchr (const char *P_STRING, int C) {return (strchr(P_STRING, C));}
00145 inline char * P_strchr (char *P_STRING, int C) {return (strchr(P_STRING, C));}
00146 
00147 inline int P_strcmp (const char *S1, const char *S2) {
00148   return (strcmp(S1, S2));}
00149 inline char * P_strcpy (char *TO, const char *FROM) {
00150   return (strcpy(TO, FROM));}
00151 inline char *P_strdup(const char *S) { return (strdup(S));}
00152 inline size_t P_strlen (const char *S) { return (strlen(S));}
00153 inline char * P_strncat (char *TO, const char *FROM, size_t SIZE) {
00154   return (strncat(TO, FROM, SIZE)); }
00155 inline int P_strncmp (const char *S1, const char *S2, size_t SIZE) {
00156   return (strncmp(S1, S2, SIZE));}
00157 inline char * P_strncpy (char *TO, const char *FROM, size_t SIZE) {
00158   return (strncpy(TO, FROM, SIZE));}
00159 
00160 inline const char * P_strrchr (const char *P_STRING, int C) {return (strrchr(P_STRING, C));}
00161 inline char * P_strrchr (char *P_STRING, int C) {return (strrchr(P_STRING, C));}
00162 
00163 inline const char * P_strstr (const char *HAYSTACK, const char *NEEDLE) {return (strstr(HAYSTACK, NEEDLE));}
00164 inline char * P_strstr (char *HAYSTACK, const char *NEEDLE) {return (strstr(HAYSTACK, NEEDLE));}
00165 
00166 inline double P_strtod (const char *P_STRING, char **TAILPTR) {
00167   return (strtod(P_STRING, TAILPTR));}
00168 inline char * P_strtok (char *NEWP_STRING, const char *DELIMITERS) {
00169   return (strtok(NEWP_STRING, DELIMITERS));}
00170 inline long int P_strtol (const char *P_STRING, char **TAILPTR, int BASE) {
00171   return (strtol(P_STRING, TAILPTR, BASE));}
00172 inline unsigned long int P_strtoul(const char *P_STRING, char **TAILPTR, int BASE) { 
00173   return (strtoul(P_STRING, TAILPTR, BASE));}
00174 
00175 /* BSD */
00176 inline int P_accept (int SOCK, struct sockaddr *ADDR, size_t *LENGTH_PTR) {
00177   return (accept(SOCK, ADDR, LENGTH_PTR));}
00178 inline int P_bind(int socket, struct sockaddr *addr, size_t len) {
00179   return (bind(socket, addr, len));}
00180 inline int P_connect(int socket, struct sockaddr *addr, size_t len) {
00181   return (connect(socket, addr, len));}
00182 inline struct hostent * P_gethostbyname (const char *NAME) {
00183   return (gethostbyname(NAME));}
00184 /* inline int P_gethostname(char *name, size_t size) {
00185    return (gethostname(name, size));} */
00186 /* inline int P_getrusage(int i, struct rusage *ru) { 
00187    return (getrusage(i, ru));} */
00188 inline struct servent * P_getservbyname (const char *NAME, const char *PROTO) {
00189   return (getservbyname(NAME, PROTO));}
00190 inline int P_getsockname (int SOCKET, struct sockaddr *ADDR, size_t *LENGTH_PTR) {
00191   return (getsockname(SOCKET, ADDR, LENGTH_PTR));}
00192 inline int P_getsockopt(int s, int level, int optname, void *optval, 
00193             unsigned int *optlen) {
00194    return getsockopt(s, level, optname, optval, 
00195              static_cast<socklen_t*>(optlen));
00196 }
00197 inline int P_setsockopt(int s, int level, int optname, void *optval, int optlen) {
00198    return setsockopt(s, level, optname, (const char*)optval, optlen);
00199 }
00200 
00201 /* inline int P_gettimeofday (struct timeval *TP, struct timezone *TZP) {
00202   return (gettimeofday(TP, TZP));} */
00203 inline int P_listen (int socket, unsigned int n) { return (listen(socket, n));}
00204 inline caddr_t P_mmap(caddr_t addr, size_t len, int prot, int flags,
00205               int fd, off_t off) {
00206   return (static_cast<caddr_t>(mmap(addr, len, prot, flags, fd, off)));}
00207 inline int P_munmap(caddr_t addr, int i) { return (munmap(addr, i));}
00208 inline int P_socket (int NAMESPACE, int STYLE, int PROTOCOL) {
00209   return (socket(NAMESPACE, STYLE, PROTOCOL));}
00210 inline int P_socketpair(int namesp, int style, int protocol, int filedes[2]) {
00211   return (socketpair(namesp, style, protocol, filedes));}
00212 inline int P_pipe(int fds[2]) { return (pipe(fds)); }
00213 inline int P_strcasecmp(const char *s1, const char *s2) {
00214   return (strcasecmp(s1, s2));}
00215 inline int P_strncasecmp (const char *S1, const char *S2, size_t N) {
00216   return (strncasecmp(S1, S2,N));}
00217 inline void P_endservent(void) { endservent(); }
00218 inline int P_getpagesize() { return getpagesize(); }
00219 inline int P_recv(int s, void *buf, size_t len, int flags) {
00220    return (recv(s, buf, len, flags));
00221 }
00222 
00223 /* Ugly */
00224 
00225 inline int P_ptrace(int req, pid_t pid, int addr, int data, int /*word_len*/) {
00226   return (ptrace(req, pid, addr, data));}
00227 
00228 inline int P_select(int wid, fd_set *rd, fd_set *wr, fd_set *ex,
00229             struct timeval *tm) {
00230   return (select(wid, rd, wr, ex, tm));}
00231 
00232 inline int P_rexec(char **ahost, u_short inport, char *user,
00233            char *passwd, char *cmd, int *fd2p) {
00234   return (rexec(ahost, inport, user, passwd, cmd, fd2p));}
00235 
00236 #if defined(__GNUC__)
00237 #define DMGL_PARAMS      (1 << 0)       /* Include function args */
00238 #define DMGL_ANSI        (1 << 1)       /* Include const, volatile, etc */
00239 
00240 extern "C" char *cplus_demangle(char *, int);
00241 
00242 /* Hack to allow nativeDemanglerBrokenness() to compile under gcc. */
00243 #define DEMANGLE_ESPACE -1
00244 #define DEMANGLE_ENAME  1
00245 
00246 #else
00247 
00248 #include <demangle.h>
00249 
00250 #endif
00251 
00252 inline char * nativeDemanglerBrokenness( int (*P_native_demangle)(const char *, char *, size_t),
00253                     char * symbol ) {
00254     int length = 1024;
00255     char * demangled = NULL;
00256 
00257         /* Solaris native compiler adds "$X*." prefix to static variables compiled with
00258        debuggur option. The native demangler does not handle this prefix for now.
00259            So we strip the prefix. We look for the first occurance of period is the string. */
00260 
00261         char *stripsymbol = symbol;
00262         char *prefix1 = strstr (stripsymbol, "$X"); 
00263         if (prefix1 == stripsymbol ) {
00264             char *prefix2 = strchr(stripsymbol, '.');
00265             if (prefix2) {
00266         prefix2++;
00267         stripsymbol = prefix2 ;
00268             }
00269         }
00270 
00271     while( true ) {
00272         demangled = (char *)malloc( length * sizeof( char ) );
00273         if( demangled == NULL ) { return NULL; }
00274         
00275         int result = (* P_native_demangle)( stripsymbol, demangled, length );
00276 
00277         switch( result ) {
00278             case 0:
00279                                 if (!strcmp(demangled,symbol)) {
00280                                    free(demangled);
00281                                    demangled = NULL;
00282                                 }
00283                 return demangled;
00284             case DEMANGLE_ENAME:
00285                 return NULL;
00286             case DEMANGLE_ESPACE:
00287                 break;
00288             default:
00289                 assert( 0 );
00290             } /* end result switch */
00291 
00292         length += 1024;
00293         free( demangled );
00294         } /* end sizing loop */
00295     } /* end nativeCompilerBrokenness() */
00296 
00297 extern void dedemangle( char * demangled, char * dedemangled );
00298 inline char * P_cplus_demangle( const char *symbol, bool nativeCompiler,
00299                     bool includeTypes = false ) {
00300     char * demangled = NULL;
00301 
00302 #if defined( __GNUC__ )
00303   /* If the native demangler exists, try to demangled with it.
00304      Otherwise, use the GNU demangler. */
00305   if( ! nativeCompiler || P_native_demangle == NULL ) {
00306     /* If we've been compiled with GNU and we're
00307        demangling a GNU name, use cplus_demangle(). */
00308     demangled = cplus_demangle( const_cast<char *>( symbol ), 
00309                                     includeTypes ? DMGL_PARAMS|DMGL_ANSI  : 0 );
00310     if( demangled == NULL ) { return NULL; }
00311     } /* end if there's no native demangler */
00312   else {
00313     /* Use the native demangler. */
00314     demangled = nativeDemanglerBrokenness( P_native_demangle, const_cast< char * >( symbol ) );
00315 
00316     if( demangled == NULL ) { return NULL; }
00317     } /* end if we're using the native demangler. */
00318 
00319 #else 
00320 
00321   /* We were compiled with the native compiler, so use its demangler. */
00322   demangled = nativeDemanglerBrokenness( cplus_demangle, (char *)symbol );
00323 
00324   if( demangled == NULL ) { return NULL; }  
00325 
00326 #endif
00327 
00328   if( ! includeTypes ) {
00329         /* de-demangling never increases the length */
00330         char * dedemangled = strdup( demangled );
00331         assert( dedemangled != NULL );
00332         dedemangle( demangled, dedemangled );
00333         assert( dedemangled != NULL );
00334 
00335         free( demangled );
00336         return dedemangled;  
00337         }
00338 
00339   return demangled;
00340   } /* end P_cplus_demangle() */
00341 
00342 inline void   P_xdr_destroy(XDR *x) { xdr_destroy(x);}
00343 inline bool_t P_xdr_u_char(XDR *x, u_char *uc) { return (xdr_u_char(x, uc));}
00344 inline bool_t P_xdr_int(XDR *x, int *i) { return (xdr_int(x, i));}
00345 inline bool_t P_xdr_double(XDR *x, double *d) {
00346   return (xdr_double(x, d));}
00347 inline bool_t P_xdr_u_int(XDR *x, u_int *u){
00348   return (xdr_u_int(x, u));}
00349 inline bool_t P_xdr_float(XDR *x, float *f) {
00350   return (xdr_float(x, f));}
00351 inline bool_t P_xdr_char(XDR *x, char *c) {
00352   return (xdr_char(x, c));}
00353 inline bool_t P_xdr_string(XDR *x, char **h, const u_int maxsize) {
00354   return (xdr_string(x, h, maxsize));}
00355 
00356 inline void P_xdrrec_create(XDR *x, const u_int send_sz, const u_int rec_sz,
00357                 const caddr_t handle, 
00358                 xdr_rd_func read_r, xdr_wr_func write_f) {
00359 #if !defined(__GNUC__)
00360   xdrrec_create(x, send_sz, rec_sz, handle,
00361         read_r, write_f);
00362 #else
00363   xdrrec_create(x, send_sz, rec_sz, handle, read_r, write_f);
00364 #endif
00365 }
00366 inline bool_t P_xdrrec_endofrecord(XDR *x, int now) { 
00367   return (xdrrec_endofrecord(x, now));}
00368 inline bool_t P_xdrrec_skiprecord(XDR *x) { return (xdrrec_skiprecord(x));}
00369 inline bool_t P_xdrrec_eof(XDR *x) { return (xdrrec_eof(x)); }
00370 inline int P_mkdir(const char *pathname, mode_t mode) {
00371     return mkdir(pathname, mode);
00372 }
00373 inline int P_unlink(const char *pathname) {
00374     return unlink(pathname);
00375 }
00376 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1