summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-12-09 04:17:52 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-12-09 04:17:52 +0000
commit087ca94b49336fa91e2e52fe7f9e5aeae74a15c3 (patch)
tree4bfc6afa730f42e9a301cf58440c81c5b11b2957
parente64ef413a603db3937b913c22ae57d41255f9039 (diff)
parent7055799a3e85ef571725202f3772efe3289f7331 (diff)
downloadapf-087ca94b49336fa91e2e52fe7f9e5aeae74a15c3.tar.gz
Snap for 11200327 from 7055799a3e85ef571725202f3772efe3289f7331 to 24Q1-release
Change-Id: I21355490838436c32e5305a1063fa71f5c68d1ff
-rw-r--r--v5/Android.bp18
-rw-r--r--v5/apf_interpreter.c20
-rw-r--r--v5/test_buf_allocator.c4
-rw-r--r--v5/test_buf_allocator.h2
4 files changed, 31 insertions, 13 deletions
diff --git a/v5/Android.bp b/v5/Android.bp
index 9dbfd9f..6623e64 100644
--- a/v5/Android.bp
+++ b/v5/Android.bp
@@ -18,9 +18,25 @@ package {
default_applicable_licenses: ["hardware_google_apf_license"],
}
+cc_defaults {
+ name: "apfv5_defaults",
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ "-Werror=implicit-fallthrough",
+ "-Wnullable-to-nonnull-conversion",
+ "-Wsign-compare",
+ "-Wsign-conversion",
+ "-Wthread-safety",
+ "-Wunused-parameter",
+ "-Wuninitialized",
+ ],
+}
+
cc_library_static {
name: "libapf_v5",
- defaults: ["apf_defaults"],
+ defaults: ["apfv5_defaults"],
srcs: [
"apf_interpreter.c",
"test_buf_allocator.c"
diff --git a/v5/apf_interpreter.c b/v5/apf_interpreter.c
index a10fd5c..fb63b1b 100644
--- a/v5/apf_interpreter.c
+++ b/v5/apf_interpreter.c
@@ -32,6 +32,8 @@ extern void APF_TRACE_HOOK(uint32_t pc, const uint32_t* regs, const uint8_t* pro
} while (0)
#endif
+// Frame header size should be 14
+#define APF_FRAME_HEADER_SIZE 14
// Return code indicating "packet" should accepted.
#define PASS_PACKET 1
// Return code indicating "packet" should be dropped.
@@ -99,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
- uint32_t allocate_buffer_len = 0;
+ int allocate_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) <= allocate_buffer_len && \
+ (p) + (size) <= (uint32_t) allocate_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))
@@ -135,7 +137,7 @@ int apf_run(void* ctx, uint8_t* const program, const uint32_t program_len,
ASSERT_FORWARD_IN_PROGRAM(pc + imm_len - 1);
DECODE_IMM(imm, imm_len);
// Sign extend imm into signed_imm.
- signed_imm = imm << ((4 - imm_len) * 8);
+ signed_imm = (int32_t) (imm << ((4 - imm_len) * 8));
signed_imm >>= (4 - imm_len) * 8;
}
@@ -265,7 +267,7 @@ int apf_run(void* ctx, uint8_t* const program, const uint32_t program_len,
break;
}
case LI_OPCODE:
- REG = signed_imm;
+ REG = (uint32_t) signed_imm;
break;
case EXT_OPCODE:
if (
@@ -298,7 +300,7 @@ 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 = REG;
+ allocate_buffer_len = (int) REG;
allocated_buffer =
apf_allocate_buffer(ctx, allocate_buffer_len);
ASSERT_RETURN(allocated_buffer != NULL);
@@ -306,8 +308,8 @@ int apf_run(void* ctx, uint8_t* const program, const uint32_t program_len,
break;
case TRANS_EXT_OPCODE:
ASSERT_RETURN(allocated_buffer != NULL);
- uint32_t pkt_len =
- memory[MEMORY_OFFSET_OUTPUT_BUFFER_OFFSET];
+ int pkt_len =
+ (int) 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) {
@@ -341,7 +343,7 @@ int apf_run(void* ctx, uint8_t* const program, const uint32_t program_len,
}
break;
case LDDW_OPCODE: {
- uint32_t offs = OTHER_REG + signed_imm;
+ uint32_t offs = OTHER_REG + (uint32_t) signed_imm;
uint32_t size = 4;
uint32_t val = 0;
// Negative offsets wrap around the end of the address space.
@@ -357,7 +359,7 @@ int apf_run(void* ctx, uint8_t* const program, const uint32_t program_len,
break;
}
case STDW_OPCODE: {
- uint32_t offs = OTHER_REG + signed_imm;
+ uint32_t offs = OTHER_REG + (uint32_t) signed_imm;
uint32_t size = 4;
uint32_t val = REG;
// Negative offsets wrap around the end of the address space.
diff --git a/v5/test_buf_allocator.c b/v5/test_buf_allocator.c
index 013754e..a8c789b 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];
-uint32_t apf_test_tx_packet_len;
+int apf_test_tx_packet_len;
uint8_t apf_test_tx_dscp;
/**
@@ -46,6 +46,6 @@ int apf_transmit_buffer(__attribute__((unused)) void* ctx, uint8_t* ptr,
int len, uint8_t dscp) {
apf_test_tx_packet_len = len;
apf_test_tx_dscp = dscp;
- memcpy(apf_test_tx_packet, ptr, len);
+ memcpy(apf_test_tx_packet, ptr, (size_t) len);
return 0;
}
diff --git a/v5/test_buf_allocator.h b/v5/test_buf_allocator.h
index 3916cf8..287c8bc 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 uint32_t apf_test_tx_packet_len;
+extern int apf_test_tx_packet_len;
extern uint8_t apf_test_tx_dscp;
#endif // TEST_BUF_ALLOCATOR