diff options
author | Konstantin Belousov <kib@FreeBSD.org> | 2015-06-29 06:59:08 +0000 |
---|---|---|
committer | Konstantin Belousov <kib@FreeBSD.org> | 2015-06-29 06:59:08 +0000 |
commit | 06d058bd2377dbca032ff45a6eeb37d9354944a8 (patch) | |
tree | 6648d00b11e168b3f48491d560e5ce12989c0741 /sys/i386/i386/sys_machdep.c | |
parent | 13742523978fc8259a7d9a6e594c64cbfcfa9e8b (diff) | |
download | src-06d058bd2377dbca032ff45a6eeb37d9354944a8.tar.gz src-06d058bd2377dbca032ff45a6eeb37d9354944a8.zip |
Reduce code duplication. Add helper fill_based_sd(9) which creates a
based user data descriptor covering whole VA.
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Notes
Notes:
svn path=/head/; revision=284918
Diffstat (limited to 'sys/i386/i386/sys_machdep.c')
-rw-r--r-- | sys/i386/i386/sys_machdep.c | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/sys/i386/i386/sys_machdep.c b/sys/i386/i386/sys_machdep.c index 9044d19b2654..0928b72600fe 100644 --- a/sys/i386/i386/sys_machdep.c +++ b/sys/i386/i386/sys_machdep.c @@ -74,6 +74,22 @@ static int i386_set_ldt_data(struct thread *, int start, int num, union descriptor *descs); static int i386_ldt_grow(struct thread *td, int len); +void +fill_based_sd(struct segment_descriptor *sdp, uint32_t base) +{ + + sdp->sd_lobase = base & 0xffffff; + sdp->sd_hibase = (base >> 24) & 0xff; + sdp->sd_lolimit = 0xffff; /* 4GB limit, wraps around */ + sdp->sd_hilimit = 0xf; + sdp->sd_type = SDT_MEMRWA; + sdp->sd_dpl = SEL_UPL; + sdp->sd_p = 1; + sdp->sd_xx = 0; + sdp->sd_def32 = 1; + sdp->sd_gran = 1; +} + #ifndef _SYS_SYSPROTO_H_ struct sysarch_args { int op; @@ -188,23 +204,14 @@ sysarch(td, uap) break; case I386_SET_FSBASE: error = copyin(uap->parms, &base, sizeof(base)); - if (!error) { + if (error == 0) { /* * Construct a descriptor and store it in the pcb for * the next context switch. Also store it in the gdt * so that the load of tf_fs into %fs will activate it * at return to userland. */ - sd.sd_lobase = base & 0xffffff; - sd.sd_hibase = (base >> 24) & 0xff; - sd.sd_lolimit = 0xffff; /* 4GB limit, wraps around */ - sd.sd_hilimit = 0xf; - sd.sd_type = SDT_MEMRWA; - sd.sd_dpl = SEL_UPL; - sd.sd_p = 1; - sd.sd_xx = 0; - sd.sd_def32 = 1; - sd.sd_gran = 1; + fill_based_sd(&sd, base); critical_enter(); td->td_pcb->pcb_fsd = sd; PCPU_GET(fsgs_gdt)[0] = sd; @@ -219,23 +226,13 @@ sysarch(td, uap) break; case I386_SET_GSBASE: error = copyin(uap->parms, &base, sizeof(base)); - if (!error) { + if (error == 0) { /* * Construct a descriptor and store it in the pcb for * the next context switch. Also store it in the gdt * because we have to do a load_gs() right now. */ - sd.sd_lobase = base & 0xffffff; - sd.sd_hibase = (base >> 24) & 0xff; - - sd.sd_lolimit = 0xffff; /* 4GB limit, wraps around */ - sd.sd_hilimit = 0xf; - sd.sd_type = SDT_MEMRWA; - sd.sd_dpl = SEL_UPL; - sd.sd_p = 1; - sd.sd_xx = 0; - sd.sd_def32 = 1; - sd.sd_gran = 1; + fill_based_sd(&sd, base); critical_enter(); td->td_pcb->pcb_gsd = sd; PCPU_GET(fsgs_gdt)[1] = sd; |