12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 1988 AT&T
29 * All Rights Reserved
30 */
31
32 #include <memory.h>
33 #include <malloc.h>
34 #include <limits.h>
35
36 #include <sgs.h>
37 #include "decl.h"
38 #include "msg.h"
39
40 /*
41 * This module is compiled twice, the second time having
42 * -D_ELF64 defined. The following set of macros, along
43 * with machelf.h, represent the differences between the
44 * two compilations. Be careful *not* to add any class-
45 * dependent code (anything that has elf32 or elf64 in the
46 * name) to this code without hiding it behind a switch-
47 * able macro like these.
48 */
49 #if defined(_ELF64)
50
51 #define FSZ_LONG ELF64_FSZ_XWORD
726 * storage. If the elf descriptor does not have a valid
727 * file descriptor (opened with elf_begin(0, ELF_C_IMAGE, 0))
728 * then the image will be allocated from dynamic memory (malloc()).
729 *
730 * elf_update() will return the size of the memory image built
731 * when sucessful.
732 *
733 * When a subsequent call to elf_update() with ELF_C_WRITE as
734 * the command is performed it will sync the image created
735 * by ELF_C_WRIMAGE to disk (if fd available) and
736 * free the memory allocated.
737 */
738
739 off_t
740 _elfxx_update(Elf * elf, Elf_Cmd cmd)
741 {
742 size_t sz;
743 unsigned u;
744 Ehdr *eh = elf->ed_ehdr;
745
746 if (elf == 0)
747 return (-1);
748
749 ELFWLOCK(elf)
750 switch (cmd) {
751 default:
752 _elf_seterr(EREQ_UPDATE, 0);
753 ELFUNLOCK(elf)
754 return (-1);
755
756 case ELF_C_WRIMAGE:
757 if ((elf->ed_myflags & EDF_WRITE) == 0) {
758 _elf_seterr(EREQ_UPDWRT, 0);
759 ELFUNLOCK(elf)
760 return (-1);
761 }
762 break;
763 case ELF_C_WRITE:
764 if ((elf->ed_myflags & EDF_WRITE) == 0) {
765 _elf_seterr(EREQ_UPDWRT, 0);
766 ELFUNLOCK(elf)
767 return (-1);
768 }
|
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 1988 AT&T
29 * All Rights Reserved
30 */
31
32 /*
33 * Copyright (c) 2018, Joyent, Inc.
34 */
35
36 #include <memory.h>
37 #include <malloc.h>
38 #include <limits.h>
39
40 #include <sgs.h>
41 #include "decl.h"
42 #include "msg.h"
43
44 /*
45 * This module is compiled twice, the second time having
46 * -D_ELF64 defined. The following set of macros, along
47 * with machelf.h, represent the differences between the
48 * two compilations. Be careful *not* to add any class-
49 * dependent code (anything that has elf32 or elf64 in the
50 * name) to this code without hiding it behind a switch-
51 * able macro like these.
52 */
53 #if defined(_ELF64)
54
55 #define FSZ_LONG ELF64_FSZ_XWORD
730 * storage. If the elf descriptor does not have a valid
731 * file descriptor (opened with elf_begin(0, ELF_C_IMAGE, 0))
732 * then the image will be allocated from dynamic memory (malloc()).
733 *
734 * elf_update() will return the size of the memory image built
735 * when sucessful.
736 *
737 * When a subsequent call to elf_update() with ELF_C_WRITE as
738 * the command is performed it will sync the image created
739 * by ELF_C_WRIMAGE to disk (if fd available) and
740 * free the memory allocated.
741 */
742
743 off_t
744 _elfxx_update(Elf * elf, Elf_Cmd cmd)
745 {
746 size_t sz;
747 unsigned u;
748 Ehdr *eh = elf->ed_ehdr;
749
750 ELFWLOCK(elf)
751 switch (cmd) {
752 default:
753 _elf_seterr(EREQ_UPDATE, 0);
754 ELFUNLOCK(elf)
755 return (-1);
756
757 case ELF_C_WRIMAGE:
758 if ((elf->ed_myflags & EDF_WRITE) == 0) {
759 _elf_seterr(EREQ_UPDWRT, 0);
760 ELFUNLOCK(elf)
761 return (-1);
762 }
763 break;
764 case ELF_C_WRITE:
765 if ((elf->ed_myflags & EDF_WRITE) == 0) {
766 _elf_seterr(EREQ_UPDWRT, 0);
767 ELFUNLOCK(elf)
768 return (-1);
769 }
|