MCPcopy Create free account
hub / github.com/F-Stack/f-stack / exec_linux_imgact

Function exec_linux_imgact

freebsd/i386/linux/imgact_linux.c:60–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58static int exec_linux_imgact(struct image_params *iparams);
59
60static int
61exec_linux_imgact(struct image_params *imgp)
62{
63 const struct exec *a_out = (const struct exec *) imgp->image_header;
64 struct vmspace *vmspace;
65 vm_offset_t vmaddr;
66 unsigned long virtual_offset, file_offset;
67 unsigned long bss_size;
68 ssize_t aresid;
69 int error;
70
71 if (((a_out->a_magic >> 16) & 0xff) != 0x64)
72 return (-1);
73
74 /*
75 * Set file/virtual offset based on a.out variant.
76 */
77 switch ((int)(a_out->a_magic & 0xffff)) {
78 case 0413:
79 virtual_offset = 0;
80 file_offset = 1024;
81 break;
82 case 0314:
83 virtual_offset = 4096;
84 file_offset = 0;
85 break;
86 default:
87 return (-1);
88 }
89 bss_size = round_page(a_out->a_bss);
90#ifdef DEBUG
91 printf("imgact: text: %08lx, data: %08lx, bss: %08lx\n",
92 (u_long)a_out->a_text, (u_long)a_out->a_data, bss_size);
93#endif
94
95 /*
96 * Check various fields in header for validity/bounds.
97 */
98 if (a_out->a_entry < virtual_offset ||
99 a_out->a_entry >= virtual_offset + a_out->a_text ||
100 a_out->a_text & PAGE_MASK || a_out->a_data & PAGE_MASK)
101 return (-1);
102
103 /* text + data can't exceed file size */
104 if (a_out->a_data + a_out->a_text > imgp->attr->va_size)
105 return (EFAULT);
106 /*
107 * text/data/bss must not exceed limits
108 */
109 PROC_LOCK(imgp->proc);
110 if (a_out->a_text > maxtsiz ||
111 a_out->a_data + bss_size > lim_cur_proc(imgp->proc, RLIMIT_DATA) ||
112 racct_set(imgp->proc, RACCT_DATA, a_out->a_data + bss_size) != 0) {
113 PROC_UNLOCK(imgp->proc);
114 return (ENOMEM);
115 }
116 PROC_UNLOCK(imgp->proc);
117

Callers

nothing calls this directly

Calls 9

exec_new_vmspaceFunction · 0.85
vm_map_findFunction · 0.85
vm_map_protectFunction · 0.85
vm_mmapFunction · 0.85
vn_lockFunction · 0.85
printfFunction · 0.50
lim_cur_procFunction · 0.50
racct_setFunction · 0.50
vn_rdwrFunction · 0.50

Tested by

no test coverage detected