Skip to content

Commit 0689616

Browse files
authored
Merge pull request #508 from jphickey/fix-506-task-stacksize
Fix #506, enforce nonzero stack size
2 parents 9157dde + d6bf132 commit 0689616

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

src/os/posix/src/os-impl-tasks.c

+4-19
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@
3131
#include "os-shared-task.h"
3232
#include "os-shared-idmap.h"
3333

34-
/*
35-
* Defines
36-
*/
37-
#ifndef PTHREAD_STACK_MIN
38-
#define PTHREAD_STACK_MIN (8*1024)
39-
#endif
40-
4134
/* Tables where the OS object information is stored */
4235
OS_impl_task_internal_record_t OS_impl_task_table [OS_MAX_TASKS];
4336

@@ -467,19 +460,11 @@ int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t
467460
/*
468461
** Set the Stack Size
469462
*/
470-
if (stacksz > 0)
463+
return_code = pthread_attr_setstacksize(&custom_attr, stacksz);
464+
if (return_code != 0)
471465
{
472-
if (stacksz < PTHREAD_STACK_MIN)
473-
{
474-
stacksz = PTHREAD_STACK_MIN;
475-
}
476-
477-
return_code = pthread_attr_setstacksize(&custom_attr, stacksz);
478-
if (return_code != 0)
479-
{
480-
OS_DEBUG("pthread_attr_setstacksize error in OS_TaskCreate: %s\n",strerror(return_code));
481-
return(OS_ERROR);
482-
}
466+
OS_DEBUG("pthread_attr_setstacksize error in OS_TaskCreate: %s\n",strerror(return_code));
467+
return(OS_ERROR);
483468
}
484469

485470
/*

src/os/shared/src/osapi-task.c

+7
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ int32 OS_TaskCreate (uint32 *task_id, const char *task_name, osal_task_entry fun
196196
return OS_INVALID_POINTER;
197197
}
198198

199+
/* Check for bad stack size. Note that NULL stack_pointer is
200+
* OK (impl will allocate) but size must be nonzero. */
201+
if (stack_size == 0)
202+
{
203+
return OS_ERROR;
204+
}
205+
199206
/* we don't want to allow names too long*/
200207
/* if truncated, two names might be the same */
201208
if (strlen(task_name) >= OS_MAX_API_NAME)

src/tests/idmap-api-test/idmap-api-test.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void TestIdMapApi_Setup(void)
100100
/*
101101
* Create all allowed objects
102102
*/
103-
status = OS_TaskCreate( &task_id, "Task", Test_Void_Fn, 0, 0, 0, 0);
103+
status = OS_TaskCreate( &task_id, "Task", Test_Void_Fn, NULL, 4096, 50, 0);
104104
UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status);
105105
status = OS_QueueCreate( &queue_id, "Queue", 5, 5, 0);
106106
UtAssert_True(status == OS_SUCCESS, "OS_QueueCreate() (%ld) == OS_SUCCESS", (long)status);

src/unit-test-coverage/shared/src/coveragetest-task.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,16 @@ void Test_OS_TaskCreate(void)
106106
*/
107107
int32 expected = OS_SUCCESS;
108108
uint32 objid = 0xFFFFFFFF;
109-
int32 actual = OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 0, 0,0);
109+
int32 actual = OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 128, 0, 0);
110110

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

114114
OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(NULL, NULL, NULL, NULL, 0, 0,0), OS_INVALID_POINTER);
115-
OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 0, 10 + OS_MAX_TASK_PRIORITY,0), OS_ERR_INVALID_PRIORITY);
115+
OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 0, 0, 0), OS_ERROR);
116+
OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 128, 10 + OS_MAX_TASK_PRIORITY,0), OS_ERR_INVALID_PRIORITY);
116117
UT_SetForceFail(UT_KEY(OCS_strlen), 10 + OS_MAX_API_NAME);
117-
OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 0, 0,0), OS_ERR_NAME_TOO_LONG);
118+
OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 128, 0,0), OS_ERR_NAME_TOO_LONG);
118119
}
119120

120121
void Test_OS_TaskDelete(void)

0 commit comments

Comments
 (0)