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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [compat/] [posix/] [current/] [src/] [misc.cxx] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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