Skip to content

Commit

Permalink
kernel: fix k_thread_stack_t definition
Browse files Browse the repository at this point in the history
Currently this is defined as a k_thread_stack_t pointer.
However this isn't correct, stacks are defined as arrays. Extern
references to k_thread_stack_t doesn't work properly as the compiler
treats it as a pointer to the stack array and not the array itself.

Declaring as an unsized array of k_thread_stack_t doesn't work
well either. The least amount of confusion is to leave out the
pointer/array status completely, use pointers for function prototypes,
and define K_THREAD_STACK_EXTERN() to properly create an extern
reference.

The definitions for all functions and struct that use
k_thread_stack_t need to be updated, but code that uses them should
be unchanged.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
  • Loading branch information
Andrew Boie authored and andrewboie committed Oct 17, 2017
1 parent 094f2cb commit c5c104f
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 35 deletions.
2 changes: 1 addition & 1 deletion arch/arc/core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct init_stack_frame {
*
* @return N/A
*/
void _new_thread(struct k_thread *thread, k_thread_stack_t stack,
void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
size_t stackSize, k_thread_entry_t pEntry,
void *parameter1, void *parameter2, void *parameter3,
int priority, unsigned int options)
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
* @return N/A
*/

void _new_thread(struct k_thread *thread, k_thread_stack_t stack,
void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
size_t stackSize, k_thread_entry_t pEntry,
void *parameter1, void *parameter2, void *parameter3,
int priority, unsigned int options)
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/include/kernel_arch_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static ALWAYS_INLINE void kernel_arch_init(void)

static ALWAYS_INLINE void
_arch_switch_to_main_thread(struct k_thread *main_thread,
k_thread_stack_t main_stack,
k_thread_stack_t *main_stack,
size_t main_stack_size, k_thread_entry_t _main)
{
/* get high address of the stack, i.e. its start (stack grows down) */
Expand Down
2 changes: 1 addition & 1 deletion arch/nios2/core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct init_stack_frame {
};


void _new_thread(struct k_thread *thread, k_thread_stack_t stack,
void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
size_t stack_size, k_thread_entry_t thread_func,
void *arg1, void *arg2, void *arg3,
int priority, unsigned int options)
Expand Down
2 changes: 1 addition & 1 deletion arch/riscv32/core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void _thread_entry_wrapper(k_thread_entry_t thread,
void *arg2,
void *arg3);

void _new_thread(struct k_thread *thread, k_thread_stack_t stack,
void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
size_t stack_size, k_thread_entry_t thread_func,
void *arg1, void *arg2, void *arg3,
int priority, unsigned int options)
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct _x86_initial_frame {
* @param priority thread priority
* @param options thread options: K_ESSENTIAL, K_FP_REGS, K_SSE_REGS
*/
void _new_thread(struct k_thread *thread, k_thread_stack_t stack,
void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
size_t stack_size, k_thread_entry_t entry,
void *parameter1, void *parameter2, void *parameter3,
int priority, unsigned int options)
Expand Down
2 changes: 1 addition & 1 deletion arch/xtensa/core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extern void _xt_user_exit(void);
* @return N/A
*/

void _new_thread(struct k_thread *thread, k_thread_stack_t stack,
void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
size_t stackSize, k_thread_entry_t pEntry,
void *p1, void *p2, void *p3,
int priority, unsigned int options)
Expand Down
2 changes: 1 addition & 1 deletion include/drivers/console/ipm_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct ipm_console_receiver_config_info {
* Stack for the receiver's thread, which prints out messages as
* they come in. Should be sized CONFIG_IPM_CONSOLE_STACK_SIZE
*/
k_thread_stack_t thread_stack;
k_thread_stack_t *thread_stack;

/**
* Ring buffer data area for stashing characters from the interrupt
Expand Down
25 changes: 18 additions & 7 deletions include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void k_object_access_all_grant(void *object);
struct __packed _k_thread_stack_element {
char data;
};
typedef struct _k_thread_stack_element *k_thread_stack_t;
typedef struct _k_thread_stack_element k_thread_stack_t;

/* timeouts */

Expand Down Expand Up @@ -445,7 +445,7 @@ struct k_thread {
/* memory domain info of the thread */
struct _mem_domain_info mem_domain_info;
/* Base address of thread stack */
k_thread_stack_t stack_obj;
k_thread_stack_t *stack_obj;
#endif /* CONFIG_USERSPACE */

/* arch-specifics: must always be at the end */
Expand Down Expand Up @@ -568,7 +568,7 @@ extern void k_call_stacks_analyze(void);
* @return ID of new thread.
*/
__syscall k_tid_t k_thread_create(struct k_thread *new_thread,
k_thread_stack_t stack,
k_thread_stack_t *stack,
size_t stack_size,
k_thread_entry_t entry,
void *p1, void *p2, void *p3,
Expand Down Expand Up @@ -692,7 +692,7 @@ __syscall void k_thread_start(k_tid_t thread);

struct _static_thread_data {
struct k_thread *init_thread;
k_thread_stack_t init_stack;
k_thread_stack_t *init_stack;
unsigned int init_stack_size;
k_thread_entry_t init_entry;
void *init_p1;
Expand Down Expand Up @@ -2244,7 +2244,7 @@ static inline int k_work_pending(struct k_work *work)
* @return N/A
*/
extern void k_work_q_start(struct k_work_q *work_q,
k_thread_stack_t stack,
k_thread_stack_t *stack,
size_t stack_size, int prio);

/**
Expand Down Expand Up @@ -4031,13 +4031,24 @@ extern void _timer_expiration_handler(struct _timeout *t);
* for properly declaring stacks, compatible with MMU/MPU constraints if
* enabled
*/

/**
* @brief Obtain an extern reference to a stack
*
* This macro properly brings the symbol of a thread stack declared
* elsewhere into scope.
*
* @param sym Thread stack symbol name
*/
#define K_THREAD_STACK_EXTERN(sym) extern k_thread_stack_t sym[]

#ifdef _ARCH_THREAD_STACK_DEFINE
#define K_THREAD_STACK_DEFINE(sym, size) _ARCH_THREAD_STACK_DEFINE(sym, size)
#define K_THREAD_STACK_ARRAY_DEFINE(sym, nmemb, size) \
_ARCH_THREAD_STACK_ARRAY_DEFINE(sym, nmemb, size)
#define K_THREAD_STACK_MEMBER(sym, size) _ARCH_THREAD_STACK_MEMBER(sym, size)
#define K_THREAD_STACK_SIZEOF(sym) _ARCH_THREAD_STACK_SIZEOF(sym)
static inline char *K_THREAD_STACK_BUFFER(k_thread_stack_t sym)
static inline char *K_THREAD_STACK_BUFFER(k_thread_stack_t *sym)
{
return _ARCH_THREAD_STACK_BUFFER(sym);
}
Expand Down Expand Up @@ -4129,7 +4140,7 @@ static inline char *K_THREAD_STACK_BUFFER(k_thread_stack_t sym)
* @param sym Declared stack symbol name
* @return The buffer itself, a char *
*/
static inline char *K_THREAD_STACK_BUFFER(k_thread_stack_t sym)
static inline char *K_THREAD_STACK_BUFFER(k_thread_stack_t *sym)
{
return (char *)sym;
}
Expand Down
8 changes: 4 additions & 4 deletions include/net/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ struct http_client_ctx {
#if defined(CONFIG_HTTPS)
struct {
/** HTTPS stack for mbedtls library. */
k_thread_stack_t stack;
k_thread_stack_t *stack;

/** HTTPS stack size. */
int stack_size;
Expand Down Expand Up @@ -586,7 +586,7 @@ int https_client_init(struct http_client_ctx *http_ctx,
const char *cert_host,
https_entropy_src_cb_t entropy_src_cb,
struct k_mem_pool *pool,
k_thread_stack_t https_stack,
k_thread_stack_t *https_stack,
size_t https_stack_size);
#endif /* CONFIG_HTTPS */

Expand Down Expand Up @@ -790,7 +790,7 @@ struct http_server_ctx {
#if defined(CONFIG_HTTPS)
struct {
/** HTTPS stack for mbedtls library. */
k_thread_stack_t stack;
k_thread_stack_t *stack;

/** HTTPS stack size. */
int stack_size;
Expand Down Expand Up @@ -922,7 +922,7 @@ int https_server_init(struct http_server_ctx *http_ctx,
https_server_cert_cb_t cert_cb,
https_entropy_src_cb_t entropy_src_cb,
struct k_mem_pool *pool,
k_thread_stack_t https_stack,
k_thread_stack_t *https_stack,
size_t https_stack_len);
#endif /* CONFIG_HTTPS */

Expand Down
2 changes: 1 addition & 1 deletion include/net/mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct mqtt_ctx {

/** TLS thread parameters */
struct k_mem_pool *tls_mem_pool;
k_thread_stack_t tls_stack;
k_thread_stack_t *tls_stack;
size_t tls_stack_size;

/** TLS callback */
Expand Down
6 changes: 3 additions & 3 deletions include/net/net_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ struct net_app_ctx {
#if defined(CONFIG_NET_APP_TLS) || defined(CONFIG_NET_APP_DTLS)
struct {
/** TLS stack for mbedtls library. */
k_thread_stack_t stack;
k_thread_stack_t *stack;

/** TLS stack size. */
int stack_size;
Expand Down Expand Up @@ -914,7 +914,7 @@ int net_app_client_tls(struct net_app_ctx *ctx,
const char *cert_host,
net_app_entropy_src_cb_t entropy_src_cb,
struct k_mem_pool *pool,
k_thread_stack_t stack,
k_thread_stack_t *stack,
size_t stack_size);
#endif /* CONFIG_NET_APP_CLIENT */

Expand Down Expand Up @@ -950,7 +950,7 @@ int net_app_server_tls(struct net_app_ctx *ctx,
net_app_cert_cb_t cert_cb,
net_app_entropy_src_cb_t entropy_src_cb,
struct k_mem_pool *pool,
k_thread_stack_t stack,
k_thread_stack_t *stack,
size_t stack_len);

#endif /* CONFIG_NET_APP_SERVER */
Expand Down
2 changes: 1 addition & 1 deletion include/net/net_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int net_recv_data(struct net_if *iface, struct net_pkt *pkt);
int net_send_data(struct net_pkt *pkt);

struct net_stack_info {
k_thread_stack_t stack;
k_thread_stack_t *stack;
const char *pretty_name;
const char *name;
size_t orig_size;
Expand Down
4 changes: 2 additions & 2 deletions kernel/include/nano_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ extern FUNC_NORETURN void _thread_entry(k_thread_entry_t entry,
void *p1, void *p2, void *p3);

/* Implemented by architectures. Only called from _setup_new_thread. */
extern void _new_thread(struct k_thread *thread, k_thread_stack_t pStack,
extern void _new_thread(struct k_thread *thread, k_thread_stack_t *pStack,
size_t stackSize, k_thread_entry_t entry,
void *p1, void *p2, void *p3,
int prio, unsigned int options);

extern void _setup_new_thread(struct k_thread *new_thread,
k_thread_stack_t stack, size_t stack_size,
k_thread_stack_t *stack, size_t stack_size,
k_thread_entry_t entry,
void *p1, void *p2, void *p3,
int prio, u32_t options);
Expand Down
6 changes: 3 additions & 3 deletions kernel/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ static void schedule_new_thread(struct k_thread *thread, s32_t delay)
#endif

void _setup_new_thread(struct k_thread *new_thread,
k_thread_stack_t stack, size_t stack_size,
k_thread_stack_t *stack, size_t stack_size,
k_thread_entry_t entry,
void *p1, void *p2, void *p3,
int prio, u32_t options)
Expand All @@ -340,7 +340,7 @@ void _setup_new_thread(struct k_thread *new_thread,

#ifdef CONFIG_MULTITHREADING
k_tid_t _impl_k_thread_create(struct k_thread *new_thread,
k_thread_stack_t stack,
k_thread_stack_t *stack,
size_t stack_size, k_thread_entry_t entry,
void *p1, void *p2, void *p3,
int prio, u32_t options, s32_t delay)
Expand All @@ -366,7 +366,7 @@ _SYSCALL_HANDLER(k_thread_create,
struct k_thread *new_thread = (struct k_thread *)new_thread_p;
volatile struct _syscall_10_args *margs =
(volatile struct _syscall_10_args *)more_args;
k_thread_stack_t stack = (k_thread_stack_t)stack_p;
k_thread_stack_t *stack = (k_thread_stack_t *)stack_p;

/* The thread and stack objects *must* be in an uninitialized state */
_SYSCALL_OBJ_NEVER_INIT(new_thread, K_OBJ_THREAD);
Expand Down
2 changes: 1 addition & 1 deletion kernel/work_q.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static void work_q_main(void *work_q_ptr, void *p2, void *p3)
}
}

void k_work_q_start(struct k_work_q *work_q, k_thread_stack_t stack,
void k_work_q_start(struct k_work_q *work_q, k_thread_stack_t *stack,
size_t stack_size, int prio)
{
k_queue_init(&work_q->queue);
Expand Down
2 changes: 1 addition & 1 deletion subsys/net/lib/app/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ int net_app_client_tls(struct net_app_ctx *ctx,
const char *cert_host,
net_app_entropy_src_cb_t entropy_src_cb,
struct k_mem_pool *pool,
k_thread_stack_t stack,
k_thread_stack_t *stack,
size_t stack_size)
{
if (!request_buf || request_buf_len == 0) {
Expand Down
2 changes: 1 addition & 1 deletion subsys/net/lib/app/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ int net_app_server_tls(struct net_app_ctx *ctx,
net_app_cert_cb_t cert_cb,
net_app_entropy_src_cb_t entropy_src_cb,
struct k_mem_pool *pool,
k_thread_stack_t stack,
k_thread_stack_t *stack,
size_t stack_size)
{
if (!request_buf || request_buf_len == 0) {
Expand Down
2 changes: 1 addition & 1 deletion subsys/net/lib/http/http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,7 @@ int https_client_init(struct http_client_ctx *ctx,
const char *cert_host,
https_entropy_src_cb_t entropy_src_cb,
struct k_mem_pool *pool,
k_thread_stack_t https_stack,
k_thread_stack_t *https_stack,
size_t https_stack_size)
{
int ret;
Expand Down
2 changes: 1 addition & 1 deletion subsys/net/lib/http/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ int https_server_init(struct http_server_ctx *ctx,
https_server_cert_cb_t cert_cb,
https_entropy_src_cb_t entropy_src_cb,
struct k_mem_pool *pool,
k_thread_stack_t https_stack,
k_thread_stack_t *https_stack,
size_t https_stack_size)
{
int ret;
Expand Down
2 changes: 1 addition & 1 deletion tests/kernel/fatal/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static K_THREAD_STACK_DEFINE(alt_stack, STACKSIZE);

#ifdef CONFIG_STACK_SENTINEL
#define OVERFLOW_STACKSIZE 1024
static k_thread_stack_t overflow_stack =
static k_thread_stack_t *overflow_stack =
alt_stack + (STACKSIZE - OVERFLOW_STACKSIZE);
#else
#define OVERFLOW_STACKSIZE STACKSIZE
Expand Down

0 comments on commit c5c104f

Please sign in to comment.