From c238a2189d15121d62faa56982cbf17f22bd5b3e Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Fri, 31 May 1996 21:40:48 +0000 Subject: added checks to validate values passed to set attribute routines --- c/src/exec/posix/src/cond.c | 11 +++++-- c/src/exec/posix/src/mutex.c | 23 +++++++++++--- c/src/exec/posix/src/psignal.c | 6 ++++ c/src/exec/posix/src/pthread.c | 70 +++++++++++++++++++++++++++++++----------- c/src/exec/posix/src/sched.c | 18 ++++++++++- c/src/exec/posix/src/types.c | 3 +- 6 files changed, 105 insertions(+), 26 deletions(-) (limited to 'c/src/exec') diff --git a/c/src/exec/posix/src/cond.c b/c/src/exec/posix/src/cond.c index bba0f1991f..5dd5493808 100644 --- a/c/src/exec/posix/src/cond.c +++ b/c/src/exec/posix/src/cond.c @@ -142,8 +142,15 @@ int pthread_condattr_setpshared( if ( !attr ) return EINVAL; - attr->process_shared = pshared; - return 0; + switch ( pshared ) { + case PTHREAD_PROCESS_SHARED: + case PTHREAD_PROCESS_PRIVATE: + attr->process_shared = pshared; + return 0; + + default: + return EINVAL; + } } /*PAGE diff --git a/c/src/exec/posix/src/mutex.c b/c/src/exec/posix/src/mutex.c index 51ac6e097c..a3b81da52d 100644 --- a/c/src/exec/posix/src/mutex.c +++ b/c/src/exec/posix/src/mutex.c @@ -151,8 +151,15 @@ int pthread_mutexattr_setpshared( if ( !attr ) return EINVAL; - attr->process_shared = pshared; - return 0; + switch ( pshared ) { + case PTHREAD_PROCESS_SHARED: + case PTHREAD_PROCESS_PRIVATE: + attr->process_shared = pshared; + return 0; + + default: + return EINVAL; + } } /*PAGE @@ -466,8 +473,16 @@ int pthread_mutexattr_setprotocol( if ( !attr ) return EINVAL; - attr->protocol = protocol; - return 0; + switch ( protocol ) { + case PTHREAD_PRIO_NONE: + case PTHREAD_PRIO_INHERIT: + case PTHREAD_PRIO_PROTECT: + attr->protocol = protocol; + return 0; + + default: + return EINVAL; + } } /*PAGE diff --git a/c/src/exec/posix/src/psignal.c b/c/src/exec/posix/src/psignal.c index 5a4222b075..b0c79b9589 100644 --- a/c/src/exec/posix/src/psignal.c +++ b/c/src/exec/posix/src/psignal.c @@ -31,6 +31,12 @@ int kill( int sig ) { + /* + * Only supported for the "calling process" (i.e. this node). + */ + + assert( pid == getpid() ); + /* SIGABRT comes from abort via assert */ if ( sig == SIGABRT ) { exit( 1 ); diff --git a/c/src/exec/posix/src/pthread.c b/c/src/exec/posix/src/pthread.c index 9fa1428282..170a15adc3 100644 --- a/c/src/exec/posix/src/pthread.c +++ b/c/src/exec/posix/src/pthread.c @@ -80,6 +80,8 @@ User_extensions_routine _POSIX_Threads_Delete_extension( (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_POSIX ] ); deleted->API_Extensions[ THREAD_API_POSIX ] = NULL; + + /* XXX run _POSIX_Keys_Run_destructors here? */ } /*PAGE @@ -225,13 +227,12 @@ int pthread_attr_setscope( switch ( contentionscope ) { case PTHREAD_SCOPE_PROCESS: case PTHREAD_SCOPE_SYSTEM: - break; + attr->contentionscope = contentionscope; + return 0; + default: return EINVAL; } - - attr->contentionscope = contentionscope; - return 0; } /*PAGE @@ -267,13 +268,12 @@ int pthread_attr_setinheritsched( switch ( inheritsched ) { case PTHREAD_INHERIT_SCHED: case PTHREAD_EXPLICIT_SCHED: - break; + attr->inheritsched = inheritsched; + return 0; + default: return EINVAL; } - - attr->inheritsched = inheritsched; - return 0; } /*PAGE @@ -306,8 +306,17 @@ int pthread_attr_setschedpolicy( if ( !attr || !attr->is_initialized ) return EINVAL; - attr->schedpolicy = policy; - return 0; + switch ( policy ) { + case SCHED_OTHER: + case SCHED_FIFO: + case SCHED_RR: + case SCHED_SPORADIC: + attr->schedpolicy = policy; + return 0; + + default: + return EINVAL; + } } /*PAGE @@ -401,9 +410,18 @@ int pthread_setschedparam( if ( !param ) return EINVAL; - attr->schedpolicy = policy; - attr->schedparam = *param; - return 0; + switch ( policy ) { + case SCHED_OTHER: + case SCHED_FIFO: + case SCHED_RR: + case SCHED_SPORADIC: + attr->schedpolicy = policy; + attr->schedparam = *param; + return 0; + + default: + return EINVAL; + } } /*PAGE @@ -468,7 +486,7 @@ int pthread_attr_setstacksize( if ( !attr || !attr->is_initialized ) return EINVAL; - if ( stacksize < STACK_MINIMUM_SIZE ) + if (stacksize < STACK_MINIMUM_SIZE) attr->stacksize = STACK_MINIMUM_SIZE; else attr->stacksize = stacksize; @@ -539,8 +557,15 @@ int pthread_attr_setdetachstate( if ( !attr || !attr->is_initialized ) return EINVAL; - attr->detachstate = detachstate; - return 0; + switch ( detachstate ) { + case PTHREAD_CREATE_DETACHED: + case PTHREAD_CREATE_JOINABLE: + attr->detachstate = detachstate; + return 0; + + default: + return EINVAL; + } } /*PAGE @@ -733,6 +758,8 @@ void pthread_exit( * XXX Will need to deal with join/detach */ + /* XXX run _POSIX_Keys_Run_destructors here? */ + _Thread_Close( &_POSIX_Threads_Information, the_thread ); _POSIX_Threads_Free( the_thread ); @@ -829,8 +856,15 @@ int pthread_attr_setcputime( if ( !attr || !attr->is_initialized ) return EINVAL; - attr->cputime_clock_allowed = clock_allowed; - return 0; + switch ( clock_allowed ) { + case CLOCK_ENABLED: + case CLOCK_DISABLED: + attr->cputime_clock_allowed = clock_allowed; + return 0; + + default: + return EINVAL; + } } /*PAGE diff --git a/c/src/exec/posix/src/sched.c b/c/src/exec/posix/src/sched.c index 44b6337c70..9da0e43091 100644 --- a/c/src/exec/posix/src/sched.c +++ b/c/src/exec/posix/src/sched.c @@ -48,6 +48,12 @@ int sched_setscheduler( const struct sched_param *param ) { + /* + * Only supported for the "calling process" (i.e. this node). + */ + + assert( pid == getpid() ); + return POSIX_NOT_IMPLEMENTED(); } @@ -60,6 +66,12 @@ int sched_getscheduler( pid_t pid ) { + /* + * Only supported for the "calling process" (i.e. this node). + */ + + assert( pid == getpid() ); + return POSIX_NOT_IMPLEMENTED(); } @@ -105,10 +117,14 @@ int sched_rr_get_interval( /* XXX should get for errors? (bad pid) */ + /* XXX some of the time routines also convert usecs to a timespec -- */ + /* XXX should this be a common routine? */ + us_per_quantum = _TOD_Microseconds_per_tick * _Thread_Ticks_per_timeslice; interval->tv_sec = us_per_quantum / TOD_MICROSECONDS_PER_SECOND; - interval->tv_nsec = (us_per_quantum % TOD_MICROSECONDS_PER_SECOND) * 1000; + interval->tv_nsec = (us_per_quantum % TOD_MICROSECONDS_PER_SECOND) * + TOD_NANOSECONDS_PER_MICROSECOND; return 0; } diff --git a/c/src/exec/posix/src/types.c b/c/src/exec/posix/src/types.c index 194840305f..c1e1c8c708 100644 --- a/c/src/exec/posix/src/types.c +++ b/c/src/exec/posix/src/types.c @@ -5,6 +5,7 @@ #include #include +#include /*PAGE * @@ -13,7 +14,7 @@ pid_t getpid( void ) { - return POSIX_NOT_IMPLEMENTED(); + return _Objects_Local_node; } /*PAGE -- cgit v1.2.3