Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #506, enforce nonzero stack size #508

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions src/os/posix/src/os-impl-tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
#include "os-shared-task.h"
#include "os-shared-idmap.h"

/*
* Defines
*/
#ifndef PTHREAD_STACK_MIN
#define PTHREAD_STACK_MIN (8*1024)
#endif

/* Tables where the OS object information is stored */
OS_impl_task_internal_record_t OS_impl_task_table [OS_MAX_TASKS];

Expand Down Expand Up @@ -467,19 +460,11 @@ int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t
/*
** Set the Stack Size
*/
if (stacksz > 0)
return_code = pthread_attr_setstacksize(&custom_attr, stacksz);
if (return_code != 0)
{
if (stacksz < PTHREAD_STACK_MIN)
{
stacksz = PTHREAD_STACK_MIN;
}

return_code = pthread_attr_setstacksize(&custom_attr, stacksz);
if (return_code != 0)
{
OS_DEBUG("pthread_attr_setstacksize error in OS_TaskCreate: %s\n",strerror(return_code));
return(OS_ERROR);
}
OS_DEBUG("pthread_attr_setstacksize error in OS_TaskCreate: %s\n",strerror(return_code));
return(OS_ERROR);
}

/*
Expand Down
7 changes: 7 additions & 0 deletions src/os/shared/src/osapi-task.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ int32 OS_TaskCreate (uint32 *task_id, const char *task_name, osal_task_entry fun
return OS_INVALID_POINTER;
}

/* Check for bad stack size. Note that NULL stack_pointer is
* OK (impl will allocate) but size must be nonzero. */
if (stack_size == 0)
{
return OS_ERROR;
}

/* we don't want to allow names too long*/
/* if truncated, two names might be the same */
if (strlen(task_name) >= OS_MAX_API_NAME)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/idmap-api-test/idmap-api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void TestIdMapApi_Setup(void)
/*
* Create all allowed objects
*/
status = OS_TaskCreate( &task_id, "Task", Test_Void_Fn, 0, 0, 0, 0);
status = OS_TaskCreate( &task_id, "Task", Test_Void_Fn, NULL, 4096, 50, 0);
UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status);
status = OS_QueueCreate( &queue_id, "Queue", 5, 5, 0);
UtAssert_True(status == OS_SUCCESS, "OS_QueueCreate() (%ld) == OS_SUCCESS", (long)status);
Expand Down
7 changes: 4 additions & 3 deletions src/unit-test-coverage/shared/src/coveragetest-task.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,16 @@ void Test_OS_TaskCreate(void)
*/
int32 expected = OS_SUCCESS;
uint32 objid = 0xFFFFFFFF;
int32 actual = OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 0, 0,0);
int32 actual = OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 128, 0, 0);

UtAssert_True(actual == expected, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)actual);
UtAssert_True(objid != 0, "objid (%lu) != 0", (unsigned long)objid);

OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(NULL, NULL, NULL, NULL, 0, 0,0), OS_INVALID_POINTER);
OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 0, 10 + OS_MAX_TASK_PRIORITY,0), OS_ERR_INVALID_PRIORITY);
OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 0, 0, 0), OS_ERROR);
OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 128, 10 + OS_MAX_TASK_PRIORITY,0), OS_ERR_INVALID_PRIORITY);
UT_SetForceFail(UT_KEY(OCS_strlen), 10 + OS_MAX_API_NAME);
OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 0, 0,0), OS_ERR_NAME_TOO_LONG);
OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 128, 0,0), OS_ERR_NAME_TOO_LONG);
}

void Test_OS_TaskDelete(void)
Expand Down