vrclient: 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
parent 3a7b436f7a
commit eaf6d83cf1

View file

@ -820,46 +820,53 @@ 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):
needs_size_adjustment = False name = canonical_typename(struct)
#check 32-bit compat abis = find_struct_abis(name)
windows_struct = find_struct(struct, 'w32') if abis is None:
assert(not windows_struct is None) #must find windows_struct return False, False
for field in struct.get_fields():
if struct.get_offset(field.spelling) != windows_struct.get_offset(field.spelling):
return True, False
if field.type.get_canonical().kind == TypeKind.RECORD and \
struct_needs_conversion(field.type.get_canonical()):
return True, False
assert(struct.get_size() <= windows_struct.get_size()) names = {a: [f.spelling for f in abis[a].get_fields()]
if struct.get_size() < windows_struct.get_size(): for a in ABIS}
needs_size_adjustment = True assert names['u32'] == names['u64']
assert names['u32'] == names['w32']
assert names['u32'] == names['w64']
#check 64-bit compat offsets = {a: {f: abis[a].get_offset(f) for f in names[a]}
windows_struct = find_struct(struct, 'w64') for a in ABIS}
assert(not windows_struct is None) #must find windows_struct if offsets['u32'] != offsets['w32']:
lin64_struct = find_struct(struct, 'u64') return True, False
assert(not lin64_struct is None) #must find lin64_struct if offsets['u64'] != offsets['w64']:
for field in lin64_struct.get_fields(): return True, False
if lin64_struct.get_offset(field.spelling) != windows_struct.get_offset(field.spelling):
return True, False
if field.type.get_canonical().kind == TypeKind.RECORD and \
struct_needs_conversion(field.type.get_canonical()):
return True, False
assert(lin64_struct.get_size() <= windows_struct.get_size()) types = {a: [f.type.get_canonical() for f in abis[a].get_fields()]
if lin64_struct.get_size() < windows_struct.get_size(): for a in ABIS}
needs_size_adjustment = True if any(t.kind == TypeKind.RECORD and struct_needs_conversion(t)
for t in types['u32']):
return True, False
if any(t.kind == TypeKind.RECORD and struct_needs_conversion(t)
for t in types['u64']):
return True, False
assert abis['u32'].get_size() <= abis['w32'].get_size()
if abis['u32'].get_size() < abis['w32'].get_size():
return False, True
assert abis['u64'].get_size() <= abis['w64'].get_size()
if abis['u64'].get_size() < abis['w64'].get_size():
return False, True
return False, False
return False, needs_size_adjustment
def struct_needs_conversion(struct): def struct_needs_conversion(struct):
name = canonical_typename(struct) name = canonical_typename(struct)
@ -883,8 +890,9 @@ def get_field_attribute_str(field):
ftype = field.type.get_canonical() ftype = field.type.get_canonical()
if ftype.kind != TypeKind.RECORD: if ftype.kind != TypeKind.RECORD:
return "" return ""
win_struct = find_struct(ftype, 'w32') name = canonical_typename(ftype)
align = win_struct.get_align() abis = find_struct_abis(name)
align = abis['w32'].get_align()
return " __attribute__((aligned(" + str(align) + ")))" return " __attribute__((aligned(" + str(align) + ")))"
generated_struct_handlers = [] generated_struct_handlers = []