lsteamclient: Return all struct abis from find_struct.

CW-Bug-Id: #22729
This commit is contained in:
Rémi Bernon 2023-09-21 22:13:09 +02:00 committed by Arkadiusz Hiler
parent c5a4bc1729
commit 9bf3f81987

View File

@ -611,10 +611,12 @@ def canonical_typename(cursor):
return name.removeprefix("const ") return name.removeprefix("const ")
def find_struct(struct, abi): def find_struct_abis(name):
name = canonical_typename(struct) records = all_records[sdkver]
ret = all_records[sdkver][abi].get(name, None) missing = [name not in records[abi] for abi in ABIS]
return ret.type if ret else None assert all(missing) or not any(missing)
if any(missing): return None
return {abi: records[abi][name].type for abi in ABIS}
def struct_needs_conversion_nocache(struct): def struct_needs_conversion_nocache(struct):
@ -624,37 +626,37 @@ def struct_needs_conversion_nocache(struct):
if name in MANUAL_STRUCTS: if name in MANUAL_STRUCTS:
return True return True
#check 32-bit compat abis = find_struct_abis(name)
windows_struct = find_struct(struct, 'w32') if abis is None:
if windows_struct is None: return False
print("Couldn't find windows struct for " + struct.spelling)
assert(not windows_struct is None) #must find windows_struct
for field in struct.get_fields():
if struct.get_offset(field.spelling) != windows_struct.get_offset(field.spelling):
return True
if field.type.kind == TypeKind.RECORD and \
struct_needs_conversion(field.type):
return True
#check 64-bit compat names = {a: [f.spelling for f in abis[a].get_fields()]
windows_struct = find_struct(struct, 'w64') for a in ABIS}
assert(not windows_struct is None) #must find windows_struct assert names['u32'] == names['u64']
lin64_struct = find_struct(struct, 'u64') assert names['u32'] == names['w32']
assert names['u32'] == names['w64']
assert(not lin64_struct is None) #must find lin64_struct offsets = {a: {f: abis[a].get_offset(f) for f in names[a]}
for field in lin64_struct.get_fields(): for a in ABIS}
if lin64_struct.get_offset(field.spelling) != windows_struct.get_offset(field.spelling): if offsets['u32'] != offsets['w32']:
return True return True
if field.type.kind == TypeKind.RECORD and \ if offsets['u64'] != offsets['w64']:
struct_needs_conversion(field.type): return True
return True
#check if any members need path conversion types = {a: [f.type.get_canonical() for f in abis[a].get_fields()]
path_conv = get_path_converter(struct) for a in ABIS}
if path_conv: if any(t.kind == TypeKind.RECORD and struct_needs_conversion(t)
for t in types['u32']):
return True
if any(t.kind == TypeKind.RECORD and struct_needs_conversion(t)
for t in types['u64']):
return True
if get_path_converter(struct):
return True return True
return False return False
def struct_needs_conversion(struct): def struct_needs_conversion(struct):
name = canonical_typename(struct) name = canonical_typename(struct)
if not sdkver in struct_conversion_cache: if not sdkver in struct_conversion_cache:
@ -1018,14 +1020,9 @@ cb_table = {}
cb_table64 = {} cb_table64 = {}
def get_field_attribute_str(field): def get_field_attribute_str(field):
if field.type.kind != TypeKind.RECORD: if field.type.kind != TypeKind.RECORD: return ""
return "" name = canonical_typename(field)
win_struct = find_struct(field, 'w32') return f" __attribute__((aligned({find_struct_abis(name)['w32'].get_align()})))"
if win_struct is None:
align = field.type.get_align()
else:
align = win_struct.get_align()
return " __attribute__((aligned(" + str(align) + ")))"
#because of struct packing differences between win32 and linux, we #because of struct packing differences between win32 and linux, we
#need to convert these structs from their linux layout to the win32 #need to convert these structs from their linux layout to the win32
@ -1099,14 +1096,14 @@ def handle_struct(sdkver, struct):
hfile.write("#endif\n\n") hfile.write("#endif\n\n")
else: else:
#for callbacks, we use the windows struct size in the cb dispatch switch #for callbacks, we use the windows struct size in the cb dispatch switch
windows_struct = find_struct(struct, 'w32') name = canonical_typename(struct)
windows_struct64 = find_struct(struct, 'w64') abis = find_struct_abis(name)
struct64 = find_struct(struct, 'u64') size = {a: abis[a].get_size() for a in abis.keys()}
struct_name = f"{struct.displayname}_{windows_struct.get_size()}" struct_name = f"{struct.displayname}_{size['w32']}"
l2w_handler_name = f"cb_{struct_name}" l2w_handler_name = f"cb_{struct_name}"
if windows_struct64.get_size() != windows_struct.get_size(): if size['w64'] != size['w32']:
struct_name64 = f"{struct.displayname}_{windows_struct64.get_size()}" struct_name64 = f"{struct.displayname}_{size['w64']}"
l2w_handler_name64 = f"cb_{struct_name64}" l2w_handler_name64 = f"cb_{struct_name64}"
else: else:
l2w_handler_name64 = None l2w_handler_name64 = None
@ -1116,8 +1113,8 @@ def handle_struct(sdkver, struct):
if not struct_needs_conversion(struct.type): if not struct_needs_conversion(struct.type):
return return
cb_id = cb_num | (struct.type.get_size() << 16) cb_id = cb_num | (size['u32'] << 16)
cb_id64 = cb_num | (struct64.get_size() << 16) cb_id64 = cb_num | (size['u64'] << 16)
if cb_id in generated_cb_ids: if cb_id in generated_cb_ids:
# either this cb changed name, or steam used the same ID for different structs # either this cb changed name, or steam used the same ID for different structs
return return
@ -1127,29 +1124,29 @@ def handle_struct(sdkver, struct):
datfile = open("cb_converters.dat", "a") datfile = open("cb_converters.dat", "a")
if l2w_handler_name64: if l2w_handler_name64:
datfile.write("#ifdef __i386__\n") datfile.write("#ifdef __i386__\n")
datfile.write(f"case 0x{cb_id:08x}: win_msg->m_cubParam = {windows_struct.get_size()}; win_msg->m_pubParam = HeapAlloc(GetProcessHeap(), 0, win_msg->m_cubParam); {l2w_handler_name}((void*)lin_msg.m_pubParam, (void*)win_msg->m_pubParam); break;\n") datfile.write(f"case 0x{cb_id:08x}: win_msg->m_cubParam = {size['w32']}; win_msg->m_pubParam = HeapAlloc(GetProcessHeap(), 0, win_msg->m_cubParam); {l2w_handler_name}((void*)lin_msg.m_pubParam, (void*)win_msg->m_pubParam); break;\n")
datfile.write("#endif\n") datfile.write("#endif\n")
datfile.write("#ifdef __x86_64__\n") datfile.write("#ifdef __x86_64__\n")
datfile.write(f"case 0x{cb_id64:08x}: win_msg->m_cubParam = {windows_struct64.get_size()}; win_msg->m_pubParam = HeapAlloc(GetProcessHeap(), 0, win_msg->m_cubParam); {l2w_handler_name64}((void*)lin_msg.m_pubParam, (void*)win_msg->m_pubParam); break;\n") datfile.write(f"case 0x{cb_id64:08x}: win_msg->m_cubParam = {size['w64']}; win_msg->m_pubParam = HeapAlloc(GetProcessHeap(), 0, win_msg->m_cubParam); {l2w_handler_name64}((void*)lin_msg.m_pubParam, (void*)win_msg->m_pubParam); break;\n")
datfile.write("#endif\n") datfile.write("#endif\n")
else: else:
datfile.write(f"case 0x{cb_id:08x}: win_msg->m_cubParam = {windows_struct.get_size()}; win_msg->m_pubParam = HeapAlloc(GetProcessHeap(), 0, win_msg->m_cubParam); {l2w_handler_name}((void*)lin_msg.m_pubParam, (void*)win_msg->m_pubParam); break;\n") datfile.write(f"case 0x{cb_id:08x}: win_msg->m_cubParam = {size['w32']}; win_msg->m_pubParam = HeapAlloc(GetProcessHeap(), 0, win_msg->m_cubParam); {l2w_handler_name}((void*)lin_msg.m_pubParam, (void*)win_msg->m_pubParam); break;\n")
generated_cb_handlers.append(l2w_handler_name) generated_cb_handlers.append(l2w_handler_name)
if not cb_num in cb_table.keys(): if not cb_num in cb_table.keys():
# latest SDK linux size, list of windows struct sizes and names # latest SDK linux size, list of windows struct sizes and names
cb_table[cb_num] = (struct.type.get_size(), []) cb_table[cb_num] = (size['u32'], [])
if l2w_handler_name64: if l2w_handler_name64:
cb_table64[cb_num] = (struct64.get_size(), []) cb_table64[cb_num] = (size['u64'], [])
else: else:
cb_table64[cb_num] = (struct.type.get_size(), []) cb_table64[cb_num] = (size['u32'], [])
cb_table[cb_num][1].append((windows_struct.get_size(), struct_name)) cb_table[cb_num][1].append((size['w32'], struct_name))
if l2w_handler_name64: if l2w_handler_name64:
cb_table64[cb_num][1].append((windows_struct64.get_size(), struct_name64)) cb_table64[cb_num][1].append((size['w64'], struct_name64))
else: else:
cb_table64[cb_num][1].append((windows_struct.get_size(), struct_name)) cb_table64[cb_num][1].append((size['w32'], struct_name))
hfile = open("cb_converters.h", "a") hfile = open("cb_converters.h", "a")
hfile.write(f"struct {struct.displayname};\n") hfile.write(f"struct {struct.displayname};\n")