@@ -5456,6 +5456,41 @@ struct k_mem_slab {
5456
5456
* @{
5457
5457
*/
5458
5458
5459
+ /**
5460
+ * @brief Statically define and initialize a memory slab in a user-provided memory section with
5461
+ * public (non-static) scope.
5462
+ *
5463
+ * The memory slab's buffer contains @a slab_num_blocks memory blocks
5464
+ * that are @a slab_block_size bytes long. The buffer is aligned to a
5465
+ * @a slab_align -byte boundary. To ensure that each memory block is similarly
5466
+ * aligned to this boundary, @a slab_block_size must also be a multiple of
5467
+ * @a slab_align.
5468
+ *
5469
+ * The memory slab can be accessed outside the module where it is defined
5470
+ * using:
5471
+ *
5472
+ * @code extern struct k_mem_slab <name>; @endcode
5473
+ *
5474
+ * @note This macro cannot be used together with a static keyword.
5475
+ * If such a use-case is desired, use @ref K_MEM_SLAB_DEFINE_IN_SECT_STATIC
5476
+ * instead.
5477
+ *
5478
+ * @param name Name of the memory slab.
5479
+ * @param in_section Section attribute specifier such as Z_GENERIC_SECTION.
5480
+ * @param slab_block_size Size of each memory block (in bytes).
5481
+ * @param slab_num_blocks Number memory blocks.
5482
+ * @param slab_align Alignment of the memory slab's buffer (power of 2).
5483
+ */
5484
+ #define K_MEM_SLAB_DEFINE_IN_SECT (name , in_section , slab_block_size , slab_num_blocks , slab_align ) \
5485
+ BUILD_ASSERT(((slab_block_size) % (slab_align)) == 0, \
5486
+ "slab_block_size must be a multiple of slab_align"); \
5487
+ BUILD_ASSERT((((slab_align) & ((slab_align) - 1)) == 0), \
5488
+ "slab_align must be a power of 2"); \
5489
+ char in_section __aligned(WB_UP( \
5490
+ slab_align)) _k_mem_slab_buf_##name[(slab_num_blocks) * WB_UP(slab_block_size)]; \
5491
+ STRUCT_SECTION_ITERABLE(k_mem_slab, name) = Z_MEM_SLAB_INITIALIZER( \
5492
+ name, _k_mem_slab_buf_##name, WB_UP(slab_block_size), slab_num_blocks)
5493
+
5459
5494
/**
5460
5495
* @brief Statically define and initialize a memory slab in a public (non-static) scope.
5461
5496
*
@@ -5479,13 +5514,36 @@ struct k_mem_slab {
5479
5514
* @param slab_num_blocks Number memory blocks.
5480
5515
* @param slab_align Alignment of the memory slab's buffer (power of 2).
5481
5516
*/
5482
- #define K_MEM_SLAB_DEFINE (name , slab_block_size , slab_num_blocks , slab_align ) \
5483
- char __noinit_named(k_mem_slab_buf_##name) \
5484
- __aligned(WB_UP(slab_align)) \
5485
- _k_mem_slab_buf_##name[(slab_num_blocks) * WB_UP(slab_block_size)]; \
5486
- STRUCT_SECTION_ITERABLE(k_mem_slab, name) = \
5487
- Z_MEM_SLAB_INITIALIZER(name, _k_mem_slab_buf_##name, \
5488
- WB_UP(slab_block_size), slab_num_blocks)
5517
+ #define K_MEM_SLAB_DEFINE (name , slab_block_size , slab_num_blocks , slab_align ) \
5518
+ K_MEM_SLAB_DEFINE_IN_SECT(name, __noinit_named(k_mem_slab_buf_##name), slab_block_size, \
5519
+ slab_num_blocks, slab_align)
5520
+
5521
+ /**
5522
+ * @brief Statically define and initialize a memory slab in a user-provided memory section with
5523
+ * private (static) scope.
5524
+ *
5525
+ * The memory slab's buffer contains @a slab_num_blocks memory blocks
5526
+ * that are @a slab_block_size bytes long. The buffer is aligned to a
5527
+ * @a slab_align -byte boundary. To ensure that each memory block is similarly
5528
+ * aligned to this boundary, @a slab_block_size must also be a multiple of
5529
+ * @a slab_align.
5530
+ *
5531
+ * @param name Name of the memory slab.
5532
+ * @param in_section Section attribute specifier such as Z_GENERIC_SECTION.
5533
+ * @param slab_block_size Size of each memory block (in bytes).
5534
+ * @param slab_num_blocks Number memory blocks.
5535
+ * @param slab_align Alignment of the memory slab's buffer (power of 2).
5536
+ */
5537
+ #define K_MEM_SLAB_DEFINE_IN_SECT_STATIC (name , in_section , slab_block_size , slab_num_blocks , \
5538
+ slab_align ) \
5539
+ BUILD_ASSERT(((slab_block_size) % (slab_align)) == 0, \
5540
+ "slab_block_size must be a multiple of slab_align"); \
5541
+ BUILD_ASSERT((((slab_align) & ((slab_align) - 1)) == 0), \
5542
+ "slab_align must be a power of 2"); \
5543
+ static char in_section __aligned(WB_UP( \
5544
+ slab_align)) _k_mem_slab_buf_##name[(slab_num_blocks) * WB_UP(slab_block_size)]; \
5545
+ static STRUCT_SECTION_ITERABLE(k_mem_slab, name) = Z_MEM_SLAB_INITIALIZER( \
5546
+ name, _k_mem_slab_buf_##name, WB_UP(slab_block_size), slab_num_blocks)
5489
5547
5490
5548
/**
5491
5549
* @brief Statically define and initialize a memory slab in a private (static) scope.
@@ -5501,13 +5559,9 @@ struct k_mem_slab {
5501
5559
* @param slab_num_blocks Number memory blocks.
5502
5560
* @param slab_align Alignment of the memory slab's buffer (power of 2).
5503
5561
*/
5504
- #define K_MEM_SLAB_DEFINE_STATIC (name , slab_block_size , slab_num_blocks , slab_align ) \
5505
- static char __noinit_named(k_mem_slab_buf_##name) \
5506
- __aligned(WB_UP(slab_align)) \
5507
- _k_mem_slab_buf_##name[(slab_num_blocks) * WB_UP(slab_block_size)]; \
5508
- static STRUCT_SECTION_ITERABLE(k_mem_slab, name) = \
5509
- Z_MEM_SLAB_INITIALIZER(name, _k_mem_slab_buf_##name, \
5510
- WB_UP(slab_block_size), slab_num_blocks)
5562
+ #define K_MEM_SLAB_DEFINE_STATIC (name , slab_block_size , slab_num_blocks , slab_align ) \
5563
+ K_MEM_SLAB_DEFINE_IN_SECT_STATIC(name, __noinit_named(k_mem_slab_buf_##name), \
5564
+ slab_block_size, slab_num_blocks, slab_align)
5511
5565
5512
5566
/**
5513
5567
* @brief Initialize a memory slab.
@@ -5806,7 +5860,7 @@ void k_heap_free(struct k_heap *h, void *mem) __attribute_nonnull(1);
5806
5860
*
5807
5861
* @param name Symbol name for the struct k_heap object
5808
5862
* @param bytes Size of memory region, in bytes
5809
- * @param in_section __attribute__((section(name))
5863
+ * @param in_section Section attribute specifier such as Z_GENERIC_SECTION.
5810
5864
*/
5811
5865
#define Z_HEAP_DEFINE_IN_SECT (name , bytes , in_section ) \
5812
5866
char in_section \
0 commit comments