OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [services/] [loader/] [current/] [src/] [dload.cxx] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      dload.cxx
4
//
5
//      Dynamic loader API
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):           nickg
43
// Contributors:        nickg
44
// Date:                2000-11-03
45
// Purpose:             Loader class implementation
46
// Description:         This file contains the dynamic ELF loader API.
47
//                      This presents the standard dlxxx() calls by invoking
48
//                      the loader classes as appropriate.
49
//              
50
//              
51
//
52
//####DESCRIPTIONEND####
53
//
54
//==========================================================================
55
 
56
#include <pkgconf/hal.h>
57
#include <pkgconf/kernel.h>
58
#include <pkgconf/isoinfra.h>
59
 
60
#include <cyg/kernel/ktypes.h>          // base kernel types
61
#include <cyg/infra/cyg_trac.h>         // tracing macros
62
#include <cyg/infra/cyg_ass.h>          // assertion macros
63
 
64
#include <string.h>
65
 
66
#include <cyg/loader/loader.hxx>        // Loader header
67
 
68
#include <sys/types.h>
69
#include <sys/stat.h>
70
#include <fcntl.h>
71
#include <unistd.h>
72
#include <dlfcn.h>                      // API definitions
73
 
74
// =========================================================================
75
// Cyg_LoaderStream_File class
76
 
77
// =========================================================================
78
// API calls
79
 
80
cyg_uint32 global_symbol_object;
81
 
82
// =========================================================================
83
// Load and open object
84
 
85
__externC void *dlopen (const char *file, int mode)
86
{
87
    CYG_REPORT_FUNCTION();
88
 
89
    void *ret = NULL;
90
 
91
    if( file == NULL )
92
    {
93
        // Special case to allow access to all symbols.
94
 
95
        ret = (void *)&global_symbol_object;
96
    }
97
#ifdef CYGPKG_IO_FILEIO    
98
    else
99
    {
100
        int fd = open( file, O_RDONLY );
101
 
102
        if( fd < 0 )
103
            return NULL;
104
 
105
        Cyg_LoaderStream_File filestream( fd );
106
 
107
        Cyg_LoadObject *obj;
108
 
109
        cyg_code error = Cyg_Loader::loader->load( filestream, mode, &obj );
110
 
111
        if( error == 0)
112
        {
113
            ret = (void *)obj;
114
        }
115
 
116
        close( fd );
117
    }
118
#endif
119
 
120
    CYG_REPORT_RETVAL(ret);
121
    return ret;
122
}
123
 
124
// =========================================================================
125
 
126
__externC void *dlopenmem(const void *addr, size_t size, int mode)
127
{
128
    CYG_REPORT_FUNCTION();
129
 
130
    void *ret = NULL;
131
 
132
    Cyg_LoaderStream_Mem memstream( addr, size );
133
 
134
    Cyg_LoadObject *obj;
135
 
136
    cyg_code error = Cyg_Loader::loader->load( memstream, mode, &obj );
137
 
138
    if( error == 0)
139
        ret = (void *)obj;
140
 
141
    CYG_REPORT_RETVAL(ret);
142
    return ret;
143
}
144
 
145
// =========================================================================
146
 
147
__externC int dlclose (void *handle)
148
{
149
    CYG_REPORT_FUNCTION();
150
 
151
    int ret = 0;
152
 
153
    if( handle == (void *)global_symbol_object )
154
    {
155
        // Nothing to do here...
156
    }
157
    else
158
    {
159
        Cyg_LoadObject *obj = (Cyg_LoadObject *)handle;
160
 
161
        Cyg_Loader::loader->close( obj );
162
    }
163
 
164
    CYG_REPORT_RETVAL(ret);
165
    return ret;
166
}
167
 
168
// =========================================================================
169
 
170
__externC void *dlsym (void *handle, const char *name)
171
{
172
    CYG_REPORT_FUNCTION();
173
 
174
    void *ret = NULL;
175
 
176
    Cyg_LoadObject *obj = (Cyg_LoadObject *)handle;
177
 
178
    ret = obj->symbol( name );
179
 
180
    CYG_REPORT_RETVAL(ret);
181
    return ret;
182
}
183
 
184
// =========================================================================
185
 
186
__externC const char *dlerror (void)
187
{
188
    CYG_REPORT_FUNCTION();
189
 
190
    const char *ret = Cyg_Loader::loader->error_string();
191
 
192
    CYG_REPORT_RETVAL(ret);
193
    return ret;
194
}
195
 
196
 
197
// =========================================================================
198
// EOF dload.cxx

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.