Exemplo n.º 1
0
def wrap_struct(syscall_name, i, ctype, param_ctypes):
  global STRUCT_WRAPPERS
  global ARRAY_CTYPES

  ctype_printed = pretty_print_type(ctype)
  if make_struct_wrapper(ctype, ctype_printed):
    array_key = (syscall_name, ctype.name)
    if array_key in ARRAY_CTYPES:
      j = ARRAY_CTYPES[array_key] + i
      return wrap_array_of_struct(ctype_printed,
                                  pretty_print_type(param_ctypes[j]), i, j)
    else:
      return "WRAP_SYSCALL_ARG_PSTRUCT(%d, %s)" % (i,ctype_printed)
  else:
    return wrap_pointer(i)
Exemplo n.º 2
0
def wrap_struct(syscall_name, i, ctype, param_ctypes):
    global STRUCT_WRAPPERS
    global ARRAY_CTYPES

    ctype_printed = pretty_print_type(ctype)
    if make_struct_wrapper(ctype, ctype_printed):
        array_key = (syscall_name, ctype.name)
        if array_key in ARRAY_CTYPES:
            j = ARRAY_CTYPES[array_key] + i
            return wrap_array_of_struct(ctype_printed,
                                        pretty_print_type(param_ctypes[j]), i,
                                        j)
        else:
            return "WRAP_SYSCALL_ARG_PSTRUCT(%d, %s)" % (i, ctype_printed)
    else:
        return wrap_pointer(i)
Exemplo n.º 3
0
def make_struct_wrapper(ctype, ctype_printed):
    global STRUCT_WRAPPERS
    global ARRAY_CTYPES

    if ctype in STRUCT_WRAPPERS:
        return STRUCT_WRAPPERS[ctype]

    actions = []
    for (field_ctype, field_name) in ctype.fields():
        field_ctype = field_ctype.base_type()
        if isinstance(field_ctype, CTypePointer) \
        and not is_function_pointer(field_ctype):
            # Establish a base case, just in case we get `A.x -> ... -> A` and loop
            # infinitely when trying to generate a struct wrapper for `A`.
            STRUCT_WRAPPERS[ctype] = True

            # Try to see if we explicitly recognize this structure field as being
            # a pointer to an array of structures, where the size of the array is
            # defined by another field in `ctype`.
            array_key = (ctype_printed, field_name)
            if array_key in ARRAY_CTYPES:
                len_field = ARRAY_CTYPES[array_key]
                field_ptype = field_ctype.ctype.base_type()
                is_struct = make_struct_wrapper(field_ptype,
                                                pretty_print_type(field_ptype))
                assert is_struct
                actions.append("WRAP_STRUCT_ASTRUCT(%s,%s)" %
                               (field_name, len_field))

            # Just a regular pointer field.
            else:
                actions.append("WRAP_STRUCT_PFIELD(%s)" % field_name)

    if actions:
        print "WRAP_STRUCT(%s,%s)" % (ctype_printed, ";".join(actions))
        return True
    else:
        STRUCT_WRAPPERS[ctype] = False
        return False
Exemplo n.º 4
0
def make_struct_wrapper(ctype, ctype_printed):
  global STRUCT_WRAPPERS
  global ARRAY_CTYPES

  if ctype in STRUCT_WRAPPERS:
    return STRUCT_WRAPPERS[ctype]

  actions = []
  for (field_ctype, field_name) in ctype.fields():
    field_ctype = field_ctype.base_type()
    if isinstance(field_ctype, CTypePointer) \
    and not is_function_pointer(field_ctype):
      # Establish a base case, just in case we get `A.x -> ... -> A` and loop
      # infinitely when trying to generate a struct wrapper for `A`.
      STRUCT_WRAPPERS[ctype] = True

      # Try to see if we explicitly recognize this structure field as being
      # a pointer to an array of structures, where the size of the array is
      # defined by another field in `ctype`.
      array_key = (ctype_printed, field_name)
      if array_key in ARRAY_CTYPES:
        len_field = ARRAY_CTYPES[array_key]
        field_ptype = field_ctype.ctype.base_type()
        is_struct = make_struct_wrapper(field_ptype,
                                        pretty_print_type(field_ptype))
        assert is_struct
        actions.append("WRAP_STRUCT_ASTRUCT(%s,%s)" % (field_name,len_field))

      # Just a regular pointer field.
      else:
        actions.append("WRAP_STRUCT_PFIELD(%s)" % field_name)

  if actions:
    print "WRAP_STRUCT(%s,%s)" % (ctype_printed, ";".join(actions))
    return True
  else:
    STRUCT_WRAPPERS[ctype] = False
    return False