sys_machdep.c (9b2dc15ca0fb622177f64aec7470545687d11030) sys_machdep.c (bc2e774a377f1286ace08bf3afb3966e68a4be52)
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 496 unchanged lines hidden (view full) ---

505i386_set_ldt(td, uap, descs)
506 struct thread *td;
507 struct i386_ldt_args *uap;
508 union descriptor *descs;
509{
510 int error = 0, i;
511 int largest_ld;
512 struct mdproc *mdp = &td->td_proc->p_md;
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 496 unchanged lines hidden (view full) ---

505i386_set_ldt(td, uap, descs)
506 struct thread *td;
507 struct i386_ldt_args *uap;
508 union descriptor *descs;
509{
510 int error = 0, i;
511 int largest_ld;
512 struct mdproc *mdp = &td->td_proc->p_md;
513 struct proc_ldt *pldt = NULL;
513 struct proc_ldt *pldt;
514 union descriptor *dp;
515
516#ifdef DEBUG
517 printf("i386_set_ldt: start=%d num=%d descs=%p\n",
518 uap->start, uap->num, (void *)uap->descs);
519#endif
520
521 if (descs == NULL) {

--- 170 unchanged lines hidden (view full) ---

692 struct proc_ldt *pldt;
693 caddr_t old_ldt_base;
694 int old_ldt_len;
695
696 if (len > MAX_LD)
697 return (ENOMEM);
698 if (len < NLDT + 1)
699 len = NLDT + 1;
514 union descriptor *dp;
515
516#ifdef DEBUG
517 printf("i386_set_ldt: start=%d num=%d descs=%p\n",
518 uap->start, uap->num, (void *)uap->descs);
519#endif
520
521 if (descs == NULL) {

--- 170 unchanged lines hidden (view full) ---

692 struct proc_ldt *pldt;
693 caddr_t old_ldt_base;
694 int old_ldt_len;
695
696 if (len > MAX_LD)
697 return (ENOMEM);
698 if (len < NLDT + 1)
699 len = NLDT + 1;
700
701 /* Allocate a user ldt. */
700 pldt = mdp->md_ldt;
702 pldt = mdp->md_ldt;
701 /* allocate user ldt */
702 if (!pldt || len > pldt->ldt_len) {
703 if (!pldt || len > pldt->ldt_len) {
703 struct proc_ldt *new_ldt = user_ldt_alloc(mdp, len);
704 struct proc_ldt *new_ldt;
705
706 new_ldt = user_ldt_alloc(mdp, len);
704 if (new_ldt == NULL)
705 return (ENOMEM);
706 pldt = mdp->md_ldt;
707 if (new_ldt == NULL)
708 return (ENOMEM);
709 pldt = mdp->md_ldt;
707 /* sched_lock was held by user_ldt_alloc */
710
711 /* sched_lock was acquired by user_ldt_alloc. */
708 if (pldt) {
709 if (new_ldt->ldt_len > pldt->ldt_len) {
710 old_ldt_base = pldt->ldt_base;
711 old_ldt_len = pldt->ldt_len;
712 pldt->ldt_sd = new_ldt->ldt_sd;
713 pldt->ldt_base = new_ldt->ldt_base;
714 pldt->ldt_len = new_ldt->ldt_len;
715 mtx_unlock_spin(&sched_lock);
716 kmem_free(kernel_map, (vm_offset_t)old_ldt_base,
717 old_ldt_len * sizeof(union descriptor));
718 FREE(new_ldt, M_SUBPROC);
719 mtx_lock_spin(&sched_lock);
720 } else {
721 /*
722 * If other threads already did the work,
712 if (pldt) {
713 if (new_ldt->ldt_len > pldt->ldt_len) {
714 old_ldt_base = pldt->ldt_base;
715 old_ldt_len = pldt->ldt_len;
716 pldt->ldt_sd = new_ldt->ldt_sd;
717 pldt->ldt_base = new_ldt->ldt_base;
718 pldt->ldt_len = new_ldt->ldt_len;
719 mtx_unlock_spin(&sched_lock);
720 kmem_free(kernel_map, (vm_offset_t)old_ldt_base,
721 old_ldt_len * sizeof(union descriptor));
722 FREE(new_ldt, M_SUBPROC);
723 mtx_lock_spin(&sched_lock);
724 } else {
725 /*
726 * If other threads already did the work,
723 * do nothing
727 * do nothing.
724 */
725 mtx_unlock_spin(&sched_lock);
726 kmem_free(kernel_map,
727 (vm_offset_t)new_ldt->ldt_base,
728 new_ldt->ldt_len * sizeof(union descriptor));
729 FREE(new_ldt, M_SUBPROC);
730 return (0);
731 }

--- 15 unchanged lines hidden ---
728 */
729 mtx_unlock_spin(&sched_lock);
730 kmem_free(kernel_map,
731 (vm_offset_t)new_ldt->ldt_base,
732 new_ldt->ldt_len * sizeof(union descriptor));
733 FREE(new_ldt, M_SUBPROC);
734 return (0);
735 }

--- 15 unchanged lines hidden ---