@@ -22,8 +22,6 @@ use core::ops::{Deref, DerefMut};
2222use core:: time:: Duration ;
2323use score_log:: ScoreDebug ;
2424
25- // TODO: add support for protected memory allocator.
26-
2725pub type FFIHandle = * mut core:: ffi:: c_void ;
2826
2927/// FFI return codes.
@@ -112,6 +110,7 @@ pub extern "C" fn health_monitor_builder_destroy(health_monitor_builder_handle:
112110#[ unsafe( no_mangle) ]
113111pub extern "C" fn health_monitor_builder_build (
114112 health_monitor_builder_handle : FFIHandle ,
113+ allocator_capacity : * const usize ,
115114 supervisor_cycle_ms : * const u64 ,
116115 internal_cycle_ms : * const u64 ,
117116 thread_parameters_handle : FFIHandle ,
@@ -129,8 +128,12 @@ pub extern "C" fn health_monitor_builder_build(
129128 unsafe { Box :: from_raw ( health_monitor_builder_handle as * mut HealthMonitorBuilder ) } ;
130129
131130 // SAFETY:
132- // `supervisor_cycle_ms` and `internal_cycle_ms` must be a valid pointer when non-null.
131+ // `allocator_capacity`, ` supervisor_cycle_ms` and `internal_cycle_ms` must be a valid pointer when non-null.
133132 // Values are considered unset on null.
133+ if !allocator_capacity. is_null ( ) {
134+ let allocator_capacity = unsafe { * allocator_capacity } ;
135+ health_monitor_builder. allocator_capacity_internal ( allocator_capacity) ;
136+ }
134137 if !internal_cycle_ms. is_null ( ) {
135138 let internal_cycle_ms = Duration :: from_millis ( unsafe { * internal_cycle_ms } ) ;
136139 health_monitor_builder. with_internal_processing_cycle_internal ( internal_cycle_ms) ;
@@ -482,6 +485,7 @@ mod tests {
482485 null_mut ( ) ,
483486 null_mut ( ) ,
484487 null_mut ( ) ,
488+ null_mut ( ) ,
485489 & mut health_monitor_handle as * mut FFIHandle ,
486490 ) ;
487491 assert ! ( !health_monitor_handle. is_null( ) ) ;
@@ -512,6 +516,7 @@ mod tests {
512516 let internal_cycle_ms = 100u64 ;
513517 let health_monitor_builder_build_result = health_monitor_builder_build (
514518 health_monitor_builder_handle,
519+ null_mut ( ) ,
515520 & supervisor_cycle_ms as * const _ ,
516521 & internal_cycle_ms as * const _ ,
517522 null_mut ( ) ,
@@ -526,6 +531,36 @@ mod tests {
526531 assert_eq ! ( health_monitor_destroy_result, FFICode :: Success ) ;
527532 }
528533
534+ #[ test]
535+ fn health_monitor_builder_build_invalid_allocator_capacity ( ) {
536+ let mut health_monitor_builder_handle: FFIHandle = null_mut ( ) ;
537+ let mut health_monitor_handle: FFIHandle = null_mut ( ) ;
538+ let mut deadline_monitor_builder_handle = null_mut ( ) ;
539+
540+ let _ = health_monitor_builder_create ( & mut health_monitor_builder_handle as * mut FFIHandle ) ;
541+ let deadline_monitor_tag = MonitorTag :: from ( "deadline_monitor" ) ;
542+ let _ = deadline_monitor_builder_create ( & mut deadline_monitor_builder_handle as * mut FFIHandle ) ;
543+ let _ = health_monitor_builder_add_deadline_monitor (
544+ health_monitor_builder_handle,
545+ & deadline_monitor_tag as * const MonitorTag ,
546+ deadline_monitor_builder_handle,
547+ ) ;
548+
549+ let allocator_capacity = 0usize ;
550+ let health_monitor_builder_build_result = health_monitor_builder_build (
551+ health_monitor_builder_handle,
552+ & allocator_capacity as * const _ ,
553+ null_mut ( ) ,
554+ null_mut ( ) ,
555+ null_mut ( ) ,
556+ & mut health_monitor_handle as * mut FFIHandle ,
557+ ) ;
558+ assert ! ( health_monitor_handle. is_null( ) ) ;
559+ assert_eq ! ( health_monitor_builder_build_result, FFICode :: InvalidArgument ) ;
560+
561+ // Clean-up not needed - health monitor builder was already consumed by the `build`.
562+ }
563+
529564 #[ test]
530565 fn health_monitor_builder_build_invalid_cycle_intervals ( ) {
531566 let mut health_monitor_builder_handle: FFIHandle = null_mut ( ) ;
@@ -537,6 +572,7 @@ mod tests {
537572 let internal_cycle_ms = 100u64 ;
538573 let health_monitor_builder_build_result = health_monitor_builder_build (
539574 health_monitor_builder_handle,
575+ null_mut ( ) ,
540576 & supervisor_cycle_ms as * const _ ,
541577 & internal_cycle_ms as * const _ ,
542578 null_mut ( ) ,
@@ -560,6 +596,7 @@ mod tests {
560596 null_mut ( ) ,
561597 null_mut ( ) ,
562598 null_mut ( ) ,
599+ null_mut ( ) ,
563600 & mut health_monitor_handle as * mut FFIHandle ,
564601 ) ;
565602 assert_eq ! ( health_monitor_builder_build_result, FFICode :: WrongState ) ;
@@ -576,6 +613,7 @@ mod tests {
576613 null_mut ( ) ,
577614 null_mut ( ) ,
578615 null_mut ( ) ,
616+ null_mut ( ) ,
579617 & mut health_monitor_handle as * mut FFIHandle ,
580618 ) ;
581619 assert ! ( health_monitor_handle. is_null( ) ) ;
@@ -594,6 +632,7 @@ mod tests {
594632 null_mut ( ) ,
595633 null_mut ( ) ,
596634 null_mut ( ) ,
635+ null_mut ( ) ,
597636 ) ;
598637 assert_eq ! ( health_monitor_builder_build_result, FFICode :: NullParameter ) ;
599638
@@ -623,6 +662,7 @@ mod tests {
623662 health_monitor_builder_handle,
624663 null_mut ( ) ,
625664 null_mut ( ) ,
665+ null_mut ( ) ,
626666 thread_parameters_handle,
627667 & mut health_monitor_handle as * mut FFIHandle ,
628668 ) ;
@@ -914,6 +954,7 @@ mod tests {
914954 null_mut ( ) ,
915955 null_mut ( ) ,
916956 null_mut ( ) ,
957+ null_mut ( ) ,
917958 & mut health_monitor_handle as * mut FFIHandle ,
918959 ) ;
919960
@@ -951,6 +992,7 @@ mod tests {
951992 null_mut ( ) ,
952993 null_mut ( ) ,
953994 null_mut ( ) ,
995+ null_mut ( ) ,
954996 & mut health_monitor_handle as * mut FFIHandle ,
955997 ) ;
956998
@@ -997,6 +1039,7 @@ mod tests {
9971039 null_mut ( ) ,
9981040 null_mut ( ) ,
9991041 null_mut ( ) ,
1042+ null_mut ( ) ,
10001043 & mut health_monitor_handle as * mut FFIHandle ,
10011044 ) ;
10021045
@@ -1032,6 +1075,7 @@ mod tests {
10321075 null_mut ( ) ,
10331076 null_mut ( ) ,
10341077 null_mut ( ) ,
1078+ null_mut ( ) ,
10351079 & mut health_monitor_handle as * mut FFIHandle ,
10361080 ) ;
10371081
@@ -1066,6 +1110,7 @@ mod tests {
10661110 null_mut ( ) ,
10671111 null_mut ( ) ,
10681112 null_mut ( ) ,
1113+ null_mut ( ) ,
10691114 & mut health_monitor_handle as * mut FFIHandle ,
10701115 ) ;
10711116
@@ -1100,6 +1145,7 @@ mod tests {
11001145 null_mut ( ) ,
11011146 null_mut ( ) ,
11021147 null_mut ( ) ,
1148+ null_mut ( ) ,
11031149 & mut health_monitor_handle as * mut FFIHandle ,
11041150 ) ;
11051151
@@ -1137,6 +1183,7 @@ mod tests {
11371183 null_mut ( ) ,
11381184 null_mut ( ) ,
11391185 null_mut ( ) ,
1186+ null_mut ( ) ,
11401187 & mut health_monitor_handle as * mut FFIHandle ,
11411188 ) ;
11421189
@@ -1183,6 +1230,7 @@ mod tests {
11831230 null_mut ( ) ,
11841231 null_mut ( ) ,
11851232 null_mut ( ) ,
1233+ null_mut ( ) ,
11861234 & mut health_monitor_handle as * mut FFIHandle ,
11871235 ) ;
11881236
@@ -1218,6 +1266,7 @@ mod tests {
12181266 null_mut ( ) ,
12191267 null_mut ( ) ,
12201268 null_mut ( ) ,
1269+ null_mut ( ) ,
12211270 & mut health_monitor_handle as * mut FFIHandle ,
12221271 ) ;
12231272
@@ -1252,6 +1301,7 @@ mod tests {
12521301 null_mut ( ) ,
12531302 null_mut ( ) ,
12541303 null_mut ( ) ,
1304+ null_mut ( ) ,
12551305 & mut health_monitor_handle as * mut FFIHandle ,
12561306 ) ;
12571307
@@ -1285,6 +1335,7 @@ mod tests {
12851335 null_mut ( ) ,
12861336 null_mut ( ) ,
12871337 null_mut ( ) ,
1338+ null_mut ( ) ,
12881339 & mut health_monitor_handle as * mut FFIHandle ,
12891340 ) ;
12901341
@@ -1321,6 +1372,7 @@ mod tests {
13211372 null_mut ( ) ,
13221373 null_mut ( ) ,
13231374 null_mut ( ) ,
1375+ null_mut ( ) ,
13241376 & mut health_monitor_handle as * mut FFIHandle ,
13251377 ) ;
13261378
@@ -1366,6 +1418,7 @@ mod tests {
13661418 null_mut ( ) ,
13671419 null_mut ( ) ,
13681420 null_mut ( ) ,
1421+ null_mut ( ) ,
13691422 & mut health_monitor_handle as * mut FFIHandle ,
13701423 ) ;
13711424
@@ -1400,6 +1453,7 @@ mod tests {
14001453 null_mut ( ) ,
14011454 null_mut ( ) ,
14021455 null_mut ( ) ,
1456+ null_mut ( ) ,
14031457 & mut health_monitor_handle as * mut FFIHandle ,
14041458 ) ;
14051459
@@ -1433,6 +1487,7 @@ mod tests {
14331487 null_mut ( ) ,
14341488 null_mut ( ) ,
14351489 null_mut ( ) ,
1490+ null_mut ( ) ,
14361491 & mut health_monitor_handle as * mut FFIHandle ,
14371492 ) ;
14381493
@@ -1468,6 +1523,7 @@ mod tests {
14681523 null_mut ( ) ,
14691524 null_mut ( ) ,
14701525 null_mut ( ) ,
1526+ null_mut ( ) ,
14711527 & mut health_monitor_handle as * mut FFIHandle ,
14721528 ) ;
14731529
@@ -1504,6 +1560,7 @@ mod tests {
15041560 null_mut ( ) ,
15051561 null_mut ( ) ,
15061562 null_mut ( ) ,
1563+ null_mut ( ) ,
15071564 & mut health_monitor_handle as * mut FFIHandle ,
15081565 ) ;
15091566
0 commit comments