X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/1c79356b52d46aa6b508fb032f5ae709b1f2897b..21362eb3e66fd2c787aee132bce100a44d71a99c:/osfmk/i386/user_ldt.c diff --git a/osfmk/i386/user_ldt.c b/osfmk/i386/user_ldt.c index 5e27532e7..a21105f9b 100644 --- a/osfmk/i386/user_ldt.c +++ b/osfmk/i386/user_ldt.c @@ -1,23 +1,29 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * - * The contents of this file constitute Original Code as defined in and - * are subject to the Apple Public Source License Version 1.1 (the - * "License"). You may not use this file except in compliance with the - * License. Please obtain a copy of the License at - * http://www.apple.com/publicsource and read it before using this file. + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. * - * This Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. * - * @APPLE_LICENSE_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* * @OSF_COPYRIGHT@ @@ -78,8 +84,6 @@ char acc_type[8][3] = { { 1, 0, 1 }, /* code, readable, conforming */ }; -extern struct fake_descriptor ldt[]; /* for system call gate */ - #if 0 /* Forward */ @@ -97,7 +101,7 @@ selector_check( struct user_ldt *ldt; int access; - ldt = thread->top_act->mact.pcb->ims.ldt; + ldt = thread->machine.pcb->ims.ldt; if (ldt == 0) { switch (type) { case S_CODE: @@ -134,7 +138,7 @@ selector_check( kern_return_t i386_set_ldt( - thread_act_t thr_act, + thread_t thr_act, int first_selector, descriptor_list_t desc_list, mach_msg_type_number_t count) @@ -153,7 +157,7 @@ i386_set_ldt( return KERN_INVALID_ARGUMENT; if (first_desc + count >= 8192) return KERN_INVALID_ARGUMENT; - if (thr_act == THR_ACT_NULL) + if (thr_act == THREAD_NULL) return KERN_INVALID_ARGUMENT; if ((thread = act_lock_thread(thr_act)) == THREAD_NULL) { act_unlock_thread(thr_act); @@ -173,7 +177,7 @@ i386_set_ldt( */ { kern_return_t kr; - vm_offset_t dst_addr; + vm_map_offset_t dst_addr; old_copy_object = (vm_map_copy_t) desc_list; @@ -183,11 +187,11 @@ i386_set_ldt( return kr; (void) vm_map_wire(ipc_kernel_map, - trunc_page(dst_addr), - round_page(dst_addr + + vm_map_trunc_page(dst_addr), + vm_map_round_page(dst_addr + count * sizeof(struct real_descriptor)), VM_PROT_READ|VM_PROT_WRITE, FALSE); - desc_list = (descriptor_list_t) dst_addr; + desc_list = CAST_DOWN(descriptor_list_t, dst_addr); } for (i = 0, dp = (struct real_descriptor *) desc_list; @@ -217,8 +221,8 @@ i386_set_ldt( break; default: (void) vm_map_remove(ipc_kernel_map, - (vm_offset_t) desc_list, - count * sizeof(struct real_descriptor), + vm_map_trunc_page(desc_list), + vm_map_round_page(&desc_list[count]), VM_MAP_REMOVE_KUNWIRE); return KERN_INVALID_ARGUMENT; } @@ -226,7 +230,7 @@ i386_set_ldt( ldt_size_needed = sizeof(struct real_descriptor) * (first_desc + count); - pcb = thr_act->mact.pcb; + pcb = thr_act->machine.pcb; new_ldt = 0; Retry: simple_lock(&pcb->lock); @@ -266,7 +270,7 @@ i386_set_ldt( (char *)&new_ldt->ldt[0], old_ldt->desc.limit_low + 1); } - else if (thr_act == current_act()) { + else if (thr_act == current_thread()) { struct real_descriptor template = {0, 0, 0, ACC_P, 0, 0 ,0}; for (dp = &new_ldt->ldt[0], i = 0; i < first_desc; i++, dp++) { @@ -300,22 +304,22 @@ i386_set_ldt( /* * Free the descriptor list. */ - (void) vm_map_remove(ipc_kernel_map, (vm_offset_t) desc_list, - count * sizeof(struct real_descriptor), - VM_MAP_REMOVE_KUNWIRE); + (void) vm_map_remove(ipc_kernel_map, vm_map_trunc_page(desc_list), + vm_map_round_page(&desc_list[count]), + VM_MAP_REMOVE_KUNWIRE); return KERN_SUCCESS; } kern_return_t i386_get_ldt( - thread_act_t thr_act, + thread_t thr_act, int first_selector, int selector_count, /* number wanted */ descriptor_list_t *desc_list, /* in/out */ mach_msg_type_number_t *count) /* in/out */ { struct user_ldt *user_ldt; - pcb_t pcb = thr_act->mact.pcb; + pcb_t pcb = thr_act->machine.pcb; int first_desc = sel_idx(first_selector); unsigned int ldt_count; vm_size_t ldt_size; @@ -323,7 +327,7 @@ i386_get_ldt( vm_offset_t addr; thread_t thread; - if (thr_act == THR_ACT_NULL || (thread = thr_act->thread)==THREAD_NULL) + if (thr_act == THREAD_NULL) return KERN_INVALID_ARGUMENT; if (first_desc < 0 || first_desc > 8191) @@ -412,10 +416,10 @@ i386_get_ldt( /* * Unwire the memory and make it into copyin form. */ - (void) vm_map_unwire(ipc_kernel_map, trunc_page(addr), - round_page(addr + size_used), FALSE); - (void) vm_map_copyin(ipc_kernel_map, addr, size_used, - TRUE, &memory); + (void) vm_map_unwire(ipc_kernel_map, vm_map_trunc_page(addr), + vm_map_round_page(addr + size_used), FALSE); + (void) vm_map_copyin(ipc_kernel_map, (vm_map_address_t)addr, + (vm_map_size_t)size_used, TRUE, &memory); *desc_list = (descriptor_list_t) memory; } @@ -427,6 +431,6 @@ void user_ldt_free( user_ldt_t user_ldt) { - kfree((vm_offset_t)user_ldt, + kfree(user_ldt, user_ldt->desc.limit_low+1+sizeof(struct real_descriptor)); }