1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright (c) 2016-2022, Linaro Limited 4 * Copyright (c) 2014, STMicroelectronics International N.V. 5 * Copyright (c) 2020-2021, Arm Limited 6 */ 7 8 #include <config.h> 9 #include <crypto/crypto.h> 10 #include <kernel/asan.h> 11 #include <kernel/lockdep.h> 12 #include <kernel/misc.h> 13 #include <kernel/panic.h> 14 #include <kernel/spinlock.h> 15 #include <kernel/thread.h> 16 #include <kernel/thread_private.h> 17 #include <mm/mobj.h> 18 19 struct thread_ctx threads[CFG_NUM_THREADS]; 20 21 struct thread_core_local thread_core_local[CFG_TEE_CORE_NB_CORE] __nex_bss; 22 23 /* 24 * Stacks 25 * 26 * [Lower addresses on the left] 27 * 28 * [ STACK_CANARY_SIZE/2 | STACK_CHECK_EXTRA | STACK_XXX_SIZE | STACK_CANARY_SIZE/2 ] 29 * ^ ^ ^ ^ 30 * stack_xxx[n] "hard" top "soft" top bottom 31 */ 32 33 #ifdef CFG_WITH_STACK_CANARIES 34 #define START_CANARY_VALUE 0xdededede 35 #define END_CANARY_VALUE 0xabababab 36 #define GET_START_CANARY(name, stack_num) name[stack_num][0] 37 #define GET_END_CANARY(name, stack_num) \ 38 name[stack_num][sizeof(name[stack_num]) / sizeof(uint32_t) - 1] 39 #endif 40 41 #define DECLARE_STACK(name, num_stacks, stack_size, linkage) \ 42 linkage uint32_t name[num_stacks] \ 43 [ROUNDUP(stack_size + STACK_CANARY_SIZE + STACK_CHECK_EXTRA, \ 44 STACK_ALIGNMENT) / sizeof(uint32_t)] \ 45 __attribute__((section(".nozi_stack." # name), \ 46 aligned(STACK_ALIGNMENT))) 47 48 #define GET_STACK(stack) ((vaddr_t)(stack) + STACK_SIZE(stack)) 49 50 DECLARE_STACK(stack_tmp, CFG_TEE_CORE_NB_CORE, STACK_TMP_SIZE, 51 /* global linkage */); 52 DECLARE_STACK(stack_abt, CFG_TEE_CORE_NB_CORE, STACK_ABT_SIZE, static); 53 #ifndef CFG_WITH_PAGER 54 DECLARE_STACK(stack_thread, CFG_NUM_THREADS, STACK_THREAD_SIZE, static); 55 #endif 56 57 #define GET_STACK_TOP_HARD(stack, n) \ 58 ((vaddr_t)&(stack)[n] + STACK_CANARY_SIZE / 2) 59 #define GET_STACK_TOP_SOFT(stack, n) \ 60 (GET_STACK_TOP_HARD(stack, n) + STACK_CHECK_EXTRA) 61 #define GET_STACK_BOTTOM(stack, n) ((vaddr_t)&(stack)[n] + sizeof(stack[n]) - \ 62 STACK_CANARY_SIZE / 2) 63 64 const uint32_t stack_tmp_stride __section(".identity_map.stack_tmp_stride") = 65 sizeof(stack_tmp[0]); 66 67 /* 68 * This stack setup info is required by secondary boot cores before they 69 * each locally enable the pager (the mmu). Hence kept in pager sections. 70 */ 71 DECLARE_KEEP_PAGER(stack_tmp_stride); 72 73 static unsigned int thread_global_lock __nex_bss = SPINLOCK_UNLOCK; 74 75 void thread_init_canaries(void) 76 { 77 #ifdef CFG_WITH_STACK_CANARIES 78 size_t n; 79 #define INIT_CANARY(name) \ 80 for (n = 0; n < ARRAY_SIZE(name); n++) { \ 81 uint32_t *start_canary = &GET_START_CANARY(name, n); \ 82 uint32_t *end_canary = &GET_END_CANARY(name, n); \ 83 \ 84 *start_canary = START_CANARY_VALUE; \ 85 *end_canary = END_CANARY_VALUE; \ 86 } 87 88 INIT_CANARY(stack_tmp); 89 INIT_CANARY(stack_abt); 90 #if !defined(CFG_WITH_PAGER) && !defined(CFG_VIRTUALIZATION) 91 INIT_CANARY(stack_thread); 92 #endif 93 #endif/*CFG_WITH_STACK_CANARIES*/ 94 } 95 96 #define CANARY_DIED(stack, loc, n, addr) \ 97 do { \ 98 EMSG_RAW("Dead canary at %s of '%s[%zu]' (%p)", #loc, #stack, \ 99 n, (void *)addr); \ 100 panic(); \ 101 } while (0) 102 103 void thread_check_canaries(void) 104 { 105 #ifdef CFG_WITH_STACK_CANARIES 106 uint32_t *canary = NULL; 107 size_t n = 0; 108 109 for (n = 0; n < ARRAY_SIZE(stack_tmp); n++) { 110 canary = &GET_START_CANARY(stack_tmp, n); 111 if (*canary != START_CANARY_VALUE) 112 CANARY_DIED(stack_tmp, start, n, canary); 113 canary = &GET_END_CANARY(stack_tmp, n); 114 if (*canary != END_CANARY_VALUE) 115 CANARY_DIED(stack_tmp, end, n, canary); 116 } 117 118 for (n = 0; n < ARRAY_SIZE(stack_abt); n++) { 119 canary = &GET_START_CANARY(stack_abt, n); 120 if (*canary != START_CANARY_VALUE) 121 CANARY_DIED(stack_abt, start, n, canary); 122 canary = &GET_END_CANARY(stack_abt, n); 123 if (*canary != END_CANARY_VALUE) 124 CANARY_DIED(stack_abt, end, n, canary); 125 } 126 #if !defined(CFG_WITH_PAGER) && !defined(CFG_VIRTUALIZATION) 127 for (n = 0; n < ARRAY_SIZE(stack_thread); n++) { 128 canary = &GET_START_CANARY(stack_thread, n); 129 if (*canary != START_CANARY_VALUE) 130 CANARY_DIED(stack_thread, start, n, canary); 131 canary = &GET_END_CANARY(stack_thread, n); 132 if (*canary != END_CANARY_VALUE) 133 CANARY_DIED(stack_thread, end, n, canary); 134 } 135 #endif 136 #endif/*CFG_WITH_STACK_CANARIES*/ 137 } 138 139 void thread_lock_global(void) 140 { 141 cpu_spin_lock(&thread_global_lock); 142 } 143 144 void thread_unlock_global(void) 145 { 146 cpu_spin_unlock(&thread_global_lock); 147 } 148 149 static struct thread_core_local * __nostackcheck 150 get_core_local(unsigned int pos) 151 { 152 /* 153 * Foreign interrupts must be disabled before playing with core_local 154 * since we otherwise may be rescheduled to a different core in the 155 * middle of this function. 156 */ 157 assert(thread_get_exceptions() & THREAD_EXCP_FOREIGN_INTR); 158 159 assert(pos < CFG_TEE_CORE_NB_CORE); 160 return &thread_core_local[pos]; 161 } 162 163 struct thread_core_local * __nostackcheck thread_get_core_local(void) 164 { 165 unsigned int pos = get_core_pos(); 166 167 return get_core_local(pos); 168 } 169 170 #ifdef CFG_CORE_DEBUG_CHECK_STACKS 171 static void print_stack_limits(void) 172 { 173 size_t n = 0; 174 vaddr_t __maybe_unused start = 0; 175 vaddr_t __maybe_unused end = 0; 176 177 for (n = 0; n < CFG_TEE_CORE_NB_CORE; n++) { 178 start = GET_STACK_TOP_SOFT(stack_tmp, n); 179 end = GET_STACK_BOTTOM(stack_tmp, n); 180 DMSG("tmp [%zu] 0x%" PRIxVA "..0x%" PRIxVA, n, start, end); 181 } 182 for (n = 0; n < CFG_TEE_CORE_NB_CORE; n++) { 183 start = GET_STACK_TOP_SOFT(stack_abt, n); 184 end = GET_STACK_BOTTOM(stack_abt, n); 185 DMSG("abt [%zu] 0x%" PRIxVA "..0x%" PRIxVA, n, start, end); 186 } 187 for (n = 0; n < CFG_NUM_THREADS; n++) { 188 end = threads[n].stack_va_end; 189 start = end - STACK_THREAD_SIZE + STACK_CHECK_EXTRA; 190 DMSG("thr [%zu] 0x%" PRIxVA "..0x%" PRIxVA, n, start, end); 191 } 192 } 193 194 static void check_stack_limits(void) 195 { 196 vaddr_t stack_start = 0; 197 vaddr_t stack_end = 0; 198 /* Any value in the current stack frame will do */ 199 vaddr_t current_sp = (vaddr_t)&stack_start; 200 201 if (!get_stack_soft_limits(&stack_start, &stack_end)) 202 panic("Unknown stack limits"); 203 if (current_sp < stack_start || current_sp > stack_end) { 204 EMSG("Stack pointer out of range: 0x%" PRIxVA " not in [0x%" 205 PRIxVA " .. 0x%" PRIxVA "]", current_sp, stack_start, 206 stack_end); 207 print_stack_limits(); 208 panic(); 209 } 210 } 211 212 static bool * __nostackcheck get_stackcheck_recursion_flag(void) 213 { 214 uint32_t exceptions = thread_mask_exceptions(THREAD_EXCP_FOREIGN_INTR); 215 unsigned int pos = get_core_pos(); 216 struct thread_core_local *l = get_core_local(pos); 217 int ct = l->curr_thread; 218 bool *p = NULL; 219 220 if (l->flags & (THREAD_CLF_ABORT | THREAD_CLF_TMP)) 221 p = &l->stackcheck_recursion; 222 else if (!l->flags) 223 p = &threads[ct].tsd.stackcheck_recursion; 224 225 thread_unmask_exceptions(exceptions); 226 return p; 227 } 228 229 void __cyg_profile_func_enter(void *this_fn, void *call_site); 230 void __nostackcheck __cyg_profile_func_enter(void *this_fn __unused, 231 void *call_site __unused) 232 { 233 bool *p = get_stackcheck_recursion_flag(); 234 235 assert(p); 236 if (*p) 237 return; 238 *p = true; 239 check_stack_limits(); 240 *p = false; 241 } 242 243 void __cyg_profile_func_exit(void *this_fn, void *call_site); 244 void __nostackcheck __cyg_profile_func_exit(void *this_fn __unused, 245 void *call_site __unused) 246 { 247 } 248 #else 249 static void print_stack_limits(void) 250 { 251 } 252 #endif 253 254 void thread_init_boot_thread(void) 255 { 256 struct thread_core_local *l = thread_get_core_local(); 257 258 thread_init_threads(); 259 260 l->curr_thread = 0; 261 threads[0].state = THREAD_STATE_ACTIVE; 262 } 263 264 void __nostackcheck thread_clr_boot_thread(void) 265 { 266 struct thread_core_local *l = thread_get_core_local(); 267 268 assert(l->curr_thread >= 0 && l->curr_thread < CFG_NUM_THREADS); 269 assert(threads[l->curr_thread].state == THREAD_STATE_ACTIVE); 270 threads[l->curr_thread].state = THREAD_STATE_FREE; 271 l->curr_thread = THREAD_ID_INVALID; 272 } 273 274 void __nostackcheck *thread_get_tmp_sp(void) 275 { 276 struct thread_core_local *l = thread_get_core_local(); 277 278 /* 279 * Called from assembly when switching to the temporary stack, so flags 280 * need updating 281 */ 282 l->flags |= THREAD_CLF_TMP; 283 284 return (void *)l->tmp_stack_va_end; 285 } 286 287 vaddr_t thread_stack_start(void) 288 { 289 struct thread_ctx *thr; 290 int ct = thread_get_id_may_fail(); 291 292 if (ct == THREAD_ID_INVALID) 293 return 0; 294 295 thr = threads + ct; 296 return thr->stack_va_end - STACK_THREAD_SIZE; 297 } 298 299 size_t thread_stack_size(void) 300 { 301 return STACK_THREAD_SIZE; 302 } 303 304 bool get_stack_limits(vaddr_t *start, vaddr_t *end, bool hard) 305 { 306 uint32_t exceptions = thread_mask_exceptions(THREAD_EXCP_FOREIGN_INTR); 307 unsigned int pos = get_core_pos(); 308 struct thread_core_local *l = get_core_local(pos); 309 int ct = l->curr_thread; 310 bool ret = false; 311 312 if (l->flags & THREAD_CLF_TMP) { 313 if (hard) 314 *start = GET_STACK_TOP_HARD(stack_tmp, pos); 315 else 316 *start = GET_STACK_TOP_SOFT(stack_tmp, pos); 317 *end = GET_STACK_BOTTOM(stack_tmp, pos); 318 ret = true; 319 } else if (l->flags & THREAD_CLF_ABORT) { 320 if (hard) 321 *start = GET_STACK_TOP_HARD(stack_abt, pos); 322 else 323 *start = GET_STACK_TOP_SOFT(stack_abt, pos); 324 *end = GET_STACK_BOTTOM(stack_abt, pos); 325 ret = true; 326 } else if (!l->flags) { 327 if (ct < 0 || ct >= CFG_NUM_THREADS) 328 goto out; 329 330 *end = threads[ct].stack_va_end; 331 *start = *end - STACK_THREAD_SIZE; 332 if (!hard) 333 *start += STACK_CHECK_EXTRA; 334 ret = true; 335 } 336 out: 337 thread_unmask_exceptions(exceptions); 338 return ret; 339 } 340 341 bool thread_is_from_abort_mode(void) 342 { 343 struct thread_core_local *l = thread_get_core_local(); 344 345 return (l->flags >> THREAD_CLF_SAVED_SHIFT) & THREAD_CLF_ABORT; 346 } 347 348 /* 349 * This function should always be accurate, but it might be possible to 350 * implement a more efficient depending on cpu architecture. 351 */ 352 bool __weak thread_is_in_normal_mode(void) 353 { 354 uint32_t exceptions = thread_mask_exceptions(THREAD_EXCP_FOREIGN_INTR); 355 struct thread_core_local *l = thread_get_core_local(); 356 bool ret; 357 358 /* 359 * If any bit in l->flags is set aside from THREAD_CLF_TMP we're 360 * handling some exception. 361 */ 362 ret = (l->curr_thread != THREAD_ID_INVALID) && 363 !(l->flags & ~THREAD_CLF_TMP); 364 thread_unmask_exceptions(exceptions); 365 366 return ret; 367 } 368 369 short int thread_get_id_may_fail(void) 370 { 371 /* 372 * thread_get_core_local() requires foreign interrupts to be disabled 373 */ 374 uint32_t exceptions = thread_mask_exceptions(THREAD_EXCP_FOREIGN_INTR); 375 struct thread_core_local *l = thread_get_core_local(); 376 short int ct = l->curr_thread; 377 378 thread_unmask_exceptions(exceptions); 379 return ct; 380 } 381 382 short int thread_get_id(void) 383 { 384 short int ct = thread_get_id_may_fail(); 385 386 /* Thread ID has to fit in a short int */ 387 COMPILE_TIME_ASSERT(CFG_NUM_THREADS <= SHRT_MAX); 388 assert(ct >= 0 && ct < CFG_NUM_THREADS); 389 return ct; 390 } 391 392 #ifdef CFG_WITH_PAGER 393 static void init_thread_stacks(void) 394 { 395 size_t n = 0; 396 397 /* 398 * Allocate virtual memory for thread stacks. 399 */ 400 for (n = 0; n < CFG_NUM_THREADS; n++) { 401 tee_mm_entry_t *mm = NULL; 402 vaddr_t sp = 0; 403 size_t num_pages = 0; 404 struct fobj *fobj = NULL; 405 406 /* Find vmem for thread stack and its protection gap */ 407 mm = tee_mm_alloc(&tee_mm_vcore, 408 SMALL_PAGE_SIZE + STACK_THREAD_SIZE); 409 assert(mm); 410 411 /* Claim eventual physical page */ 412 tee_pager_add_pages(tee_mm_get_smem(mm), tee_mm_get_size(mm), 413 true); 414 415 num_pages = tee_mm_get_bytes(mm) / SMALL_PAGE_SIZE - 1; 416 fobj = fobj_locked_paged_alloc(num_pages); 417 418 /* Add the region to the pager */ 419 tee_pager_add_core_region(tee_mm_get_smem(mm) + SMALL_PAGE_SIZE, 420 PAGED_REGION_TYPE_LOCK, fobj); 421 fobj_put(fobj); 422 423 /* init effective stack */ 424 sp = tee_mm_get_smem(mm) + tee_mm_get_bytes(mm); 425 asan_tag_access((void *)tee_mm_get_smem(mm), (void *)sp); 426 if (!thread_init_stack(n, sp)) 427 panic("init stack failed"); 428 } 429 } 430 #else 431 static void init_thread_stacks(void) 432 { 433 size_t n; 434 435 /* Assign the thread stacks */ 436 for (n = 0; n < CFG_NUM_THREADS; n++) { 437 if (!thread_init_stack(n, GET_STACK_BOTTOM(stack_thread, n))) 438 panic("thread_init_stack failed"); 439 } 440 } 441 #endif /*CFG_WITH_PAGER*/ 442 443 void thread_init_threads(void) 444 { 445 size_t n = 0; 446 447 init_thread_stacks(); 448 print_stack_limits(); 449 pgt_init(); 450 451 mutex_lockdep_init(); 452 453 for (n = 0; n < CFG_NUM_THREADS; n++) { 454 TAILQ_INIT(&threads[n].tsd.sess_stack); 455 SLIST_INIT(&threads[n].tsd.pgt_cache); 456 } 457 } 458 459 void __nostackcheck thread_init_thread_core_local(void) 460 { 461 size_t n = 0; 462 struct thread_core_local *tcl = thread_core_local; 463 464 for (n = 0; n < CFG_TEE_CORE_NB_CORE; n++) { 465 tcl[n].curr_thread = THREAD_ID_INVALID; 466 tcl[n].flags = THREAD_CLF_TMP; 467 } 468 tcl[0].tmp_stack_va_end = GET_STACK_BOTTOM(stack_tmp, 0); 469 } 470 471 void thread_init_core_local_stacks(void) 472 { 473 size_t n = 0; 474 struct thread_core_local *tcl = thread_core_local; 475 476 for (n = 0; n < CFG_TEE_CORE_NB_CORE; n++) { 477 tcl[n].tmp_stack_va_end = GET_STACK_BOTTOM(stack_tmp, n) - 478 STACK_TMP_OFFS; 479 tcl[n].abt_stack_va_end = GET_STACK_BOTTOM(stack_abt, n); 480 } 481 } 482 483 #if defined(CFG_CORE_PAUTH) 484 void thread_init_thread_pauth_keys(void) 485 { 486 size_t n = 0; 487 488 for (n = 0; n < CFG_NUM_THREADS; n++) 489 if (crypto_rng_read(&threads[n].keys, sizeof(threads[n].keys))) 490 panic("Failed to init thread pauth keys"); 491 } 492 493 void thread_init_core_local_pauth_keys(void) 494 { 495 struct thread_core_local *tcl = thread_core_local; 496 size_t n = 0; 497 498 for (n = 0; n < CFG_TEE_CORE_NB_CORE; n++) 499 if (crypto_rng_read(&tcl[n].keys, sizeof(tcl[n].keys))) 500 panic("Failed to init core local pauth keys"); 501 } 502 #endif 503 504 struct thread_specific_data *thread_get_tsd(void) 505 { 506 return &threads[thread_get_id()].tsd; 507 } 508 509 struct thread_ctx_regs * __nostackcheck thread_get_ctx_regs(void) 510 { 511 struct thread_core_local *l = thread_get_core_local(); 512 513 assert(l->curr_thread != THREAD_ID_INVALID); 514 return &threads[l->curr_thread].regs; 515 } 516 517 void thread_set_foreign_intr(bool enable) 518 { 519 /* thread_get_core_local() requires foreign interrupts to be disabled */ 520 uint32_t exceptions = thread_mask_exceptions(THREAD_EXCP_FOREIGN_INTR); 521 struct thread_core_local *l; 522 523 l = thread_get_core_local(); 524 525 assert(l->curr_thread != THREAD_ID_INVALID); 526 527 if (enable) { 528 threads[l->curr_thread].flags |= 529 THREAD_FLAGS_FOREIGN_INTR_ENABLE; 530 thread_set_exceptions(exceptions & ~THREAD_EXCP_FOREIGN_INTR); 531 } else { 532 /* 533 * No need to disable foreign interrupts here since they're 534 * already disabled above. 535 */ 536 threads[l->curr_thread].flags &= 537 ~THREAD_FLAGS_FOREIGN_INTR_ENABLE; 538 } 539 } 540 541 void thread_restore_foreign_intr(void) 542 { 543 /* thread_get_core_local() requires foreign interrupts to be disabled */ 544 uint32_t exceptions = thread_mask_exceptions(THREAD_EXCP_FOREIGN_INTR); 545 struct thread_core_local *l; 546 547 l = thread_get_core_local(); 548 549 assert(l->curr_thread != THREAD_ID_INVALID); 550 551 if (threads[l->curr_thread].flags & THREAD_FLAGS_FOREIGN_INTR_ENABLE) 552 thread_set_exceptions(exceptions & ~THREAD_EXCP_FOREIGN_INTR); 553 } 554 555 static struct mobj *alloc_shm(enum thread_shm_type shm_type, size_t size) 556 { 557 switch (shm_type) { 558 case THREAD_SHM_TYPE_APPLICATION: 559 return thread_rpc_alloc_payload(size); 560 case THREAD_SHM_TYPE_KERNEL_PRIVATE: 561 return thread_rpc_alloc_kernel_payload(size); 562 case THREAD_SHM_TYPE_GLOBAL: 563 return thread_rpc_alloc_global_payload(size); 564 default: 565 return NULL; 566 } 567 } 568 569 static void clear_shm_cache_entry(struct thread_shm_cache_entry *ce) 570 { 571 if (ce->mobj) { 572 switch (ce->type) { 573 case THREAD_SHM_TYPE_APPLICATION: 574 thread_rpc_free_payload(ce->mobj); 575 break; 576 case THREAD_SHM_TYPE_KERNEL_PRIVATE: 577 thread_rpc_free_kernel_payload(ce->mobj); 578 break; 579 case THREAD_SHM_TYPE_GLOBAL: 580 thread_rpc_free_global_payload(ce->mobj); 581 break; 582 default: 583 assert(0); /* "can't happen" */ 584 break; 585 } 586 } 587 ce->mobj = NULL; 588 ce->size = 0; 589 } 590 591 static struct thread_shm_cache_entry * 592 get_shm_cache_entry(enum thread_shm_cache_user user) 593 { 594 struct thread_shm_cache *cache = &threads[thread_get_id()].shm_cache; 595 struct thread_shm_cache_entry *ce = NULL; 596 597 SLIST_FOREACH(ce, cache, link) 598 if (ce->user == user) 599 return ce; 600 601 ce = calloc(1, sizeof(*ce)); 602 if (ce) { 603 ce->user = user; 604 SLIST_INSERT_HEAD(cache, ce, link); 605 } 606 607 return ce; 608 } 609 610 void *thread_rpc_shm_cache_alloc(enum thread_shm_cache_user user, 611 enum thread_shm_type shm_type, 612 size_t size, struct mobj **mobj) 613 { 614 struct thread_shm_cache_entry *ce = NULL; 615 size_t sz = size; 616 paddr_t p = 0; 617 void *va = NULL; 618 619 if (!size) 620 return NULL; 621 622 ce = get_shm_cache_entry(user); 623 if (!ce) 624 return NULL; 625 626 /* 627 * Always allocate in page chunks as normal world allocates payload 628 * memory as complete pages. 629 */ 630 sz = ROUNDUP(size, SMALL_PAGE_SIZE); 631 632 if (ce->type != shm_type || sz > ce->size) { 633 clear_shm_cache_entry(ce); 634 635 ce->mobj = alloc_shm(shm_type, sz); 636 if (!ce->mobj) 637 return NULL; 638 639 if (mobj_get_pa(ce->mobj, 0, 0, &p)) 640 goto err; 641 642 if (!IS_ALIGNED_WITH_TYPE(p, uint64_t)) 643 goto err; 644 645 va = mobj_get_va(ce->mobj, 0, sz); 646 if (!va) 647 goto err; 648 649 ce->size = sz; 650 ce->type = shm_type; 651 } else { 652 va = mobj_get_va(ce->mobj, 0, sz); 653 if (!va) 654 goto err; 655 } 656 *mobj = ce->mobj; 657 658 return va; 659 err: 660 clear_shm_cache_entry(ce); 661 return NULL; 662 } 663 664 void thread_rpc_shm_cache_clear(struct thread_shm_cache *cache) 665 { 666 while (true) { 667 struct thread_shm_cache_entry *ce = SLIST_FIRST(cache); 668 669 if (!ce) 670 break; 671 SLIST_REMOVE_HEAD(cache, link); 672 clear_shm_cache_entry(ce); 673 free(ce); 674 } 675 } 676