added checks to validate values passed to set attribute routines

This commit is contained in:
Joel Sherrill
1996-05-31 21:40:48 +00:00
parent f31da72ce4
commit c238a2189d
12 changed files with 210 additions and 52 deletions

View File

@@ -142,8 +142,15 @@ int pthread_condattr_setpshared(
if ( !attr )
return EINVAL;
switch ( pshared ) {
case PTHREAD_PROCESS_SHARED:
case PTHREAD_PROCESS_PRIVATE:
attr->process_shared = pshared;
return 0;
default:
return EINVAL;
}
}
/*PAGE

View File

@@ -151,8 +151,15 @@ int pthread_mutexattr_setpshared(
if ( !attr )
return EINVAL;
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;
switch ( protocol ) {
case PTHREAD_PRIO_NONE:
case PTHREAD_PRIO_INHERIT:
case PTHREAD_PRIO_PROTECT:
attr->protocol = protocol;
return 0;
default:
return EINVAL;
}
}
/*PAGE

View File

@@ -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 );

View File

@@ -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;
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;
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
@@ -539,8 +557,15 @@ int pthread_attr_setdetachstate(
if ( !attr || !attr->is_initialized )
return EINVAL;
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;
switch ( clock_allowed ) {
case CLOCK_ENABLED:
case CLOCK_DISABLED:
attr->cputime_clock_allowed = clock_allowed;
return 0;
default:
return EINVAL;
}
}
/*PAGE

View File

@@ -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;
}

View File

@@ -5,6 +5,7 @@
#include <sys/types.h>
#include <rtems/system.h>
#include <rtems/score/object.h>
/*PAGE
*
@@ -13,7 +14,7 @@
pid_t getpid( void )
{
return POSIX_NOT_IMPLEMENTED();
return _Objects_Local_node;
}
/*PAGE

View File

@@ -142,8 +142,15 @@ int pthread_condattr_setpshared(
if ( !attr )
return EINVAL;
switch ( pshared ) {
case PTHREAD_PROCESS_SHARED:
case PTHREAD_PROCESS_PRIVATE:
attr->process_shared = pshared;
return 0;
default:
return EINVAL;
}
}
/*PAGE

View File

@@ -151,8 +151,15 @@ int pthread_mutexattr_setpshared(
if ( !attr )
return EINVAL;
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;
switch ( protocol ) {
case PTHREAD_PRIO_NONE:
case PTHREAD_PRIO_INHERIT:
case PTHREAD_PRIO_PROTECT:
attr->protocol = protocol;
return 0;
default:
return EINVAL;
}
}
/*PAGE

View File

@@ -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 );

View File

@@ -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;
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;
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
@@ -539,8 +557,15 @@ int pthread_attr_setdetachstate(
if ( !attr || !attr->is_initialized )
return EINVAL;
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;
switch ( clock_allowed ) {
case CLOCK_ENABLED:
case CLOCK_DISABLED:
attr->cputime_clock_allowed = clock_allowed;
return 0;
default:
return EINVAL;
}
}
/*PAGE

View File

@@ -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;
}

View File

@@ -5,6 +5,7 @@
#include <sys/types.h>
#include <rtems/system.h>
#include <rtems/score/object.h>
/*PAGE
*
@@ -13,7 +14,7 @@
pid_t getpid( void )
{
return POSIX_NOT_IMPLEMENTED();
return _Objects_Local_node;
}
/*PAGE