mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-11-25 15:22:19 -08:00
symbol server abstraction layer; http layer; fix to 'prefer_disasm' rule when no disassembly tabs are open; small fixes / cleanup
This commit is contained in:
1 parent
1ef94cb759
commit
5c664261a3
38 files changed
+1347
-81
No files matched your search
@@ -1942,30 +1942,12 @@ w32_entry_point_caller(int argc, WCHAR **wargv)
|
||||
{
|
||||
String16 string16 = str16((U16 *)this_proc_env + start_idx, idx - start_idx);
|
||||
String8 string = str8_from_16(arena, string16);
|
||||
if(str8_match(string, s("_NT_SYMBOL_PATH="), StringMatchFlag_RightSideSloppy))
|
||||
{
|
||||
info->symbol_cache_path = str8_skip(string, 16);
|
||||
info->symbol_cache_path = str8_skip_chop_whitespace(info->symbol_cache_path);
|
||||
}
|
||||
str8_list_push(arena, &info->environment, string);
|
||||
start_idx = idx+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(info->symbol_cache_path.size == 0)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
U64 size = KB(32);
|
||||
U16 *buffer = push_array_no_zero(scratch.arena, U16, size);
|
||||
if(SUCCEEDED(SHGetFolderPathW(0, CSIDL_LOCAL_APPDATA, 0, 0, (WCHAR*)buffer)))
|
||||
{
|
||||
String8 local_appdata = str8_from_16(scratch.arena, str16_cstring(buffer));
|
||||
info->symbol_cache_path = str8f(arena, "%S\\Temp\\SymbolCache", local_appdata);
|
||||
|
||||
}
|
||||
scratch_end(scratch);
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: set up entity storage
|
||||
|
||||
@@ -0,0 +1,501 @@
|
||||
// Copyright (c) Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Status Callback
|
||||
|
||||
internal void
|
||||
w32_http_status_callback(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus, void *lpvStatusInformation, DWORD dwStatusInformationLength)
|
||||
{
|
||||
W32_HTTP_Request *req = (W32_HTTP_Request *)dwContext;
|
||||
B32 reloop = 1;
|
||||
switch(dwInternetStatus)
|
||||
{
|
||||
default:{reloop = 0;}break;
|
||||
case WINHTTP_CALLBACK_STATUS_REQUEST_ERROR:
|
||||
{
|
||||
ins_atomic_u32_eval_assign(&req->status, W32_HTTP_RequestStatus_Failed);
|
||||
}break;
|
||||
case WINHTTP_CALLBACK_STATUS_REQUEST_SENT:
|
||||
{
|
||||
ins_atomic_u32_eval_cond_assign(&req->status, W32_HTTP_RequestStatus_Sent, W32_HTTP_RequestStatus_PendingSend);
|
||||
}break;
|
||||
case WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE:
|
||||
{
|
||||
req->next_body_piece = 0;
|
||||
req->next_body_piece_size = 0;
|
||||
ins_atomic_u32_eval_cond_assign(&req->status, W32_HTTP_RequestStatus_Recvd, W32_HTTP_RequestStatus_PendingRecv);
|
||||
}break;
|
||||
case WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE:
|
||||
{
|
||||
DWORD *size_ptr = (DWORD *)lpvStatusInformation;
|
||||
req->next_body_piece_size = size_ptr[0];
|
||||
if(size_ptr[0] != 0)
|
||||
{
|
||||
ins_atomic_u32_eval_assign(&req->status, W32_HTTP_RequestStatus_DataSized);
|
||||
}
|
||||
else
|
||||
{
|
||||
ins_atomic_u32_eval_assign(&req->status, W32_HTTP_RequestStatus_Done);
|
||||
}
|
||||
}break;
|
||||
case WINHTTP_CALLBACK_STATUS_READ_COMPLETE:
|
||||
{
|
||||
req->next_body_piece_size = dwStatusInformationLength;
|
||||
ins_atomic_u32_eval_assign(&req->status, W32_HTTP_RequestStatus_Recvd);
|
||||
}break;
|
||||
}
|
||||
if(reloop)
|
||||
{
|
||||
ins_atomic_u32_eval_assign(&async_loop_again, 1);
|
||||
cond_var_broadcast(async_tick_start_cond_var);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: @per_os_impl Top-Level Layer Calls
|
||||
|
||||
internal void
|
||||
http_init(void)
|
||||
{
|
||||
Arena *arena = arena_alloc();
|
||||
w32_http_state = push_array(arena, W32_HTTP_State, 1);
|
||||
w32_http_state->arena = arena;
|
||||
w32_http_state->request_ring = guarded_ring_alloc(arena, MB(1));
|
||||
for EachElement(idx, w32_http_state->active_requests)
|
||||
{
|
||||
w32_http_state->active_requests[idx].arena = arena_alloc();
|
||||
}
|
||||
w32_http_state->hSession = WinHttpOpen(0, WINHTTP_ACCESS_TYPE_NO_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, WINHTTP_FLAG_ASYNC);
|
||||
WinHttpSetStatusCallback(w32_http_state->hSession, w32_http_status_callback, WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS, 0);
|
||||
}
|
||||
|
||||
internal void
|
||||
http_async_tick(void)
|
||||
{
|
||||
//- rjf: pop requests, fill active request slots
|
||||
if(lane_idx() == 0)
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
|
||||
//- rjf: find a free active request slot
|
||||
U64 free_slot_num = 0;
|
||||
for EachElement(idx, w32_http_state->active_requests)
|
||||
{
|
||||
if(!w32_http_state->active_requests[idx].active)
|
||||
{
|
||||
free_slot_num = idx+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: if we got one -> pop request data
|
||||
String8 request_data = {0};
|
||||
if(free_slot_num != 0)
|
||||
{
|
||||
RingGuard guard = guarded_ring_open(w32_http_state->request_ring);
|
||||
guarded_ring_try_read_struct(&guard, &request_data.size);
|
||||
if(request_data.size != 0)
|
||||
{
|
||||
request_data.str = push_array(scratch.arena, U8, request_data.size);
|
||||
guarded_ring_read_or_wait(&guard, request_data.size, request_data.str, max_U64);
|
||||
}
|
||||
guarded_ring_close(&guard);
|
||||
}
|
||||
|
||||
//- rjf: deserialize
|
||||
GuardedRing *out_ring = 0;
|
||||
HTTP_RequestParams params = {0};
|
||||
if(request_data.size != 0)
|
||||
{
|
||||
U64 off = 0;
|
||||
off += str8_deserial_read_struct(request_data, off, &out_ring);
|
||||
off += str8_deserial_read_struct(request_data, off, ¶ms.id);
|
||||
off += str8_deserial_read_struct(request_data, off, ¶ms.method);
|
||||
off += str8_deserial_read_struct(request_data, off, ¶ms.url.size);
|
||||
params.url = str8_substr(request_data, r1u64(off, off+params.url.size));
|
||||
off += params.url.size;
|
||||
off += str8_deserial_read_struct(request_data, off, ¶ms.body.size);
|
||||
params.body = str8_substr(request_data, r1u64(off, off+params.body.size));
|
||||
off += params.body.size;
|
||||
off += str8_deserial_read_struct(request_data, off, ¶ms.user_agent.size);
|
||||
params.user_agent = str8_substr(request_data, r1u64(off, off+params.user_agent.size));
|
||||
off += params.user_agent.size;
|
||||
off += str8_deserial_read_struct(request_data, off, ¶ms.authorization.size);
|
||||
params.authorization = str8_substr(request_data, r1u64(off, off+params.authorization.size));
|
||||
off += params.authorization.size;
|
||||
off += str8_deserial_read_struct(request_data, off, ¶ms.content_type.size);
|
||||
params.content_type = str8_substr(request_data, r1u64(off, off+params.content_type.size));
|
||||
off += params.content_type.size;
|
||||
}
|
||||
|
||||
//- rjf: fill active request slot
|
||||
W32_HTTP_Request *req = 0;
|
||||
if(free_slot_num != 0 && request_data.size != 0)
|
||||
{
|
||||
req = &w32_http_state->active_requests[free_slot_num-1];
|
||||
req->active = 1;
|
||||
arena_clear(req->arena);
|
||||
req->out_ring = out_ring;
|
||||
req->id = params.id;
|
||||
req->status = W32_HTTP_RequestStatus_Null;
|
||||
}
|
||||
|
||||
//- rjf: kick off request
|
||||
if(req != 0)
|
||||
{
|
||||
B32 good = 0;
|
||||
|
||||
//- rjf: unpack
|
||||
HTTP_Method method = params.method;
|
||||
String8 url = params.url;
|
||||
String8 body = params.body;
|
||||
String8 user_agent = params.user_agent;
|
||||
String8 authorization = params.authorization;
|
||||
String8 content_type = params.content_type;
|
||||
|
||||
//- rjf: extract URL info
|
||||
String8 url_protocol_part = {0};
|
||||
String8 url_port_part = {0};
|
||||
String8 url_hostname_part = {0};
|
||||
String8 url_path_part = {0};
|
||||
{
|
||||
U64 protocol_delimiter_pos = str8_find_needle(url, 0, s("://"), 0);
|
||||
U64 post_protocol_pos = 0;
|
||||
if(protocol_delimiter_pos < url.size)
|
||||
{
|
||||
post_protocol_pos = protocol_delimiter_pos+3;
|
||||
url_protocol_part = str8_prefix(url, post_protocol_pos);
|
||||
}
|
||||
U64 last_colon_pos = str8_find_needle(url, post_protocol_pos, s(":"), 0);
|
||||
if(last_colon_pos < url.size)
|
||||
{
|
||||
url_port_part = str8_skip(url, last_colon_pos+1);
|
||||
}
|
||||
U64 first_non_protocol_slash_pos = str8_find_needle(url, post_protocol_pos, s("/"), 0);
|
||||
if(first_non_protocol_slash_pos < url.size)
|
||||
{
|
||||
url_hostname_part = str8_prefix(url, first_non_protocol_slash_pos);
|
||||
url_hostname_part = str8_skip(url_hostname_part, post_protocol_pos);
|
||||
url_path_part = str8_skip(url, first_non_protocol_slash_pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
url_hostname_part = str8_skip(url, post_protocol_pos);
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: convert url parts to connection parameters
|
||||
U16 port = INTERNET_DEFAULT_HTTPS_PORT;
|
||||
String16 hostname16 = {0};
|
||||
{
|
||||
if(url_port_part.size != 0)
|
||||
{
|
||||
port = (U16)u64_from_str8(url_port_part, 10);
|
||||
}
|
||||
else if(str8_match(url_protocol_part, s("https://"), StringMatchFlag_CaseInsensitive))
|
||||
{
|
||||
port = INTERNET_DEFAULT_HTTPS_PORT;
|
||||
}
|
||||
else if(str8_match(url_protocol_part, s("http://"), StringMatchFlag_CaseInsensitive))
|
||||
{
|
||||
port = INTERNET_DEFAULT_HTTP_PORT;
|
||||
}
|
||||
else if(str8_match(url_protocol_part, s("ftp://"), StringMatchFlag_CaseInsensitive))
|
||||
{
|
||||
port = 21;
|
||||
}
|
||||
else if(str8_match(url_protocol_part, s("ssh://"), StringMatchFlag_CaseInsensitive))
|
||||
{
|
||||
port = 22;
|
||||
}
|
||||
hostname16 = str16_from_8(scratch.arena, url_hostname_part);
|
||||
}
|
||||
|
||||
//- rjf: convert method to verb wchar
|
||||
WCHAR *verb = L"GET";
|
||||
switch(method)
|
||||
{
|
||||
default:
|
||||
case HTTP_Method_Get: {verb = L"GET";}break;
|
||||
case HTTP_Method_Head: {verb = L"HEAD";}break;
|
||||
case HTTP_Method_Post: {verb = L"POST";}break;
|
||||
case HTTP_Method_Put: {verb = L"PUT";}break;
|
||||
case HTTP_Method_Delete: {verb = L"DELETE";}break;
|
||||
case HTTP_Method_Connect: {verb = L"CONNECT";}break;
|
||||
case HTTP_Method_Options: {verb = L"OPTIONS";}break;
|
||||
case HTTP_Method_Trace: {verb = L"TRACE";}break;
|
||||
case HTTP_Method_Patch: {verb = L"PATCH";}break;
|
||||
}
|
||||
|
||||
//- rjf: convert url parts to request parameters
|
||||
WCHAR *path_name = L"";
|
||||
if(url_path_part.size != 0)
|
||||
{
|
||||
String16 url_path_part16 = str16_from_8(scratch.arena, url_path_part);
|
||||
path_name = (WCHAR *)url_path_part16.str;
|
||||
}
|
||||
|
||||
//- rjf: unpack body params
|
||||
String16 header16 = {0};
|
||||
{
|
||||
String8List header_strings = {0};
|
||||
if(user_agent.size != 0) { str8_list_pushf(scratch.arena, &header_strings, "User-Agent: %S\n", user_agent); }
|
||||
if(authorization.size != 0) { str8_list_pushf(scratch.arena, &header_strings, "Authorization: %S\n", authorization); }
|
||||
if(content_type.size != 0) { str8_list_pushf(scratch.arena, &header_strings, "Content-Type: %S\n", content_type); }
|
||||
String8 header = str8_list_join(scratch.arena, &header_strings, 0);
|
||||
header16 = str16_from_8(scratch.arena, header);
|
||||
}
|
||||
|
||||
//- rjf: convert body/header info to winhttp expected params
|
||||
WCHAR *header = WINHTTP_NO_ADDITIONAL_HEADERS;
|
||||
U64 header_size = 0;
|
||||
void *optional = WINHTTP_NO_REQUEST_DATA;
|
||||
U64 optional_size = 0;
|
||||
if(header16.size != 0)
|
||||
{
|
||||
header = (WCHAR *)header16.str;
|
||||
header_size = header16.size;
|
||||
}
|
||||
if(body.size != 0)
|
||||
{
|
||||
String8 body_copy = str8_copy(req->arena, body);
|
||||
optional = body_copy.str;
|
||||
optional_size = body_copy.size;
|
||||
}
|
||||
|
||||
//- rjf: open connection
|
||||
HINTERNET hConnect = 0;
|
||||
if(w32_http_state->hSession != 0)
|
||||
{
|
||||
hConnect = WinHttpConnect(w32_http_state->hSession, (WCHAR *)hostname16.str, port, 0);
|
||||
good = (hConnect != 0);
|
||||
}
|
||||
|
||||
//- rjf: open request
|
||||
HINTERNET hRequest = 0;
|
||||
if(good)
|
||||
{
|
||||
hRequest = WinHttpOpenRequest(hConnect, verb, path_name, 0, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE);
|
||||
good = (hRequest != 0);
|
||||
}
|
||||
|
||||
//- rjf: fill info
|
||||
if(good)
|
||||
{
|
||||
req->status = W32_HTTP_RequestStatus_PendingSend;
|
||||
}
|
||||
else
|
||||
{
|
||||
req->status = W32_HTTP_RequestStatus_Failed;
|
||||
}
|
||||
req->hConnect = hConnect;
|
||||
req->hRequest = hRequest;
|
||||
|
||||
//- rjf: send request
|
||||
if(good)
|
||||
{
|
||||
WinHttpSendRequest(hRequest, header, header_size, optional, optional_size, optional_size, (DWORD_PTR)req);
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
if(free_slot_num == 0 || request_data.size == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
lane_sync();
|
||||
|
||||
//- rjf: kick off receives
|
||||
{
|
||||
Rng1U64 range = lane_range(ArrayCount(w32_http_state->active_requests));
|
||||
for EachInRange(idx, range)
|
||||
{
|
||||
W32_HTTP_Request *req = &w32_http_state->active_requests[idx];
|
||||
if(req->active && ins_atomic_u32_eval(&req->status) == W32_HTTP_RequestStatus_Sent)
|
||||
{
|
||||
ins_atomic_u32_eval_assign(&req->status, W32_HTTP_RequestStatus_PendingRecv);
|
||||
WinHttpReceiveResponse(req->hRequest, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: kick off body size queries
|
||||
{
|
||||
Rng1U64 range = lane_range(ArrayCount(w32_http_state->active_requests));
|
||||
for EachInRange(idx, range)
|
||||
{
|
||||
W32_HTTP_Request *req = &w32_http_state->active_requests[idx];
|
||||
if(req->active && ins_atomic_u32_eval(&req->status) == W32_HTTP_RequestStatus_Recvd)
|
||||
{
|
||||
if(req->next_body_piece_size != 0)
|
||||
{
|
||||
str8_list_push(req->arena, &req->finished_body_pieces, str8((U8 *)req->next_body_piece, req->next_body_piece_size));
|
||||
}
|
||||
ins_atomic_u32_eval_assign(&req->status, W32_HTTP_RequestStatus_PendingDataSize);
|
||||
WinHttpQueryDataAvailable(req->hRequest, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: kick off body reads
|
||||
{
|
||||
Rng1U64 range = lane_range(ArrayCount(w32_http_state->active_requests));
|
||||
for EachInRange(idx, range)
|
||||
{
|
||||
W32_HTTP_Request *req = &w32_http_state->active_requests[idx];
|
||||
if(req->active && ins_atomic_u32_eval(&req->status) == W32_HTTP_RequestStatus_DataSized)
|
||||
{
|
||||
req->next_body_piece = push_array(req->arena, U8, req->next_body_piece_size);
|
||||
ins_atomic_u32_eval_assign(&req->status, W32_HTTP_RequestStatus_PendingRead);
|
||||
WinHttpReadData(req->hRequest, req->next_body_piece, req->next_body_piece_size, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: complete requests
|
||||
{
|
||||
Rng1U64 range = lane_range(ArrayCount(w32_http_state->active_requests));
|
||||
for EachInRange(idx, range)
|
||||
{
|
||||
W32_HTTP_Request *req = &w32_http_state->active_requests[idx];
|
||||
W32_HTTP_RequestStatus status = ins_atomic_u32_eval(&req->status);
|
||||
if(req->active &&
|
||||
(status == W32_HTTP_RequestStatus_Done ||
|
||||
status == W32_HTTP_RequestStatus_Failed))
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
B32 good = (status == W32_HTTP_RequestStatus_Done);
|
||||
|
||||
//- rjf: unpack
|
||||
HINTERNET hRequest = req->hRequest;
|
||||
|
||||
//- rjf: read response code
|
||||
HTTP_StatusCode code = 0;
|
||||
if(good)
|
||||
{
|
||||
DWORD status_code = 0;
|
||||
DWORD status_code_size = sizeof(status_code);
|
||||
WinHttpQueryHeaders(hRequest,
|
||||
WINHTTP_QUERY_STATUS_CODE|WINHTTP_QUERY_FLAG_NUMBER,
|
||||
WINHTTP_HEADER_NAME_BY_INDEX,
|
||||
&status_code, &status_code_size, WINHTTP_NO_HEADER_INDEX);
|
||||
code = status_code;
|
||||
}
|
||||
|
||||
//- rjf: serialize response
|
||||
String8 response_data = {0};
|
||||
U64 response_data_min_size = sizeof(U64) + sizeof(U64) + sizeof(HTTP_StatusCode) + sizeof(U64);
|
||||
U64 response_data_max_size = req->out_ring->ring->size;
|
||||
B32 response_is_possible = (response_data_min_size < response_data_max_size);
|
||||
if(response_is_possible)
|
||||
{
|
||||
U64 body_size = req->finished_body_pieces.total_size;
|
||||
String8List pieces = {0};
|
||||
str8_list_push(scratch.arena, &pieces, str8_struct(&req->id));
|
||||
str8_list_push(scratch.arena, &pieces, str8_struct(&code));
|
||||
str8_list_push(scratch.arena, &pieces, str8_struct(&body_size));
|
||||
str8_list_concat_in_place(&pieces, &req->finished_body_pieces);
|
||||
U64 data_size = pieces.total_size;
|
||||
str8_list_push_front(scratch.arena, &pieces, str8_struct(&data_size));
|
||||
if(data_size + sizeof(U64) > response_data_max_size)
|
||||
{
|
||||
U64 overkill = data_size + sizeof(U64) - response_data_max_size;
|
||||
data_size -= overkill;
|
||||
}
|
||||
response_data = str8_list_join(scratch.arena, &pieces, 0);
|
||||
response_data.size = data_size + sizeof(U64);
|
||||
}
|
||||
|
||||
//- rjf: write response
|
||||
if(response_is_possible)
|
||||
{
|
||||
RingGuard g = guarded_ring_open(req->out_ring);
|
||||
guarded_ring_write_string_or_wait(&g, response_data, max_U64);
|
||||
guarded_ring_close(&g);
|
||||
}
|
||||
|
||||
//- rjf: free this request slot
|
||||
req->active = 0;
|
||||
arena_clear(req->arena);
|
||||
MemoryZeroStruct(&req->finished_body_pieces);
|
||||
req->next_body_piece = 0;
|
||||
req->next_body_piece_size = 0;
|
||||
WinHttpCloseHandle(req->hConnect);
|
||||
WinHttpCloseHandle(req->hRequest);
|
||||
|
||||
scratch_end(scratch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: @per_os_impl I/O Ring Functions
|
||||
|
||||
internal B32
|
||||
http_push_request(GuardedRing *out_ring, HTTP_RequestParams *params, U64 endt_us)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
B32 result = 0;
|
||||
|
||||
// rjf: serialize
|
||||
String8 data = {0};
|
||||
{
|
||||
String8List pieces = {0};
|
||||
str8_list_push(scratch.arena, &pieces, str8_struct(&out_ring));
|
||||
str8_list_push(scratch.arena, &pieces, str8_struct(¶ms->id));
|
||||
str8_list_push(scratch.arena, &pieces, str8_struct(¶ms->method));
|
||||
str8_list_push(scratch.arena, &pieces, str8_struct(¶ms->url.size));
|
||||
str8_list_push(scratch.arena, &pieces, params->url);
|
||||
str8_list_push(scratch.arena, &pieces, str8_struct(¶ms->body.size));
|
||||
str8_list_push(scratch.arena, &pieces, params->body);
|
||||
str8_list_push(scratch.arena, &pieces, str8_struct(¶ms->user_agent.size));
|
||||
str8_list_push(scratch.arena, &pieces, params->user_agent);
|
||||
str8_list_push(scratch.arena, &pieces, str8_struct(¶ms->authorization.size));
|
||||
str8_list_push(scratch.arena, &pieces, params->authorization);
|
||||
str8_list_push(scratch.arena, &pieces, str8_struct(¶ms->content_type.size));
|
||||
str8_list_push(scratch.arena, &pieces, params->content_type);
|
||||
U64 data_size = pieces.total_size;
|
||||
str8_list_push_front(scratch.arena, &pieces, str8_struct(&data_size));
|
||||
data = str8_list_join(scratch.arena, &pieces, 0);
|
||||
}
|
||||
|
||||
// rjf: write
|
||||
if(data.size < w32_http_state->request_ring->ring->size)
|
||||
{
|
||||
RingGuard g = guarded_ring_open(w32_http_state->request_ring);
|
||||
result = guarded_ring_write_string_or_wait(&g, data, endt_us);
|
||||
guarded_ring_close(&g);
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal B32
|
||||
http_pop_response(Arena *arena, GuardedRing *out_ring, HTTP_Response *response_out, U64 endt_us)
|
||||
{
|
||||
U64 data_size = 0;
|
||||
RingGuard g = guarded_ring_open(out_ring);
|
||||
B32 result = guarded_ring_read_struct_or_wait(&g, &data_size, endt_us);
|
||||
if(result)
|
||||
{
|
||||
String8 data = {0};
|
||||
data.size = data_size;
|
||||
data.str = push_array(arena, U8, data.size);
|
||||
guarded_ring_read_or_wait(&g, data.size, data.str, max_U64);
|
||||
U64 off = 0;
|
||||
off += str8_deserial_read_struct(data, off, &response_out->id);
|
||||
off += str8_deserial_read_struct(data, off, &response_out->code);
|
||||
off += str8_deserial_read_struct(data, off, &response_out->body.size);
|
||||
response_out->body.str = push_array(arena, U8, response_out->body.size);
|
||||
off += str8_deserial_read(data, off, response_out->body.str, response_out->body.size, 1);
|
||||
}
|
||||
guarded_ring_close(&g);
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright (c) Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef WIN32_HTTP_H
|
||||
#define WIN32_HTTP_H
|
||||
|
||||
#include <winhttp.h>
|
||||
#pragma comment(lib, "winhttp")
|
||||
|
||||
typedef enum W32_HTTP_RequestStatus
|
||||
{
|
||||
W32_HTTP_RequestStatus_Null,
|
||||
W32_HTTP_RequestStatus_PendingSend,
|
||||
W32_HTTP_RequestStatus_Sent,
|
||||
W32_HTTP_RequestStatus_PendingRecv,
|
||||
W32_HTTP_RequestStatus_Recvd,
|
||||
W32_HTTP_RequestStatus_PendingDataSize,
|
||||
W32_HTTP_RequestStatus_DataSized,
|
||||
W32_HTTP_RequestStatus_PendingRead,
|
||||
W32_HTTP_RequestStatus_Done,
|
||||
W32_HTTP_RequestStatus_Failed,
|
||||
}
|
||||
W32_HTTP_RequestStatus;
|
||||
|
||||
typedef struct W32_HTTP_Request W32_HTTP_Request;
|
||||
struct W32_HTTP_Request
|
||||
{
|
||||
B32 active;
|
||||
Arena *arena;
|
||||
GuardedRing *out_ring;
|
||||
U64 id;
|
||||
W32_HTTP_RequestStatus status;
|
||||
HINTERNET hConnect;
|
||||
HINTERNET hRequest;
|
||||
void *optional; // NOTE(rjf): must persist with in-flight requests
|
||||
U64 optional_size;
|
||||
String8List finished_body_pieces;
|
||||
void *next_body_piece;
|
||||
U64 next_body_piece_size;
|
||||
};
|
||||
|
||||
typedef struct W32_HTTP_State W32_HTTP_State;
|
||||
struct W32_HTTP_State
|
||||
{
|
||||
Arena *arena;
|
||||
HINTERNET hSession;
|
||||
GuardedRing *request_ring;
|
||||
W32_HTTP_Request active_requests[16];
|
||||
};
|
||||
|
||||
global W32_HTTP_State *w32_http_state = 0;
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Status Callback
|
||||
|
||||
internal void w32_http_status_callback(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus, void *lpvStatusInformation, DWORD dwStatusInformationLength);
|
||||
|
||||
#endif // WIN32_HTTP_H
|
||||
@@ -0,0 +1,114 @@
|
||||
// Copyright (c) Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
internal void
|
||||
smsv_init(void)
|
||||
{
|
||||
Arena *arena = arena_alloc();
|
||||
w32_smsv_state = push_array(arena, W32_SMSV_State, 1);
|
||||
w32_smsv_state->arena = arena;
|
||||
{
|
||||
// rjf: extract parameterizations from _NT_SYMBOL_PATH
|
||||
{
|
||||
// rjf: get rules string from environment
|
||||
String8 rules = {0};
|
||||
for EachNode(n, String8Node, get_process_info()->environment.first)
|
||||
{
|
||||
String8 string = n->string;
|
||||
if(str8_match(string, s("_NT_SYMBOL_PATH="), StringMatchFlag_RightSideSloppy))
|
||||
{
|
||||
rules = str8_skip(string, 16);
|
||||
}
|
||||
}
|
||||
|
||||
// rjf: parse rules string
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
if(str8_match(rules, s("srv*"), StringMatchFlag_RightSideSloppy))
|
||||
{
|
||||
String8List parts = str8_split(scratch.arena, rules, (U8 *)"*", 1, 0);
|
||||
for EachNode(n, String8Node, parts.first)
|
||||
{
|
||||
PathStyle style = path_style_from_str8(n->string);
|
||||
if(w32_smsv_state->symbol_cache_path.size != 0 && style == PathStyle_WindowsAbsolute)
|
||||
{
|
||||
w32_smsv_state->symbol_cache_path = n->string;
|
||||
}
|
||||
else if(str8_match(n->string, s("https://"), StringMatchFlag_RightSideSloppy) ||
|
||||
str8_match(n->string, s("http://"), StringMatchFlag_RightSideSloppy))
|
||||
{
|
||||
str8_list_push(arena, &w32_smsv_state->symbol_server_urls, n->string);
|
||||
}
|
||||
else if(str8_match(n->string, s("\\\\"), StringMatchFlag_RightSideSloppy))
|
||||
{
|
||||
// TODO(rjf): network share; currently unsupported
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
w32_smsv_state->symbol_cache_path = str8_skip_chop_whitespace(rules);
|
||||
}
|
||||
scratch_end(scratch);
|
||||
}
|
||||
}
|
||||
|
||||
// rjf: always fall back to public MS server
|
||||
{
|
||||
String8 public_ms_server = s("https://msdl.microsoft.com/download/symbols");
|
||||
B32 public_ms_server_already_present = 0;
|
||||
for EachNode(n, String8Node, w32_smsv_state->symbol_server_urls.first)
|
||||
{
|
||||
if(str8_match(public_ms_server, n->string, 0))
|
||||
{
|
||||
public_ms_server_already_present = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!public_ms_server_already_present)
|
||||
{
|
||||
str8_list_push(arena, &w32_smsv_state->symbol_server_urls, public_ms_server);
|
||||
}
|
||||
}
|
||||
|
||||
// rjf fall back to using local appdata temp symbol cache folder
|
||||
if(w32_smsv_state->symbol_cache_path.size == 0)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
U64 size = KB(32);
|
||||
U16 *buffer = push_array_no_zero(scratch.arena, U16, size);
|
||||
if(SUCCEEDED(SHGetFolderPathW(0, CSIDL_LOCAL_APPDATA, 0, 0, (WCHAR*)buffer)))
|
||||
{
|
||||
String8 local_appdata = str8_from_16(scratch.arena, str16_cstring(buffer));
|
||||
w32_smsv_state->symbol_cache_path = str8f(arena, "%S\\Temp\\SymbolCache", local_appdata);
|
||||
}
|
||||
scratch_end(scratch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal String8
|
||||
smsv_local_path_from_key(Arena *arena, String8 module_name, String8 dbg_name, Guid guid, U64 age)
|
||||
{
|
||||
String8 result = {0};
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
{
|
||||
// rjf: form unique identifier based on guid
|
||||
String8 debug_info_unique_identifier = {0};
|
||||
{
|
||||
debug_info_unique_identifier = str8f(scratch.arena, "%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X%x",
|
||||
guid.data1, guid.data2, guid.data3, guid.data4[0], guid.data4[1], guid.data4[2], guid.data4[3], guid.data4[4], guid.data4[5], guid.data4[6], guid.data4[7], age);
|
||||
}
|
||||
|
||||
// rjf: form full path
|
||||
if(debug_info_unique_identifier.size != 0)
|
||||
{
|
||||
// TODO(rjf): assuming 'stripped' for now
|
||||
String8 symbol_cache_path = w32_smsv_state->symbol_cache_path;
|
||||
String8 path = str8f(scratch.arena, "%S/%S/%S/stripped/%S", symbol_cache_path, module_name, debug_info_unique_identifier, dbg_name);
|
||||
result = path_normalized_from_string(arena, path);
|
||||
}
|
||||
}
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef WIN32_SYMBOL_SERVER_H
|
||||
#define WIN32_SYMBOL_SERVER_H
|
||||
|
||||
typedef struct W32_SMSV_State W32_SMSV_State;
|
||||
struct W32_SMSV_State
|
||||
{
|
||||
Arena *arena;
|
||||
String8 symbol_cache_path;
|
||||
String8List symbol_server_urls;
|
||||
};
|
||||
|
||||
global W32_SMSV_State *w32_smsv_state = 0;
|
||||
|
||||
#endif // WIN32_SYMBOL_SERVER_H
|
||||
Reference in new issue
Block a user