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

Function exec_setregs

freebsd/i386/i386/machdep.c:1127–1206  ·  view source on GitHub ↗

* Reset registers to default values on exec. */

Source from the content-addressed store, hash-verified

1125 * Reset registers to default values on exec.
1126 */
1127void
1128exec_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
1129{
1130 struct trapframe *regs;
1131 struct pcb *pcb;
1132 register_t saved_eflags;
1133
1134 regs = td->td_frame;
1135 pcb = td->td_pcb;
1136
1137 /* Reset pc->pcb_gs and %gs before possibly invalidating it. */
1138 pcb->pcb_gs = _udatasel;
1139 load_gs(_udatasel);
1140
1141 mtx_lock_spin(&dt_lock);
1142 if (td->td_proc->p_md.md_ldt != NULL)
1143 user_ldt_free(td);
1144 else
1145 mtx_unlock_spin(&dt_lock);
1146
1147#ifdef COMPAT_43
1148 if (td->td_proc->p_sysent->sv_psstrings !=
1149 elf32_freebsd_sysvec.sv_psstrings)
1150 setup_priv_lcall_gate(td->td_proc);
1151#endif
1152
1153 /*
1154 * Reset the fs and gs bases. The values from the old address
1155 * space do not make sense for the new program. In particular,
1156 * gsbase might be the TLS base for the old program but the new
1157 * program has no TLS now.
1158 */
1159 set_fsbase(td, 0);
1160 set_gsbase(td, 0);
1161
1162 /* Make sure edx is 0x0 on entry. Linux binaries depend on it. */
1163 saved_eflags = regs->tf_eflags & PSL_T;
1164 bzero((char *)regs, sizeof(struct trapframe));
1165 regs->tf_eip = imgp->entry_addr;
1166 regs->tf_esp = stack;
1167 regs->tf_eflags = PSL_USER | saved_eflags;
1168 regs->tf_ss = _udatasel;
1169 regs->tf_ds = _udatasel;
1170 regs->tf_es = _udatasel;
1171 regs->tf_fs = _udatasel;
1172 regs->tf_cs = _ucodesel;
1173
1174 /* PS_STRINGS value for BSD/OS binaries. It is 0 for non-BSD/OS. */
1175 regs->tf_ebx = (register_t)imgp->ps_strings;
1176
1177 /*
1178 * Reset the hardware debug registers if they were in use.
1179 * They won't have any meaning for the newly exec'd process.
1180 */
1181 if (pcb->pcb_flags & PCB_DBREGS) {
1182 pcb->pcb_dr0 = 0;
1183 pcb->pcb_dr1 = 0;
1184 pcb->pcb_dr2 = 0;

Callers 2

linux_exec_setregsFunction · 0.50
cloudabi32_proc_setregsFunction · 0.50

Calls 8

setup_priv_lcall_gateFunction · 0.85
set_fsbaseFunction · 0.85
set_gsbaseFunction · 0.85
bzeroFunction · 0.85
reset_dbregsFunction · 0.85
user_ldt_freeFunction · 0.70
fpstate_dropFunction · 0.70
load_gsFunction · 0.50

Tested by

no test coverage detected