/* Adapted from arch/i386/kernel/ldt.c read_ldt() is not really atomic - this is not a problem since synchronization of reads and writes done to the LDT has to be assured by user-space anyway. Writes are atomic, to protect the security checks done on new descriptors.  */
static int read_ldt(void __user *ptr, unsigned long bytecount)
/* Adapted from arch/i386/kernel/ldt.c read_ldt() is not really atomic - this is not a problem since synchronization of reads and writes done to the LDT has to be assured by user-space anyway. Writes are atomic, to protect the security checks done on new descriptors.  */
static int read_ldt(void __user *ptr, unsigned long bytecount)
{
	unsigned long bytes_left, n;
	char __user *src, *dst;
	char buf[256];
	if (bytecount > IA32_LDT_ENTRIES*IA32_LDT_ENTRY_SIZE)
		bytecount = IA32_LDT_ENTRIES*IA32_LDT_ENTRY_SIZE;
	bytes_left = bytecount;
	src = (void __user *) IA32_LDT_OFFSET;
	dst = ptr;
	while (bytes_left) {
		n = sizeof(buf);
		if (n > bytes_left)
			n = bytes_left;
		if (__copy_from_user(buf, src, n))
			return -EFAULT;
		if (copy_to_user(dst, buf, n))
			return -EFAULT;
		src += n;
		dst += n;
		bytes_left -= n;
	}
	return bytecount;
}