Skip to content

Commit f62aa74

Browse files
author
icex2
committed
wip
1 parent ad62c00 commit f62aa74

9 files changed

Lines changed: 452 additions & 105 deletions

File tree

src/main/launcher/avs.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,67 @@ static void _avs_context_create_config_fs_dir(
155155
}
156156
}
157157

158+
static void avs_config_setup(
159+
struct bootstrap_config *bootstrap_config,
160+
const char* dev_nvram_raw_path,
161+
bool override_loglevel_enabled,
162+
enum log_level loglevel,
163+
struct property **avs_config_property)
158164
void avs_init(
165+
const struct bootstrap_avs_config *config,
159166
struct property *config_prop,
160167
struct property_node *config_node,
161168
uint32_t avs_heap_size,
162169
uint32_t std_heap_size)
163170
{
171+
log_assert(bootstrap_config);
172+
log_assert(avs_config_property);
173+
174+
175+
176+
*avs_config_property = avs_config_load_from_file_path(config->config_file);
177+
178+
if (dev_nvram_raw_path) {
179+
if (!path_exists(dev_nvram_raw_path)) {
180+
log_warning("Override local file system dev/nvram and dev/raw path %s does not exist, creating",
181+
dev_nvram_raw_path);
182+
183+
if (!path_mkdir(dev_nvram_raw_path)) {
184+
log_fatal("Creating directory %s failed", dev_nvram_raw_path);
185+
}
186+
}
187+
188+
avs_config_set_local_fs_path_dev_nvram_and_raw(
189+
*avs_config_property,
190+
dev_nvram_raw_path);
191+
}
192+
193+
if (override_loglevel_enabled) {
194+
avs_config_set_log_level(*avs_config_property, loglevel);
195+
}
196+
197+
198+
199+
200+
201+
202+
avs_config_set_mode_product(avs_property, true);
203+
avs_config_set_net_raw(avs_property, true);
204+
avs_config_set_net_eaudp(avs_property, true);
205+
avs_config_set_sntp_ea(avs_property, true);
206+
207+
if (config->startup.drm.device[0]) {
208+
avs_config_set_fs_root_device(avs_property, config->startup.drm.device);
209+
}
210+
211+
if (config->log_node) {
212+
avs_config_set_logging(avs_property, config);
213+
}
214+
215+
216+
217+
218+
164219
log_assert(config_prop);
165220
log_assert(config_node);
166221

src/main/launcher/bootstrap-config.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ PSMAP_END
195195
#define ROOT_NODE "/config"
196196
#define MODULE_PATH_PREFIX "modules/"
197197

198+
#define DEFAULT_HEAP_SIZE 16777216
199+
198200
const char *const inherited_nodes[] = {
199201
"develop",
200202
"default",
@@ -212,7 +214,7 @@ const char *const inherited_nodes[] = {
212214

213215
void bootstrap_config_init(struct bootstrap_config *config)
214216
{
215-
memset(config, 0, sizeof(*config));
217+
memset(config, 0, sizeof(*config));
216218
}
217219

218220
bool bootstrap_config_from_property(
@@ -374,23 +376,6 @@ bool bootstrap_config_from_property(
374376
return true;
375377
}
376378

377-
void bootstrap_config_update_avs(
378-
const struct bootstrap_config *config, struct property *avs_property)
379-
{
380-
avs_config_set_mode_product(avs_property, true);
381-
avs_config_set_net_raw(avs_property, true);
382-
avs_config_set_net_eaudp(avs_property, true);
383-
avs_config_set_sntp_ea(avs_property, true);
384-
385-
if (config->startup.drm.device[0]) {
386-
avs_config_set_fs_root_device(avs_property, config->startup.drm.device);
387-
}
388-
389-
if (config->log_node) {
390-
avs_config_set_logging(avs_property, config);
391-
}
392-
}
393-
394379
bool bootstrap_config_iter_default_file(
395380
struct bootstrap_config *config,
396381
struct bootstrap_default_file_config *default_file)

src/main/launcher/bootstrap-config.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ bool bootstrap_config_from_property(
138138
const char *profile);
139139

140140
// TODO this should rather move somewhere else?
141-
void bootstrap_config_update_avs(
142-
const struct bootstrap_config *config, struct property *avs_property);
143141
bool bootstrap_config_iter_default_file(
144142
struct bootstrap_config *config,
145143
struct bootstrap_default_file_config *default_file);
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
#include <string.h>
2+
3+
#include "imports/avs.h"
4+
5+
#include "launcher/launcher-config.h"
6+
7+
// clang-format off
8+
PSMAP_BEGIN(launcher_bootstrap_psmap)
9+
PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct launcher_bootstrap_config, file,
10+
"bootstrap/file", "prop/bootstrap.xml")
11+
PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct launcher_bootstrap_config, selector,
12+
"bootstrap/selector", "")
13+
PSMAP_END
14+
15+
PSMAP_BEGIN(launcher_ea3_ident_psmap)
16+
PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct launcher_bootstrap_config, file,
17+
"ea3_ident/file", "prop/ea3-ident.xml")
18+
PSMAP_END
19+
20+
PSMAP_BEGIN(launcher_app_config_psmap)
21+
PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct launcher_app_config_config, file,
22+
"app_config/file", "prop/app-config.xml")
23+
PSMAP_END
24+
25+
PSMAP_BEGIN(launcher_debug_psmap)
26+
PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, remote_debugger,
27+
"debug/remote_debugger", false)
28+
PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, log_property_configs,
29+
"debug/log_property_configs", false)
30+
PSMAP_END
31+
// clang-format on
32+
33+
#define ROOT_NODE "/launcher"
34+
35+
static void _launcher_config_parse_hook_dlls(
36+
const property_node *node,
37+
const char *node_path,
38+
char *dlls[MAX_PATH])
39+
{
40+
int cnt;
41+
struct property_node *cur;
42+
struct property_node *next;
43+
char full_node_path[128];
44+
45+
strcpy(full_node_path, ROOT_NODE);
46+
strcat(full_node_path, node_path);
47+
strcat(full_node_path, "/dll");
48+
49+
cnt = 0;
50+
cur = property_search(NULL, node, full_node_path);
51+
52+
while (cur) {
53+
if (cnt >= LAUNCHER_CONFIG_MAX_HOOK_DLL) {
54+
log_warning("Currently not supporting more than %d dlls, skipping remaining", cnt);
55+
break;
56+
}
57+
58+
next = property_node_traversal(node, TRAVERSE_NEXT_SEARCH_RESULT);
59+
60+
property_node_read(next, PROPERTY_TYPE_STR, dlls[cnt], MAX_PATH);
61+
62+
cnt++;
63+
cur = next;
64+
}
65+
}
66+
67+
void launcher_config_init(struct launcher_config *config)
68+
{
69+
log_assert(config);
70+
71+
strcpy(config->bootstrap.file, "prop/bootstrap.xml");
72+
memset(config->bootstrap.selector, 0, sizeof(config->bootstrap.selector));
73+
74+
strcpy(config->ea3_ident.file, "prop/ea3-ident.xml");
75+
76+
strcpy(config->app_config.file, "prop/app-config.xml");
77+
78+
memset(config->hook.hook_dlls, 0, sizeof(config->hook.hook_dlls));
79+
memset(config->hook.before_hook_dlls, 0, sizeof(config->hook.before_hook_dlls));
80+
memset(config->hook.iat_hook_dlls, 0, sizeof(config->hook.iat_hook_dlls));
81+
82+
config->debug.remote_debugger = false;
83+
config->debug.log_property_configs = false;
84+
}
85+
86+
void launcher_config_load_from_file_path(
87+
const char *filepath,
88+
struct launcher_config *config)
89+
{
90+
struct property *property;
91+
struct node *node;
92+
93+
log_assert(filepath);
94+
log_assert(config);
95+
96+
log_misc("Loading launcher config from file path: %s", filepath);
97+
98+
property = property_util_load_file(filepath);
99+
100+
node = property_search(property, 0, ROOT_NODE);
101+
102+
if (node == NULL) {
103+
log_fatal("Root node " ROOT_NODE " in launcher config missing");
104+
}
105+
106+
if (!property_psmap_import(
107+
NULL, node, &config->bootstrap, launcher_bootstrap_psmap)) {
108+
log_fatal(ROOT_NODE "/bootstrap: load failed");
109+
}
110+
111+
if (!property_psmap_import(
112+
NULL, node, &config->ea3_ident, launcher_ea3_ident_psmap)) {
113+
log_fatal(ROOT_NODE "/ea3_ident: load failed");
114+
}
115+
116+
if (!property_psmap_import(
117+
NULL, node, &config->app_config, launcher_app_config_psmap)) {
118+
log_fatal(ROOT_NODE "/app_config: load failed");
119+
}
120+
121+
_launcher_config_parse_hook_dlls(node, "hook/hook_dlls", config->hook.hook_dlls);
122+
_launcher_config_parse_hook_dlls(node, "hook/before_hook_dlls", config->hook.before_hook_dlls);
123+
_launcher_config_parse_hook_dlls(node, "hook/iat_hook_dlls", config->hook.iat_hook_dlls);
124+
125+
if (!property_psmap_import(
126+
NULL, node, &config->hook, launcher_ea3_ident_psmap)) {
127+
log_fatal(ROOT_NODE "/hook: load failed");
128+
}
129+
130+
if (!property_psmap_import(
131+
NULL, node, &config->debug, launcher_debug_psmap)) {
132+
log_fatal(ROOT_NODE "/debug: load failed");
133+
}
134+
}
135+
136+
void launcher_config_save_to_file_path(
137+
const struct launcher_config *config,
138+
const char *filepath)
139+
{
140+
char buffer[4096];
141+
struct property *property;
142+
struct property_node *root_node;
143+
int i;
144+
145+
property = property_create(
146+
PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE,
147+
buffer,
148+
sizeof(buffer));
149+
150+
root_node = property_node_create(
151+
property, NULL, PROPERTY_TYPE_VOID, ROOT_NODE, 0);
152+
153+
property_psmap_export(property, root_node, config->bootstrap, launcher_bootstrap_psmap);
154+
property_psmap_export(property, root_node, config->ea3_ident, launcher_ea3_ident_psmap);
155+
property_psmap_export(property, root_node, config->app_config, launcher_app_config_psmap);
156+
157+
property_node_create(property, root_node, PROPERTY_TYPE_VOID, "hook/hook_dlls", 0);
158+
159+
for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOK_DLL; i++) {
160+
if (config->hook.hook_dlls[i] != '\0') {
161+
property_node_create(
162+
property, root_node, PROPERTY_TYPE_STR, "hook/hook_dlls/file", config->hook.hook_dlls[i]);
163+
} else {
164+
break;
165+
}
166+
}
167+
168+
property_node_create(property, root_node, PROPERTY_TYPE_VOID, "hook/before_hook_dlls", 0);
169+
170+
for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOK_DLL; i++) {
171+
if (config->hook.hook_dlls[i] != '\0') {
172+
property_node_create(
173+
property, root_node, PROPERTY_TYPE_STR, "hook/before_hook_dlls/file", config->hook.before_hook_dlls[i]);
174+
} else {
175+
break;
176+
}
177+
}
178+
179+
property_node_create(property, root_node, PROPERTY_TYPE_VOID, "hook/iat_hook_dlls", 0);
180+
181+
for (i = 0; i < LAUNCHER_CONFIG_MAX_HOOK_DLL; i++) {
182+
if (config->hook.hook_dlls[i] != '\0') {
183+
property_node_create(
184+
property, root_node, PROPERTY_TYPE_STR, "hook/iat_hook_dlls/file", config->hook.iat_hook_dlls[i]);
185+
} else {
186+
break;
187+
}
188+
}
189+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef LAUNCHER_CONFIG_H
2+
#define LAUNCHER_CONFIG_H
3+
4+
#include <windows.h>
5+
6+
#include "util/array.h"
7+
8+
#define LAUNCHER_CONFIG_MAX_HOOK_DLL 16
9+
10+
struct launcher_config {
11+
struct launcher_bootstrap_config {
12+
char file[MAX_PATH];
13+
char selector[128];
14+
} bootstrap;
15+
16+
struct launcher_ea3_ident_config {
17+
char file[MAX_PATH];
18+
} ea3_ident;
19+
20+
struct launcher_app_config_config {
21+
char file[MAX_PATH]
22+
} app_config;
23+
24+
struct launcher_hook_config {
25+
char hook_dlls[LAUNCHER_CONFIG_MAX_HOOK_DLL][MAX_PATH];
26+
char before_hook_dlls[LAUNCHER_CONFIG_MAX_HOOK_DLL][MAX_PATH];
27+
char iat_hook_dlls[LAUNCHER_CONFIG_MAX_HOOK_DLL][MAX_PATH];
28+
} hook;
29+
30+
struct launcher_debug_config {
31+
bool remote_debugger;
32+
bool log_property_configs;
33+
} debug;
34+
};
35+
36+
void launcher_config_init(struct launcher_config *config);
37+
38+
void launcher_config_load_from_file_path(
39+
const char *filepath,
40+
struct launcher_config *config);
41+
42+
void launcher_config_save_to_file_path(
43+
const struct launcher_config *config,
44+
const char *filepath);
45+
46+
#endif

0 commit comments

Comments
 (0)