<filename>core/exports.py
#!/usr/bin/env python
import glob
import sys
import subprocess
import re 
import os

# Exports symbols for client kernel modules to use.

# TODO(peter): I copied this function from debugging/setup_gdb.py. This code
# should be unified.
def check_open(args):
    popen = subprocess.Popen(args, stdout=subprocess.PIPE)
    result = popen.communicate()[0]
    assert popen.returncode == 0
    return result

def excluded_functions():
    return set(["dr_get_app_PEB",
                "instr_exit_stub_code",
                "dr_syscall_get_result",
                "dr_is_wow64",
                "dr_create_client_thread",
                "dr_syscall_get_param",
                "instr_branch_targets_prefix",
                "INSTR_CREATE_nop2byte_reg",
                "dr_get_stdin_file",
                "dr_add_prefixes_to_basic_blocks",
                "instr_branch_set_prefix_target",
                "instr_set_exit_stub_code",
                "opnd_get_immed_float",
                "dr_client_thread_set_suspendable",
                "dr_syscall_invoke_another",
                "dr_get_stdout_file",
                "dr_syscall_set_sysnum",
                "dr_syscall_set_result",
                "dr_syscall_set_param",
                "dr_get_stderr_file"])

def extra_symbols():
    return set(['our_stderr',
                'our_stdout',
                'depth_first_traverse_page_table',
                'page_table_get_region',
                'follow_page_table_entry',
                'get_l4_page_table',
                'page_table_get_page',
                'page_table_get_physical_address',
                'page_table_get_region',
                'page_table_readable_without_exception',
                'page_table_writable_without_exception',
                'traverse_page_table',
                'traverse_page_table_contiguous',
                ])

def main():
    assert len(sys.argv) == 2
    functions = set()
    for path in glob.glob('%s/*.h' % sys.argv[1]):
        code = check_open(('cpp -DX86_64 -DLINUX -DLINUX_KERNEL %s' % path).split())
        for match in re.findall('(^[a-zA-Z0-9_]+)(\(.*)$', code, re.MULTILINE):
            functions.add(match[0])
    # This is a dirty hack. We don't export certain functions that aren't #
    # implemented. The lib/genapi.pl script should probably be modified to not include
    # functions that are IFDEF'd out.
    functions.difference_update(excluded_functions())
    functions.update(extra_symbols())
    print '/* This file was automatically generated by %s. */' % os.path.abspath(sys.argv[0])
    print '#include <linux/module.h>'
    for function in functions:
        print 'extern void *%s;' % function
        print 'EXPORT_SYMBOL_GPL(%s);' % function

    #cpp -DX86_64 -DLINUX -DLINUX_KERNEL

if __name__ == '__main__':
    main()


<filename>core/exports.py
#!/usr/bin/env python
import glob
import sys
import subprocess
import re 
import os

# Exports symbols for client kernel modules to use.

# TODO(peter): I copied this function from debugging/setup_gdb.py. This code
# should be unified.
def check_open(args):
    popen = subprocess.Popen(args, stdout=subprocess.PIPE)
    result = popen.communicate()[0]
    assert popen.returncode == 0
    return result

def excluded_functions():
    return set(["dr_get_app_PEB",
                "instr_exit_stub_code",
                "dr_syscall_get_result",
                "dr_is_wow64",
                "dr_create_client_thread",
                "dr_syscall_get_param",
                "instr_branch_targets_prefix",
                "INSTR_CREATE_nop2byte_reg",
                "dr_get_stdin_file",
                "dr_add_prefixes_to_basic_blocks",
                "instr_branch_set_prefix_target",
                "instr_set_exit_stub_code",
                "opnd_get_immed_float",
                "dr_client_thread_set_suspendable",
                "dr_syscall_invoke_another",
                "dr_get_stdout_file",
                "dr_syscall_set_sysnum",
                "dr_syscall_set_result",
                "dr_syscall_set_param",
                "dr_get_stderr_file"])

def extra_symbols():
    return set(['our_stderr',
                'our_stdout',
                'depth_first_traverse_page_table',
                'page_table_get_region',
                'follow_page_table_entry',
                'get_l4_page_table',
                'page_table_get_page',
                'page_table_get_physical_address',
                'page_table_get_region',
                'page_table_readable_without_exception',
                'page_table_writable_without_exception',
                'traverse_page_table',
                'traverse_page_table_contiguous',
                ])

def main():
    assert len(sys.argv) == 2
    functions = set()
    for path in glob.glob('%s/*.h' % sys.argv[1]):
        code = check_open(('cpp -DX86_64 -DLINUX -DLINUX_KERNEL %s' % path).split())
        for match in re.findall('(^[a-zA-Z0-9_]+)(\(.*)$', code, re.MULTILINE):
            functions.add(match[0])
    # This is a dirty hack. We don't export certain functions that aren't #
    # implemented. The lib/genapi.pl script should probably be modified to not include
    # functions that are IFDEF'd out.
    functions.difference_update(excluded_functions())
    functions.update(extra_symbols())
    print '/* This file was automatically generated by %s. */' % os.path.abspath(sys.argv[0])
    print '#include <linux/module.h>'
    for function in functions:
        print 'extern void *%s;' % function
        print 'EXPORT_SYMBOL_GPL(%s);' % function

    #cpp -DX86_64 -DLINUX -DLINUX_KERNEL

if __name__ == '__main__':
    main()


#!/usr/bin/env python # Exports symbols for client kernel modules to use. # TODO(peter): I copied this function from debugging/setup_gdb.py. This code # should be unified. # This is a dirty hack. We don't export certain functions that aren't # # implemented. The lib/genapi.pl script should probably be modified to not include # functions that are IFDEF'd out. #cpp -DX86_64 -DLINUX -DLINUX_KERNEL