Author: kib
Date: Mon Jun 29 06:59:08 2015
New Revision: 284918
URL: https://svnweb.freebsd.org/changeset/base/284918

Log:
  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

Modified:
  head/sys/i386/i386/sys_machdep.c
  head/sys/i386/include/md_var.h

Modified: head/sys/i386/i386/sys_machdep.c
==============================================================================
--- head/sys/i386/i386/sys_machdep.c    Mon Jun 29 00:30:30 2015        
(r284917)
+++ head/sys/i386/i386/sys_machdep.c    Mon Jun 29 06:59:08 2015        
(r284918)
@@ -74,6 +74,22 @@ static int i386_set_ldt_data(struct thre
        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;

Modified: head/sys/i386/include/md_var.h
==============================================================================
--- head/sys/i386/include/md_var.h      Mon Jun 29 00:30:30 2015        
(r284917)
+++ head/sys/i386/include/md_var.h      Mon Jun 29 06:59:08 2015        
(r284918)
@@ -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);
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to