From 1ddea3a1908f5d005b90dde746a3db148bd290df Mon Sep 17 00:00:00 2001 From: Yuyang Huang Date: Sat, 9 Dec 2023 10:31:02 +0900 Subject: Update allocate/transmit API parameter type Update apf_allocate_buffer() and apf_transmit_buffer() parameter to take uint32_t instead of int. Bug: 293811969 Test: TH Change-Id: Ida3f5e8662fc7a4372d44f429c6f80071906c685 --- v5/apf_interpreter.c | 15 +++++++-------- v5/apf_interpreter.h | 4 ++-- v5/test_buf_allocator.c | 6 +++--- v5/test_buf_allocator.h | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/v5/apf_interpreter.c b/v5/apf_interpreter.c index fb63b1b..9e9317b 100644 --- a/v5/apf_interpreter.c +++ b/v5/apf_interpreter.c @@ -46,7 +46,7 @@ extern void APF_TRACE_HOOK(uint32_t pc, const uint32_t* regs, const uint8_t* pro #define ENFORCE_UNSIGNED(c) ((c)==(uint32_t)(c)) uint32_t apf_version() { - return 20231207; + return 20231211; } int apf_run(void* ctx, uint8_t* const program, const uint32_t program_len, @@ -101,11 +101,11 @@ int apf_run(void* ctx, uint8_t* const program, const uint32_t program_len, // The output buffer pointer uint8_t* allocated_buffer = NULL; // The length of the output buffer - int allocate_buffer_len = 0; + uint32_t allocated_buffer_len = 0; // Is access to offset |p| length |size| within output buffer bounds? #define IN_OUTPUT_BOUNDS(p, size) (ENFORCE_UNSIGNED(p) && \ ENFORCE_UNSIGNED(size) && \ - (p) + (size) <= (uint32_t) allocate_buffer_len && \ + (p) + (size) <= allocated_buffer_len && \ (p) + (size) >= (p)) // Accept packet if not write within allocated output buffer #define ASSERT_IN_OUTPUT_BOUNDS(p, size) ASSERT_RETURN(IN_OUTPUT_BOUNDS(p, size)) @@ -300,19 +300,18 @@ int apf_run(void* ctx, uint8_t* const program, const uint32_t program_len, break; case ALLOC_EXT_OPCODE: ASSERT_RETURN(allocated_buffer == NULL); - allocate_buffer_len = (int) REG; + allocated_buffer_len = REG; allocated_buffer = - apf_allocate_buffer(ctx, allocate_buffer_len); + apf_allocate_buffer(ctx, allocated_buffer_len); ASSERT_RETURN(allocated_buffer != NULL); memory[MEMORY_OFFSET_OUTPUT_BUFFER_OFFSET] = 0; break; case TRANS_EXT_OPCODE: ASSERT_RETURN(allocated_buffer != NULL); - int pkt_len = - (int) memory[MEMORY_OFFSET_OUTPUT_BUFFER_OFFSET]; + uint32_t pkt_len = memory[MEMORY_OFFSET_OUTPUT_BUFFER_OFFSET]; // If pkt_len > allocate_buffer_len, it means sth. wrong // happened and the allocated_buffer should be deallocated. - if (pkt_len > allocate_buffer_len) { + if (pkt_len > allocated_buffer_len) { apf_transmit_buffer( ctx, allocated_buffer, diff --git a/v5/apf_interpreter.h b/v5/apf_interpreter.h index a64a68e..9954d37 100644 --- a/v5/apf_interpreter.h +++ b/v5/apf_interpreter.h @@ -52,7 +52,7 @@ uint32_t apf_version(); * pending transmit. Returning NULL will most likely result in the * apf_run() returning PASS. */ -uint8_t* apf_allocate_buffer(void* ctx, int size); +uint8_t* apf_allocate_buffer(void* ctx, uint32_t size); /** * Transmits the allocated buffer and deallocates it. @@ -84,7 +84,7 @@ uint8_t* apf_allocate_buffer(void* ctx, int size); * the firmware thinks the transmit will succeed. Returning an error * will likely result in apf_run() returning PASS. */ -int apf_transmit_buffer(void* ctx, uint8_t* ptr, int len, uint8_t dscp); +int apf_transmit_buffer(void* ctx, uint8_t* ptr, uint32_t len, uint8_t dscp); /** * Runs an APF program over a packet. diff --git a/v5/test_buf_allocator.c b/v5/test_buf_allocator.c index a8c789b..a889dea 100644 --- a/v5/test_buf_allocator.c +++ b/v5/test_buf_allocator.c @@ -21,7 +21,7 @@ uint8_t apf_test_buffer[APF_TX_BUFFER_SIZE]; uint8_t apf_test_tx_packet[APF_TX_BUFFER_SIZE]; -int apf_test_tx_packet_len; +uint32_t apf_test_tx_packet_len; uint8_t apf_test_tx_dscp; /** @@ -29,7 +29,7 @@ uint8_t apf_test_tx_dscp; * * Clean up the apf_test_buffer and return the pointer to beginning of the buffer region. */ -uint8_t* apf_allocate_buffer(__attribute__ ((unused)) void* ctx, int size) { +uint8_t* apf_allocate_buffer(__attribute__ ((unused)) void* ctx, uint32_t size) { if (size > APF_TX_BUFFER_SIZE) { return NULL; } @@ -43,7 +43,7 @@ uint8_t* apf_allocate_buffer(__attribute__ ((unused)) void* ctx, int size) { * Copy the content of allocated buffer to the apf_test_tx_packet region. */ int apf_transmit_buffer(__attribute__((unused)) void* ctx, uint8_t* ptr, - int len, uint8_t dscp) { + uint32_t len, uint8_t dscp) { apf_test_tx_packet_len = len; apf_test_tx_dscp = dscp; memcpy(apf_test_tx_packet, ptr, (size_t) len); diff --git a/v5/test_buf_allocator.h b/v5/test_buf_allocator.h index 287c8bc..3916cf8 100644 --- a/v5/test_buf_allocator.h +++ b/v5/test_buf_allocator.h @@ -23,7 +23,7 @@ extern uint8_t apf_test_buffer[APF_TX_BUFFER_SIZE]; extern uint8_t apf_test_tx_packet[APF_TX_BUFFER_SIZE]; -extern int apf_test_tx_packet_len; +extern uint32_t apf_test_tx_packet_len; extern uint8_t apf_test_tx_dscp; #endif // TEST_BUF_ALLOCATOR -- cgit v1.2.3