1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
4 for INTEL64(R), AMD64(R)
6 Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
11 1. Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
31 /* File Info -----------------------------------------------------------
35 ----------------------------------------------------------------------*/
37 #define DRD64_SRC_LIBBROWNIE_LDSOHINTS
38 #include"drd64_libbrownie.h"
40 static char *gpstr_solibpath[LIBBROWNIE_LDHINTS_MAX];
43 /***********************************************************************
44 ***********************************************************************/
45 LIBBROWNIE_LDSOHINTS_API
47 LibBrownie_GetLoadLibraryPath(
52 char **ppstr_solibpath;
54 struct elfhints_hdr t_elfhints_header;
56 if( b_ldbits == LIBBROWNIE_LDHINTS_ELF64 )
57 { pstr_hintsfile = LIBBROWNIE_LDHINST_HINTSFILE64; }
58 else if( b_ldbits == LIBBROWNIE_LDHINTS_ELF32 )
59 { pstr_hintsfile = LIBBROWNIE_LDHINST_HINTSFILE32; }
63 ppstr_solibpath = &(gpstr_solibpath[b_ldbits]);
64 if( NULL != *ppstr_solibpath ) { return *ppstr_solibpath; }
66 i_fd = open( pstr_hintsfile, O_RDONLY );
71 t_size = read( i_fd, &t_elfhints_header, sizeof( struct elfhints_hdr ) );
72 if( sizeof( struct elfhints_hdr ) != t_size ) {
73 goto goto_LibBrownie_GetLoadLibraryPath_FileClose;
76 if( ELFHINTS_MAGIC != t_elfhints_header.magic ) {
77 goto goto_LibBrownie_GetLoadLibraryPath_FileClose;
80 *ppstr_solibpath = (char *)malloc( t_elfhints_header.strsize + 1 );
81 if( NULL == *ppstr_solibpath ) {
82 goto goto_LibBrownie_GetLoadLibraryPath_FileClose;
84 memset( *ppstr_solibpath, 0x00, (t_elfhints_header.strsize + 1) );
86 t_size = read( i_fd, *ppstr_solibpath, t_elfhints_header.strsize );
87 if( t_elfhints_header.strsize != t_size ) {
88 goto goto_LibBrownie_GetLoadLibraryPath_FileClose ;
91 goto_LibBrownie_GetLoadLibraryPath_FileClose:
94 return *ppstr_solibpath;
98 /***********************************************************************
99 ***********************************************************************/
100 LIBBROWNIE_LDSOHINTS_API
102 LibBrownie_FreeLoadLibraryPath(
105 char **ppstr_solibpath;
107 if(( b_ldbits != LIBBROWNIE_LDHINTS_ELF64 )
108 && ( b_ldbits != LIBBROWNIE_LDHINTS_ELF32 )) {
112 ppstr_solibpath = &(gpstr_solibpath[b_ldbits]);
114 if( NULL != *ppstr_solibpath ) {
115 free( *ppstr_solibpath );
116 *ppstr_solibpath = NULL;
123 /*----------------------------------------------------------------------
124 ----------------------------------------------------------------------*/
125 LIBBROWNIE_LDSOHINTS_EXTERN
127 LibBrownie_LdSoHints_Init(
130 gpstr_solibpath[ LIBBROWNIE_LDHINTS_ELF64 ] = NULL;
131 gpstr_solibpath[ LIBBROWNIE_LDHINTS_ELF32 ] = NULL;
137 /*----------------------------------------------------------------------
138 ----------------------------------------------------------------------*/
139 LIBBROWNIE_LDSOHINTS_EXTERN
141 LibBrownie_LdSoHints_Term(
144 if( NULL != gpstr_solibpath[ LIBBROWNIE_LDHINTS_ELF64 ] ) {
145 free( gpstr_solibpath[ LIBBROWNIE_LDHINTS_ELF64 ] );
146 gpstr_solibpath[ LIBBROWNIE_LDHINTS_ELF64 ] = NULL;
149 if( NULL != gpstr_solibpath[ LIBBROWNIE_LDHINTS_ELF32 ] ) {
150 free( gpstr_solibpath[ LIBBROWNIE_LDHINTS_ELF32 ] );
151 gpstr_solibpath[ LIBBROWNIE_LDHINTS_ELF32 ] = NULL;
158 /* EOF of drd64_.c ----------------------------------- */