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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [compat/] [posix/] [v2_0/] [src/] [misc.cxx] - Blame information for rev 313

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      misc.cxx
4
//
5
//      POSIX misc function implementations
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-07-18
46
// Purpose:             POSIX misc function implementation
47
// Description:         This file contains the implementation of miscellaneous POSIX
48
//                      functions that do not belong elsewhere.
49
//              
50
//              
51
//
52
//####DESCRIPTIONEND####
53
//
54
//==========================================================================
55
 
56
#include <pkgconf/system.h>
57
#include <pkgconf/hal.h>
58
#include <pkgconf/kernel.h>
59
#include <pkgconf/posix.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 "pprivate.h"                   // POSIX private header
66
 
67
#include <unistd.h>
68
#include <sys/utsname.h>                // My header
69
#include <string.h>                     // strcpy
70
#include <limits.h>
71
#include <time.h>
72
 
73
#include <cyg/kernel/sched.hxx>
74
 
75
#include <cyg/kernel/sched.inl>
76
 
77
// -------------------------------------------------------------------------
78
// Supply some suitable values for constants that may not be present
79
// in all configurations.
80
 
81
#ifndef MQ_OPEN_MAX
82
#define MQ_OPEN_MAX 0
83
#endif
84
#ifndef MQ_PRIO_MAX
85
#define MQ_PRIO_MAX 0
86
#endif
87
 
88
// -------------------------------------------------------------------------
89
 
90
#define __string(_x) #_x
91
#define __xstring(_x) __string(_x)
92
 
93
// -------------------------------------------------------------------------
94
// uname()
95
 
96
__externC int uname( struct utsname *name )
97
{
98
    CYG_REPORT_FUNCTYPE( "returning %d" );
99
 
100
    strcpy( name->sysname, "eCos" );
101
    strcpy( name->nodename, "" );       // should use gethostname()
102
    strcpy( name->release, __xstring( CYGNUM_KERNEL_VERSION_MAJOR ) );
103
    strcpy( name->version, __xstring( CYGNUM_KERNEL_VERSION_MINOR ) );
104
    strcpy( name->machine, "" );
105
 
106
    CYG_REPORT_RETVAL(0);
107
    return 0;
108
}
109
 
110
// -------------------------------------------------------------------------
111
// sysconf()
112
 
113
#define SC_CASE( _name, _val ) case _name: return _val
114
 
115
__externC long sysconf( int name )
116
{
117
 
118
    switch( name )
119
    {
120
        SC_CASE( _SC_AIO_LISTIO_MAX,                    AIO_LISTIO_MAX );
121
        SC_CASE( _SC_AIO_MAX,                           AIO_MAX );
122
        SC_CASE( _SC_AIO_PRIO_DELTA_MAX,                AIO_PRIO_DELTA_MAX );
123
        SC_CASE( _SC_ARG_MAX,                           ARG_MAX );
124
        SC_CASE( _SC_CHILD_MAX,                         CHILD_MAX );
125
        SC_CASE( _SC_DELAYTIMER_MAX,                    DELAYTIMER_MAX );
126
        SC_CASE( _SC_GETGR_R_SIZE_MAX,                  0 );
127
        SC_CASE( _SC_GETPW_R_SIZE_MAX,                  0 );
128
        SC_CASE( _SC_LOGIN_NAME_MAX,                    LOGIN_NAME_MAX );
129
        SC_CASE( _SC_MQ_OPEN_MAX,                       MQ_OPEN_MAX );
130
        SC_CASE( _SC_MQ_PRIO_MAX,                       MQ_PRIO_MAX );
131
        SC_CASE( _SC_NGROUPS_MAX,                       NGROUPS_MAX );
132
        SC_CASE( _SC_OPEN_MAX,                          OPEN_MAX );
133
        SC_CASE( _SC_PAGESIZE,                          PAGESIZE );
134
        SC_CASE( _SC_RTSIG_MAX,                         RTSIG_MAX );
135
        SC_CASE( _SC_SEM_NSEMS_MAX,                     SEM_NSEMS_MAX );
136
        SC_CASE( _SC_SEM_VALUE_MAX,                     SEM_VALUE_MAX );
137
        SC_CASE( _SC_SIGQUEUE_MAX,                      SIGQUEUE_MAX );
138
        SC_CASE( _SC_STREAM_MAX,                        STREAM_MAX );
139
#ifdef CYGPKG_POSIX_PTHREAD
140
        SC_CASE( _SC_THREAD_DESTRUCTOR_ITERATIONS,      PTHREAD_DESTRUCTOR_ITERATIONS );
141
        SC_CASE( _SC_THREAD_KEYS_MAX,                   PTHREAD_KEYS_MAX );
142
        SC_CASE( _SC_THREAD_STACK_MIN,                  PTHREAD_STACK_MIN );
143
        SC_CASE( _SC_THREAD_THREADS_MAX,                PTHREAD_THREADS_MAX );
144
#endif
145
        SC_CASE( _SC_TIMER_MAX,                         TIMER_MAX );
146
        SC_CASE( _SC_TTY_NAME_MAX,                      TTY_NAME_MAX );
147
        SC_CASE( _SC_TZNAME_MAX,                        TZNAME_MAX );
148
        SC_CASE( _SC_VERSION,                           _POSIX_VERSION );
149
 
150
#ifdef CYGPKG_POSIX_TIMERS
151
    case _SC_CLK_TCK:
152
    {
153
        struct timespec ts;
154
        ts.tv_sec = 1;
155
        ts.tv_nsec = 0;
156
        cyg_tick_count ticks = cyg_timespec_to_ticks( &ts );
157
        return ticks;
158
    }
159
#endif
160
 
161
    case _SC_ASYNCHRONOUS_IO:
162
    #ifdef _POSIX_ASYNCHRONOUS_IO
163
        return 1;
164
    #else
165
        return -1;
166
    #endif
167
 
168
    case _SC_FSYNC:
169
    #ifdef _POSIX_FSYNC
170
        return 1;
171
    #else
172
        return -1;
173
    #endif
174
 
175
    case _SC_JOB_CONTROL:
176
    #ifdef _POSIX_JOB_CONTROL
177
        return 1;
178
    #else
179
        return -1;
180
    #endif
181
 
182
    case _SC_MAPPED_FILES:
183
    #ifdef _POSIX_MAPPED_FILES
184
        return 1;
185
    #else
186
        return -1;
187
    #endif
188
 
189
    case _SC_MEMLOCK:
190
    #ifdef _POSIX_MEMLOCK
191
        return 1;
192
    #else
193
        return -1;
194
    #endif
195
 
196
    case _SC_MEMLOCK_RANGE:
197
    #ifdef _POSIX_MEMLOCK_RANGE
198
        return 1;
199
    #else
200
        return -1        ;
201
    #endif      
202
 
203
    case _SC_MEMORY_PROTECTION:
204
    #ifdef _POSIX_MEMORY_PROTECTION
205
        return 1;
206
    #else
207
        return -1;
208
    #endif
209
 
210
    case _SC_MESSAGE_PASSING:
211
    #ifdef _POSIX_MESSAGE_PASSING
212
        return 1;
213
    #else
214
        return -1;
215
    #endif
216
 
217
    case _SC_PRIORITIZED_IO:
218
    #ifdef _POSIX_PRIORITIZED_IO
219
        return 1;
220
    #else
221
        return -1;
222
    #endif
223
 
224
    case _SC_PRIORITY_SCHEDULING:
225
    #ifdef _POSIX_PRIORITY_SCHEDULING
226
        return 1;
227
    #else
228
        return -1;
229
    #endif
230
 
231
    case _SC_REALTIME_SIGNALS:
232
    #ifdef _POSIX_REALTIME_SIGNALS
233
        return 1;
234
    #else
235
        return -1;
236
    #endif
237
 
238
    case _SC_SAVED_IDS:
239
    #ifdef _POSIX_SAVED_IDS
240
        return 1;
241
    #else
242
        return -1;
243
    #endif
244
 
245
    case _SC_SEMAPHORES:
246
    #ifdef _POSIX_SEMAPHORES
247
        return 1;
248
    #else
249
        return -1;
250
    #endif
251
 
252
    case _SC_SHARED_MEMORY_OBJECTS:
253
    #ifdef _POSIX_SHARED_MEMORY_OBJECTS
254
        return 1;
255
    #else
256
        return -1;
257
    #endif
258
 
259
    case _SC_SYNCHRONIZED_IO:
260
    #ifdef _POSIX_SYNCHRONIZED_IO
261
        return 1;
262
    #else
263
        return -1;
264
    #endif
265
 
266
    case _SC_THREADS:
267
    #ifdef _POSIX_THREADS
268
        return 1;
269
    #else
270
        return -1;
271
    #endif
272
 
273
    case _SC_THREAD_ATTR_STACKADDR:
274
    #ifdef _POSIX_THREAD_ATTR_STACKADDR
275
        return 1;
276
    #else
277
        return -1;
278
    #endif
279
 
280
    case _SC_THREAD_ATTR_STACKSIZE:
281
    #ifdef _POSIX_THREAD_ATTR_STACKSIZE
282
        return 1;
283
    #else
284
        return -1;
285
    #endif
286
 
287
    case _SC_THREAD_PRIO_INHERIT:
288
    #ifdef _POSIX_THREAD_PRIO_INHERIT
289
        return 1;
290
    #else
291
        return -1;
292
    #endif
293
 
294
    case _SC_THREAD_PRIO_PROTECT:
295
    #ifdef _POSIX_THREAD_PRIO_PROTECT
296
        return 1;
297
    #else
298
        return -1;
299
    #endif
300
 
301
    case _SC_THREAD_PRIORITY_SCHEDULING:
302
    #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
303
        return 1;
304
    #else
305
        return -1;
306
    #endif
307
 
308
    case _SC_THREAD_PROCESS_SHARED:
309
    #ifdef _POSIX_THREAD_PROCESS_SHARED
310
        return 1;
311
    #else
312
        return -1;
313
    #endif
314
 
315
    case _SC_THREAD_SAFE_FUNCTIONS:
316
    #ifdef _POSIX_THREAD_SAFE_FUNCTIONS
317
        return 1;
318
    #else
319
        return -1;
320
    #endif
321
 
322
    case _SC_TIMERS:
323
    #ifdef _POSIX_TIMERS
324
        return 1;
325
    #else
326
        return -1;
327
    #endif
328
 
329
 
330
    default:
331
        errno = EINVAL;
332
        return -1;
333
    }
334
}
335
 
336
//==========================================================================
337
// Some trivial compatibility functions.
338
// These are merely present to permit existing code to be ported a little
339
// more easily, and to provide adequate standards compatibility.
340
 
341
__externC pid_t getpid    ( void ) { return 42; }
342
__externC pid_t getppid   ( void ) { return 41; }
343
__externC uid_t getuid    ( void ) { return 666; }
344
__externC uid_t geteuid   ( void ) { return 666; }
345
__externC gid_t getgid    ( void ) { return 88; }
346
__externC gid_t getegid   ( void ) { return 88; }
347
__externC int   setuid    ( uid_t uid ) { errno = EPERM; return -1; }
348
__externC int   setgid    ( uid_t gid ) { errno = EPERM; return -1; }
349
__externC int   getgroups ( int gidsetsize, gid_t grouplist[] ) { return 0; };
350
__externC pid_t getpgrp   ( void ) { return 42; }
351
__externC pid_t setsid    ( void ) { errno = EPERM; return -1; }
352
__externC int   setpgid   ( pid_t pid, pid_t pgid ) { errno = ENOSYS; return -1; }
353
 
354
//==========================================================================
355
// Exports to other packages
356
 
357
// -------------------------------------------------------------------------
358
// POSIX API function entry
359
 
360
__externC void cyg_posix_function_start()
361
{
362
    Cyg_Thread *self = Cyg_Scheduler::get_current_thread();
363
 
364
    // Inhibit ASR delivery in this function until it returns.
365
 
366
    self->set_asr_inhibit();
367
}
368
 
369
// -------------------------------------------------------------------------
370
 
371
__externC void cyg_posix_function_finish()
372
{
373
    Cyg_Thread *self = Cyg_Scheduler::get_current_thread();
374
 
375
    // Re-allow ASR delivery.
376
 
377
    self->clear_asr_inhibit();
378
 
379
    // After clearing the inhibit flag, blip the scheduler lock
380
    // to get any pending ASRs delivered.
381
    Cyg_Scheduler::lock();
382
    Cyg_Scheduler::unlock();
383
}
384
 
385
// -------------------------------------------------------------------------
386
// EOF misc.cxx

powered by: WebSVN 2.1.0

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