From becb4df6f61b74350d49f0284d1623b36417ff81 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 13 Mar 2022 16:59:59 -0700 Subject: [PATCH] use actual lowest/highest priorities, ignoring field names --- src/elf2kip.c | 8 ++++++-- src/npdmtool.c | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/elf2kip.c b/src/elf2kip.c index 6bf852d..005957c 100644 --- a/src/elf2kip.c +++ b/src/elf2kip.c @@ -341,13 +341,17 @@ int ParseKipConfiguration(const char *json, KipHeader *kip_hdr) { status = 0; goto PARSE_CAPS_END; } + + u8 real_highest_prio = (lowest_prio < highest_prio) ? lowest_prio : highest_prio; + u8 real_lowest_prio = (lowest_prio > highest_prio) ? lowest_prio : highest_prio; + desc = highest_cpu; desc <<= 8; desc |= lowest_cpu; desc <<= 6; - desc |= (lowest_prio & 0x3F); + desc |= (real_highest_prio & 0x3F); desc <<= 6; - desc |= (highest_prio & 0x3F); + desc |= (real_lowest_prio & 0x3F); kip_hdr->Capabilities[cur_cap++] = (u32)((desc << 4) | (0x0007)); } else if (!strcmp(type_str, "syscalls")) { if (!cJSON_IsObject(value)) { diff --git a/src/npdmtool.c b/src/npdmtool.c index 1de8b77..0481b2d 100644 --- a/src/npdmtool.c +++ b/src/npdmtool.c @@ -646,13 +646,17 @@ int CreateNpdm(const char *json, void **dst, u32 *dst_size) { status = 0; goto NPDM_BUILD_END; } + + u8 real_highest_prio = (lowest_prio < highest_prio) ? lowest_prio : highest_prio; + u8 real_lowest_prio = (lowest_prio > highest_prio) ? lowest_prio : highest_prio; + desc = highest_cpu; desc <<= 8; desc |= lowest_cpu; desc <<= 6; - desc |= (lowest_prio & 0x3F); + desc |= (real_highest_prio & 0x3F); desc <<= 6; - desc |= (highest_prio & 0x3F); + desc |= (real_lowest_prio & 0x3F); caps[cur_cap++] = (u32)((desc << 4) | (0x0007)); } else if (!strcmp(type_str, "syscalls")) { if (!cJSON_IsObject(value)) {