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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [loader/] [v2_0/] [src/] [dload.cxx] - Blame information for rev 565

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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