ctf_open.c (256281) | ctf_open.c (268578) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * --- 11 unchanged lines hidden (view full) --- 20 * CDDL HEADER END 21 */ 22 23/* 24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 25 * Use is subject to license terms. 26 */ 27/* | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * --- 11 unchanged lines hidden (view full) --- 20 * CDDL HEADER END 21 */ 22 23/* 24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 25 * Use is subject to license terms. 26 */ 27/* |
28 * Copyright (c) 2012, Joyent, Inc. All rights reserved. | 28 * Copyright (c) 2013, Joyent, Inc. All rights reserved. |
29 */ 30 31#include <ctf_impl.h> 32#include <sys/mman.h> 33#include <sys/zmod.h> 34 35static const ctf_dmodel_t _libctf_models[] = { 36 { "ILP32", CTF_MODEL_ILP32, 4, 1, 2, 4, 4 }, --- 746 unchanged lines hidden (view full) --- 783 return (fp); 784 785bad: 786 ctf_close(fp); 787 return (NULL); 788} 789 790/* | 29 */ 30 31#include <ctf_impl.h> 32#include <sys/mman.h> 33#include <sys/zmod.h> 34 35static const ctf_dmodel_t _libctf_models[] = { 36 { "ILP32", CTF_MODEL_ILP32, 4, 1, 2, 4, 4 }, --- 746 unchanged lines hidden (view full) --- 783 return (fp); 784 785bad: 786 ctf_close(fp); 787 return (NULL); 788} 789 790/* |
791 * Dupliate a ctf_file_t and its underlying section information into a new 792 * container. This works by copying the three ctf_sect_t's of the original 793 * container if they exist and passing those into ctf_bufopen. To copy those, we 794 * mmap anonymous memory with ctf_data_alloc and bcopy the data across. It's not 795 * the cheapest thing, but it's what we've got. 796 */ 797ctf_file_t * 798ctf_dup(ctf_file_t *ofp) 799{ 800 ctf_file_t *fp; 801 ctf_sect_t ctfsect, symsect, strsect; 802 ctf_sect_t *ctp, *symp, *strp; 803 void *cbuf, *symbuf, *strbuf; 804 int err; 805 806 cbuf = symbuf = strbuf = NULL; 807 /* 808 * The ctfsect isn't allowed to not exist, but the symbol and string 809 * section might not. We only need to copy the data of the section, not 810 * the name, as ctf_bufopen will take care of that. 811 */ 812 bcopy(&ofp->ctf_data, &ctfsect, sizeof (ctf_sect_t)); 813 cbuf = ctf_data_alloc(ctfsect.cts_size); 814 if (cbuf == NULL) { 815 (void) ctf_set_errno(ofp, ECTF_MMAP); 816 return (NULL); 817 } 818 819 bcopy(ctfsect.cts_data, cbuf, ctfsect.cts_size); 820 ctf_data_protect(cbuf, ctfsect.cts_size); 821 ctfsect.cts_data = cbuf; 822 ctfsect.cts_offset = 0; 823 ctp = &ctfsect; 824 825 if (ofp->ctf_symtab.cts_data != NULL) { 826 bcopy(&ofp->ctf_symtab, &symsect, sizeof (ctf_sect_t)); 827 symbuf = ctf_data_alloc(symsect.cts_size); 828 if (symbuf == NULL) { 829 (void) ctf_set_errno(ofp, ECTF_MMAP); 830 goto err; 831 } 832 bcopy(symsect.cts_data, symbuf, symsect.cts_size); 833 ctf_data_protect(symbuf, symsect.cts_size); 834 symsect.cts_data = symbuf; 835 symsect.cts_offset = 0; 836 symp = &symsect; 837 } else { 838 symp = NULL; 839 } 840 841 if (ofp->ctf_strtab.cts_data != NULL) { 842 bcopy(&ofp->ctf_strtab, &strsect, sizeof (ctf_sect_t)); 843 strbuf = ctf_data_alloc(strsect.cts_size); 844 if (strbuf == NULL) { 845 (void) ctf_set_errno(ofp, ECTF_MMAP); 846 goto err; 847 } 848 bcopy(strsect.cts_data, strbuf, strsect.cts_size); 849 ctf_data_protect(strbuf, strsect.cts_size); 850 strsect.cts_data = strbuf; 851 strsect.cts_offset = 0; 852 strp = &strsect; 853 } else { 854 strp = NULL; 855 } 856 857 fp = ctf_bufopen(ctp, symp, strp, &err); 858 if (fp == NULL) { 859 (void) ctf_set_errno(ofp, err); 860 goto err; 861 } 862 863 fp->ctf_flags |= LCTF_MMAP; 864 865 return (fp); 866 867err: 868 ctf_data_free(cbuf, ctfsect.cts_size); 869 if (symbuf != NULL) 870 ctf_data_free(symbuf, symsect.cts_size); 871 if (strbuf != NULL) 872 ctf_data_free(strbuf, strsect.cts_size); 873 return (NULL); 874} 875 876/* |
|
791 * Close the specified CTF container and free associated data structures. Note 792 * that ctf_close() is a reference counted operation: if the specified file is 793 * the parent of other active containers, its reference count will be greater 794 * than one and it will be freed later when no active children exist. 795 */ 796void 797ctf_close(ctf_file_t *fp) 798{ --- 161 unchanged lines hidden --- | 877 * Close the specified CTF container and free associated data structures. Note 878 * that ctf_close() is a reference counted operation: if the specified file is 879 * the parent of other active containers, its reference count will be greater 880 * than one and it will be freed later when no active children exist. 881 */ 882void 883ctf_close(ctf_file_t *fp) 884{ --- 161 unchanged lines hidden --- |