@@ -75,17 +75,21 @@ void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
75
75
struct init_stack_frame * pInitCtx ;
76
76
77
77
#if CONFIG_USERSPACE
78
+ /* adjust stack and stack size */
78
79
#if CONFIG_ARC_MPU_VER == 2
79
80
stackSize = POW2_CEIL (STACK_SIZE_ALIGN (stackSize ));
80
81
#elif CONFIG_ARC_MPU_VER == 3
81
82
stackSize = ROUND_UP (stackSize , STACK_ALIGN );
82
- #endif
83
83
#endif
84
84
stackEnd = pStackMem + stackSize ;
85
85
86
- #if CONFIG_USERSPACE
86
+ if (options & K_USER ) {
87
+ thread -> arch .priv_stack_start =
88
+ (u32_t )(stackEnd + STACK_GUARD_SIZE );
89
+ thread -> arch .priv_stack_size =
90
+ (u32_t )(CONFIG_PRIVILEGED_STACK_SIZE );
91
+ } else {
87
92
/* for kernel thread, the privilege stack is merged into thread stack */
88
- if (!(options & K_USER )) {
89
93
/* if MPU_STACK_GUARD is enabled, reserve the the stack area
90
94
* |---------------------| |----------------|
91
95
* | user stack | | stack guard |
@@ -98,8 +102,11 @@ void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
98
102
pStackMem += STACK_GUARD_SIZE ;
99
103
stackSize = stackSize + CONFIG_PRIVILEGED_STACK_SIZE ;
100
104
stackEnd += CONFIG_PRIVILEGED_STACK_SIZE + STACK_GUARD_SIZE ;
105
+
106
+ thread -> arch .priv_stack_start = 0 ;
107
+ thread -> arch .priv_stack_size = 0 ;
101
108
}
102
- #endif
109
+
103
110
_new_thread_init (thread , pStackMem , stackSize , priority , options );
104
111
105
112
stackAdjEnd = stackEnd ;
@@ -111,20 +118,41 @@ void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
111
118
thread -> userspace_local_data =
112
119
(struct _thread_userspace_local_data * )stackAdjEnd ;
113
120
#endif
121
+ /* carve the thread entry struct from the "base" of
122
+ the user stack */
123
+ pInitCtx = (struct init_stack_frame * )(
124
+ STACK_ROUND_DOWN (stackAdjEnd ) -
125
+ sizeof (struct init_stack_frame ));
114
126
115
- /* carve the thread entry struct from the "base" of the stack */
116
- pInitCtx = (struct init_stack_frame * )(STACK_ROUND_DOWN (stackAdjEnd ) -
117
- sizeof (struct init_stack_frame ));
118
- #if CONFIG_USERSPACE
127
+ /* fill init context */
119
128
if (options & K_USER ) {
120
- pInitCtx -> pc = ((u32_t )_user_thread_entry_wrapper );
121
129
/* through exception return to user mode */
122
130
pInitCtx -> status32 = _ARC_V2_STATUS32_AE ;
131
+ pInitCtx -> pc = ((u32_t )_user_thread_entry_wrapper );
123
132
} else {
124
133
pInitCtx -> status32 = 0 ;
125
134
pInitCtx -> pc = ((u32_t )_thread_entry_wrapper );
126
135
}
127
- #else
136
+
137
+ /*
138
+ * enable US bit, US is read as zero in user mode. This will allow use
139
+ * mode sleep instructions, and it enables a form of denial-of-service
140
+ * attack by putting the processor in sleep mode, but since interrupt
141
+ * level/mask can't be set from user space that's not worse than
142
+ * executing a loop without yielding.
143
+ */
144
+ pInitCtx -> status32 |= _ARC_V2_STATUS32_US ;
145
+ #else /* For no USERSPACE feature */
146
+ stackEnd = pStackMem + stackSize ;
147
+
148
+ _new_thread_init (thread , pStackMem , stackSize , priority , options );
149
+
150
+ stackAdjEnd = stackEnd ;
151
+
152
+ pInitCtx = (struct init_stack_frame * )(
153
+ STACK_ROUND_DOWN (stackAdjEnd ) -
154
+ sizeof (struct init_stack_frame ));
155
+
128
156
pInitCtx -> status32 = 0 ;
129
157
pInitCtx -> pc = ((u32_t )_thread_entry_wrapper );
130
158
#endif
@@ -137,20 +165,13 @@ void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
137
165
pInitCtx -> r1 = (u32_t )parameter1 ;
138
166
pInitCtx -> r2 = (u32_t )parameter2 ;
139
167
pInitCtx -> r3 = (u32_t )parameter3 ;
140
- /*
141
- * For now set the interrupt priority to 15
142
- * we can leave interrupt enable flag set to 0 as
143
- * seti instruction in the end of the _Swap() will
144
- * enable the interrupts based on intlock_key
145
- * value.
146
- */
168
+
169
+ /* stack check configuration */
147
170
#ifdef CONFIG_ARC_STACK_CHECKING
148
171
#ifdef CONFIG_ARC_HAS_SECURE
149
172
pInitCtx -> sec_stat |= _ARC_V2_SEC_STAT_SSC ;
150
- pInitCtx -> status32 |= _ARC_V2_STATUS32_E (_ARC_V2_DEF_IRQ_LEVEL );
151
173
#else
152
- pInitCtx -> status32 |= _ARC_V2_STATUS32_SC |
153
- _ARC_V2_STATUS32_E (_ARC_V2_DEF_IRQ_LEVEL );
174
+ pInitCtx -> status32 |= _ARC_V2_STATUS32_SC ;
154
175
#endif
155
176
#ifdef CONFIG_USERSPACE
156
177
if (options & K_USER ) {
@@ -170,31 +191,12 @@ void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
170
191
thread -> arch .k_stack_top = (u32_t ) pStackMem ;
171
192
thread -> arch .k_stack_base = (u32_t ) stackEnd ;
172
193
#endif
173
- #else
174
- pInitCtx -> status32 = _ARC_V2_STATUS32_E (_ARC_V2_DEF_IRQ_LEVEL );
175
- #endif
176
-
177
- #if CONFIG_USERSPACE
178
- /*
179
- * enable US bit, US is read as zero in user mode. This will allow use
180
- * mode sleep instructions, and it enables a form of denial-of-service
181
- * attack by putting the processor in sleep mode, but since interrupt
182
- * level/mask can't be set from user space that's not worse than
183
- * executing a loop without yielding.
184
- */
185
- pInitCtx -> status32 |= _ARC_V2_STATUS32_US ;
186
-
187
- if (options & K_USER ) {
188
- thread -> arch .priv_stack_start =
189
- (u32_t )(stackEnd + STACK_GUARD_SIZE );
190
- thread -> arch .priv_stack_size =
191
- (u32_t )CONFIG_PRIVILEGED_STACK_SIZE ;
192
- } else {
193
- thread -> arch .priv_stack_start = 0 ;
194
- thread -> arch .priv_stack_size = 0 ;
195
- }
196
194
#endif
197
195
/*
196
+ * seti instruction in the end of the _Swap() will
197
+ * enable the interrupts based on intlock_key
198
+ * value.
199
+ *
198
200
* intlock_key is constructed based on ARCv2 ISA Programmer's
199
201
* Reference Manual CLRI instruction description:
200
202
* dst[31:6] dst[5] dst[4] dst[3:0]
0 commit comments