| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * sys_ia32.c: Conversion between 32bit and 64bit native syscalls. Derived from sys_sparc32.c. | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 2000		VA Linux Co | 
|  | 5 | * Copyright (C) 2000		Don Dugger <n0ano@valinux.com> | 
|  | 6 | * Copyright (C) 1999		Arun Sharma <arun.sharma@intel.com> | 
|  | 7 | * Copyright (C) 1997,1998	Jakub Jelinek (jj@sunsite.mff.cuni.cz) | 
|  | 8 | * Copyright (C) 1997		David S. Miller (davem@caip.rutgers.edu) | 
|  | 9 | * Copyright (C) 2000-2003, 2005 Hewlett-Packard Co | 
|  | 10 | *	David Mosberger-Tang <davidm@hpl.hp.com> | 
|  | 11 | * Copyright (C) 2004		Gordon Jin <gordon.jin@intel.com> | 
|  | 12 | * | 
|  | 13 | * These routines maintain argument size conversion between 32bit and 64bit | 
|  | 14 | * environment. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #include <linux/config.h> | 
|  | 18 | #include <linux/kernel.h> | 
|  | 19 | #include <linux/syscalls.h> | 
|  | 20 | #include <linux/sysctl.h> | 
|  | 21 | #include <linux/sched.h> | 
|  | 22 | #include <linux/fs.h> | 
|  | 23 | #include <linux/file.h> | 
|  | 24 | #include <linux/signal.h> | 
|  | 25 | #include <linux/resource.h> | 
|  | 26 | #include <linux/times.h> | 
|  | 27 | #include <linux/utsname.h> | 
|  | 28 | #include <linux/timex.h> | 
|  | 29 | #include <linux/smp.h> | 
|  | 30 | #include <linux/smp_lock.h> | 
|  | 31 | #include <linux/sem.h> | 
|  | 32 | #include <linux/msg.h> | 
|  | 33 | #include <linux/mm.h> | 
|  | 34 | #include <linux/shm.h> | 
|  | 35 | #include <linux/slab.h> | 
|  | 36 | #include <linux/uio.h> | 
|  | 37 | #include <linux/nfs_fs.h> | 
|  | 38 | #include <linux/quota.h> | 
|  | 39 | #include <linux/sunrpc/svc.h> | 
|  | 40 | #include <linux/nfsd/nfsd.h> | 
|  | 41 | #include <linux/nfsd/cache.h> | 
|  | 42 | #include <linux/nfsd/xdr.h> | 
|  | 43 | #include <linux/nfsd/syscall.h> | 
|  | 44 | #include <linux/poll.h> | 
|  | 45 | #include <linux/eventpoll.h> | 
|  | 46 | #include <linux/personality.h> | 
|  | 47 | #include <linux/ptrace.h> | 
|  | 48 | #include <linux/stat.h> | 
|  | 49 | #include <linux/ipc.h> | 
|  | 50 | #include <linux/compat.h> | 
|  | 51 | #include <linux/vfs.h> | 
|  | 52 | #include <linux/mman.h> | 
|  | 53 |  | 
|  | 54 | #include <asm/intrinsics.h> | 
|  | 55 | #include <asm/semaphore.h> | 
|  | 56 | #include <asm/types.h> | 
|  | 57 | #include <asm/uaccess.h> | 
|  | 58 | #include <asm/unistd.h> | 
|  | 59 |  | 
|  | 60 | #include "ia32priv.h" | 
|  | 61 |  | 
|  | 62 | #include <net/scm.h> | 
|  | 63 | #include <net/sock.h> | 
|  | 64 |  | 
|  | 65 | #define DEBUG	0 | 
|  | 66 |  | 
|  | 67 | #if DEBUG | 
|  | 68 | # define DBG(fmt...)	printk(KERN_DEBUG fmt) | 
|  | 69 | #else | 
|  | 70 | # define DBG(fmt...) | 
|  | 71 | #endif | 
|  | 72 |  | 
|  | 73 | #define ROUND_UP(x,a)	((__typeof__(x))(((unsigned long)(x) + ((a) - 1)) & ~((a) - 1))) | 
|  | 74 |  | 
|  | 75 | #define OFFSET4K(a)		((a) & 0xfff) | 
|  | 76 | #define PAGE_START(addr)	((addr) & PAGE_MASK) | 
|  | 77 | #define MINSIGSTKSZ_IA32	2048 | 
|  | 78 |  | 
|  | 79 | #define high2lowuid(uid) ((uid) > 65535 ? 65534 : (uid)) | 
|  | 80 | #define high2lowgid(gid) ((gid) > 65535 ? 65534 : (gid)) | 
|  | 81 |  | 
|  | 82 | /* | 
|  | 83 | * Anything that modifies or inspects ia32 user virtual memory must hold this semaphore | 
|  | 84 | * while doing so. | 
|  | 85 | */ | 
|  | 86 | /* XXX make per-mm: */ | 
|  | 87 | static DECLARE_MUTEX(ia32_mmap_sem); | 
|  | 88 |  | 
|  | 89 | asmlinkage long | 
|  | 90 | sys32_execve (char __user *name, compat_uptr_t __user *argv, compat_uptr_t __user *envp, | 
|  | 91 | struct pt_regs *regs) | 
|  | 92 | { | 
|  | 93 | long error; | 
|  | 94 | char *filename; | 
|  | 95 | unsigned long old_map_base, old_task_size, tssd; | 
|  | 96 |  | 
|  | 97 | filename = getname(name); | 
|  | 98 | error = PTR_ERR(filename); | 
|  | 99 | if (IS_ERR(filename)) | 
|  | 100 | return error; | 
|  | 101 |  | 
|  | 102 | old_map_base  = current->thread.map_base; | 
|  | 103 | old_task_size = current->thread.task_size; | 
|  | 104 | tssd = ia64_get_kr(IA64_KR_TSSD); | 
|  | 105 |  | 
|  | 106 | /* we may be exec'ing a 64-bit process: reset map base, task-size, and io-base: */ | 
|  | 107 | current->thread.map_base  = DEFAULT_MAP_BASE; | 
|  | 108 | current->thread.task_size = DEFAULT_TASK_SIZE; | 
|  | 109 | ia64_set_kr(IA64_KR_IO_BASE, current->thread.old_iob); | 
|  | 110 | ia64_set_kr(IA64_KR_TSSD, current->thread.old_k1); | 
|  | 111 |  | 
|  | 112 | error = compat_do_execve(filename, argv, envp, regs); | 
|  | 113 | putname(filename); | 
|  | 114 |  | 
|  | 115 | if (error < 0) { | 
|  | 116 | /* oops, execve failed, switch back to old values... */ | 
|  | 117 | ia64_set_kr(IA64_KR_IO_BASE, IA32_IOBASE); | 
|  | 118 | ia64_set_kr(IA64_KR_TSSD, tssd); | 
|  | 119 | current->thread.map_base  = old_map_base; | 
|  | 120 | current->thread.task_size = old_task_size; | 
|  | 121 | } | 
|  | 122 |  | 
|  | 123 | return error; | 
|  | 124 | } | 
|  | 125 |  | 
|  | 126 | int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf) | 
|  | 127 | { | 
|  | 128 | int err; | 
|  | 129 |  | 
|  | 130 | if ((u64) stat->size > MAX_NON_LFS || | 
|  | 131 | !old_valid_dev(stat->dev) || | 
|  | 132 | !old_valid_dev(stat->rdev)) | 
|  | 133 | return -EOVERFLOW; | 
|  | 134 |  | 
|  | 135 | if (clear_user(ubuf, sizeof(*ubuf))) | 
|  | 136 | return -EFAULT; | 
|  | 137 |  | 
|  | 138 | err  = __put_user(old_encode_dev(stat->dev), &ubuf->st_dev); | 
|  | 139 | err |= __put_user(stat->ino, &ubuf->st_ino); | 
|  | 140 | err |= __put_user(stat->mode, &ubuf->st_mode); | 
|  | 141 | err |= __put_user(stat->nlink, &ubuf->st_nlink); | 
|  | 142 | err |= __put_user(high2lowuid(stat->uid), &ubuf->st_uid); | 
|  | 143 | err |= __put_user(high2lowgid(stat->gid), &ubuf->st_gid); | 
|  | 144 | err |= __put_user(old_encode_dev(stat->rdev), &ubuf->st_rdev); | 
|  | 145 | err |= __put_user(stat->size, &ubuf->st_size); | 
|  | 146 | err |= __put_user(stat->atime.tv_sec, &ubuf->st_atime); | 
|  | 147 | err |= __put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec); | 
|  | 148 | err |= __put_user(stat->mtime.tv_sec, &ubuf->st_mtime); | 
|  | 149 | err |= __put_user(stat->mtime.tv_nsec, &ubuf->st_mtime_nsec); | 
|  | 150 | err |= __put_user(stat->ctime.tv_sec, &ubuf->st_ctime); | 
|  | 151 | err |= __put_user(stat->ctime.tv_nsec, &ubuf->st_ctime_nsec); | 
|  | 152 | err |= __put_user(stat->blksize, &ubuf->st_blksize); | 
|  | 153 | err |= __put_user(stat->blocks, &ubuf->st_blocks); | 
|  | 154 | return err; | 
|  | 155 | } | 
|  | 156 |  | 
|  | 157 | #if PAGE_SHIFT > IA32_PAGE_SHIFT | 
|  | 158 |  | 
|  | 159 |  | 
|  | 160 | static int | 
|  | 161 | get_page_prot (struct vm_area_struct *vma, unsigned long addr) | 
|  | 162 | { | 
|  | 163 | int prot = 0; | 
|  | 164 |  | 
|  | 165 | if (!vma || vma->vm_start > addr) | 
|  | 166 | return 0; | 
|  | 167 |  | 
|  | 168 | if (vma->vm_flags & VM_READ) | 
|  | 169 | prot |= PROT_READ; | 
|  | 170 | if (vma->vm_flags & VM_WRITE) | 
|  | 171 | prot |= PROT_WRITE; | 
|  | 172 | if (vma->vm_flags & VM_EXEC) | 
|  | 173 | prot |= PROT_EXEC; | 
|  | 174 | return prot; | 
|  | 175 | } | 
|  | 176 |  | 
|  | 177 | /* | 
|  | 178 | * Map a subpage by creating an anonymous page that contains the union of the old page and | 
|  | 179 | * the subpage. | 
|  | 180 | */ | 
|  | 181 | static unsigned long | 
|  | 182 | mmap_subpage (struct file *file, unsigned long start, unsigned long end, int prot, int flags, | 
|  | 183 | loff_t off) | 
|  | 184 | { | 
|  | 185 | void *page = NULL; | 
|  | 186 | struct inode *inode; | 
|  | 187 | unsigned long ret = 0; | 
|  | 188 | struct vm_area_struct *vma = find_vma(current->mm, start); | 
|  | 189 | int old_prot = get_page_prot(vma, start); | 
|  | 190 |  | 
|  | 191 | DBG("mmap_subpage(file=%p,start=0x%lx,end=0x%lx,prot=%x,flags=%x,off=0x%llx)\n", | 
|  | 192 | file, start, end, prot, flags, off); | 
|  | 193 |  | 
|  | 194 |  | 
|  | 195 | /* Optimize the case where the old mmap and the new mmap are both anonymous */ | 
|  | 196 | if ((old_prot & PROT_WRITE) && (flags & MAP_ANONYMOUS) && !vma->vm_file) { | 
|  | 197 | if (clear_user((void __user *) start, end - start)) { | 
|  | 198 | ret = -EFAULT; | 
|  | 199 | goto out; | 
|  | 200 | } | 
|  | 201 | goto skip_mmap; | 
|  | 202 | } | 
|  | 203 |  | 
|  | 204 | page = (void *) get_zeroed_page(GFP_KERNEL); | 
|  | 205 | if (!page) | 
|  | 206 | return -ENOMEM; | 
|  | 207 |  | 
|  | 208 | if (old_prot) | 
|  | 209 | copy_from_user(page, (void __user *) PAGE_START(start), PAGE_SIZE); | 
|  | 210 |  | 
|  | 211 | down_write(¤t->mm->mmap_sem); | 
|  | 212 | { | 
|  | 213 | ret = do_mmap(NULL, PAGE_START(start), PAGE_SIZE, prot | PROT_WRITE, | 
|  | 214 | flags | MAP_FIXED | MAP_ANONYMOUS, 0); | 
|  | 215 | } | 
|  | 216 | up_write(¤t->mm->mmap_sem); | 
|  | 217 |  | 
|  | 218 | if (IS_ERR((void *) ret)) | 
|  | 219 | goto out; | 
|  | 220 |  | 
|  | 221 | if (old_prot) { | 
|  | 222 | /* copy back the old page contents.  */ | 
|  | 223 | if (offset_in_page(start)) | 
|  | 224 | copy_to_user((void __user *) PAGE_START(start), page, | 
|  | 225 | offset_in_page(start)); | 
|  | 226 | if (offset_in_page(end)) | 
|  | 227 | copy_to_user((void __user *) end, page + offset_in_page(end), | 
|  | 228 | PAGE_SIZE - offset_in_page(end)); | 
|  | 229 | } | 
|  | 230 |  | 
|  | 231 | if (!(flags & MAP_ANONYMOUS)) { | 
|  | 232 | /* read the file contents */ | 
|  | 233 | inode = file->f_dentry->d_inode; | 
|  | 234 | if (!inode->i_fop || !file->f_op->read | 
|  | 235 | || ((*file->f_op->read)(file, (char __user *) start, end - start, &off) < 0)) | 
|  | 236 | { | 
|  | 237 | ret = -EINVAL; | 
|  | 238 | goto out; | 
|  | 239 | } | 
|  | 240 | } | 
|  | 241 |  | 
|  | 242 | skip_mmap: | 
|  | 243 | if (!(prot & PROT_WRITE)) | 
|  | 244 | ret = sys_mprotect(PAGE_START(start), PAGE_SIZE, prot | old_prot); | 
|  | 245 | out: | 
|  | 246 | if (page) | 
|  | 247 | free_page((unsigned long) page); | 
|  | 248 | return ret; | 
|  | 249 | } | 
|  | 250 |  | 
|  | 251 | /* SLAB cache for partial_page structures */ | 
|  | 252 | kmem_cache_t *partial_page_cachep; | 
|  | 253 |  | 
|  | 254 | /* | 
|  | 255 | * init partial_page_list. | 
|  | 256 | * return 0 means kmalloc fail. | 
|  | 257 | */ | 
|  | 258 | struct partial_page_list* | 
|  | 259 | ia32_init_pp_list(void) | 
|  | 260 | { | 
|  | 261 | struct partial_page_list *p; | 
|  | 262 |  | 
|  | 263 | if ((p = kmalloc(sizeof(*p), GFP_KERNEL)) == NULL) | 
|  | 264 | return p; | 
|  | 265 | p->pp_head = NULL; | 
|  | 266 | p->ppl_rb = RB_ROOT; | 
|  | 267 | p->pp_hint = NULL; | 
|  | 268 | atomic_set(&p->pp_count, 1); | 
|  | 269 | return p; | 
|  | 270 | } | 
|  | 271 |  | 
|  | 272 | /* | 
|  | 273 | * Search for the partial page with @start in partial page list @ppl. | 
|  | 274 | * If finds the partial page, return the found partial page. | 
|  | 275 | * Else, return 0 and provide @pprev, @rb_link, @rb_parent to | 
|  | 276 | * be used by later __ia32_insert_pp(). | 
|  | 277 | */ | 
|  | 278 | static struct partial_page * | 
|  | 279 | __ia32_find_pp(struct partial_page_list *ppl, unsigned int start, | 
|  | 280 | struct partial_page **pprev, struct rb_node ***rb_link, | 
|  | 281 | struct rb_node **rb_parent) | 
|  | 282 | { | 
|  | 283 | struct partial_page *pp; | 
|  | 284 | struct rb_node **__rb_link, *__rb_parent, *rb_prev; | 
|  | 285 |  | 
|  | 286 | pp = ppl->pp_hint; | 
|  | 287 | if (pp && pp->base == start) | 
|  | 288 | return pp; | 
|  | 289 |  | 
|  | 290 | __rb_link = &ppl->ppl_rb.rb_node; | 
|  | 291 | rb_prev = __rb_parent = NULL; | 
|  | 292 |  | 
|  | 293 | while (*__rb_link) { | 
|  | 294 | __rb_parent = *__rb_link; | 
|  | 295 | pp = rb_entry(__rb_parent, struct partial_page, pp_rb); | 
|  | 296 |  | 
|  | 297 | if (pp->base == start) { | 
|  | 298 | ppl->pp_hint = pp; | 
|  | 299 | return pp; | 
|  | 300 | } else if (pp->base < start) { | 
|  | 301 | rb_prev = __rb_parent; | 
|  | 302 | __rb_link = &__rb_parent->rb_right; | 
|  | 303 | } else { | 
|  | 304 | __rb_link = &__rb_parent->rb_left; | 
|  | 305 | } | 
|  | 306 | } | 
|  | 307 |  | 
|  | 308 | *rb_link = __rb_link; | 
|  | 309 | *rb_parent = __rb_parent; | 
|  | 310 | *pprev = NULL; | 
|  | 311 | if (rb_prev) | 
|  | 312 | *pprev = rb_entry(rb_prev, struct partial_page, pp_rb); | 
|  | 313 | return NULL; | 
|  | 314 | } | 
|  | 315 |  | 
|  | 316 | /* | 
|  | 317 | * insert @pp into @ppl. | 
|  | 318 | */ | 
|  | 319 | static void | 
|  | 320 | __ia32_insert_pp(struct partial_page_list *ppl, struct partial_page *pp, | 
|  | 321 | struct partial_page *prev, struct rb_node **rb_link, | 
|  | 322 | struct rb_node *rb_parent) | 
|  | 323 | { | 
|  | 324 | /* link list */ | 
|  | 325 | if (prev) { | 
|  | 326 | pp->next = prev->next; | 
|  | 327 | prev->next = pp; | 
|  | 328 | } else { | 
|  | 329 | ppl->pp_head = pp; | 
|  | 330 | if (rb_parent) | 
|  | 331 | pp->next = rb_entry(rb_parent, | 
|  | 332 | struct partial_page, pp_rb); | 
|  | 333 | else | 
|  | 334 | pp->next = NULL; | 
|  | 335 | } | 
|  | 336 |  | 
|  | 337 | /* link rb */ | 
|  | 338 | rb_link_node(&pp->pp_rb, rb_parent, rb_link); | 
|  | 339 | rb_insert_color(&pp->pp_rb, &ppl->ppl_rb); | 
|  | 340 |  | 
|  | 341 | ppl->pp_hint = pp; | 
|  | 342 | } | 
|  | 343 |  | 
|  | 344 | /* | 
|  | 345 | * delete @pp from partial page list @ppl. | 
|  | 346 | */ | 
|  | 347 | static void | 
|  | 348 | __ia32_delete_pp(struct partial_page_list *ppl, struct partial_page *pp, | 
|  | 349 | struct partial_page *prev) | 
|  | 350 | { | 
|  | 351 | if (prev) { | 
|  | 352 | prev->next = pp->next; | 
|  | 353 | if (ppl->pp_hint == pp) | 
|  | 354 | ppl->pp_hint = prev; | 
|  | 355 | } else { | 
|  | 356 | ppl->pp_head = pp->next; | 
|  | 357 | if (ppl->pp_hint == pp) | 
|  | 358 | ppl->pp_hint = pp->next; | 
|  | 359 | } | 
|  | 360 | rb_erase(&pp->pp_rb, &ppl->ppl_rb); | 
|  | 361 | kmem_cache_free(partial_page_cachep, pp); | 
|  | 362 | } | 
|  | 363 |  | 
|  | 364 | static struct partial_page * | 
|  | 365 | __pp_prev(struct partial_page *pp) | 
|  | 366 | { | 
|  | 367 | struct rb_node *prev = rb_prev(&pp->pp_rb); | 
|  | 368 | if (prev) | 
|  | 369 | return rb_entry(prev, struct partial_page, pp_rb); | 
|  | 370 | else | 
|  | 371 | return NULL; | 
|  | 372 | } | 
|  | 373 |  | 
|  | 374 | /* | 
|  | 375 | * Delete partial pages with address between @start and @end. | 
|  | 376 | * @start and @end are page aligned. | 
|  | 377 | */ | 
|  | 378 | static void | 
|  | 379 | __ia32_delete_pp_range(unsigned int start, unsigned int end) | 
|  | 380 | { | 
|  | 381 | struct partial_page *pp, *prev; | 
|  | 382 | struct rb_node **rb_link, *rb_parent; | 
|  | 383 |  | 
|  | 384 | if (start >= end) | 
|  | 385 | return; | 
|  | 386 |  | 
|  | 387 | pp = __ia32_find_pp(current->thread.ppl, start, &prev, | 
|  | 388 | &rb_link, &rb_parent); | 
|  | 389 | if (pp) | 
|  | 390 | prev = __pp_prev(pp); | 
|  | 391 | else { | 
|  | 392 | if (prev) | 
|  | 393 | pp = prev->next; | 
|  | 394 | else | 
|  | 395 | pp = current->thread.ppl->pp_head; | 
|  | 396 | } | 
|  | 397 |  | 
|  | 398 | while (pp && pp->base < end) { | 
|  | 399 | struct partial_page *tmp = pp->next; | 
|  | 400 | __ia32_delete_pp(current->thread.ppl, pp, prev); | 
|  | 401 | pp = tmp; | 
|  | 402 | } | 
|  | 403 | } | 
|  | 404 |  | 
|  | 405 | /* | 
|  | 406 | * Set the range between @start and @end in bitmap. | 
|  | 407 | * @start and @end should be IA32 page aligned and in the same IA64 page. | 
|  | 408 | */ | 
|  | 409 | static int | 
|  | 410 | __ia32_set_pp(unsigned int start, unsigned int end, int flags) | 
|  | 411 | { | 
|  | 412 | struct partial_page *pp, *prev; | 
|  | 413 | struct rb_node ** rb_link, *rb_parent; | 
|  | 414 | unsigned int pstart, start_bit, end_bit, i; | 
|  | 415 |  | 
|  | 416 | pstart = PAGE_START(start); | 
|  | 417 | start_bit = (start % PAGE_SIZE) / IA32_PAGE_SIZE; | 
|  | 418 | end_bit = (end % PAGE_SIZE) / IA32_PAGE_SIZE; | 
|  | 419 | if (end_bit == 0) | 
|  | 420 | end_bit = PAGE_SIZE / IA32_PAGE_SIZE; | 
|  | 421 | pp = __ia32_find_pp(current->thread.ppl, pstart, &prev, | 
|  | 422 | &rb_link, &rb_parent); | 
|  | 423 | if (pp) { | 
|  | 424 | for (i = start_bit; i < end_bit; i++) | 
|  | 425 | set_bit(i, &pp->bitmap); | 
|  | 426 | /* | 
|  | 427 | * Check: if this partial page has been set to a full page, | 
|  | 428 | * then delete it. | 
|  | 429 | */ | 
|  | 430 | if (find_first_zero_bit(&pp->bitmap, sizeof(pp->bitmap)*8) >= | 
|  | 431 | PAGE_SIZE/IA32_PAGE_SIZE) { | 
|  | 432 | __ia32_delete_pp(current->thread.ppl, pp, __pp_prev(pp)); | 
|  | 433 | } | 
|  | 434 | return 0; | 
|  | 435 | } | 
|  | 436 |  | 
|  | 437 | /* | 
|  | 438 | * MAP_FIXED may lead to overlapping mmap. | 
|  | 439 | * In this case, the requested mmap area may already mmaped as a full | 
|  | 440 | * page. So check vma before adding a new partial page. | 
|  | 441 | */ | 
|  | 442 | if (flags & MAP_FIXED) { | 
|  | 443 | struct vm_area_struct *vma = find_vma(current->mm, pstart); | 
|  | 444 | if (vma && vma->vm_start <= pstart) | 
|  | 445 | return 0; | 
|  | 446 | } | 
|  | 447 |  | 
|  | 448 | /* new a partial_page */ | 
|  | 449 | pp = kmem_cache_alloc(partial_page_cachep, GFP_KERNEL); | 
|  | 450 | if (!pp) | 
|  | 451 | return -ENOMEM; | 
|  | 452 | pp->base = pstart; | 
|  | 453 | pp->bitmap = 0; | 
|  | 454 | for (i=start_bit; i<end_bit; i++) | 
|  | 455 | set_bit(i, &(pp->bitmap)); | 
|  | 456 | pp->next = NULL; | 
|  | 457 | __ia32_insert_pp(current->thread.ppl, pp, prev, rb_link, rb_parent); | 
|  | 458 | return 0; | 
|  | 459 | } | 
|  | 460 |  | 
|  | 461 | /* | 
|  | 462 | * @start and @end should be IA32 page aligned, but don't need to be in the | 
|  | 463 | * same IA64 page. Split @start and @end to make sure they're in the same IA64 | 
|  | 464 | * page, then call __ia32_set_pp(). | 
|  | 465 | */ | 
|  | 466 | static void | 
|  | 467 | ia32_set_pp(unsigned int start, unsigned int end, int flags) | 
|  | 468 | { | 
|  | 469 | down_write(¤t->mm->mmap_sem); | 
|  | 470 | if (flags & MAP_FIXED) { | 
|  | 471 | /* | 
|  | 472 | * MAP_FIXED may lead to overlapping mmap. When this happens, | 
|  | 473 | * a series of complete IA64 pages results in deletion of | 
|  | 474 | * old partial pages in that range. | 
|  | 475 | */ | 
|  | 476 | __ia32_delete_pp_range(PAGE_ALIGN(start), PAGE_START(end)); | 
|  | 477 | } | 
|  | 478 |  | 
|  | 479 | if (end < PAGE_ALIGN(start)) { | 
|  | 480 | __ia32_set_pp(start, end, flags); | 
|  | 481 | } else { | 
|  | 482 | if (offset_in_page(start)) | 
|  | 483 | __ia32_set_pp(start, PAGE_ALIGN(start), flags); | 
|  | 484 | if (offset_in_page(end)) | 
|  | 485 | __ia32_set_pp(PAGE_START(end), end, flags); | 
|  | 486 | } | 
|  | 487 | up_write(¤t->mm->mmap_sem); | 
|  | 488 | } | 
|  | 489 |  | 
|  | 490 | /* | 
|  | 491 | * Unset the range between @start and @end in bitmap. | 
|  | 492 | * @start and @end should be IA32 page aligned and in the same IA64 page. | 
|  | 493 | * After doing that, if the bitmap is 0, then free the page and return 1, | 
|  | 494 | * 	else return 0; | 
|  | 495 | * If not find the partial page in the list, then | 
|  | 496 | * 	If the vma exists, then the full page is set to a partial page; | 
|  | 497 | *	Else return -ENOMEM. | 
|  | 498 | */ | 
|  | 499 | static int | 
|  | 500 | __ia32_unset_pp(unsigned int start, unsigned int end) | 
|  | 501 | { | 
|  | 502 | struct partial_page *pp, *prev; | 
|  | 503 | struct rb_node ** rb_link, *rb_parent; | 
|  | 504 | unsigned int pstart, start_bit, end_bit, i; | 
|  | 505 | struct vm_area_struct *vma; | 
|  | 506 |  | 
|  | 507 | pstart = PAGE_START(start); | 
|  | 508 | start_bit = (start % PAGE_SIZE) / IA32_PAGE_SIZE; | 
|  | 509 | end_bit = (end % PAGE_SIZE) / IA32_PAGE_SIZE; | 
|  | 510 | if (end_bit == 0) | 
|  | 511 | end_bit = PAGE_SIZE / IA32_PAGE_SIZE; | 
|  | 512 |  | 
|  | 513 | pp = __ia32_find_pp(current->thread.ppl, pstart, &prev, | 
|  | 514 | &rb_link, &rb_parent); | 
|  | 515 | if (pp) { | 
|  | 516 | for (i = start_bit; i < end_bit; i++) | 
|  | 517 | clear_bit(i, &pp->bitmap); | 
|  | 518 | if (pp->bitmap == 0) { | 
|  | 519 | __ia32_delete_pp(current->thread.ppl, pp, __pp_prev(pp)); | 
|  | 520 | return 1; | 
|  | 521 | } | 
|  | 522 | return 0; | 
|  | 523 | } | 
|  | 524 |  | 
|  | 525 | vma = find_vma(current->mm, pstart); | 
|  | 526 | if (!vma || vma->vm_start > pstart) { | 
|  | 527 | return -ENOMEM; | 
|  | 528 | } | 
|  | 529 |  | 
|  | 530 | /* new a partial_page */ | 
|  | 531 | pp = kmem_cache_alloc(partial_page_cachep, GFP_KERNEL); | 
|  | 532 | if (!pp) | 
|  | 533 | return -ENOMEM; | 
|  | 534 | pp->base = pstart; | 
|  | 535 | pp->bitmap = 0; | 
|  | 536 | for (i = 0; i < start_bit; i++) | 
|  | 537 | set_bit(i, &(pp->bitmap)); | 
|  | 538 | for (i = end_bit; i < PAGE_SIZE / IA32_PAGE_SIZE; i++) | 
|  | 539 | set_bit(i, &(pp->bitmap)); | 
|  | 540 | pp->next = NULL; | 
|  | 541 | __ia32_insert_pp(current->thread.ppl, pp, prev, rb_link, rb_parent); | 
|  | 542 | return 0; | 
|  | 543 | } | 
|  | 544 |  | 
|  | 545 | /* | 
|  | 546 | * Delete pp between PAGE_ALIGN(start) and PAGE_START(end) by calling | 
|  | 547 | * __ia32_delete_pp_range(). Unset possible partial pages by calling | 
|  | 548 | * __ia32_unset_pp(). | 
|  | 549 | * The returned value see __ia32_unset_pp(). | 
|  | 550 | */ | 
|  | 551 | static int | 
|  | 552 | ia32_unset_pp(unsigned int *startp, unsigned int *endp) | 
|  | 553 | { | 
|  | 554 | unsigned int start = *startp, end = *endp; | 
|  | 555 | int ret = 0; | 
|  | 556 |  | 
|  | 557 | down_write(¤t->mm->mmap_sem); | 
|  | 558 |  | 
|  | 559 | __ia32_delete_pp_range(PAGE_ALIGN(start), PAGE_START(end)); | 
|  | 560 |  | 
|  | 561 | if (end < PAGE_ALIGN(start)) { | 
|  | 562 | ret = __ia32_unset_pp(start, end); | 
|  | 563 | if (ret == 1) { | 
|  | 564 | *startp = PAGE_START(start); | 
|  | 565 | *endp = PAGE_ALIGN(end); | 
|  | 566 | } | 
|  | 567 | if (ret == 0) { | 
|  | 568 | /* to shortcut sys_munmap() in sys32_munmap() */ | 
|  | 569 | *startp = PAGE_START(start); | 
|  | 570 | *endp = PAGE_START(end); | 
|  | 571 | } | 
|  | 572 | } else { | 
|  | 573 | if (offset_in_page(start)) { | 
|  | 574 | ret = __ia32_unset_pp(start, PAGE_ALIGN(start)); | 
|  | 575 | if (ret == 1) | 
|  | 576 | *startp = PAGE_START(start); | 
|  | 577 | if (ret == 0) | 
|  | 578 | *startp = PAGE_ALIGN(start); | 
|  | 579 | if (ret < 0) | 
|  | 580 | goto out; | 
|  | 581 | } | 
|  | 582 | if (offset_in_page(end)) { | 
|  | 583 | ret = __ia32_unset_pp(PAGE_START(end), end); | 
|  | 584 | if (ret == 1) | 
|  | 585 | *endp = PAGE_ALIGN(end); | 
|  | 586 | if (ret == 0) | 
|  | 587 | *endp = PAGE_START(end); | 
|  | 588 | } | 
|  | 589 | } | 
|  | 590 |  | 
|  | 591 | out: | 
|  | 592 | up_write(¤t->mm->mmap_sem); | 
|  | 593 | return ret; | 
|  | 594 | } | 
|  | 595 |  | 
|  | 596 | /* | 
|  | 597 | * Compare the range between @start and @end with bitmap in partial page. | 
|  | 598 | * @start and @end should be IA32 page aligned and in the same IA64 page. | 
|  | 599 | */ | 
|  | 600 | static int | 
|  | 601 | __ia32_compare_pp(unsigned int start, unsigned int end) | 
|  | 602 | { | 
|  | 603 | struct partial_page *pp, *prev; | 
|  | 604 | struct rb_node ** rb_link, *rb_parent; | 
|  | 605 | unsigned int pstart, start_bit, end_bit, size; | 
|  | 606 | unsigned int first_bit, next_zero_bit;	/* the first range in bitmap */ | 
|  | 607 |  | 
|  | 608 | pstart = PAGE_START(start); | 
|  | 609 |  | 
|  | 610 | pp = __ia32_find_pp(current->thread.ppl, pstart, &prev, | 
|  | 611 | &rb_link, &rb_parent); | 
|  | 612 | if (!pp) | 
|  | 613 | return 1; | 
|  | 614 |  | 
|  | 615 | start_bit = (start % PAGE_SIZE) / IA32_PAGE_SIZE; | 
|  | 616 | end_bit = (end % PAGE_SIZE) / IA32_PAGE_SIZE; | 
|  | 617 | size = sizeof(pp->bitmap) * 8; | 
|  | 618 | first_bit = find_first_bit(&pp->bitmap, size); | 
|  | 619 | next_zero_bit = find_next_zero_bit(&pp->bitmap, size, first_bit); | 
|  | 620 | if ((start_bit < first_bit) || (end_bit > next_zero_bit)) { | 
|  | 621 | /* exceeds the first range in bitmap */ | 
|  | 622 | return -ENOMEM; | 
|  | 623 | } else if ((start_bit == first_bit) && (end_bit == next_zero_bit)) { | 
|  | 624 | first_bit = find_next_bit(&pp->bitmap, size, next_zero_bit); | 
|  | 625 | if ((next_zero_bit < first_bit) && (first_bit < size)) | 
|  | 626 | return 1;	/* has next range */ | 
|  | 627 | else | 
|  | 628 | return 0; 	/* no next range */ | 
|  | 629 | } else | 
|  | 630 | return 1; | 
|  | 631 | } | 
|  | 632 |  | 
|  | 633 | /* | 
|  | 634 | * @start and @end should be IA32 page aligned, but don't need to be in the | 
|  | 635 | * same IA64 page. Split @start and @end to make sure they're in the same IA64 | 
|  | 636 | * page, then call __ia32_compare_pp(). | 
|  | 637 | * | 
|  | 638 | * Take this as example: the range is the 1st and 2nd 4K page. | 
|  | 639 | * Return 0 if they fit bitmap exactly, i.e. bitmap = 00000011; | 
|  | 640 | * Return 1 if the range doesn't cover whole bitmap, e.g. bitmap = 00001111; | 
|  | 641 | * Return -ENOMEM if the range exceeds the bitmap, e.g. bitmap = 00000001 or | 
|  | 642 | * 	bitmap = 00000101. | 
|  | 643 | */ | 
|  | 644 | static int | 
|  | 645 | ia32_compare_pp(unsigned int *startp, unsigned int *endp) | 
|  | 646 | { | 
|  | 647 | unsigned int start = *startp, end = *endp; | 
|  | 648 | int retval = 0; | 
|  | 649 |  | 
|  | 650 | down_write(¤t->mm->mmap_sem); | 
|  | 651 |  | 
|  | 652 | if (end < PAGE_ALIGN(start)) { | 
|  | 653 | retval = __ia32_compare_pp(start, end); | 
|  | 654 | if (retval == 0) { | 
|  | 655 | *startp = PAGE_START(start); | 
|  | 656 | *endp = PAGE_ALIGN(end); | 
|  | 657 | } | 
|  | 658 | } else { | 
|  | 659 | if (offset_in_page(start)) { | 
|  | 660 | retval = __ia32_compare_pp(start, | 
|  | 661 | PAGE_ALIGN(start)); | 
|  | 662 | if (retval == 0) | 
|  | 663 | *startp = PAGE_START(start); | 
|  | 664 | if (retval < 0) | 
|  | 665 | goto out; | 
|  | 666 | } | 
|  | 667 | if (offset_in_page(end)) { | 
|  | 668 | retval = __ia32_compare_pp(PAGE_START(end), end); | 
|  | 669 | if (retval == 0) | 
|  | 670 | *endp = PAGE_ALIGN(end); | 
|  | 671 | } | 
|  | 672 | } | 
|  | 673 |  | 
|  | 674 | out: | 
|  | 675 | up_write(¤t->mm->mmap_sem); | 
|  | 676 | return retval; | 
|  | 677 | } | 
|  | 678 |  | 
|  | 679 | static void | 
|  | 680 | __ia32_drop_pp_list(struct partial_page_list *ppl) | 
|  | 681 | { | 
|  | 682 | struct partial_page *pp = ppl->pp_head; | 
|  | 683 |  | 
|  | 684 | while (pp) { | 
|  | 685 | struct partial_page *next = pp->next; | 
|  | 686 | kmem_cache_free(partial_page_cachep, pp); | 
|  | 687 | pp = next; | 
|  | 688 | } | 
|  | 689 |  | 
|  | 690 | kfree(ppl); | 
|  | 691 | } | 
|  | 692 |  | 
|  | 693 | void | 
|  | 694 | ia32_drop_partial_page_list(struct task_struct *task) | 
|  | 695 | { | 
|  | 696 | struct partial_page_list* ppl = task->thread.ppl; | 
|  | 697 |  | 
|  | 698 | if (ppl && atomic_dec_and_test(&ppl->pp_count)) | 
|  | 699 | __ia32_drop_pp_list(ppl); | 
|  | 700 | } | 
|  | 701 |  | 
|  | 702 | /* | 
|  | 703 | * Copy current->thread.ppl to ppl (already initialized). | 
|  | 704 | */ | 
|  | 705 | static int | 
|  | 706 | __ia32_copy_pp_list(struct partial_page_list *ppl) | 
|  | 707 | { | 
|  | 708 | struct partial_page *pp, *tmp, *prev; | 
|  | 709 | struct rb_node **rb_link, *rb_parent; | 
|  | 710 |  | 
|  | 711 | ppl->pp_head = NULL; | 
|  | 712 | ppl->pp_hint = NULL; | 
|  | 713 | ppl->ppl_rb = RB_ROOT; | 
|  | 714 | rb_link = &ppl->ppl_rb.rb_node; | 
|  | 715 | rb_parent = NULL; | 
|  | 716 | prev = NULL; | 
|  | 717 |  | 
|  | 718 | for (pp = current->thread.ppl->pp_head; pp; pp = pp->next) { | 
|  | 719 | tmp = kmem_cache_alloc(partial_page_cachep, GFP_KERNEL); | 
|  | 720 | if (!tmp) | 
|  | 721 | return -ENOMEM; | 
|  | 722 | *tmp = *pp; | 
|  | 723 | __ia32_insert_pp(ppl, tmp, prev, rb_link, rb_parent); | 
|  | 724 | prev = tmp; | 
|  | 725 | rb_link = &tmp->pp_rb.rb_right; | 
|  | 726 | rb_parent = &tmp->pp_rb; | 
|  | 727 | } | 
|  | 728 | return 0; | 
|  | 729 | } | 
|  | 730 |  | 
|  | 731 | int | 
|  | 732 | ia32_copy_partial_page_list(struct task_struct *p, unsigned long clone_flags) | 
|  | 733 | { | 
|  | 734 | int retval = 0; | 
|  | 735 |  | 
|  | 736 | if (clone_flags & CLONE_VM) { | 
|  | 737 | atomic_inc(¤t->thread.ppl->pp_count); | 
|  | 738 | p->thread.ppl = current->thread.ppl; | 
|  | 739 | } else { | 
|  | 740 | p->thread.ppl = ia32_init_pp_list(); | 
|  | 741 | if (!p->thread.ppl) | 
|  | 742 | return -ENOMEM; | 
|  | 743 | down_write(¤t->mm->mmap_sem); | 
|  | 744 | { | 
|  | 745 | retval = __ia32_copy_pp_list(p->thread.ppl); | 
|  | 746 | } | 
|  | 747 | up_write(¤t->mm->mmap_sem); | 
|  | 748 | } | 
|  | 749 |  | 
|  | 750 | return retval; | 
|  | 751 | } | 
|  | 752 |  | 
|  | 753 | static unsigned long | 
|  | 754 | emulate_mmap (struct file *file, unsigned long start, unsigned long len, int prot, int flags, | 
|  | 755 | loff_t off) | 
|  | 756 | { | 
|  | 757 | unsigned long tmp, end, pend, pstart, ret, is_congruent, fudge = 0; | 
|  | 758 | struct inode *inode; | 
|  | 759 | loff_t poff; | 
|  | 760 |  | 
|  | 761 | end = start + len; | 
|  | 762 | pstart = PAGE_START(start); | 
|  | 763 | pend = PAGE_ALIGN(end); | 
|  | 764 |  | 
|  | 765 | if (flags & MAP_FIXED) { | 
|  | 766 | ia32_set_pp((unsigned int)start, (unsigned int)end, flags); | 
|  | 767 | if (start > pstart) { | 
|  | 768 | if (flags & MAP_SHARED) | 
|  | 769 | printk(KERN_INFO | 
|  | 770 | "%s(%d): emulate_mmap() can't share head (addr=0x%lx)\n", | 
|  | 771 | current->comm, current->pid, start); | 
|  | 772 | ret = mmap_subpage(file, start, min(PAGE_ALIGN(start), end), prot, flags, | 
|  | 773 | off); | 
|  | 774 | if (IS_ERR((void *) ret)) | 
|  | 775 | return ret; | 
|  | 776 | pstart += PAGE_SIZE; | 
|  | 777 | if (pstart >= pend) | 
|  | 778 | goto out;	/* done */ | 
|  | 779 | } | 
|  | 780 | if (end < pend) { | 
|  | 781 | if (flags & MAP_SHARED) | 
|  | 782 | printk(KERN_INFO | 
|  | 783 | "%s(%d): emulate_mmap() can't share tail (end=0x%lx)\n", | 
|  | 784 | current->comm, current->pid, end); | 
|  | 785 | ret = mmap_subpage(file, max(start, PAGE_START(end)), end, prot, flags, | 
|  | 786 | (off + len) - offset_in_page(end)); | 
|  | 787 | if (IS_ERR((void *) ret)) | 
|  | 788 | return ret; | 
|  | 789 | pend -= PAGE_SIZE; | 
|  | 790 | if (pstart >= pend) | 
|  | 791 | goto out;	/* done */ | 
|  | 792 | } | 
|  | 793 | } else { | 
|  | 794 | /* | 
|  | 795 | * If a start address was specified, use it if the entire rounded out area | 
|  | 796 | * is available. | 
|  | 797 | */ | 
|  | 798 | if (start && !pstart) | 
|  | 799 | fudge = 1;	/* handle case of mapping to range (0,PAGE_SIZE) */ | 
|  | 800 | tmp = arch_get_unmapped_area(file, pstart - fudge, pend - pstart, 0, flags); | 
|  | 801 | if (tmp != pstart) { | 
|  | 802 | pstart = tmp; | 
|  | 803 | start = pstart + offset_in_page(off);	/* make start congruent with off */ | 
|  | 804 | end = start + len; | 
|  | 805 | pend = PAGE_ALIGN(end); | 
|  | 806 | } | 
|  | 807 | } | 
|  | 808 |  | 
|  | 809 | poff = off + (pstart - start);	/* note: (pstart - start) may be negative */ | 
|  | 810 | is_congruent = (flags & MAP_ANONYMOUS) || (offset_in_page(poff) == 0); | 
|  | 811 |  | 
|  | 812 | if ((flags & MAP_SHARED) && !is_congruent) | 
|  | 813 | printk(KERN_INFO "%s(%d): emulate_mmap() can't share contents of incongruent mmap " | 
|  | 814 | "(addr=0x%lx,off=0x%llx)\n", current->comm, current->pid, start, off); | 
|  | 815 |  | 
|  | 816 | DBG("mmap_body: mapping [0x%lx-0x%lx) %s with poff 0x%llx\n", pstart, pend, | 
|  | 817 | is_congruent ? "congruent" : "not congruent", poff); | 
|  | 818 |  | 
|  | 819 | down_write(¤t->mm->mmap_sem); | 
|  | 820 | { | 
|  | 821 | if (!(flags & MAP_ANONYMOUS) && is_congruent) | 
|  | 822 | ret = do_mmap(file, pstart, pend - pstart, prot, flags | MAP_FIXED, poff); | 
|  | 823 | else | 
|  | 824 | ret = do_mmap(NULL, pstart, pend - pstart, | 
|  | 825 | prot | ((flags & MAP_ANONYMOUS) ? 0 : PROT_WRITE), | 
|  | 826 | flags | MAP_FIXED | MAP_ANONYMOUS, 0); | 
|  | 827 | } | 
|  | 828 | up_write(¤t->mm->mmap_sem); | 
|  | 829 |  | 
|  | 830 | if (IS_ERR((void *) ret)) | 
|  | 831 | return ret; | 
|  | 832 |  | 
|  | 833 | if (!is_congruent) { | 
|  | 834 | /* read the file contents */ | 
|  | 835 | inode = file->f_dentry->d_inode; | 
|  | 836 | if (!inode->i_fop || !file->f_op->read | 
|  | 837 | || ((*file->f_op->read)(file, (char __user *) pstart, pend - pstart, &poff) | 
|  | 838 | < 0)) | 
|  | 839 | { | 
|  | 840 | sys_munmap(pstart, pend - pstart); | 
|  | 841 | return -EINVAL; | 
|  | 842 | } | 
|  | 843 | if (!(prot & PROT_WRITE) && sys_mprotect(pstart, pend - pstart, prot) < 0) | 
|  | 844 | return -EINVAL; | 
|  | 845 | } | 
|  | 846 |  | 
|  | 847 | if (!(flags & MAP_FIXED)) | 
|  | 848 | ia32_set_pp((unsigned int)start, (unsigned int)end, flags); | 
|  | 849 | out: | 
|  | 850 | return start; | 
|  | 851 | } | 
|  | 852 |  | 
|  | 853 | #endif /* PAGE_SHIFT > IA32_PAGE_SHIFT */ | 
|  | 854 |  | 
|  | 855 | static inline unsigned int | 
|  | 856 | get_prot32 (unsigned int prot) | 
|  | 857 | { | 
|  | 858 | if (prot & PROT_WRITE) | 
|  | 859 | /* on x86, PROT_WRITE implies PROT_READ which implies PROT_EEC */ | 
|  | 860 | prot |= PROT_READ | PROT_WRITE | PROT_EXEC; | 
|  | 861 | else if (prot & (PROT_READ | PROT_EXEC)) | 
|  | 862 | /* on x86, there is no distinction between PROT_READ and PROT_EXEC */ | 
|  | 863 | prot |= (PROT_READ | PROT_EXEC); | 
|  | 864 |  | 
|  | 865 | return prot; | 
|  | 866 | } | 
|  | 867 |  | 
|  | 868 | unsigned long | 
|  | 869 | ia32_do_mmap (struct file *file, unsigned long addr, unsigned long len, int prot, int flags, | 
|  | 870 | loff_t offset) | 
|  | 871 | { | 
|  | 872 | DBG("ia32_do_mmap(file=%p,addr=0x%lx,len=0x%lx,prot=%x,flags=%x,offset=0x%llx)\n", | 
|  | 873 | file, addr, len, prot, flags, offset); | 
|  | 874 |  | 
|  | 875 | if (file && (!file->f_op || !file->f_op->mmap)) | 
|  | 876 | return -ENODEV; | 
|  | 877 |  | 
|  | 878 | len = IA32_PAGE_ALIGN(len); | 
|  | 879 | if (len == 0) | 
|  | 880 | return addr; | 
|  | 881 |  | 
|  | 882 | if (len > IA32_PAGE_OFFSET || addr > IA32_PAGE_OFFSET - len) | 
|  | 883 | { | 
|  | 884 | if (flags & MAP_FIXED) | 
|  | 885 | return -ENOMEM; | 
|  | 886 | else | 
|  | 887 | return -EINVAL; | 
|  | 888 | } | 
|  | 889 |  | 
|  | 890 | if (OFFSET4K(offset)) | 
|  | 891 | return -EINVAL; | 
|  | 892 |  | 
|  | 893 | prot = get_prot32(prot); | 
|  | 894 |  | 
|  | 895 | #if PAGE_SHIFT > IA32_PAGE_SHIFT | 
|  | 896 | down(&ia32_mmap_sem); | 
|  | 897 | { | 
|  | 898 | addr = emulate_mmap(file, addr, len, prot, flags, offset); | 
|  | 899 | } | 
|  | 900 | up(&ia32_mmap_sem); | 
|  | 901 | #else | 
|  | 902 | down_write(¤t->mm->mmap_sem); | 
|  | 903 | { | 
|  | 904 | addr = do_mmap(file, addr, len, prot, flags, offset); | 
|  | 905 | } | 
|  | 906 | up_write(¤t->mm->mmap_sem); | 
|  | 907 | #endif | 
|  | 908 | DBG("ia32_do_mmap: returning 0x%lx\n", addr); | 
|  | 909 | return addr; | 
|  | 910 | } | 
|  | 911 |  | 
|  | 912 | /* | 
|  | 913 | * Linux/i386 didn't use to be able to handle more than 4 system call parameters, so these | 
|  | 914 | * system calls used a memory block for parameter passing.. | 
|  | 915 | */ | 
|  | 916 |  | 
|  | 917 | struct mmap_arg_struct { | 
|  | 918 | unsigned int addr; | 
|  | 919 | unsigned int len; | 
|  | 920 | unsigned int prot; | 
|  | 921 | unsigned int flags; | 
|  | 922 | unsigned int fd; | 
|  | 923 | unsigned int offset; | 
|  | 924 | }; | 
|  | 925 |  | 
|  | 926 | asmlinkage long | 
|  | 927 | sys32_mmap (struct mmap_arg_struct __user *arg) | 
|  | 928 | { | 
|  | 929 | struct mmap_arg_struct a; | 
|  | 930 | struct file *file = NULL; | 
|  | 931 | unsigned long addr; | 
|  | 932 | int flags; | 
|  | 933 |  | 
|  | 934 | if (copy_from_user(&a, arg, sizeof(a))) | 
|  | 935 | return -EFAULT; | 
|  | 936 |  | 
|  | 937 | if (OFFSET4K(a.offset)) | 
|  | 938 | return -EINVAL; | 
|  | 939 |  | 
|  | 940 | flags = a.flags; | 
|  | 941 |  | 
|  | 942 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | 
|  | 943 | if (!(flags & MAP_ANONYMOUS)) { | 
|  | 944 | file = fget(a.fd); | 
|  | 945 | if (!file) | 
|  | 946 | return -EBADF; | 
|  | 947 | } | 
|  | 948 |  | 
|  | 949 | addr = ia32_do_mmap(file, a.addr, a.len, a.prot, flags, a.offset); | 
|  | 950 |  | 
|  | 951 | if (file) | 
|  | 952 | fput(file); | 
|  | 953 | return addr; | 
|  | 954 | } | 
|  | 955 |  | 
|  | 956 | asmlinkage long | 
|  | 957 | sys32_mmap2 (unsigned int addr, unsigned int len, unsigned int prot, unsigned int flags, | 
|  | 958 | unsigned int fd, unsigned int pgoff) | 
|  | 959 | { | 
|  | 960 | struct file *file = NULL; | 
|  | 961 | unsigned long retval; | 
|  | 962 |  | 
|  | 963 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | 
|  | 964 | if (!(flags & MAP_ANONYMOUS)) { | 
|  | 965 | file = fget(fd); | 
|  | 966 | if (!file) | 
|  | 967 | return -EBADF; | 
|  | 968 | } | 
|  | 969 |  | 
|  | 970 | retval = ia32_do_mmap(file, addr, len, prot, flags, | 
|  | 971 | (unsigned long) pgoff << IA32_PAGE_SHIFT); | 
|  | 972 |  | 
|  | 973 | if (file) | 
|  | 974 | fput(file); | 
|  | 975 | return retval; | 
|  | 976 | } | 
|  | 977 |  | 
|  | 978 | asmlinkage long | 
|  | 979 | sys32_munmap (unsigned int start, unsigned int len) | 
|  | 980 | { | 
|  | 981 | unsigned int end = start + len; | 
|  | 982 | long ret; | 
|  | 983 |  | 
|  | 984 | #if PAGE_SHIFT <= IA32_PAGE_SHIFT | 
|  | 985 | ret = sys_munmap(start, end - start); | 
|  | 986 | #else | 
|  | 987 | if (OFFSET4K(start)) | 
|  | 988 | return -EINVAL; | 
|  | 989 |  | 
|  | 990 | end = IA32_PAGE_ALIGN(end); | 
|  | 991 | if (start >= end) | 
|  | 992 | return -EINVAL; | 
|  | 993 |  | 
|  | 994 | ret = ia32_unset_pp(&start, &end); | 
|  | 995 | if (ret < 0) | 
|  | 996 | return ret; | 
|  | 997 |  | 
|  | 998 | if (start >= end) | 
|  | 999 | return 0; | 
|  | 1000 |  | 
|  | 1001 | down(&ia32_mmap_sem); | 
|  | 1002 | { | 
|  | 1003 | ret = sys_munmap(start, end - start); | 
|  | 1004 | } | 
|  | 1005 | up(&ia32_mmap_sem); | 
|  | 1006 | #endif | 
|  | 1007 | return ret; | 
|  | 1008 | } | 
|  | 1009 |  | 
|  | 1010 | #if PAGE_SHIFT > IA32_PAGE_SHIFT | 
|  | 1011 |  | 
|  | 1012 | /* | 
|  | 1013 | * When mprotect()ing a partial page, we set the permission to the union of the old | 
|  | 1014 | * settings and the new settings.  In other words, it's only possible to make access to a | 
|  | 1015 | * partial page less restrictive. | 
|  | 1016 | */ | 
|  | 1017 | static long | 
|  | 1018 | mprotect_subpage (unsigned long address, int new_prot) | 
|  | 1019 | { | 
|  | 1020 | int old_prot; | 
|  | 1021 | struct vm_area_struct *vma; | 
|  | 1022 |  | 
|  | 1023 | if (new_prot == PROT_NONE) | 
|  | 1024 | return 0;		/* optimize case where nothing changes... */ | 
|  | 1025 | vma = find_vma(current->mm, address); | 
|  | 1026 | old_prot = get_page_prot(vma, address); | 
|  | 1027 | return sys_mprotect(address, PAGE_SIZE, new_prot | old_prot); | 
|  | 1028 | } | 
|  | 1029 |  | 
|  | 1030 | #endif /* PAGE_SHIFT > IA32_PAGE_SHIFT */ | 
|  | 1031 |  | 
|  | 1032 | asmlinkage long | 
|  | 1033 | sys32_mprotect (unsigned int start, unsigned int len, int prot) | 
|  | 1034 | { | 
|  | 1035 | unsigned int end = start + len; | 
|  | 1036 | #if PAGE_SHIFT > IA32_PAGE_SHIFT | 
|  | 1037 | long retval = 0; | 
|  | 1038 | #endif | 
|  | 1039 |  | 
|  | 1040 | prot = get_prot32(prot); | 
|  | 1041 |  | 
|  | 1042 | #if PAGE_SHIFT <= IA32_PAGE_SHIFT | 
|  | 1043 | return sys_mprotect(start, end - start, prot); | 
|  | 1044 | #else | 
|  | 1045 | if (OFFSET4K(start)) | 
|  | 1046 | return -EINVAL; | 
|  | 1047 |  | 
|  | 1048 | end = IA32_PAGE_ALIGN(end); | 
|  | 1049 | if (end < start) | 
|  | 1050 | return -EINVAL; | 
|  | 1051 |  | 
|  | 1052 | retval = ia32_compare_pp(&start, &end); | 
|  | 1053 |  | 
|  | 1054 | if (retval < 0) | 
|  | 1055 | return retval; | 
|  | 1056 |  | 
|  | 1057 | down(&ia32_mmap_sem); | 
|  | 1058 | { | 
|  | 1059 | if (offset_in_page(start)) { | 
|  | 1060 | /* start address is 4KB aligned but not page aligned. */ | 
|  | 1061 | retval = mprotect_subpage(PAGE_START(start), prot); | 
|  | 1062 | if (retval < 0) | 
|  | 1063 | goto out; | 
|  | 1064 |  | 
|  | 1065 | start = PAGE_ALIGN(start); | 
|  | 1066 | if (start >= end) | 
|  | 1067 | goto out;	/* retval is already zero... */ | 
|  | 1068 | } | 
|  | 1069 |  | 
|  | 1070 | if (offset_in_page(end)) { | 
|  | 1071 | /* end address is 4KB aligned but not page aligned. */ | 
|  | 1072 | retval = mprotect_subpage(PAGE_START(end), prot); | 
|  | 1073 | if (retval < 0) | 
|  | 1074 | goto out; | 
|  | 1075 |  | 
|  | 1076 | end = PAGE_START(end); | 
|  | 1077 | } | 
|  | 1078 | retval = sys_mprotect(start, end - start, prot); | 
|  | 1079 | } | 
|  | 1080 | out: | 
|  | 1081 | up(&ia32_mmap_sem); | 
|  | 1082 | return retval; | 
|  | 1083 | #endif | 
|  | 1084 | } | 
|  | 1085 |  | 
|  | 1086 | asmlinkage long | 
|  | 1087 | sys32_mremap (unsigned int addr, unsigned int old_len, unsigned int new_len, | 
|  | 1088 | unsigned int flags, unsigned int new_addr) | 
|  | 1089 | { | 
|  | 1090 | long ret; | 
|  | 1091 |  | 
|  | 1092 | #if PAGE_SHIFT <= IA32_PAGE_SHIFT | 
|  | 1093 | ret = sys_mremap(addr, old_len, new_len, flags, new_addr); | 
|  | 1094 | #else | 
|  | 1095 | unsigned int old_end, new_end; | 
|  | 1096 |  | 
|  | 1097 | if (OFFSET4K(addr)) | 
|  | 1098 | return -EINVAL; | 
|  | 1099 |  | 
|  | 1100 | old_len = IA32_PAGE_ALIGN(old_len); | 
|  | 1101 | new_len = IA32_PAGE_ALIGN(new_len); | 
|  | 1102 | old_end = addr + old_len; | 
|  | 1103 | new_end = addr + new_len; | 
|  | 1104 |  | 
|  | 1105 | if (!new_len) | 
|  | 1106 | return -EINVAL; | 
|  | 1107 |  | 
|  | 1108 | if ((flags & MREMAP_FIXED) && (OFFSET4K(new_addr))) | 
|  | 1109 | return -EINVAL; | 
|  | 1110 |  | 
|  | 1111 | if (old_len >= new_len) { | 
|  | 1112 | ret = sys32_munmap(addr + new_len, old_len - new_len); | 
|  | 1113 | if (ret && old_len != new_len) | 
|  | 1114 | return ret; | 
|  | 1115 | ret = addr; | 
|  | 1116 | if (!(flags & MREMAP_FIXED) || (new_addr == addr)) | 
|  | 1117 | return ret; | 
|  | 1118 | old_len = new_len; | 
|  | 1119 | } | 
|  | 1120 |  | 
|  | 1121 | addr = PAGE_START(addr); | 
|  | 1122 | old_len = PAGE_ALIGN(old_end) - addr; | 
|  | 1123 | new_len = PAGE_ALIGN(new_end) - addr; | 
|  | 1124 |  | 
|  | 1125 | down(&ia32_mmap_sem); | 
|  | 1126 | { | 
|  | 1127 | ret = sys_mremap(addr, old_len, new_len, flags, new_addr); | 
|  | 1128 | } | 
|  | 1129 | up(&ia32_mmap_sem); | 
|  | 1130 |  | 
|  | 1131 | if ((ret >= 0) && (old_len < new_len)) { | 
|  | 1132 | /* mremap expanded successfully */ | 
|  | 1133 | ia32_set_pp(old_end, new_end, flags); | 
|  | 1134 | } | 
|  | 1135 | #endif | 
|  | 1136 | return ret; | 
|  | 1137 | } | 
|  | 1138 |  | 
|  | 1139 | asmlinkage long | 
|  | 1140 | sys32_pipe (int __user *fd) | 
|  | 1141 | { | 
|  | 1142 | int retval; | 
|  | 1143 | int fds[2]; | 
|  | 1144 |  | 
|  | 1145 | retval = do_pipe(fds); | 
|  | 1146 | if (retval) | 
|  | 1147 | goto out; | 
|  | 1148 | if (copy_to_user(fd, fds, sizeof(fds))) | 
|  | 1149 | retval = -EFAULT; | 
|  | 1150 | out: | 
|  | 1151 | return retval; | 
|  | 1152 | } | 
|  | 1153 |  | 
|  | 1154 | static inline long | 
|  | 1155 | get_tv32 (struct timeval *o, struct compat_timeval __user *i) | 
|  | 1156 | { | 
|  | 1157 | return (!access_ok(VERIFY_READ, i, sizeof(*i)) || | 
|  | 1158 | (__get_user(o->tv_sec, &i->tv_sec) | __get_user(o->tv_usec, &i->tv_usec))); | 
|  | 1159 | } | 
|  | 1160 |  | 
|  | 1161 | static inline long | 
|  | 1162 | put_tv32 (struct compat_timeval __user *o, struct timeval *i) | 
|  | 1163 | { | 
|  | 1164 | return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) || | 
|  | 1165 | (__put_user(i->tv_sec, &o->tv_sec) | __put_user(i->tv_usec, &o->tv_usec))); | 
|  | 1166 | } | 
|  | 1167 |  | 
|  | 1168 | asmlinkage unsigned long | 
|  | 1169 | sys32_alarm (unsigned int seconds) | 
|  | 1170 | { | 
|  | 1171 | struct itimerval it_new, it_old; | 
|  | 1172 | unsigned int oldalarm; | 
|  | 1173 |  | 
|  | 1174 | it_new.it_interval.tv_sec = it_new.it_interval.tv_usec = 0; | 
|  | 1175 | it_new.it_value.tv_sec = seconds; | 
|  | 1176 | it_new.it_value.tv_usec = 0; | 
|  | 1177 | do_setitimer(ITIMER_REAL, &it_new, &it_old); | 
|  | 1178 | oldalarm = it_old.it_value.tv_sec; | 
|  | 1179 | /* ehhh.. We can't return 0 if we have an alarm pending.. */ | 
|  | 1180 | /* And we'd better return too much than too little anyway */ | 
|  | 1181 | if (it_old.it_value.tv_usec) | 
|  | 1182 | oldalarm++; | 
|  | 1183 | return oldalarm; | 
|  | 1184 | } | 
|  | 1185 |  | 
|  | 1186 | /* Translations due to time_t size differences.  Which affects all | 
|  | 1187 | sorts of things, like timeval and itimerval.  */ | 
|  | 1188 |  | 
|  | 1189 | extern struct timezone sys_tz; | 
|  | 1190 |  | 
|  | 1191 | asmlinkage long | 
|  | 1192 | sys32_gettimeofday (struct compat_timeval __user *tv, struct timezone __user *tz) | 
|  | 1193 | { | 
|  | 1194 | if (tv) { | 
|  | 1195 | struct timeval ktv; | 
|  | 1196 | do_gettimeofday(&ktv); | 
|  | 1197 | if (put_tv32(tv, &ktv)) | 
|  | 1198 | return -EFAULT; | 
|  | 1199 | } | 
|  | 1200 | if (tz) { | 
|  | 1201 | if (copy_to_user(tz, &sys_tz, sizeof(sys_tz))) | 
|  | 1202 | return -EFAULT; | 
|  | 1203 | } | 
|  | 1204 | return 0; | 
|  | 1205 | } | 
|  | 1206 |  | 
|  | 1207 | asmlinkage long | 
|  | 1208 | sys32_settimeofday (struct compat_timeval __user *tv, struct timezone __user *tz) | 
|  | 1209 | { | 
|  | 1210 | struct timeval ktv; | 
|  | 1211 | struct timespec kts; | 
|  | 1212 | struct timezone ktz; | 
|  | 1213 |  | 
|  | 1214 | if (tv) { | 
|  | 1215 | if (get_tv32(&ktv, tv)) | 
|  | 1216 | return -EFAULT; | 
|  | 1217 | kts.tv_sec = ktv.tv_sec; | 
|  | 1218 | kts.tv_nsec = ktv.tv_usec * 1000; | 
|  | 1219 | } | 
|  | 1220 | if (tz) { | 
|  | 1221 | if (copy_from_user(&ktz, tz, sizeof(ktz))) | 
|  | 1222 | return -EFAULT; | 
|  | 1223 | } | 
|  | 1224 |  | 
|  | 1225 | return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL); | 
|  | 1226 | } | 
|  | 1227 |  | 
|  | 1228 | struct getdents32_callback { | 
|  | 1229 | struct compat_dirent __user *current_dir; | 
|  | 1230 | struct compat_dirent __user *previous; | 
|  | 1231 | int count; | 
|  | 1232 | int error; | 
|  | 1233 | }; | 
|  | 1234 |  | 
|  | 1235 | struct readdir32_callback { | 
|  | 1236 | struct old_linux32_dirent __user * dirent; | 
|  | 1237 | int count; | 
|  | 1238 | }; | 
|  | 1239 |  | 
|  | 1240 | static int | 
|  | 1241 | filldir32 (void *__buf, const char *name, int namlen, loff_t offset, ino_t ino, | 
|  | 1242 | unsigned int d_type) | 
|  | 1243 | { | 
|  | 1244 | struct compat_dirent __user * dirent; | 
|  | 1245 | struct getdents32_callback * buf = (struct getdents32_callback *) __buf; | 
|  | 1246 | int reclen = ROUND_UP(offsetof(struct compat_dirent, d_name) + namlen + 1, 4); | 
|  | 1247 |  | 
|  | 1248 | buf->error = -EINVAL;	/* only used if we fail.. */ | 
|  | 1249 | if (reclen > buf->count) | 
|  | 1250 | return -EINVAL; | 
|  | 1251 | buf->error = -EFAULT;	/* only used if we fail.. */ | 
|  | 1252 | dirent = buf->previous; | 
|  | 1253 | if (dirent) | 
|  | 1254 | if (put_user(offset, &dirent->d_off)) | 
|  | 1255 | return -EFAULT; | 
|  | 1256 | dirent = buf->current_dir; | 
|  | 1257 | buf->previous = dirent; | 
|  | 1258 | if (put_user(ino, &dirent->d_ino) | 
|  | 1259 | || put_user(reclen, &dirent->d_reclen) | 
|  | 1260 | || copy_to_user(dirent->d_name, name, namlen) | 
|  | 1261 | || put_user(0, dirent->d_name + namlen)) | 
|  | 1262 | return -EFAULT; | 
|  | 1263 | dirent = (struct compat_dirent __user *) ((char __user *) dirent + reclen); | 
|  | 1264 | buf->current_dir = dirent; | 
|  | 1265 | buf->count -= reclen; | 
|  | 1266 | return 0; | 
|  | 1267 | } | 
|  | 1268 |  | 
|  | 1269 | asmlinkage long | 
|  | 1270 | sys32_getdents (unsigned int fd, struct compat_dirent __user *dirent, unsigned int count) | 
|  | 1271 | { | 
|  | 1272 | struct file * file; | 
|  | 1273 | struct compat_dirent __user * lastdirent; | 
|  | 1274 | struct getdents32_callback buf; | 
|  | 1275 | int error; | 
|  | 1276 |  | 
|  | 1277 | error = -EBADF; | 
|  | 1278 | file = fget(fd); | 
|  | 1279 | if (!file) | 
|  | 1280 | goto out; | 
|  | 1281 |  | 
|  | 1282 | buf.current_dir = dirent; | 
|  | 1283 | buf.previous = NULL; | 
|  | 1284 | buf.count = count; | 
|  | 1285 | buf.error = 0; | 
|  | 1286 |  | 
|  | 1287 | error = vfs_readdir(file, filldir32, &buf); | 
|  | 1288 | if (error < 0) | 
|  | 1289 | goto out_putf; | 
|  | 1290 | error = buf.error; | 
|  | 1291 | lastdirent = buf.previous; | 
|  | 1292 | if (lastdirent) { | 
|  | 1293 | error = -EINVAL; | 
|  | 1294 | if (put_user(file->f_pos, &lastdirent->d_off)) | 
|  | 1295 | goto out_putf; | 
|  | 1296 | error = count - buf.count; | 
|  | 1297 | } | 
|  | 1298 |  | 
|  | 1299 | out_putf: | 
|  | 1300 | fput(file); | 
|  | 1301 | out: | 
|  | 1302 | return error; | 
|  | 1303 | } | 
|  | 1304 |  | 
|  | 1305 | static int | 
|  | 1306 | fillonedir32 (void * __buf, const char * name, int namlen, loff_t offset, ino_t ino, | 
|  | 1307 | unsigned int d_type) | 
|  | 1308 | { | 
|  | 1309 | struct readdir32_callback * buf = (struct readdir32_callback *) __buf; | 
|  | 1310 | struct old_linux32_dirent __user * dirent; | 
|  | 1311 |  | 
|  | 1312 | if (buf->count) | 
|  | 1313 | return -EINVAL; | 
|  | 1314 | buf->count++; | 
|  | 1315 | dirent = buf->dirent; | 
|  | 1316 | if (put_user(ino, &dirent->d_ino) | 
|  | 1317 | || put_user(offset, &dirent->d_offset) | 
|  | 1318 | || put_user(namlen, &dirent->d_namlen) | 
|  | 1319 | || copy_to_user(dirent->d_name, name, namlen) | 
|  | 1320 | || put_user(0, dirent->d_name + namlen)) | 
|  | 1321 | return -EFAULT; | 
|  | 1322 | return 0; | 
|  | 1323 | } | 
|  | 1324 |  | 
|  | 1325 | asmlinkage long | 
|  | 1326 | sys32_readdir (unsigned int fd, void __user *dirent, unsigned int count) | 
|  | 1327 | { | 
|  | 1328 | int error; | 
|  | 1329 | struct file * file; | 
|  | 1330 | struct readdir32_callback buf; | 
|  | 1331 |  | 
|  | 1332 | error = -EBADF; | 
|  | 1333 | file = fget(fd); | 
|  | 1334 | if (!file) | 
|  | 1335 | goto out; | 
|  | 1336 |  | 
|  | 1337 | buf.count = 0; | 
|  | 1338 | buf.dirent = dirent; | 
|  | 1339 |  | 
|  | 1340 | error = vfs_readdir(file, fillonedir32, &buf); | 
|  | 1341 | if (error >= 0) | 
|  | 1342 | error = buf.count; | 
|  | 1343 | fput(file); | 
|  | 1344 | out: | 
|  | 1345 | return error; | 
|  | 1346 | } | 
|  | 1347 |  | 
|  | 1348 | struct sel_arg_struct { | 
|  | 1349 | unsigned int n; | 
|  | 1350 | unsigned int inp; | 
|  | 1351 | unsigned int outp; | 
|  | 1352 | unsigned int exp; | 
|  | 1353 | unsigned int tvp; | 
|  | 1354 | }; | 
|  | 1355 |  | 
|  | 1356 | asmlinkage long | 
|  | 1357 | sys32_old_select (struct sel_arg_struct __user *arg) | 
|  | 1358 | { | 
|  | 1359 | struct sel_arg_struct a; | 
|  | 1360 |  | 
|  | 1361 | if (copy_from_user(&a, arg, sizeof(a))) | 
|  | 1362 | return -EFAULT; | 
|  | 1363 | return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp), | 
|  | 1364 | compat_ptr(a.exp), compat_ptr(a.tvp)); | 
|  | 1365 | } | 
|  | 1366 |  | 
|  | 1367 | #define SEMOP		 1 | 
|  | 1368 | #define SEMGET		 2 | 
|  | 1369 | #define SEMCTL		 3 | 
|  | 1370 | #define SEMTIMEDOP	 4 | 
|  | 1371 | #define MSGSND		11 | 
|  | 1372 | #define MSGRCV		12 | 
|  | 1373 | #define MSGGET		13 | 
|  | 1374 | #define MSGCTL		14 | 
|  | 1375 | #define SHMAT		21 | 
|  | 1376 | #define SHMDT		22 | 
|  | 1377 | #define SHMGET		23 | 
|  | 1378 | #define SHMCTL		24 | 
|  | 1379 |  | 
|  | 1380 | asmlinkage long | 
|  | 1381 | sys32_ipc(u32 call, int first, int second, int third, u32 ptr, u32 fifth) | 
|  | 1382 | { | 
|  | 1383 | int version; | 
|  | 1384 |  | 
|  | 1385 | version = call >> 16; /* hack for backward compatibility */ | 
|  | 1386 | call &= 0xffff; | 
|  | 1387 |  | 
|  | 1388 | switch (call) { | 
|  | 1389 | case SEMTIMEDOP: | 
|  | 1390 | if (fifth) | 
|  | 1391 | return compat_sys_semtimedop(first, compat_ptr(ptr), | 
|  | 1392 | second, compat_ptr(fifth)); | 
|  | 1393 | /* else fall through for normal semop() */ | 
|  | 1394 | case SEMOP: | 
|  | 1395 | /* struct sembuf is the same on 32 and 64bit :)) */ | 
|  | 1396 | return sys_semtimedop(first, compat_ptr(ptr), second, | 
|  | 1397 | NULL); | 
|  | 1398 | case SEMGET: | 
|  | 1399 | return sys_semget(first, second, third); | 
|  | 1400 | case SEMCTL: | 
|  | 1401 | return compat_sys_semctl(first, second, third, compat_ptr(ptr)); | 
|  | 1402 |  | 
|  | 1403 | case MSGSND: | 
|  | 1404 | return compat_sys_msgsnd(first, second, third, compat_ptr(ptr)); | 
|  | 1405 | case MSGRCV: | 
|  | 1406 | return compat_sys_msgrcv(first, second, fifth, third, version, compat_ptr(ptr)); | 
|  | 1407 | case MSGGET: | 
|  | 1408 | return sys_msgget((key_t) first, second); | 
|  | 1409 | case MSGCTL: | 
|  | 1410 | return compat_sys_msgctl(first, second, compat_ptr(ptr)); | 
|  | 1411 |  | 
|  | 1412 | case SHMAT: | 
|  | 1413 | return compat_sys_shmat(first, second, third, version, compat_ptr(ptr)); | 
|  | 1414 | break; | 
|  | 1415 | case SHMDT: | 
|  | 1416 | return sys_shmdt(compat_ptr(ptr)); | 
|  | 1417 | case SHMGET: | 
|  | 1418 | return sys_shmget(first, (unsigned)second, third); | 
|  | 1419 | case SHMCTL: | 
|  | 1420 | return compat_sys_shmctl(first, second, compat_ptr(ptr)); | 
|  | 1421 |  | 
|  | 1422 | default: | 
|  | 1423 | return -ENOSYS; | 
|  | 1424 | } | 
|  | 1425 | return -EINVAL; | 
|  | 1426 | } | 
|  | 1427 |  | 
|  | 1428 | asmlinkage long | 
|  | 1429 | compat_sys_wait4 (compat_pid_t pid, compat_uint_t * stat_addr, int options, | 
|  | 1430 | struct compat_rusage *ru); | 
|  | 1431 |  | 
|  | 1432 | asmlinkage long | 
|  | 1433 | sys32_waitpid (int pid, unsigned int *stat_addr, int options) | 
|  | 1434 | { | 
|  | 1435 | return compat_sys_wait4(pid, stat_addr, options, NULL); | 
|  | 1436 | } | 
|  | 1437 |  | 
|  | 1438 | static unsigned int | 
|  | 1439 | ia32_peek (struct task_struct *child, unsigned long addr, unsigned int *val) | 
|  | 1440 | { | 
|  | 1441 | size_t copied; | 
|  | 1442 | unsigned int ret; | 
|  | 1443 |  | 
|  | 1444 | copied = access_process_vm(child, addr, val, sizeof(*val), 0); | 
|  | 1445 | return (copied != sizeof(ret)) ? -EIO : 0; | 
|  | 1446 | } | 
|  | 1447 |  | 
|  | 1448 | static unsigned int | 
|  | 1449 | ia32_poke (struct task_struct *child, unsigned long addr, unsigned int val) | 
|  | 1450 | { | 
|  | 1451 |  | 
|  | 1452 | if (access_process_vm(child, addr, &val, sizeof(val), 1) != sizeof(val)) | 
|  | 1453 | return -EIO; | 
|  | 1454 | return 0; | 
|  | 1455 | } | 
|  | 1456 |  | 
|  | 1457 | /* | 
|  | 1458 | *  The order in which registers are stored in the ptrace regs structure | 
|  | 1459 | */ | 
|  | 1460 | #define PT_EBX	0 | 
|  | 1461 | #define PT_ECX	1 | 
|  | 1462 | #define PT_EDX	2 | 
|  | 1463 | #define PT_ESI	3 | 
|  | 1464 | #define PT_EDI	4 | 
|  | 1465 | #define PT_EBP	5 | 
|  | 1466 | #define PT_EAX	6 | 
|  | 1467 | #define PT_DS	7 | 
|  | 1468 | #define PT_ES	8 | 
|  | 1469 | #define PT_FS	9 | 
|  | 1470 | #define PT_GS	10 | 
|  | 1471 | #define PT_ORIG_EAX 11 | 
|  | 1472 | #define PT_EIP	12 | 
|  | 1473 | #define PT_CS	13 | 
|  | 1474 | #define PT_EFL	14 | 
|  | 1475 | #define PT_UESP	15 | 
|  | 1476 | #define PT_SS	16 | 
|  | 1477 |  | 
|  | 1478 | static unsigned int | 
|  | 1479 | getreg (struct task_struct *child, int regno) | 
|  | 1480 | { | 
|  | 1481 | struct pt_regs *child_regs; | 
|  | 1482 |  | 
|  | 1483 | child_regs = ia64_task_regs(child); | 
|  | 1484 | switch (regno / sizeof(int)) { | 
|  | 1485 | case PT_EBX: return child_regs->r11; | 
|  | 1486 | case PT_ECX: return child_regs->r9; | 
|  | 1487 | case PT_EDX: return child_regs->r10; | 
|  | 1488 | case PT_ESI: return child_regs->r14; | 
|  | 1489 | case PT_EDI: return child_regs->r15; | 
|  | 1490 | case PT_EBP: return child_regs->r13; | 
|  | 1491 | case PT_EAX: return child_regs->r8; | 
|  | 1492 | case PT_ORIG_EAX: return child_regs->r1; /* see dispatch_to_ia32_handler() */ | 
|  | 1493 | case PT_EIP: return child_regs->cr_iip; | 
|  | 1494 | case PT_UESP: return child_regs->r12; | 
|  | 1495 | case PT_EFL: return child->thread.eflag; | 
|  | 1496 | case PT_DS: case PT_ES: case PT_FS: case PT_GS: case PT_SS: | 
|  | 1497 | return __USER_DS; | 
|  | 1498 | case PT_CS: return __USER_CS; | 
|  | 1499 | default: | 
|  | 1500 | printk(KERN_ERR "ia32.getreg(): unknown register %d\n", regno); | 
|  | 1501 | break; | 
|  | 1502 | } | 
|  | 1503 | return 0; | 
|  | 1504 | } | 
|  | 1505 |  | 
|  | 1506 | static void | 
|  | 1507 | putreg (struct task_struct *child, int regno, unsigned int value) | 
|  | 1508 | { | 
|  | 1509 | struct pt_regs *child_regs; | 
|  | 1510 |  | 
|  | 1511 | child_regs = ia64_task_regs(child); | 
|  | 1512 | switch (regno / sizeof(int)) { | 
|  | 1513 | case PT_EBX: child_regs->r11 = value; break; | 
|  | 1514 | case PT_ECX: child_regs->r9 = value; break; | 
|  | 1515 | case PT_EDX: child_regs->r10 = value; break; | 
|  | 1516 | case PT_ESI: child_regs->r14 = value; break; | 
|  | 1517 | case PT_EDI: child_regs->r15 = value; break; | 
|  | 1518 | case PT_EBP: child_regs->r13 = value; break; | 
|  | 1519 | case PT_EAX: child_regs->r8 = value; break; | 
|  | 1520 | case PT_ORIG_EAX: child_regs->r1 = value; break; | 
|  | 1521 | case PT_EIP: child_regs->cr_iip = value; break; | 
|  | 1522 | case PT_UESP: child_regs->r12 = value; break; | 
|  | 1523 | case PT_EFL: child->thread.eflag = value; break; | 
|  | 1524 | case PT_DS: case PT_ES: case PT_FS: case PT_GS: case PT_SS: | 
|  | 1525 | if (value != __USER_DS) | 
|  | 1526 | printk(KERN_ERR | 
|  | 1527 | "ia32.putreg: attempt to set invalid segment register %d = %x\n", | 
|  | 1528 | regno, value); | 
|  | 1529 | break; | 
|  | 1530 | case PT_CS: | 
|  | 1531 | if (value != __USER_CS) | 
|  | 1532 | printk(KERN_ERR | 
|  | 1533 | "ia32.putreg: attempt to to set invalid segment register %d = %x\n", | 
|  | 1534 | regno, value); | 
|  | 1535 | break; | 
|  | 1536 | default: | 
|  | 1537 | printk(KERN_ERR "ia32.putreg: unknown register %d\n", regno); | 
|  | 1538 | break; | 
|  | 1539 | } | 
|  | 1540 | } | 
|  | 1541 |  | 
|  | 1542 | static void | 
|  | 1543 | put_fpreg (int regno, struct _fpreg_ia32 __user *reg, struct pt_regs *ptp, | 
|  | 1544 | struct switch_stack *swp, int tos) | 
|  | 1545 | { | 
|  | 1546 | struct _fpreg_ia32 *f; | 
|  | 1547 | char buf[32]; | 
|  | 1548 |  | 
|  | 1549 | f = (struct _fpreg_ia32 *)(((unsigned long)buf + 15) & ~15); | 
|  | 1550 | if ((regno += tos) >= 8) | 
|  | 1551 | regno -= 8; | 
|  | 1552 | switch (regno) { | 
|  | 1553 | case 0: | 
|  | 1554 | ia64f2ia32f(f, &ptp->f8); | 
|  | 1555 | break; | 
|  | 1556 | case 1: | 
|  | 1557 | ia64f2ia32f(f, &ptp->f9); | 
|  | 1558 | break; | 
|  | 1559 | case 2: | 
|  | 1560 | ia64f2ia32f(f, &ptp->f10); | 
|  | 1561 | break; | 
|  | 1562 | case 3: | 
|  | 1563 | ia64f2ia32f(f, &ptp->f11); | 
|  | 1564 | break; | 
|  | 1565 | case 4: | 
|  | 1566 | case 5: | 
|  | 1567 | case 6: | 
|  | 1568 | case 7: | 
|  | 1569 | ia64f2ia32f(f, &swp->f12 + (regno - 4)); | 
|  | 1570 | break; | 
|  | 1571 | } | 
|  | 1572 | copy_to_user(reg, f, sizeof(*reg)); | 
|  | 1573 | } | 
|  | 1574 |  | 
|  | 1575 | static void | 
|  | 1576 | get_fpreg (int regno, struct _fpreg_ia32 __user *reg, struct pt_regs *ptp, | 
|  | 1577 | struct switch_stack *swp, int tos) | 
|  | 1578 | { | 
|  | 1579 |  | 
|  | 1580 | if ((regno += tos) >= 8) | 
|  | 1581 | regno -= 8; | 
|  | 1582 | switch (regno) { | 
|  | 1583 | case 0: | 
|  | 1584 | copy_from_user(&ptp->f8, reg, sizeof(*reg)); | 
|  | 1585 | break; | 
|  | 1586 | case 1: | 
|  | 1587 | copy_from_user(&ptp->f9, reg, sizeof(*reg)); | 
|  | 1588 | break; | 
|  | 1589 | case 2: | 
|  | 1590 | copy_from_user(&ptp->f10, reg, sizeof(*reg)); | 
|  | 1591 | break; | 
|  | 1592 | case 3: | 
|  | 1593 | copy_from_user(&ptp->f11, reg, sizeof(*reg)); | 
|  | 1594 | break; | 
|  | 1595 | case 4: | 
|  | 1596 | case 5: | 
|  | 1597 | case 6: | 
|  | 1598 | case 7: | 
|  | 1599 | copy_from_user(&swp->f12 + (regno - 4), reg, sizeof(*reg)); | 
|  | 1600 | break; | 
|  | 1601 | } | 
|  | 1602 | return; | 
|  | 1603 | } | 
|  | 1604 |  | 
|  | 1605 | int | 
|  | 1606 | save_ia32_fpstate (struct task_struct *tsk, struct ia32_user_i387_struct __user *save) | 
|  | 1607 | { | 
|  | 1608 | struct switch_stack *swp; | 
|  | 1609 | struct pt_regs *ptp; | 
|  | 1610 | int i, tos; | 
|  | 1611 |  | 
|  | 1612 | if (!access_ok(VERIFY_WRITE, save, sizeof(*save))) | 
|  | 1613 | return -EFAULT; | 
|  | 1614 |  | 
|  | 1615 | __put_user(tsk->thread.fcr & 0xffff, &save->cwd); | 
|  | 1616 | __put_user(tsk->thread.fsr & 0xffff, &save->swd); | 
|  | 1617 | __put_user((tsk->thread.fsr>>16) & 0xffff, &save->twd); | 
|  | 1618 | __put_user(tsk->thread.fir, &save->fip); | 
|  | 1619 | __put_user((tsk->thread.fir>>32) & 0xffff, &save->fcs); | 
|  | 1620 | __put_user(tsk->thread.fdr, &save->foo); | 
|  | 1621 | __put_user((tsk->thread.fdr>>32) & 0xffff, &save->fos); | 
|  | 1622 |  | 
|  | 1623 | /* | 
|  | 1624 | *  Stack frames start with 16-bytes of temp space | 
|  | 1625 | */ | 
|  | 1626 | swp = (struct switch_stack *)(tsk->thread.ksp + 16); | 
|  | 1627 | ptp = ia64_task_regs(tsk); | 
|  | 1628 | tos = (tsk->thread.fsr >> 11) & 7; | 
|  | 1629 | for (i = 0; i < 8; i++) | 
|  | 1630 | put_fpreg(i, &save->st_space[i], ptp, swp, tos); | 
|  | 1631 | return 0; | 
|  | 1632 | } | 
|  | 1633 |  | 
|  | 1634 | static int | 
|  | 1635 | restore_ia32_fpstate (struct task_struct *tsk, struct ia32_user_i387_struct __user *save) | 
|  | 1636 | { | 
|  | 1637 | struct switch_stack *swp; | 
|  | 1638 | struct pt_regs *ptp; | 
|  | 1639 | int i, tos; | 
|  | 1640 | unsigned int fsrlo, fsrhi, num32; | 
|  | 1641 |  | 
|  | 1642 | if (!access_ok(VERIFY_READ, save, sizeof(*save))) | 
|  | 1643 | return(-EFAULT); | 
|  | 1644 |  | 
|  | 1645 | __get_user(num32, (unsigned int __user *)&save->cwd); | 
|  | 1646 | tsk->thread.fcr = (tsk->thread.fcr & (~0x1f3f)) | (num32 & 0x1f3f); | 
|  | 1647 | __get_user(fsrlo, (unsigned int __user *)&save->swd); | 
|  | 1648 | __get_user(fsrhi, (unsigned int __user *)&save->twd); | 
|  | 1649 | num32 = (fsrhi << 16) | fsrlo; | 
|  | 1650 | tsk->thread.fsr = (tsk->thread.fsr & (~0xffffffff)) | num32; | 
|  | 1651 | __get_user(num32, (unsigned int __user *)&save->fip); | 
|  | 1652 | tsk->thread.fir = (tsk->thread.fir & (~0xffffffff)) | num32; | 
|  | 1653 | __get_user(num32, (unsigned int __user *)&save->foo); | 
|  | 1654 | tsk->thread.fdr = (tsk->thread.fdr & (~0xffffffff)) | num32; | 
|  | 1655 |  | 
|  | 1656 | /* | 
|  | 1657 | *  Stack frames start with 16-bytes of temp space | 
|  | 1658 | */ | 
|  | 1659 | swp = (struct switch_stack *)(tsk->thread.ksp + 16); | 
|  | 1660 | ptp = ia64_task_regs(tsk); | 
|  | 1661 | tos = (tsk->thread.fsr >> 11) & 7; | 
|  | 1662 | for (i = 0; i < 8; i++) | 
|  | 1663 | get_fpreg(i, &save->st_space[i], ptp, swp, tos); | 
|  | 1664 | return 0; | 
|  | 1665 | } | 
|  | 1666 |  | 
|  | 1667 | int | 
|  | 1668 | save_ia32_fpxstate (struct task_struct *tsk, struct ia32_user_fxsr_struct __user *save) | 
|  | 1669 | { | 
|  | 1670 | struct switch_stack *swp; | 
|  | 1671 | struct pt_regs *ptp; | 
|  | 1672 | int i, tos; | 
|  | 1673 | unsigned long mxcsr=0; | 
|  | 1674 | unsigned long num128[2]; | 
|  | 1675 |  | 
|  | 1676 | if (!access_ok(VERIFY_WRITE, save, sizeof(*save))) | 
|  | 1677 | return -EFAULT; | 
|  | 1678 |  | 
|  | 1679 | __put_user(tsk->thread.fcr & 0xffff, &save->cwd); | 
|  | 1680 | __put_user(tsk->thread.fsr & 0xffff, &save->swd); | 
|  | 1681 | __put_user((tsk->thread.fsr>>16) & 0xffff, &save->twd); | 
|  | 1682 | __put_user(tsk->thread.fir, &save->fip); | 
|  | 1683 | __put_user((tsk->thread.fir>>32) & 0xffff, &save->fcs); | 
|  | 1684 | __put_user(tsk->thread.fdr, &save->foo); | 
|  | 1685 | __put_user((tsk->thread.fdr>>32) & 0xffff, &save->fos); | 
|  | 1686 |  | 
|  | 1687 | /* | 
|  | 1688 | *  Stack frames start with 16-bytes of temp space | 
|  | 1689 | */ | 
|  | 1690 | swp = (struct switch_stack *)(tsk->thread.ksp + 16); | 
|  | 1691 | ptp = ia64_task_regs(tsk); | 
|  | 1692 | tos = (tsk->thread.fsr >> 11) & 7; | 
|  | 1693 | for (i = 0; i < 8; i++) | 
|  | 1694 | put_fpreg(i, (struct _fpreg_ia32 __user *)&save->st_space[4*i], ptp, swp, tos); | 
|  | 1695 |  | 
|  | 1696 | mxcsr = ((tsk->thread.fcr>>32) & 0xff80) | ((tsk->thread.fsr>>32) & 0x3f); | 
|  | 1697 | __put_user(mxcsr & 0xffff, &save->mxcsr); | 
|  | 1698 | for (i = 0; i < 8; i++) { | 
|  | 1699 | memcpy(&(num128[0]), &(swp->f16) + i*2, sizeof(unsigned long)); | 
|  | 1700 | memcpy(&(num128[1]), &(swp->f17) + i*2, sizeof(unsigned long)); | 
|  | 1701 | copy_to_user(&save->xmm_space[0] + 4*i, num128, sizeof(struct _xmmreg_ia32)); | 
|  | 1702 | } | 
|  | 1703 | return 0; | 
|  | 1704 | } | 
|  | 1705 |  | 
|  | 1706 | static int | 
|  | 1707 | restore_ia32_fpxstate (struct task_struct *tsk, struct ia32_user_fxsr_struct __user *save) | 
|  | 1708 | { | 
|  | 1709 | struct switch_stack *swp; | 
|  | 1710 | struct pt_regs *ptp; | 
|  | 1711 | int i, tos; | 
|  | 1712 | unsigned int fsrlo, fsrhi, num32; | 
|  | 1713 | int mxcsr; | 
|  | 1714 | unsigned long num64; | 
|  | 1715 | unsigned long num128[2]; | 
|  | 1716 |  | 
|  | 1717 | if (!access_ok(VERIFY_READ, save, sizeof(*save))) | 
|  | 1718 | return(-EFAULT); | 
|  | 1719 |  | 
|  | 1720 | __get_user(num32, (unsigned int __user *)&save->cwd); | 
|  | 1721 | tsk->thread.fcr = (tsk->thread.fcr & (~0x1f3f)) | (num32 & 0x1f3f); | 
|  | 1722 | __get_user(fsrlo, (unsigned int __user *)&save->swd); | 
|  | 1723 | __get_user(fsrhi, (unsigned int __user *)&save->twd); | 
|  | 1724 | num32 = (fsrhi << 16) | fsrlo; | 
|  | 1725 | tsk->thread.fsr = (tsk->thread.fsr & (~0xffffffff)) | num32; | 
|  | 1726 | __get_user(num32, (unsigned int __user *)&save->fip); | 
|  | 1727 | tsk->thread.fir = (tsk->thread.fir & (~0xffffffff)) | num32; | 
|  | 1728 | __get_user(num32, (unsigned int __user *)&save->foo); | 
|  | 1729 | tsk->thread.fdr = (tsk->thread.fdr & (~0xffffffff)) | num32; | 
|  | 1730 |  | 
|  | 1731 | /* | 
|  | 1732 | *  Stack frames start with 16-bytes of temp space | 
|  | 1733 | */ | 
|  | 1734 | swp = (struct switch_stack *)(tsk->thread.ksp + 16); | 
|  | 1735 | ptp = ia64_task_regs(tsk); | 
|  | 1736 | tos = (tsk->thread.fsr >> 11) & 7; | 
|  | 1737 | for (i = 0; i < 8; i++) | 
|  | 1738 | get_fpreg(i, (struct _fpreg_ia32 __user *)&save->st_space[4*i], ptp, swp, tos); | 
|  | 1739 |  | 
|  | 1740 | __get_user(mxcsr, (unsigned int __user *)&save->mxcsr); | 
|  | 1741 | num64 = mxcsr & 0xff10; | 
|  | 1742 | tsk->thread.fcr = (tsk->thread.fcr & (~0xff1000000000UL)) | (num64<<32); | 
|  | 1743 | num64 = mxcsr & 0x3f; | 
|  | 1744 | tsk->thread.fsr = (tsk->thread.fsr & (~0x3f00000000UL)) | (num64<<32); | 
|  | 1745 |  | 
|  | 1746 | for (i = 0; i < 8; i++) { | 
|  | 1747 | copy_from_user(num128, &save->xmm_space[0] + 4*i, sizeof(struct _xmmreg_ia32)); | 
|  | 1748 | memcpy(&(swp->f16) + i*2, &(num128[0]), sizeof(unsigned long)); | 
|  | 1749 | memcpy(&(swp->f17) + i*2, &(num128[1]), sizeof(unsigned long)); | 
|  | 1750 | } | 
|  | 1751 | return 0; | 
|  | 1752 | } | 
|  | 1753 |  | 
|  | 1754 | asmlinkage long | 
|  | 1755 | sys32_ptrace (int request, pid_t pid, unsigned int addr, unsigned int data) | 
|  | 1756 | { | 
|  | 1757 | struct task_struct *child; | 
|  | 1758 | unsigned int value, tmp; | 
|  | 1759 | long i, ret; | 
|  | 1760 |  | 
|  | 1761 | lock_kernel(); | 
|  | 1762 | if (request == PTRACE_TRACEME) { | 
|  | 1763 | ret = sys_ptrace(request, pid, addr, data); | 
|  | 1764 | goto out; | 
|  | 1765 | } | 
|  | 1766 |  | 
|  | 1767 | ret = -ESRCH; | 
|  | 1768 | read_lock(&tasklist_lock); | 
|  | 1769 | child = find_task_by_pid(pid); | 
|  | 1770 | if (child) | 
|  | 1771 | get_task_struct(child); | 
|  | 1772 | read_unlock(&tasklist_lock); | 
|  | 1773 | if (!child) | 
|  | 1774 | goto out; | 
|  | 1775 | ret = -EPERM; | 
|  | 1776 | if (pid == 1)		/* no messing around with init! */ | 
|  | 1777 | goto out_tsk; | 
|  | 1778 |  | 
|  | 1779 | if (request == PTRACE_ATTACH) { | 
|  | 1780 | ret = sys_ptrace(request, pid, addr, data); | 
|  | 1781 | goto out_tsk; | 
|  | 1782 | } | 
|  | 1783 |  | 
|  | 1784 | ret = ptrace_check_attach(child, request == PTRACE_KILL); | 
|  | 1785 | if (ret < 0) | 
|  | 1786 | goto out_tsk; | 
|  | 1787 |  | 
|  | 1788 | switch (request) { | 
|  | 1789 | case PTRACE_PEEKTEXT: | 
|  | 1790 | case PTRACE_PEEKDATA:	/* read word at location addr */ | 
|  | 1791 | ret = ia32_peek(child, addr, &value); | 
|  | 1792 | if (ret == 0) | 
|  | 1793 | ret = put_user(value, (unsigned int __user *) compat_ptr(data)); | 
|  | 1794 | else | 
|  | 1795 | ret = -EIO; | 
|  | 1796 | goto out_tsk; | 
|  | 1797 |  | 
|  | 1798 | case PTRACE_POKETEXT: | 
|  | 1799 | case PTRACE_POKEDATA:	/* write the word at location addr */ | 
|  | 1800 | ret = ia32_poke(child, addr, data); | 
|  | 1801 | goto out_tsk; | 
|  | 1802 |  | 
|  | 1803 | case PTRACE_PEEKUSR:	/* read word at addr in USER area */ | 
|  | 1804 | ret = -EIO; | 
|  | 1805 | if ((addr & 3) || addr > 17*sizeof(int)) | 
|  | 1806 | break; | 
|  | 1807 |  | 
|  | 1808 | tmp = getreg(child, addr); | 
|  | 1809 | if (!put_user(tmp, (unsigned int __user *) compat_ptr(data))) | 
|  | 1810 | ret = 0; | 
|  | 1811 | break; | 
|  | 1812 |  | 
|  | 1813 | case PTRACE_POKEUSR:	/* write word at addr in USER area */ | 
|  | 1814 | ret = -EIO; | 
|  | 1815 | if ((addr & 3) || addr > 17*sizeof(int)) | 
|  | 1816 | break; | 
|  | 1817 |  | 
|  | 1818 | putreg(child, addr, data); | 
|  | 1819 | ret = 0; | 
|  | 1820 | break; | 
|  | 1821 |  | 
|  | 1822 | case IA32_PTRACE_GETREGS: | 
|  | 1823 | if (!access_ok(VERIFY_WRITE, compat_ptr(data), 17*sizeof(int))) { | 
|  | 1824 | ret = -EIO; | 
|  | 1825 | break; | 
|  | 1826 | } | 
|  | 1827 | for (i = 0; i < (int) (17*sizeof(int)); i += sizeof(int) ) { | 
|  | 1828 | put_user(getreg(child, i), (unsigned int __user *) compat_ptr(data)); | 
|  | 1829 | data += sizeof(int); | 
|  | 1830 | } | 
|  | 1831 | ret = 0; | 
|  | 1832 | break; | 
|  | 1833 |  | 
|  | 1834 | case IA32_PTRACE_SETREGS: | 
|  | 1835 | if (!access_ok(VERIFY_READ, compat_ptr(data), 17*sizeof(int))) { | 
|  | 1836 | ret = -EIO; | 
|  | 1837 | break; | 
|  | 1838 | } | 
|  | 1839 | for (i = 0; i < (int) (17*sizeof(int)); i += sizeof(int) ) { | 
|  | 1840 | get_user(tmp, (unsigned int __user *) compat_ptr(data)); | 
|  | 1841 | putreg(child, i, tmp); | 
|  | 1842 | data += sizeof(int); | 
|  | 1843 | } | 
|  | 1844 | ret = 0; | 
|  | 1845 | break; | 
|  | 1846 |  | 
|  | 1847 | case IA32_PTRACE_GETFPREGS: | 
|  | 1848 | ret = save_ia32_fpstate(child, (struct ia32_user_i387_struct __user *) | 
|  | 1849 | compat_ptr(data)); | 
|  | 1850 | break; | 
|  | 1851 |  | 
|  | 1852 | case IA32_PTRACE_GETFPXREGS: | 
|  | 1853 | ret = save_ia32_fpxstate(child, (struct ia32_user_fxsr_struct __user *) | 
|  | 1854 | compat_ptr(data)); | 
|  | 1855 | break; | 
|  | 1856 |  | 
|  | 1857 | case IA32_PTRACE_SETFPREGS: | 
|  | 1858 | ret = restore_ia32_fpstate(child, (struct ia32_user_i387_struct __user *) | 
|  | 1859 | compat_ptr(data)); | 
|  | 1860 | break; | 
|  | 1861 |  | 
|  | 1862 | case IA32_PTRACE_SETFPXREGS: | 
|  | 1863 | ret = restore_ia32_fpxstate(child, (struct ia32_user_fxsr_struct __user *) | 
|  | 1864 | compat_ptr(data)); | 
|  | 1865 | break; | 
|  | 1866 |  | 
|  | 1867 | case PTRACE_GETEVENTMSG: | 
|  | 1868 | ret = put_user(child->ptrace_message, (unsigned int __user *) compat_ptr(data)); | 
|  | 1869 | break; | 
|  | 1870 |  | 
|  | 1871 | case PTRACE_SYSCALL:	/* continue, stop after next syscall */ | 
|  | 1872 | case PTRACE_CONT:		/* restart after signal. */ | 
|  | 1873 | case PTRACE_KILL: | 
|  | 1874 | case PTRACE_SINGLESTEP:	/* execute chile for one instruction */ | 
|  | 1875 | case PTRACE_DETACH:	/* detach a process */ | 
|  | 1876 | ret = sys_ptrace(request, pid, addr, data); | 
|  | 1877 | break; | 
|  | 1878 |  | 
|  | 1879 | default: | 
|  | 1880 | ret = ptrace_request(child, request, addr, data); | 
|  | 1881 | break; | 
|  | 1882 |  | 
|  | 1883 | } | 
|  | 1884 | out_tsk: | 
|  | 1885 | put_task_struct(child); | 
|  | 1886 | out: | 
|  | 1887 | unlock_kernel(); | 
|  | 1888 | return ret; | 
|  | 1889 | } | 
|  | 1890 |  | 
|  | 1891 | typedef struct { | 
|  | 1892 | unsigned int	ss_sp; | 
|  | 1893 | unsigned int	ss_flags; | 
|  | 1894 | unsigned int	ss_size; | 
|  | 1895 | } ia32_stack_t; | 
|  | 1896 |  | 
|  | 1897 | asmlinkage long | 
|  | 1898 | sys32_sigaltstack (ia32_stack_t __user *uss32, ia32_stack_t __user *uoss32, | 
|  | 1899 | long arg2, long arg3, long arg4, long arg5, long arg6, | 
|  | 1900 | long arg7, struct pt_regs pt) | 
|  | 1901 | { | 
|  | 1902 | stack_t uss, uoss; | 
|  | 1903 | ia32_stack_t buf32; | 
|  | 1904 | int ret; | 
|  | 1905 | mm_segment_t old_fs = get_fs(); | 
|  | 1906 |  | 
|  | 1907 | if (uss32) { | 
|  | 1908 | if (copy_from_user(&buf32, uss32, sizeof(ia32_stack_t))) | 
|  | 1909 | return -EFAULT; | 
|  | 1910 | uss.ss_sp = (void __user *) (long) buf32.ss_sp; | 
|  | 1911 | uss.ss_flags = buf32.ss_flags; | 
|  | 1912 | /* MINSIGSTKSZ is different for ia32 vs ia64. We lie here to pass the | 
|  | 1913 | check and set it to the user requested value later */ | 
|  | 1914 | if ((buf32.ss_flags != SS_DISABLE) && (buf32.ss_size < MINSIGSTKSZ_IA32)) { | 
|  | 1915 | ret = -ENOMEM; | 
|  | 1916 | goto out; | 
|  | 1917 | } | 
|  | 1918 | uss.ss_size = MINSIGSTKSZ; | 
|  | 1919 | } | 
|  | 1920 | set_fs(KERNEL_DS); | 
|  | 1921 | ret = do_sigaltstack(uss32 ? (stack_t __user *) &uss : NULL, | 
|  | 1922 | (stack_t __user *) &uoss, pt.r12); | 
|  | 1923 | current->sas_ss_size = buf32.ss_size; | 
|  | 1924 | set_fs(old_fs); | 
|  | 1925 | out: | 
|  | 1926 | if (ret < 0) | 
|  | 1927 | return(ret); | 
|  | 1928 | if (uoss32) { | 
|  | 1929 | buf32.ss_sp = (long __user) uoss.ss_sp; | 
|  | 1930 | buf32.ss_flags = uoss.ss_flags; | 
|  | 1931 | buf32.ss_size = uoss.ss_size; | 
|  | 1932 | if (copy_to_user(uoss32, &buf32, sizeof(ia32_stack_t))) | 
|  | 1933 | return -EFAULT; | 
|  | 1934 | } | 
|  | 1935 | return ret; | 
|  | 1936 | } | 
|  | 1937 |  | 
|  | 1938 | asmlinkage int | 
|  | 1939 | sys32_pause (void) | 
|  | 1940 | { | 
|  | 1941 | current->state = TASK_INTERRUPTIBLE; | 
|  | 1942 | schedule(); | 
|  | 1943 | return -ERESTARTNOHAND; | 
|  | 1944 | } | 
|  | 1945 |  | 
|  | 1946 | asmlinkage int | 
|  | 1947 | sys32_msync (unsigned int start, unsigned int len, int flags) | 
|  | 1948 | { | 
|  | 1949 | unsigned int addr; | 
|  | 1950 |  | 
|  | 1951 | if (OFFSET4K(start)) | 
|  | 1952 | return -EINVAL; | 
|  | 1953 | addr = PAGE_START(start); | 
|  | 1954 | return sys_msync(addr, len + (start - addr), flags); | 
|  | 1955 | } | 
|  | 1956 |  | 
|  | 1957 | struct sysctl32 { | 
|  | 1958 | unsigned int	name; | 
|  | 1959 | int		nlen; | 
|  | 1960 | unsigned int	oldval; | 
|  | 1961 | unsigned int	oldlenp; | 
|  | 1962 | unsigned int	newval; | 
|  | 1963 | unsigned int	newlen; | 
|  | 1964 | unsigned int	__unused[4]; | 
|  | 1965 | }; | 
|  | 1966 |  | 
|  | 1967 | #ifdef CONFIG_SYSCTL | 
|  | 1968 | asmlinkage long | 
|  | 1969 | sys32_sysctl (struct sysctl32 __user *args) | 
|  | 1970 | { | 
|  | 1971 | struct sysctl32 a32; | 
|  | 1972 | mm_segment_t old_fs = get_fs (); | 
|  | 1973 | void __user *oldvalp, *newvalp; | 
|  | 1974 | size_t oldlen; | 
|  | 1975 | int __user *namep; | 
|  | 1976 | long ret; | 
|  | 1977 |  | 
|  | 1978 | if (copy_from_user(&a32, args, sizeof(a32))) | 
|  | 1979 | return -EFAULT; | 
|  | 1980 |  | 
|  | 1981 | /* | 
|  | 1982 | * We need to pre-validate these because we have to disable address checking | 
|  | 1983 | * before calling do_sysctl() because of OLDLEN but we can't run the risk of the | 
|  | 1984 | * user specifying bad addresses here.  Well, since we're dealing with 32 bit | 
|  | 1985 | * addresses, we KNOW that access_ok() will always succeed, so this is an | 
|  | 1986 | * expensive NOP, but so what... | 
|  | 1987 | */ | 
|  | 1988 | namep = (int __user *) compat_ptr(a32.name); | 
|  | 1989 | oldvalp = compat_ptr(a32.oldval); | 
|  | 1990 | newvalp = compat_ptr(a32.newval); | 
|  | 1991 |  | 
|  | 1992 | if ((oldvalp && get_user(oldlen, (int __user *) compat_ptr(a32.oldlenp))) | 
|  | 1993 | || !access_ok(VERIFY_WRITE, namep, 0) | 
|  | 1994 | || !access_ok(VERIFY_WRITE, oldvalp, 0) | 
|  | 1995 | || !access_ok(VERIFY_WRITE, newvalp, 0)) | 
|  | 1996 | return -EFAULT; | 
|  | 1997 |  | 
|  | 1998 | set_fs(KERNEL_DS); | 
|  | 1999 | lock_kernel(); | 
|  | 2000 | ret = do_sysctl(namep, a32.nlen, oldvalp, (size_t __user *) &oldlen, | 
|  | 2001 | newvalp, (size_t) a32.newlen); | 
|  | 2002 | unlock_kernel(); | 
|  | 2003 | set_fs(old_fs); | 
|  | 2004 |  | 
|  | 2005 | if (oldvalp && put_user (oldlen, (int __user *) compat_ptr(a32.oldlenp))) | 
|  | 2006 | return -EFAULT; | 
|  | 2007 |  | 
|  | 2008 | return ret; | 
|  | 2009 | } | 
|  | 2010 | #endif | 
|  | 2011 |  | 
|  | 2012 | asmlinkage long | 
|  | 2013 | sys32_newuname (struct new_utsname __user *name) | 
|  | 2014 | { | 
|  | 2015 | int ret = sys_newuname(name); | 
|  | 2016 |  | 
|  | 2017 | if (!ret) | 
|  | 2018 | if (copy_to_user(name->machine, "i686\0\0\0", 8)) | 
|  | 2019 | ret = -EFAULT; | 
|  | 2020 | return ret; | 
|  | 2021 | } | 
|  | 2022 |  | 
|  | 2023 | asmlinkage long | 
|  | 2024 | sys32_getresuid16 (u16 __user *ruid, u16 __user *euid, u16 __user *suid) | 
|  | 2025 | { | 
|  | 2026 | uid_t a, b, c; | 
|  | 2027 | int ret; | 
|  | 2028 | mm_segment_t old_fs = get_fs(); | 
|  | 2029 |  | 
|  | 2030 | set_fs(KERNEL_DS); | 
|  | 2031 | ret = sys_getresuid((uid_t __user *) &a, (uid_t __user *) &b, (uid_t __user *) &c); | 
|  | 2032 | set_fs(old_fs); | 
|  | 2033 |  | 
|  | 2034 | if (put_user(a, ruid) || put_user(b, euid) || put_user(c, suid)) | 
|  | 2035 | return -EFAULT; | 
|  | 2036 | return ret; | 
|  | 2037 | } | 
|  | 2038 |  | 
|  | 2039 | asmlinkage long | 
|  | 2040 | sys32_getresgid16 (u16 __user *rgid, u16 __user *egid, u16 __user *sgid) | 
|  | 2041 | { | 
|  | 2042 | gid_t a, b, c; | 
|  | 2043 | int ret; | 
|  | 2044 | mm_segment_t old_fs = get_fs(); | 
|  | 2045 |  | 
|  | 2046 | set_fs(KERNEL_DS); | 
|  | 2047 | ret = sys_getresgid((gid_t __user *) &a, (gid_t __user *) &b, (gid_t __user *) &c); | 
|  | 2048 | set_fs(old_fs); | 
|  | 2049 |  | 
|  | 2050 | if (ret) | 
|  | 2051 | return ret; | 
|  | 2052 |  | 
|  | 2053 | return put_user(a, rgid) | put_user(b, egid) | put_user(c, sgid); | 
|  | 2054 | } | 
|  | 2055 |  | 
|  | 2056 | asmlinkage long | 
|  | 2057 | sys32_lseek (unsigned int fd, int offset, unsigned int whence) | 
|  | 2058 | { | 
|  | 2059 | /* Sign-extension of "offset" is important here... */ | 
|  | 2060 | return sys_lseek(fd, offset, whence); | 
|  | 2061 | } | 
|  | 2062 |  | 
|  | 2063 | static int | 
|  | 2064 | groups16_to_user(short __user *grouplist, struct group_info *group_info) | 
|  | 2065 | { | 
|  | 2066 | int i; | 
|  | 2067 | short group; | 
|  | 2068 |  | 
|  | 2069 | for (i = 0; i < group_info->ngroups; i++) { | 
|  | 2070 | group = (short)GROUP_AT(group_info, i); | 
|  | 2071 | if (put_user(group, grouplist+i)) | 
|  | 2072 | return -EFAULT; | 
|  | 2073 | } | 
|  | 2074 |  | 
|  | 2075 | return 0; | 
|  | 2076 | } | 
|  | 2077 |  | 
|  | 2078 | static int | 
|  | 2079 | groups16_from_user(struct group_info *group_info, short __user *grouplist) | 
|  | 2080 | { | 
|  | 2081 | int i; | 
|  | 2082 | short group; | 
|  | 2083 |  | 
|  | 2084 | for (i = 0; i < group_info->ngroups; i++) { | 
|  | 2085 | if (get_user(group, grouplist+i)) | 
|  | 2086 | return  -EFAULT; | 
|  | 2087 | GROUP_AT(group_info, i) = (gid_t)group; | 
|  | 2088 | } | 
|  | 2089 |  | 
|  | 2090 | return 0; | 
|  | 2091 | } | 
|  | 2092 |  | 
|  | 2093 | asmlinkage long | 
|  | 2094 | sys32_getgroups16 (int gidsetsize, short __user *grouplist) | 
|  | 2095 | { | 
|  | 2096 | int i; | 
|  | 2097 |  | 
|  | 2098 | if (gidsetsize < 0) | 
|  | 2099 | return -EINVAL; | 
|  | 2100 |  | 
|  | 2101 | get_group_info(current->group_info); | 
|  | 2102 | i = current->group_info->ngroups; | 
|  | 2103 | if (gidsetsize) { | 
|  | 2104 | if (i > gidsetsize) { | 
|  | 2105 | i = -EINVAL; | 
|  | 2106 | goto out; | 
|  | 2107 | } | 
|  | 2108 | if (groups16_to_user(grouplist, current->group_info)) { | 
|  | 2109 | i = -EFAULT; | 
|  | 2110 | goto out; | 
|  | 2111 | } | 
|  | 2112 | } | 
|  | 2113 | out: | 
|  | 2114 | put_group_info(current->group_info); | 
|  | 2115 | return i; | 
|  | 2116 | } | 
|  | 2117 |  | 
|  | 2118 | asmlinkage long | 
|  | 2119 | sys32_setgroups16 (int gidsetsize, short __user *grouplist) | 
|  | 2120 | { | 
|  | 2121 | struct group_info *group_info; | 
|  | 2122 | int retval; | 
|  | 2123 |  | 
|  | 2124 | if (!capable(CAP_SETGID)) | 
|  | 2125 | return -EPERM; | 
|  | 2126 | if ((unsigned)gidsetsize > NGROUPS_MAX) | 
|  | 2127 | return -EINVAL; | 
|  | 2128 |  | 
|  | 2129 | group_info = groups_alloc(gidsetsize); | 
|  | 2130 | if (!group_info) | 
|  | 2131 | return -ENOMEM; | 
|  | 2132 | retval = groups16_from_user(group_info, grouplist); | 
|  | 2133 | if (retval) { | 
|  | 2134 | put_group_info(group_info); | 
|  | 2135 | return retval; | 
|  | 2136 | } | 
|  | 2137 |  | 
|  | 2138 | retval = set_current_groups(group_info); | 
|  | 2139 | put_group_info(group_info); | 
|  | 2140 |  | 
|  | 2141 | return retval; | 
|  | 2142 | } | 
|  | 2143 |  | 
|  | 2144 | asmlinkage long | 
|  | 2145 | sys32_truncate64 (unsigned int path, unsigned int len_lo, unsigned int len_hi) | 
|  | 2146 | { | 
|  | 2147 | return sys_truncate(compat_ptr(path), ((unsigned long) len_hi << 32) | len_lo); | 
|  | 2148 | } | 
|  | 2149 |  | 
|  | 2150 | asmlinkage long | 
|  | 2151 | sys32_ftruncate64 (int fd, unsigned int len_lo, unsigned int len_hi) | 
|  | 2152 | { | 
|  | 2153 | return sys_ftruncate(fd, ((unsigned long) len_hi << 32) | len_lo); | 
|  | 2154 | } | 
|  | 2155 |  | 
|  | 2156 | static int | 
|  | 2157 | putstat64 (struct stat64 __user *ubuf, struct kstat *kbuf) | 
|  | 2158 | { | 
|  | 2159 | int err; | 
|  | 2160 | u64 hdev; | 
|  | 2161 |  | 
|  | 2162 | if (clear_user(ubuf, sizeof(*ubuf))) | 
|  | 2163 | return -EFAULT; | 
|  | 2164 |  | 
|  | 2165 | hdev = huge_encode_dev(kbuf->dev); | 
|  | 2166 | err  = __put_user(hdev, (u32 __user*)&ubuf->st_dev); | 
|  | 2167 | err |= __put_user(hdev >> 32, ((u32 __user*)&ubuf->st_dev) + 1); | 
|  | 2168 | err |= __put_user(kbuf->ino, &ubuf->__st_ino); | 
|  | 2169 | err |= __put_user(kbuf->ino, &ubuf->st_ino_lo); | 
|  | 2170 | err |= __put_user(kbuf->ino >> 32, &ubuf->st_ino_hi); | 
|  | 2171 | err |= __put_user(kbuf->mode, &ubuf->st_mode); | 
|  | 2172 | err |= __put_user(kbuf->nlink, &ubuf->st_nlink); | 
|  | 2173 | err |= __put_user(kbuf->uid, &ubuf->st_uid); | 
|  | 2174 | err |= __put_user(kbuf->gid, &ubuf->st_gid); | 
|  | 2175 | hdev = huge_encode_dev(kbuf->rdev); | 
|  | 2176 | err  = __put_user(hdev, (u32 __user*)&ubuf->st_rdev); | 
|  | 2177 | err |= __put_user(hdev >> 32, ((u32 __user*)&ubuf->st_rdev) + 1); | 
|  | 2178 | err |= __put_user(kbuf->size, &ubuf->st_size_lo); | 
|  | 2179 | err |= __put_user((kbuf->size >> 32), &ubuf->st_size_hi); | 
|  | 2180 | err |= __put_user(kbuf->atime.tv_sec, &ubuf->st_atime); | 
|  | 2181 | err |= __put_user(kbuf->atime.tv_nsec, &ubuf->st_atime_nsec); | 
|  | 2182 | err |= __put_user(kbuf->mtime.tv_sec, &ubuf->st_mtime); | 
|  | 2183 | err |= __put_user(kbuf->mtime.tv_nsec, &ubuf->st_mtime_nsec); | 
|  | 2184 | err |= __put_user(kbuf->ctime.tv_sec, &ubuf->st_ctime); | 
|  | 2185 | err |= __put_user(kbuf->ctime.tv_nsec, &ubuf->st_ctime_nsec); | 
|  | 2186 | err |= __put_user(kbuf->blksize, &ubuf->st_blksize); | 
|  | 2187 | err |= __put_user(kbuf->blocks, &ubuf->st_blocks); | 
|  | 2188 | return err; | 
|  | 2189 | } | 
|  | 2190 |  | 
|  | 2191 | asmlinkage long | 
|  | 2192 | sys32_stat64 (char __user *filename, struct stat64 __user *statbuf) | 
|  | 2193 | { | 
|  | 2194 | struct kstat s; | 
|  | 2195 | long ret = vfs_stat(filename, &s); | 
|  | 2196 | if (!ret) | 
|  | 2197 | ret = putstat64(statbuf, &s); | 
|  | 2198 | return ret; | 
|  | 2199 | } | 
|  | 2200 |  | 
|  | 2201 | asmlinkage long | 
|  | 2202 | sys32_lstat64 (char __user *filename, struct stat64 __user *statbuf) | 
|  | 2203 | { | 
|  | 2204 | struct kstat s; | 
|  | 2205 | long ret = vfs_lstat(filename, &s); | 
|  | 2206 | if (!ret) | 
|  | 2207 | ret = putstat64(statbuf, &s); | 
|  | 2208 | return ret; | 
|  | 2209 | } | 
|  | 2210 |  | 
|  | 2211 | asmlinkage long | 
|  | 2212 | sys32_fstat64 (unsigned int fd, struct stat64 __user *statbuf) | 
|  | 2213 | { | 
|  | 2214 | struct kstat s; | 
|  | 2215 | long ret = vfs_fstat(fd, &s); | 
|  | 2216 | if (!ret) | 
|  | 2217 | ret = putstat64(statbuf, &s); | 
|  | 2218 | return ret; | 
|  | 2219 | } | 
|  | 2220 |  | 
|  | 2221 | struct sysinfo32 { | 
|  | 2222 | s32 uptime; | 
|  | 2223 | u32 loads[3]; | 
|  | 2224 | u32 totalram; | 
|  | 2225 | u32 freeram; | 
|  | 2226 | u32 sharedram; | 
|  | 2227 | u32 bufferram; | 
|  | 2228 | u32 totalswap; | 
|  | 2229 | u32 freeswap; | 
|  | 2230 | u16 procs; | 
|  | 2231 | u16 pad; | 
|  | 2232 | u32 totalhigh; | 
|  | 2233 | u32 freehigh; | 
|  | 2234 | u32 mem_unit; | 
|  | 2235 | char _f[8]; | 
|  | 2236 | }; | 
|  | 2237 |  | 
|  | 2238 | asmlinkage long | 
|  | 2239 | sys32_sysinfo (struct sysinfo32 __user *info) | 
|  | 2240 | { | 
|  | 2241 | struct sysinfo s; | 
|  | 2242 | long ret, err; | 
|  | 2243 | int bitcount = 0; | 
|  | 2244 | mm_segment_t old_fs = get_fs(); | 
|  | 2245 |  | 
|  | 2246 | set_fs(KERNEL_DS); | 
|  | 2247 | ret = sys_sysinfo((struct sysinfo __user *) &s); | 
|  | 2248 | set_fs(old_fs); | 
|  | 2249 | /* Check to see if any memory value is too large for 32-bit and | 
|  | 2250 | * scale down if needed. | 
|  | 2251 | */ | 
|  | 2252 | if ((s.totalram >> 32) || (s.totalswap >> 32)) { | 
|  | 2253 | while (s.mem_unit < PAGE_SIZE) { | 
|  | 2254 | s.mem_unit <<= 1; | 
|  | 2255 | bitcount++; | 
|  | 2256 | } | 
|  | 2257 | s.totalram >>= bitcount; | 
|  | 2258 | s.freeram >>= bitcount; | 
|  | 2259 | s.sharedram >>= bitcount; | 
|  | 2260 | s.bufferram >>= bitcount; | 
|  | 2261 | s.totalswap >>= bitcount; | 
|  | 2262 | s.freeswap >>= bitcount; | 
|  | 2263 | s.totalhigh >>= bitcount; | 
|  | 2264 | s.freehigh >>= bitcount; | 
|  | 2265 | } | 
|  | 2266 |  | 
|  | 2267 | if (!access_ok(VERIFY_WRITE, info, sizeof(*info))) | 
|  | 2268 | return -EFAULT; | 
|  | 2269 |  | 
|  | 2270 | err  = __put_user(s.uptime, &info->uptime); | 
|  | 2271 | err |= __put_user(s.loads[0], &info->loads[0]); | 
|  | 2272 | err |= __put_user(s.loads[1], &info->loads[1]); | 
|  | 2273 | err |= __put_user(s.loads[2], &info->loads[2]); | 
|  | 2274 | err |= __put_user(s.totalram, &info->totalram); | 
|  | 2275 | err |= __put_user(s.freeram, &info->freeram); | 
|  | 2276 | err |= __put_user(s.sharedram, &info->sharedram); | 
|  | 2277 | err |= __put_user(s.bufferram, &info->bufferram); | 
|  | 2278 | err |= __put_user(s.totalswap, &info->totalswap); | 
|  | 2279 | err |= __put_user(s.freeswap, &info->freeswap); | 
|  | 2280 | err |= __put_user(s.procs, &info->procs); | 
|  | 2281 | err |= __put_user (s.totalhigh, &info->totalhigh); | 
|  | 2282 | err |= __put_user (s.freehigh, &info->freehigh); | 
|  | 2283 | err |= __put_user (s.mem_unit, &info->mem_unit); | 
|  | 2284 | if (err) | 
|  | 2285 | return -EFAULT; | 
|  | 2286 | return ret; | 
|  | 2287 | } | 
|  | 2288 |  | 
|  | 2289 | asmlinkage long | 
|  | 2290 | sys32_sched_rr_get_interval (pid_t pid, struct compat_timespec __user *interval) | 
|  | 2291 | { | 
|  | 2292 | mm_segment_t old_fs = get_fs(); | 
|  | 2293 | struct timespec t; | 
|  | 2294 | long ret; | 
|  | 2295 |  | 
|  | 2296 | set_fs(KERNEL_DS); | 
|  | 2297 | ret = sys_sched_rr_get_interval(pid, (struct timespec __user *) &t); | 
|  | 2298 | set_fs(old_fs); | 
|  | 2299 | if (put_compat_timespec(&t, interval)) | 
|  | 2300 | return -EFAULT; | 
|  | 2301 | return ret; | 
|  | 2302 | } | 
|  | 2303 |  | 
|  | 2304 | asmlinkage long | 
|  | 2305 | sys32_pread (unsigned int fd, void __user *buf, unsigned int count, u32 pos_lo, u32 pos_hi) | 
|  | 2306 | { | 
|  | 2307 | return sys_pread64(fd, buf, count, ((unsigned long) pos_hi << 32) | pos_lo); | 
|  | 2308 | } | 
|  | 2309 |  | 
|  | 2310 | asmlinkage long | 
|  | 2311 | sys32_pwrite (unsigned int fd, void __user *buf, unsigned int count, u32 pos_lo, u32 pos_hi) | 
|  | 2312 | { | 
|  | 2313 | return sys_pwrite64(fd, buf, count, ((unsigned long) pos_hi << 32) | pos_lo); | 
|  | 2314 | } | 
|  | 2315 |  | 
|  | 2316 | asmlinkage long | 
|  | 2317 | sys32_sendfile (int out_fd, int in_fd, int __user *offset, unsigned int count) | 
|  | 2318 | { | 
|  | 2319 | mm_segment_t old_fs = get_fs(); | 
|  | 2320 | long ret; | 
|  | 2321 | off_t of; | 
|  | 2322 |  | 
|  | 2323 | if (offset && get_user(of, offset)) | 
|  | 2324 | return -EFAULT; | 
|  | 2325 |  | 
|  | 2326 | set_fs(KERNEL_DS); | 
|  | 2327 | ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *) &of : NULL, count); | 
|  | 2328 | set_fs(old_fs); | 
|  | 2329 |  | 
|  | 2330 | if (!ret && offset && put_user(of, offset)) | 
|  | 2331 | return -EFAULT; | 
|  | 2332 |  | 
|  | 2333 | return ret; | 
|  | 2334 | } | 
|  | 2335 |  | 
|  | 2336 | asmlinkage long | 
|  | 2337 | sys32_personality (unsigned int personality) | 
|  | 2338 | { | 
|  | 2339 | long ret; | 
|  | 2340 |  | 
|  | 2341 | if (current->personality == PER_LINUX32 && personality == PER_LINUX) | 
|  | 2342 | personality = PER_LINUX32; | 
|  | 2343 | ret = sys_personality(personality); | 
|  | 2344 | if (ret == PER_LINUX32) | 
|  | 2345 | ret = PER_LINUX; | 
|  | 2346 | return ret; | 
|  | 2347 | } | 
|  | 2348 |  | 
|  | 2349 | asmlinkage unsigned long | 
|  | 2350 | sys32_brk (unsigned int brk) | 
|  | 2351 | { | 
|  | 2352 | unsigned long ret, obrk; | 
|  | 2353 | struct mm_struct *mm = current->mm; | 
|  | 2354 |  | 
|  | 2355 | obrk = mm->brk; | 
|  | 2356 | ret = sys_brk(brk); | 
|  | 2357 | if (ret < obrk) | 
|  | 2358 | clear_user(compat_ptr(ret), PAGE_ALIGN(ret) - ret); | 
|  | 2359 | return ret; | 
|  | 2360 | } | 
|  | 2361 |  | 
|  | 2362 | /* | 
|  | 2363 | * Exactly like fs/open.c:sys_open(), except that it doesn't set the O_LARGEFILE flag. | 
|  | 2364 | */ | 
|  | 2365 | asmlinkage long | 
|  | 2366 | sys32_open (const char __user * filename, int flags, int mode) | 
|  | 2367 | { | 
|  | 2368 | char * tmp; | 
|  | 2369 | int fd, error; | 
|  | 2370 |  | 
|  | 2371 | tmp = getname(filename); | 
|  | 2372 | fd = PTR_ERR(tmp); | 
|  | 2373 | if (!IS_ERR(tmp)) { | 
|  | 2374 | fd = get_unused_fd(); | 
|  | 2375 | if (fd >= 0) { | 
|  | 2376 | struct file *f = filp_open(tmp, flags, mode); | 
|  | 2377 | error = PTR_ERR(f); | 
|  | 2378 | if (IS_ERR(f)) | 
|  | 2379 | goto out_error; | 
|  | 2380 | fd_install(fd, f); | 
|  | 2381 | } | 
|  | 2382 | out: | 
|  | 2383 | putname(tmp); | 
|  | 2384 | } | 
|  | 2385 | return fd; | 
|  | 2386 |  | 
|  | 2387 | out_error: | 
|  | 2388 | put_unused_fd(fd); | 
|  | 2389 | fd = error; | 
|  | 2390 | goto out; | 
|  | 2391 | } | 
|  | 2392 |  | 
|  | 2393 | /* Structure for ia32 emulation on ia64 */ | 
|  | 2394 | struct epoll_event32 | 
|  | 2395 | { | 
|  | 2396 | u32 events; | 
|  | 2397 | u32 data[2]; | 
|  | 2398 | }; | 
|  | 2399 |  | 
|  | 2400 | asmlinkage long | 
|  | 2401 | sys32_epoll_ctl(int epfd, int op, int fd, struct epoll_event32 __user *event) | 
|  | 2402 | { | 
|  | 2403 | mm_segment_t old_fs = get_fs(); | 
|  | 2404 | struct epoll_event event64; | 
|  | 2405 | int error; | 
|  | 2406 | u32 data_halfword; | 
|  | 2407 |  | 
|  | 2408 | if (!access_ok(VERIFY_READ, event, sizeof(struct epoll_event32))) | 
|  | 2409 | return -EFAULT; | 
|  | 2410 |  | 
|  | 2411 | __get_user(event64.events, &event->events); | 
|  | 2412 | __get_user(data_halfword, &event->data[0]); | 
|  | 2413 | event64.data = data_halfword; | 
|  | 2414 | __get_user(data_halfword, &event->data[1]); | 
|  | 2415 | event64.data |= (u64)data_halfword << 32; | 
|  | 2416 |  | 
|  | 2417 | set_fs(KERNEL_DS); | 
|  | 2418 | error = sys_epoll_ctl(epfd, op, fd, (struct epoll_event __user *) &event64); | 
|  | 2419 | set_fs(old_fs); | 
|  | 2420 |  | 
|  | 2421 | return error; | 
|  | 2422 | } | 
|  | 2423 |  | 
|  | 2424 | asmlinkage long | 
|  | 2425 | sys32_epoll_wait(int epfd, struct epoll_event32 __user * events, int maxevents, | 
|  | 2426 | int timeout) | 
|  | 2427 | { | 
|  | 2428 | struct epoll_event *events64 = NULL; | 
|  | 2429 | mm_segment_t old_fs = get_fs(); | 
| Peter Chubb | d8caebd | 2005-05-31 22:37:00 -0700 | [diff] [blame] | 2430 | int numevents, size; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | int evt_idx; | 
|  | 2432 | int do_free_pages = 0; | 
|  | 2433 |  | 
|  | 2434 | if (maxevents <= 0) { | 
|  | 2435 | return -EINVAL; | 
|  | 2436 | } | 
|  | 2437 |  | 
|  | 2438 | /* Verify that the area passed by the user is writeable */ | 
|  | 2439 | if (!access_ok(VERIFY_WRITE, events, maxevents * sizeof(struct epoll_event32))) | 
|  | 2440 | return -EFAULT; | 
|  | 2441 |  | 
|  | 2442 | /* | 
|  | 2443 | * Allocate space for the intermediate copy.  If the space needed | 
|  | 2444 | * is large enough to cause kmalloc to fail, then try again with | 
|  | 2445 | * __get_free_pages. | 
|  | 2446 | */ | 
|  | 2447 | size = maxevents * sizeof(struct epoll_event); | 
|  | 2448 | events64 = kmalloc(size, GFP_KERNEL); | 
|  | 2449 | if (events64 == NULL) { | 
|  | 2450 | events64 = (struct epoll_event *) | 
|  | 2451 | __get_free_pages(GFP_KERNEL, get_order(size)); | 
|  | 2452 | if (events64 == NULL) | 
|  | 2453 | return -ENOMEM; | 
|  | 2454 | do_free_pages = 1; | 
|  | 2455 | } | 
|  | 2456 |  | 
|  | 2457 | /* Do the system call */ | 
|  | 2458 | set_fs(KERNEL_DS); /* copy_to/from_user should work on kernel mem*/ | 
|  | 2459 | numevents = sys_epoll_wait(epfd, (struct epoll_event __user *) events64, | 
|  | 2460 | maxevents, timeout); | 
|  | 2461 | set_fs(old_fs); | 
|  | 2462 |  | 
|  | 2463 | /* Don't modify userspace memory if we're returning an error */ | 
|  | 2464 | if (numevents > 0) { | 
|  | 2465 | /* Translate the 64-bit structures back into the 32-bit | 
|  | 2466 | structures */ | 
|  | 2467 | for (evt_idx = 0; evt_idx < numevents; evt_idx++) { | 
|  | 2468 | __put_user(events64[evt_idx].events, | 
|  | 2469 | &events[evt_idx].events); | 
|  | 2470 | __put_user((u32)events64[evt_idx].data, | 
|  | 2471 | &events[evt_idx].data[0]); | 
|  | 2472 | __put_user((u32)(events64[evt_idx].data >> 32), | 
|  | 2473 | &events[evt_idx].data[1]); | 
|  | 2474 | } | 
|  | 2475 | } | 
|  | 2476 |  | 
|  | 2477 | if (do_free_pages) | 
|  | 2478 | free_pages((unsigned long) events64, get_order(size)); | 
|  | 2479 | else | 
|  | 2480 | kfree(events64); | 
|  | 2481 | return numevents; | 
|  | 2482 | } | 
|  | 2483 |  | 
|  | 2484 | /* | 
|  | 2485 | * Get a yet unused TLS descriptor index. | 
|  | 2486 | */ | 
|  | 2487 | static int | 
|  | 2488 | get_free_idx (void) | 
|  | 2489 | { | 
|  | 2490 | struct thread_struct *t = ¤t->thread; | 
|  | 2491 | int idx; | 
|  | 2492 |  | 
|  | 2493 | for (idx = 0; idx < GDT_ENTRY_TLS_ENTRIES; idx++) | 
|  | 2494 | if (desc_empty(t->tls_array + idx)) | 
|  | 2495 | return idx + GDT_ENTRY_TLS_MIN; | 
|  | 2496 | return -ESRCH; | 
|  | 2497 | } | 
|  | 2498 |  | 
|  | 2499 | /* | 
|  | 2500 | * Set a given TLS descriptor: | 
|  | 2501 | */ | 
|  | 2502 | asmlinkage int | 
|  | 2503 | sys32_set_thread_area (struct ia32_user_desc __user *u_info) | 
|  | 2504 | { | 
|  | 2505 | struct thread_struct *t = ¤t->thread; | 
|  | 2506 | struct ia32_user_desc info; | 
|  | 2507 | struct desc_struct *desc; | 
|  | 2508 | int cpu, idx; | 
|  | 2509 |  | 
|  | 2510 | if (copy_from_user(&info, u_info, sizeof(info))) | 
|  | 2511 | return -EFAULT; | 
|  | 2512 | idx = info.entry_number; | 
|  | 2513 |  | 
|  | 2514 | /* | 
|  | 2515 | * index -1 means the kernel should try to find and allocate an empty descriptor: | 
|  | 2516 | */ | 
|  | 2517 | if (idx == -1) { | 
|  | 2518 | idx = get_free_idx(); | 
|  | 2519 | if (idx < 0) | 
|  | 2520 | return idx; | 
|  | 2521 | if (put_user(idx, &u_info->entry_number)) | 
|  | 2522 | return -EFAULT; | 
|  | 2523 | } | 
|  | 2524 |  | 
|  | 2525 | if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX) | 
|  | 2526 | return -EINVAL; | 
|  | 2527 |  | 
|  | 2528 | desc = t->tls_array + idx - GDT_ENTRY_TLS_MIN; | 
|  | 2529 |  | 
|  | 2530 | cpu = smp_processor_id(); | 
|  | 2531 |  | 
|  | 2532 | if (LDT_empty(&info)) { | 
|  | 2533 | desc->a = 0; | 
|  | 2534 | desc->b = 0; | 
|  | 2535 | } else { | 
|  | 2536 | desc->a = LDT_entry_a(&info); | 
|  | 2537 | desc->b = LDT_entry_b(&info); | 
|  | 2538 | } | 
|  | 2539 | load_TLS(t, cpu); | 
|  | 2540 | return 0; | 
|  | 2541 | } | 
|  | 2542 |  | 
|  | 2543 | /* | 
|  | 2544 | * Get the current Thread-Local Storage area: | 
|  | 2545 | */ | 
|  | 2546 |  | 
|  | 2547 | #define GET_BASE(desc) (			\ | 
|  | 2548 | (((desc)->a >> 16) & 0x0000ffff) |	\ | 
|  | 2549 | (((desc)->b << 16) & 0x00ff0000) |	\ | 
|  | 2550 | ( (desc)->b        & 0xff000000)   ) | 
|  | 2551 |  | 
|  | 2552 | #define GET_LIMIT(desc) (			\ | 
|  | 2553 | ((desc)->a & 0x0ffff) |			\ | 
|  | 2554 | ((desc)->b & 0xf0000) ) | 
|  | 2555 |  | 
|  | 2556 | #define GET_32BIT(desc)		(((desc)->b >> 22) & 1) | 
|  | 2557 | #define GET_CONTENTS(desc)	(((desc)->b >> 10) & 3) | 
|  | 2558 | #define GET_WRITABLE(desc)	(((desc)->b >>  9) & 1) | 
|  | 2559 | #define GET_LIMIT_PAGES(desc)	(((desc)->b >> 23) & 1) | 
|  | 2560 | #define GET_PRESENT(desc)	(((desc)->b >> 15) & 1) | 
|  | 2561 | #define GET_USEABLE(desc)	(((desc)->b >> 20) & 1) | 
|  | 2562 |  | 
|  | 2563 | asmlinkage int | 
|  | 2564 | sys32_get_thread_area (struct ia32_user_desc __user *u_info) | 
|  | 2565 | { | 
|  | 2566 | struct ia32_user_desc info; | 
|  | 2567 | struct desc_struct *desc; | 
|  | 2568 | int idx; | 
|  | 2569 |  | 
|  | 2570 | if (get_user(idx, &u_info->entry_number)) | 
|  | 2571 | return -EFAULT; | 
|  | 2572 | if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX) | 
|  | 2573 | return -EINVAL; | 
|  | 2574 |  | 
|  | 2575 | desc = current->thread.tls_array + idx - GDT_ENTRY_TLS_MIN; | 
|  | 2576 |  | 
|  | 2577 | info.entry_number = idx; | 
|  | 2578 | info.base_addr = GET_BASE(desc); | 
|  | 2579 | info.limit = GET_LIMIT(desc); | 
|  | 2580 | info.seg_32bit = GET_32BIT(desc); | 
|  | 2581 | info.contents = GET_CONTENTS(desc); | 
|  | 2582 | info.read_exec_only = !GET_WRITABLE(desc); | 
|  | 2583 | info.limit_in_pages = GET_LIMIT_PAGES(desc); | 
|  | 2584 | info.seg_not_present = !GET_PRESENT(desc); | 
|  | 2585 | info.useable = GET_USEABLE(desc); | 
|  | 2586 |  | 
|  | 2587 | if (copy_to_user(u_info, &info, sizeof(info))) | 
|  | 2588 | return -EFAULT; | 
|  | 2589 | return 0; | 
|  | 2590 | } | 
|  | 2591 |  | 
|  | 2592 | asmlinkage long | 
|  | 2593 | sys32_timer_create(u32 clock, struct compat_sigevent __user *se32, timer_t __user *timer_id) | 
|  | 2594 | { | 
|  | 2595 | struct sigevent se; | 
|  | 2596 | mm_segment_t oldfs; | 
|  | 2597 | timer_t t; | 
|  | 2598 | long err; | 
|  | 2599 |  | 
|  | 2600 | if (se32 == NULL) | 
|  | 2601 | return sys_timer_create(clock, NULL, timer_id); | 
|  | 2602 |  | 
|  | 2603 | if (get_compat_sigevent(&se, se32)) | 
|  | 2604 | return -EFAULT; | 
|  | 2605 |  | 
|  | 2606 | if (!access_ok(VERIFY_WRITE,timer_id,sizeof(timer_t))) | 
|  | 2607 | return -EFAULT; | 
|  | 2608 |  | 
|  | 2609 | oldfs = get_fs(); | 
|  | 2610 | set_fs(KERNEL_DS); | 
|  | 2611 | err = sys_timer_create(clock, (struct sigevent __user *) &se, (timer_t __user *) &t); | 
|  | 2612 | set_fs(oldfs); | 
|  | 2613 |  | 
|  | 2614 | if (!err) | 
|  | 2615 | err = __put_user (t, timer_id); | 
|  | 2616 |  | 
|  | 2617 | return err; | 
|  | 2618 | } | 
|  | 2619 |  | 
|  | 2620 | long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high, | 
|  | 2621 | __u32 len_low, __u32 len_high, int advice) | 
|  | 2622 | { | 
|  | 2623 | return sys_fadvise64_64(fd, | 
|  | 2624 | (((u64)offset_high)<<32) | offset_low, | 
|  | 2625 | (((u64)len_high)<<32) | len_low, | 
|  | 2626 | advice); | 
|  | 2627 | } | 
|  | 2628 |  | 
|  | 2629 | #ifdef	NOTYET  /* UNTESTED FOR IA64 FROM HERE DOWN */ | 
|  | 2630 |  | 
|  | 2631 | asmlinkage long sys32_setreuid(compat_uid_t ruid, compat_uid_t euid) | 
|  | 2632 | { | 
|  | 2633 | uid_t sruid, seuid; | 
|  | 2634 |  | 
|  | 2635 | sruid = (ruid == (compat_uid_t)-1) ? ((uid_t)-1) : ((uid_t)ruid); | 
|  | 2636 | seuid = (euid == (compat_uid_t)-1) ? ((uid_t)-1) : ((uid_t)euid); | 
|  | 2637 | return sys_setreuid(sruid, seuid); | 
|  | 2638 | } | 
|  | 2639 |  | 
|  | 2640 | asmlinkage long | 
|  | 2641 | sys32_setresuid(compat_uid_t ruid, compat_uid_t euid, | 
|  | 2642 | compat_uid_t suid) | 
|  | 2643 | { | 
|  | 2644 | uid_t sruid, seuid, ssuid; | 
|  | 2645 |  | 
|  | 2646 | sruid = (ruid == (compat_uid_t)-1) ? ((uid_t)-1) : ((uid_t)ruid); | 
|  | 2647 | seuid = (euid == (compat_uid_t)-1) ? ((uid_t)-1) : ((uid_t)euid); | 
|  | 2648 | ssuid = (suid == (compat_uid_t)-1) ? ((uid_t)-1) : ((uid_t)suid); | 
|  | 2649 | return sys_setresuid(sruid, seuid, ssuid); | 
|  | 2650 | } | 
|  | 2651 |  | 
|  | 2652 | asmlinkage long | 
|  | 2653 | sys32_setregid(compat_gid_t rgid, compat_gid_t egid) | 
|  | 2654 | { | 
|  | 2655 | gid_t srgid, segid; | 
|  | 2656 |  | 
|  | 2657 | srgid = (rgid == (compat_gid_t)-1) ? ((gid_t)-1) : ((gid_t)rgid); | 
|  | 2658 | segid = (egid == (compat_gid_t)-1) ? ((gid_t)-1) : ((gid_t)egid); | 
|  | 2659 | return sys_setregid(srgid, segid); | 
|  | 2660 | } | 
|  | 2661 |  | 
|  | 2662 | asmlinkage long | 
|  | 2663 | sys32_setresgid(compat_gid_t rgid, compat_gid_t egid, | 
|  | 2664 | compat_gid_t sgid) | 
|  | 2665 | { | 
|  | 2666 | gid_t srgid, segid, ssgid; | 
|  | 2667 |  | 
|  | 2668 | srgid = (rgid == (compat_gid_t)-1) ? ((gid_t)-1) : ((gid_t)rgid); | 
|  | 2669 | segid = (egid == (compat_gid_t)-1) ? ((gid_t)-1) : ((gid_t)egid); | 
|  | 2670 | ssgid = (sgid == (compat_gid_t)-1) ? ((gid_t)-1) : ((gid_t)sgid); | 
|  | 2671 | return sys_setresgid(srgid, segid, ssgid); | 
|  | 2672 | } | 
|  | 2673 |  | 
|  | 2674 | /* Handle adjtimex compatibility. */ | 
|  | 2675 |  | 
|  | 2676 | struct timex32 { | 
|  | 2677 | u32 modes; | 
|  | 2678 | s32 offset, freq, maxerror, esterror; | 
|  | 2679 | s32 status, constant, precision, tolerance; | 
|  | 2680 | struct compat_timeval time; | 
|  | 2681 | s32 tick; | 
|  | 2682 | s32 ppsfreq, jitter, shift, stabil; | 
|  | 2683 | s32 jitcnt, calcnt, errcnt, stbcnt; | 
|  | 2684 | s32  :32; s32  :32; s32  :32; s32  :32; | 
|  | 2685 | s32  :32; s32  :32; s32  :32; s32  :32; | 
|  | 2686 | s32  :32; s32  :32; s32  :32; s32  :32; | 
|  | 2687 | }; | 
|  | 2688 |  | 
|  | 2689 | extern int do_adjtimex(struct timex *); | 
|  | 2690 |  | 
|  | 2691 | asmlinkage long | 
|  | 2692 | sys32_adjtimex(struct timex32 *utp) | 
|  | 2693 | { | 
|  | 2694 | struct timex txc; | 
|  | 2695 | int ret; | 
|  | 2696 |  | 
|  | 2697 | memset(&txc, 0, sizeof(struct timex)); | 
|  | 2698 |  | 
|  | 2699 | if(get_user(txc.modes, &utp->modes) || | 
|  | 2700 | __get_user(txc.offset, &utp->offset) || | 
|  | 2701 | __get_user(txc.freq, &utp->freq) || | 
|  | 2702 | __get_user(txc.maxerror, &utp->maxerror) || | 
|  | 2703 | __get_user(txc.esterror, &utp->esterror) || | 
|  | 2704 | __get_user(txc.status, &utp->status) || | 
|  | 2705 | __get_user(txc.constant, &utp->constant) || | 
|  | 2706 | __get_user(txc.precision, &utp->precision) || | 
|  | 2707 | __get_user(txc.tolerance, &utp->tolerance) || | 
|  | 2708 | __get_user(txc.time.tv_sec, &utp->time.tv_sec) || | 
|  | 2709 | __get_user(txc.time.tv_usec, &utp->time.tv_usec) || | 
|  | 2710 | __get_user(txc.tick, &utp->tick) || | 
|  | 2711 | __get_user(txc.ppsfreq, &utp->ppsfreq) || | 
|  | 2712 | __get_user(txc.jitter, &utp->jitter) || | 
|  | 2713 | __get_user(txc.shift, &utp->shift) || | 
|  | 2714 | __get_user(txc.stabil, &utp->stabil) || | 
|  | 2715 | __get_user(txc.jitcnt, &utp->jitcnt) || | 
|  | 2716 | __get_user(txc.calcnt, &utp->calcnt) || | 
|  | 2717 | __get_user(txc.errcnt, &utp->errcnt) || | 
|  | 2718 | __get_user(txc.stbcnt, &utp->stbcnt)) | 
|  | 2719 | return -EFAULT; | 
|  | 2720 |  | 
|  | 2721 | ret = do_adjtimex(&txc); | 
|  | 2722 |  | 
|  | 2723 | if(put_user(txc.modes, &utp->modes) || | 
|  | 2724 | __put_user(txc.offset, &utp->offset) || | 
|  | 2725 | __put_user(txc.freq, &utp->freq) || | 
|  | 2726 | __put_user(txc.maxerror, &utp->maxerror) || | 
|  | 2727 | __put_user(txc.esterror, &utp->esterror) || | 
|  | 2728 | __put_user(txc.status, &utp->status) || | 
|  | 2729 | __put_user(txc.constant, &utp->constant) || | 
|  | 2730 | __put_user(txc.precision, &utp->precision) || | 
|  | 2731 | __put_user(txc.tolerance, &utp->tolerance) || | 
|  | 2732 | __put_user(txc.time.tv_sec, &utp->time.tv_sec) || | 
|  | 2733 | __put_user(txc.time.tv_usec, &utp->time.tv_usec) || | 
|  | 2734 | __put_user(txc.tick, &utp->tick) || | 
|  | 2735 | __put_user(txc.ppsfreq, &utp->ppsfreq) || | 
|  | 2736 | __put_user(txc.jitter, &utp->jitter) || | 
|  | 2737 | __put_user(txc.shift, &utp->shift) || | 
|  | 2738 | __put_user(txc.stabil, &utp->stabil) || | 
|  | 2739 | __put_user(txc.jitcnt, &utp->jitcnt) || | 
|  | 2740 | __put_user(txc.calcnt, &utp->calcnt) || | 
|  | 2741 | __put_user(txc.errcnt, &utp->errcnt) || | 
|  | 2742 | __put_user(txc.stbcnt, &utp->stbcnt)) | 
|  | 2743 | ret = -EFAULT; | 
|  | 2744 |  | 
|  | 2745 | return ret; | 
|  | 2746 | } | 
|  | 2747 | #endif /* NOTYET */ |