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
This commit is contained in:
Konstantin Belousov 2015-06-29 06:59:08 +00:00
parent 1374252397
commit 06d058bd23
2 changed files with 22 additions and 23 deletions

View File

@ -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;

View File

@ -94,6 +94,7 @@ struct reg;
struct fpreg;
struct dbreg;
struct dumperinfo;
struct segment_descriptor;
void *alloc_fpusave(int flags);
void bcopyb(const void *from, void *to, size_t len);
@ -114,6 +115,7 @@ void dump_add_page(vm_paddr_t);
void dump_drop_page(vm_paddr_t);
void finishidentcpu(void);
void fillw(int /*u_short*/ pat, void *base, size_t cnt);
void fill_based_sd(struct segment_descriptor *sdp, uint32_t base);
void initializecpu(void);
void initializecpucache(void);
void i686_pagezero(void *addr);