1 //==========================================================================
5 // POSIX misc function implementations
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.
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.
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
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.
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.
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.
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####
44 // Contributors: nickg
46 // Purpose: POSIX misc function implementation
47 // Description: This file contains the implementation of miscellaneous POSIX
48 // functions that do not belong elsewhere.
52 //####DESCRIPTIONEND####
54 //==========================================================================
56 #include <pkgconf/system.h>
57 #include <pkgconf/hal.h>
58 #include <pkgconf/kernel.h>
59 #include <pkgconf/posix.h>
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
65 #include "pprivate.h" // POSIX private header
68 #include <sys/utsname.h> // My header
69 #include <string.h> // strcpy
73 #include <cyg/kernel/sched.hxx>
75 #include <cyg/kernel/sched.inl>
77 // -------------------------------------------------------------------------
78 // Supply some suitable values for constants that may not be present
79 // in all configurations.
88 // -------------------------------------------------------------------------
90 #define __string(_x) #_x
91 #define __xstring(_x) __string(_x)
93 // -------------------------------------------------------------------------
96 __externC int uname( struct utsname *name )
98 CYG_REPORT_FUNCTYPE( "returning %d" );
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, "" );
106 CYG_REPORT_RETVAL(0);
110 // -------------------------------------------------------------------------
113 #define SC_CASE( _name, _val ) case _name: return _val
115 __externC long sysconf( int name )
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 );
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 );
150 #ifdef CYGPKG_POSIX_TIMERS
156 cyg_tick_count ticks = cyg_timespec_to_ticks( &ts );
161 case _SC_ASYNCHRONOUS_IO:
162 #ifdef _POSIX_ASYNCHRONOUS_IO
175 case _SC_JOB_CONTROL:
176 #ifdef _POSIX_JOB_CONTROL
182 case _SC_MAPPED_FILES:
183 #ifdef _POSIX_MAPPED_FILES
190 #ifdef _POSIX_MEMLOCK
196 case _SC_MEMLOCK_RANGE:
197 #ifdef _POSIX_MEMLOCK_RANGE
203 case _SC_MEMORY_PROTECTION:
204 #ifdef _POSIX_MEMORY_PROTECTION
210 case _SC_MESSAGE_PASSING:
211 #ifdef _POSIX_MESSAGE_PASSING
217 case _SC_PRIORITIZED_IO:
218 #ifdef _POSIX_PRIORITIZED_IO
224 case _SC_PRIORITY_SCHEDULING:
225 #ifdef _POSIX_PRIORITY_SCHEDULING
231 case _SC_REALTIME_SIGNALS:
232 #ifdef _POSIX_REALTIME_SIGNALS
239 #ifdef _POSIX_SAVED_IDS
246 #ifdef _POSIX_SEMAPHORES
252 case _SC_SHARED_MEMORY_OBJECTS:
253 #ifdef _POSIX_SHARED_MEMORY_OBJECTS
259 case _SC_SYNCHRONIZED_IO:
260 #ifdef _POSIX_SYNCHRONIZED_IO
267 #ifdef _POSIX_THREADS
273 case _SC_THREAD_ATTR_STACKADDR:
274 #ifdef _POSIX_THREAD_ATTR_STACKADDR
280 case _SC_THREAD_ATTR_STACKSIZE:
281 #ifdef _POSIX_THREAD_ATTR_STACKSIZE
287 case _SC_THREAD_PRIO_INHERIT:
288 #ifdef _POSIX_THREAD_PRIO_INHERIT
294 case _SC_THREAD_PRIO_PROTECT:
295 #ifdef _POSIX_THREAD_PRIO_PROTECT
301 case _SC_THREAD_PRIORITY_SCHEDULING:
302 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
308 case _SC_THREAD_PROCESS_SHARED:
309 #ifdef _POSIX_THREAD_PROCESS_SHARED
315 case _SC_THREAD_SAFE_FUNCTIONS:
316 #ifdef _POSIX_THREAD_SAFE_FUNCTIONS
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.
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; }
354 //==========================================================================
355 // Exports to other packages
357 // -------------------------------------------------------------------------
358 // POSIX API function entry
360 __externC void cyg_posix_function_start()
362 Cyg_Thread *self = Cyg_Scheduler::get_current_thread();
364 // Inhibit ASR delivery in this function until it returns.
366 self->set_asr_inhibit();
369 // -------------------------------------------------------------------------
371 __externC void cyg_posix_function_finish()
373 Cyg_Thread *self = Cyg_Scheduler::get_current_thread();
375 // Re-allow ASR delivery.
377 self->clear_asr_inhibit();
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();
385 // -------------------------------------------------------------------------