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.
35 // -------------------------------------------
36 //####ECOSGPLCOPYRIGHTEND####
37 //==========================================================================
38 //#####DESCRIPTIONBEGIN####
41 // Contributors: nickg
43 // Purpose: POSIX misc function implementation
44 // Description: This file contains the implementation of miscellaneous POSIX
45 // functions that do not belong elsewhere.
49 //####DESCRIPTIONEND####
51 //==========================================================================
53 #include <pkgconf/system.h>
54 #include <pkgconf/hal.h>
55 #include <pkgconf/kernel.h>
56 #include <pkgconf/posix.h>
58 #include <cyg/kernel/ktypes.h> // base kernel types
59 #include <cyg/infra/cyg_trac.h> // tracing macros
60 #include <cyg/infra/cyg_ass.h> // assertion macros
62 #include "pprivate.h" // POSIX private header
65 #ifdef CYGPKG_POSIX_UTSNAME
66 #include <sys/utsname.h> // My header
68 #include <string.h> // strcpy
72 #include <cyg/kernel/sched.hxx>
74 #include <cyg/kernel/sched.inl>
76 // -------------------------------------------------------------------------
77 // Supply some suitable values for constants that may not be present
78 // in all configurations.
87 // -------------------------------------------------------------------------
89 #define __string(_x) #_x
90 #define __xstring(_x) __string(_x)
92 // -------------------------------------------------------------------------
95 #ifdef CYGPKG_POSIX_UTSNAME
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);
111 // -------------------------------------------------------------------------
114 #define SC_CASE( _name, _val ) case _name: return _val
116 __externC long sysconf( int name )
121 SC_CASE( _SC_AIO_LISTIO_MAX, AIO_LISTIO_MAX );
122 SC_CASE( _SC_AIO_MAX, AIO_MAX );
123 SC_CASE( _SC_AIO_PRIO_DELTA_MAX, AIO_PRIO_DELTA_MAX );
124 SC_CASE( _SC_ARG_MAX, ARG_MAX );
125 SC_CASE( _SC_CHILD_MAX, CHILD_MAX );
126 SC_CASE( _SC_DELAYTIMER_MAX, DELAYTIMER_MAX );
127 SC_CASE( _SC_GETGR_R_SIZE_MAX, 0 );
128 SC_CASE( _SC_GETPW_R_SIZE_MAX, 0 );
129 SC_CASE( _SC_LOGIN_NAME_MAX, LOGIN_NAME_MAX );
130 #ifdef CYGPKG_POSIX_MQUEUES
131 SC_CASE( _SC_MQ_OPEN_MAX, MQ_OPEN_MAX );
132 SC_CASE( _SC_MQ_PRIO_MAX, MQ_PRIO_MAX );
134 SC_CASE( _SC_NGROUPS_MAX, NGROUPS_MAX );
135 SC_CASE( _SC_OPEN_MAX, OPEN_MAX );
136 SC_CASE( _SC_PAGESIZE, PAGESIZE );
137 SC_CASE( _SC_RTSIG_MAX, RTSIG_MAX );
138 #ifdef CYGPKG_POSIX_SEMAPHORES
139 SC_CASE( _SC_SEM_NSEMS_MAX, SEM_NSEMS_MAX );
140 SC_CASE( _SC_SEM_VALUE_MAX, SEM_VALUE_MAX );
142 SC_CASE( _SC_SIGQUEUE_MAX, SIGQUEUE_MAX );
143 SC_CASE( _SC_STREAM_MAX, STREAM_MAX );
144 #ifdef CYGPKG_POSIX_PTHREAD
145 SC_CASE( _SC_THREAD_DESTRUCTOR_ITERATIONS, PTHREAD_DESTRUCTOR_ITERATIONS );
146 SC_CASE( _SC_THREAD_KEYS_MAX, PTHREAD_KEYS_MAX );
147 SC_CASE( _SC_THREAD_STACK_MIN, PTHREAD_STACK_MIN );
148 SC_CASE( _SC_THREAD_THREADS_MAX, PTHREAD_THREADS_MAX );
150 SC_CASE( _SC_TIMER_MAX, TIMER_MAX );
151 SC_CASE( _SC_TTY_NAME_MAX, TTY_NAME_MAX );
152 SC_CASE( _SC_TZNAME_MAX, TZNAME_MAX );
153 SC_CASE( _SC_VERSION, _POSIX_VERSION );
155 #ifdef CYGPKG_POSIX_TIMERS
161 cyg_tick_count ticks = cyg_timespec_to_ticks( &ts );
166 case _SC_ASYNCHRONOUS_IO:
167 #ifdef _POSIX_ASYNCHRONOUS_IO
180 case _SC_JOB_CONTROL:
181 #ifdef _POSIX_JOB_CONTROL
187 case _SC_MAPPED_FILES:
188 #ifdef _POSIX_MAPPED_FILES
195 #ifdef _POSIX_MEMLOCK
201 case _SC_MEMLOCK_RANGE:
202 #ifdef _POSIX_MEMLOCK_RANGE
208 case _SC_MEMORY_PROTECTION:
209 #ifdef _POSIX_MEMORY_PROTECTION
215 case _SC_MESSAGE_PASSING:
216 #ifdef _POSIX_MESSAGE_PASSING
222 case _SC_PRIORITIZED_IO:
223 #ifdef _POSIX_PRIORITIZED_IO
229 case _SC_PRIORITY_SCHEDULING:
230 #ifdef _POSIX_PRIORITY_SCHEDULING
236 case _SC_REALTIME_SIGNALS:
237 #ifdef _POSIX_REALTIME_SIGNALS
244 #ifdef _POSIX_SAVED_IDS
251 #ifdef _POSIX_SEMAPHORES
257 case _SC_SHARED_MEMORY_OBJECTS:
258 #ifdef _POSIX_SHARED_MEMORY_OBJECTS
264 case _SC_SYNCHRONIZED_IO:
265 #ifdef _POSIX_SYNCHRONIZED_IO
272 #ifdef _POSIX_THREADS
278 case _SC_THREAD_ATTR_STACKADDR:
279 #ifdef _POSIX_THREAD_ATTR_STACKADDR
285 case _SC_THREAD_ATTR_STACKSIZE:
286 #ifdef _POSIX_THREAD_ATTR_STACKSIZE
292 case _SC_THREAD_PRIO_INHERIT:
293 #ifdef _POSIX_THREAD_PRIO_INHERIT
299 case _SC_THREAD_PRIO_PROTECT:
300 #ifdef _POSIX_THREAD_PRIO_PROTECT
306 case _SC_THREAD_PRIORITY_SCHEDULING:
307 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
313 case _SC_THREAD_PROCESS_SHARED:
314 #ifdef _POSIX_THREAD_PROCESS_SHARED
320 case _SC_THREAD_SAFE_FUNCTIONS:
321 #ifdef _POSIX_THREAD_SAFE_FUNCTIONS
341 //==========================================================================
342 // Some trivial compatibility functions.
343 // These are merely present to permit existing code to be ported a little
344 // more easily, and to provide adequate standards compatibility.
346 __externC pid_t getpid ( void ) { return 42; }
347 __externC pid_t getppid ( void ) { return 41; }
348 __externC uid_t getuid ( void ) { return 666; }
349 __externC uid_t geteuid ( void ) { return 666; }
350 __externC gid_t getgid ( void ) { return 88; }
351 __externC gid_t getegid ( void ) { return 88; }
352 __externC int setuid ( uid_t uid ) { errno = EPERM; return -1; }
353 __externC int setgid ( uid_t gid ) { errno = EPERM; return -1; }
354 __externC int getgroups ( int gidsetsize, gid_t grouplist[] ) { return 0; };
355 __externC pid_t getpgrp ( void ) { return 42; }
356 __externC pid_t setsid ( void ) { errno = EPERM; return -1; }
357 __externC int setpgid ( pid_t pid, pid_t pgid ) { errno = ENOSYS; return -1; }
359 //==========================================================================
360 // Exports to other packages
362 // -------------------------------------------------------------------------
363 // POSIX API function entry
365 __externC void cyg_posix_function_start()
367 Cyg_Thread *self = Cyg_Scheduler::get_current_thread();
369 // Inhibit ASR delivery in this function until it returns.
371 self->set_asr_inhibit();
374 // -------------------------------------------------------------------------
376 __externC void cyg_posix_function_finish()
378 Cyg_Thread *self = Cyg_Scheduler::get_current_thread();
380 // Re-allow ASR delivery.
382 self->clear_asr_inhibit();
384 // After clearing the inhibit flag, blip the scheduler lock
385 // to get any pending ASRs delivered.
386 Cyg_Scheduler::lock();
387 Cyg_Scheduler::unlock();
390 // -------------------------------------------------------------------------