7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 #include "lint.h"
  30 #include <libc.h>
  31 #include <fcntl.h>
  32 #include <stdlib.h>
  33 #include <unistd.h>
  34 #include <sys/types.h>
  35 #include <sys/stat.h>
  36 #include <sys/auxv.h>
  37 #include <mtlib.h>
  38 #include <thread.h>
  39 #include <synch.h>
  40 #include <atomic.h>
  41 
  42 static mutex_t auxlock = DEFAULTMUTEX;
  43 
  44 /*
  45  * Get auxiliary entry.
  46  * Returns pointer to entry, or 0 if entry does not exist.
  47  */
  48 static auxv_t *
  49 _getaux(int type)
  50 {
  51         static auxv_t *auxb = NULL;
  52         static size_t nauxv = 0;
  53         ssize_t i;
  54 
  55         /*
  56          * The first time through, read the initial aux vector that was
  57          * passed to the process at exec(2).  Only do this once.
  58          */
  59         if (auxb == NULL) {
  60                 lmutex_lock(&auxlock);
  61                 if (auxb == NULL) {
  62                         struct stat statb;
  63                         auxv_t *buf = NULL;
  64                         int fd;
  65 
  66                         if ((fd = open("/proc/self/auxv", O_RDONLY)) != -1 &&
  67                             fstat(fd, &statb) != -1)
  68                                 buf = libc_malloc(
  69                                     statb.st_size + sizeof (auxv_t));
  70 
  71                         if (buf != NULL) {
  72                                 i = read(fd, buf, statb.st_size);
  73                                 if (i != -1) {
  74                                         nauxv = i / sizeof (auxv_t);
  75                                         buf[nauxv].a_type = AT_NULL;
  76                                 } else {
  77                                         libc_free(buf);
  78                                         buf = NULL;
  79                                 }
  80                         }
  81 
  82                         if (fd != -1)
  83                                 (void) close(fd);
  84 
  85                         membar_producer();
  86                         auxb = buf;
 
 | 
 
 
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #include "lint.h"
  28 #include "thr_uberdata.h"
  29 #include <libc.h>
  30 #include <fcntl.h>
  31 #include <stdlib.h>
  32 #include <unistd.h>
  33 #include <sys/types.h>
  34 #include <sys/stat.h>
  35 #include <sys/auxv.h>
  36 #include <mtlib.h>
  37 #include <thread.h>
  38 #include <synch.h>
  39 #include <atomic.h>
  40 #include <limits.h>
  41 
  42 static mutex_t auxlock = DEFAULTMUTEX;
  43 
  44 /*
  45  * Get auxiliary entry.
  46  * Returns pointer to entry, or 0 if entry does not exist.
  47  */
  48 static auxv_t *
  49 _getaux(int type)
  50 {
  51         static auxv_t *auxb = NULL;
  52         static size_t nauxv = 0;
  53         ssize_t i;
  54 
  55         /*
  56          * The first time through, read the initial aux vector that was
  57          * passed to the process at exec(2).  Only do this once.
  58          */
  59         if (auxb == NULL) {
  60                 lmutex_lock(&auxlock);
  61                 if (auxb == NULL) {
  62                         uberdata_t *udp = curthread->ul_uberdata;
  63                         struct stat statb;
  64                         auxv_t *buf = NULL;
  65                         char *path = "/proc/self/auxv";
  66                         char pbuf[PATH_MAX];
  67                         int fd;
  68 
  69                         if (udp->ub_broot != NULL) {
  70                                 (void) snprintf(pbuf, sizeof (pbuf),
  71                                     "%s/proc/self/auxv", udp->ub_broot);
  72                                 path = pbuf;
  73                         }
  74 
  75                         if ((fd = open(path, O_RDONLY)) != -1 &&
  76                             fstat(fd, &statb) != -1)
  77                                 buf = libc_malloc(
  78                                     statb.st_size + sizeof (auxv_t));
  79 
  80                         if (buf != NULL) {
  81                                 i = read(fd, buf, statb.st_size);
  82                                 if (i != -1) {
  83                                         nauxv = i / sizeof (auxv_t);
  84                                         buf[nauxv].a_type = AT_NULL;
  85                                 } else {
  86                                         libc_free(buf);
  87                                         buf = NULL;
  88                                 }
  89                         }
  90 
  91                         if (fd != -1)
  92                                 (void) close(fd);
  93 
  94                         membar_producer();
  95                         auxb = buf;
 
 |