Support SystemResourceSize property in NPDM META (#26)

This commit is contained in:
Somebody Whoisbored 2020-01-10 04:35:29 -07:00 committed by fincs
parent ad647397ef
commit e607ced3e2

View File

@ -76,7 +76,8 @@ typedef struct {
u8 _0xD; u8 _0xD;
u8 MainThreadPriority; u8 MainThreadPriority;
u8 DefaultCpuId; u8 DefaultCpuId;
u64 _0x10; u32 _0x10;
u32 SystemResourceSize;
u32 ProcessCategory; u32 ProcessCategory;
u32 MainThreadStackSize; u32 MainThreadStackSize;
char Name[0x10]; char Name[0x10];
@ -219,6 +220,32 @@ int cJSON_GetU64(const cJSON *obj, const char *field, u64 *out) {
} }
} }
int cJSON_GetU32(const cJSON *obj, const char *field, u32 *out) {
const cJSON *config = cJSON_GetObjectItemCaseSensitive(obj, field);
if (cJSON_IsString(config) && (config->valuestring != NULL)) {
char *endptr = NULL;
*out = strtoul(config->valuestring, &endptr, 16);
if (config->valuestring == endptr) {
fprintf(stderr, "Failed to get %s (empty string)\n", field);
return 0;
} else if (errno == ERANGE) {
fprintf(stderr, "Failed to get %s (value out of range)\n", field);
return 0;
} else if (errno == EINVAL) {
fprintf(stderr, "Failed to get %s (not base16 string)\n", field);
return 0;
} else if (errno) {
fprintf(stderr, "Failed to get %s (unknown error)\n", field);
return 0;
} else {
return 1;
}
} else {
fprintf(stderr, "Failed to get %s (field not present).\n", field);
return 0;
}
}
int cJSON_GetU64FromObjectValue(const cJSON *config, u64 *out) { int cJSON_GetU64FromObjectValue(const cJSON *config, u64 *out) {
if (cJSON_IsString(config) && (config->valuestring != NULL)) { if (cJSON_IsString(config) && (config->valuestring != NULL)) {
char *endptr = NULL; char *endptr = NULL;
@ -305,6 +332,9 @@ int CreateNpdm(const char *json, void **dst, u32 *dst_size) {
status = 0; status = 0;
goto NPDM_BUILD_END; goto NPDM_BUILD_END;
} }
cJSON_GetU32(npdm_json, "system_resource_size", &header.SystemResourceSize); // optional
if (!cJSON_GetU8(npdm_json, "process_category", (u8 *)&header.ProcessCategory)) { if (!cJSON_GetU8(npdm_json, "process_category", (u8 *)&header.ProcessCategory)) {
status = 0; status = 0;
goto NPDM_BUILD_END; goto NPDM_BUILD_END;