]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - sys/vm/vm_mmap.c
MFC 233191:
[FreeBSD/stable/8.git] / sys / vm / vm_mmap.c
1 /*-
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1991, 1993
4  *      The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the Systems Programming Group of the University of Utah Computer
8  * Science Department.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 4. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  * from: Utah $Hdr: vm_mmap.c 1.6 91/10/21$
35  *
36  *      @(#)vm_mmap.c   8.4 (Berkeley) 1/12/94
37  */
38
39 /*
40  * Mapped file (mmap) interface to VM
41  */
42
43 #include <sys/cdefs.h>
44 __FBSDID("$FreeBSD$");
45
46 #include "opt_compat.h"
47 #include "opt_hwpmc_hooks.h"
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/lock.h>
52 #include <sys/mutex.h>
53 #include <sys/sysproto.h>
54 #include <sys/filedesc.h>
55 #include <sys/priv.h>
56 #include <sys/proc.h>
57 #include <sys/resource.h>
58 #include <sys/resourcevar.h>
59 #include <sys/vnode.h>
60 #include <sys/fcntl.h>
61 #include <sys/file.h>
62 #include <sys/mman.h>
63 #include <sys/mount.h>
64 #include <sys/conf.h>
65 #include <sys/stat.h>
66 #include <sys/sysent.h>
67 #include <sys/vmmeter.h>
68
69 #include <security/mac/mac_framework.h>
70
71 #include <vm/vm.h>
72 #include <vm/vm_param.h>
73 #include <vm/pmap.h>
74 #include <vm/vm_map.h>
75 #include <vm/vm_object.h>
76 #include <vm/vm_page.h>
77 #include <vm/vm_pager.h>
78 #include <vm/vm_pageout.h>
79 #include <vm/vm_extern.h>
80 #include <vm/vm_page.h>
81
82 #ifdef HWPMC_HOOKS
83 #include <sys/pmckern.h>
84 #endif
85
86 #ifndef _SYS_SYSPROTO_H_
87 struct sbrk_args {
88         int incr;
89 };
90 #endif
91
92 static int vm_mmap_vnode(struct thread *, vm_size_t, vm_prot_t, vm_prot_t *,
93     int *, struct vnode *, vm_ooffset_t *, vm_object_t *);
94 static int vm_mmap_cdev(struct thread *, vm_size_t, vm_prot_t, vm_prot_t *,
95     int *, struct cdev *, vm_ooffset_t *, vm_object_t *);
96 static int vm_mmap_shm(struct thread *, vm_size_t, vm_prot_t, vm_prot_t *,
97     int *, struct shmfd *, vm_ooffset_t, vm_object_t *);
98
99 /*
100  * MPSAFE
101  */
102 /* ARGSUSED */
103 int
104 sbrk(td, uap)
105         struct thread *td;
106         struct sbrk_args *uap;
107 {
108         /* Not yet implemented */
109         return (EOPNOTSUPP);
110 }
111
112 #ifndef _SYS_SYSPROTO_H_
113 struct sstk_args {
114         int incr;
115 };
116 #endif
117
118 /*
119  * MPSAFE
120  */
121 /* ARGSUSED */
122 int
123 sstk(td, uap)
124         struct thread *td;
125         struct sstk_args *uap;
126 {
127         /* Not yet implemented */
128         return (EOPNOTSUPP);
129 }
130
131 #if defined(COMPAT_43)
132 #ifndef _SYS_SYSPROTO_H_
133 struct getpagesize_args {
134         int dummy;
135 };
136 #endif
137
138 /* ARGSUSED */
139 int
140 ogetpagesize(td, uap)
141         struct thread *td;
142         struct getpagesize_args *uap;
143 {
144         /* MP SAFE */
145         td->td_retval[0] = PAGE_SIZE;
146         return (0);
147 }
148 #endif                          /* COMPAT_43 */
149
150
151 /*
152  * Memory Map (mmap) system call.  Note that the file offset
153  * and address are allowed to be NOT page aligned, though if
154  * the MAP_FIXED flag it set, both must have the same remainder
155  * modulo the PAGE_SIZE (POSIX 1003.1b).  If the address is not
156  * page-aligned, the actual mapping starts at trunc_page(addr)
157  * and the return value is adjusted up by the page offset.
158  *
159  * Generally speaking, only character devices which are themselves
160  * memory-based, such as a video framebuffer, can be mmap'd.  Otherwise
161  * there would be no cache coherency between a descriptor and a VM mapping
162  * both to the same character device.
163  */
164 #ifndef _SYS_SYSPROTO_H_
165 struct mmap_args {
166         void *addr;
167         size_t len;
168         int prot;
169         int flags;
170         int fd;
171         long pad;
172         off_t pos;
173 };
174 #endif
175
176 /*
177  * MPSAFE
178  */
179 int
180 mmap(td, uap)
181         struct thread *td;
182         struct mmap_args *uap;
183 {
184 #ifdef HWPMC_HOOKS
185         struct pmckern_map_in pkm;
186 #endif
187         struct file *fp;
188         struct vnode *vp;
189         vm_offset_t addr;
190         vm_size_t size, pageoff;
191         vm_prot_t prot, maxprot;
192         void *handle;
193         objtype_t handle_type;
194         int flags, error;
195         off_t pos;
196         struct vmspace *vms = td->td_proc->p_vmspace;
197
198         addr = (vm_offset_t) uap->addr;
199         size = uap->len;
200         prot = uap->prot & VM_PROT_ALL;
201         flags = uap->flags;
202         pos = uap->pos;
203
204         fp = NULL;
205         /* make sure mapping fits into numeric range etc */
206         if ((uap->len == 0 && !SV_CURPROC_FLAG(SV_AOUT) &&
207              curproc->p_osrel >= P_OSREL_MAP_ANON) ||
208             ((flags & MAP_ANON) && (uap->fd != -1 || pos != 0)))
209                 return (EINVAL);
210
211         if (flags & MAP_STACK) {
212                 if ((uap->fd != -1) ||
213                     ((prot & (PROT_READ | PROT_WRITE)) != (PROT_READ | PROT_WRITE)))
214                         return (EINVAL);
215                 flags |= MAP_ANON;
216                 pos = 0;
217         }
218
219         /*
220          * Align the file position to a page boundary,
221          * and save its page offset component.
222          */
223         pageoff = (pos & PAGE_MASK);
224         pos -= pageoff;
225
226         /* Adjust size for rounding (on both ends). */
227         size += pageoff;                        /* low end... */
228         size = (vm_size_t) round_page(size);    /* hi end */
229
230         /*
231          * Check for illegal addresses.  Watch out for address wrap... Note
232          * that VM_*_ADDRESS are not constants due to casts (argh).
233          */
234         if (flags & MAP_FIXED) {
235                 /*
236                  * The specified address must have the same remainder
237                  * as the file offset taken modulo PAGE_SIZE, so it
238                  * should be aligned after adjustment by pageoff.
239                  */
240                 addr -= pageoff;
241                 if (addr & PAGE_MASK)
242                         return (EINVAL);
243                 /* Address range must be all in user VM space. */
244                 if (addr < vm_map_min(&vms->vm_map) ||
245                     addr + size > vm_map_max(&vms->vm_map))
246                         return (EINVAL);
247                 if (addr + size < addr)
248                         return (EINVAL);
249         } else {
250         /*
251          * XXX for non-fixed mappings where no hint is provided or
252          * the hint would fall in the potential heap space,
253          * place it after the end of the largest possible heap.
254          *
255          * There should really be a pmap call to determine a reasonable
256          * location.
257          */
258                 PROC_LOCK(td->td_proc);
259                 if (addr == 0 ||
260                     (addr >= round_page((vm_offset_t)vms->vm_taddr) &&
261                     addr < round_page((vm_offset_t)vms->vm_daddr +
262                     lim_max(td->td_proc, RLIMIT_DATA))))
263                         addr = round_page((vm_offset_t)vms->vm_daddr +
264                             lim_max(td->td_proc, RLIMIT_DATA));
265                 PROC_UNLOCK(td->td_proc);
266         }
267         if (flags & MAP_ANON) {
268                 /*
269                  * Mapping blank space is trivial.
270                  */
271                 handle = NULL;
272                 handle_type = OBJT_DEFAULT;
273                 maxprot = VM_PROT_ALL;
274         } else {
275                 /*
276                  * Mapping file, get fp for validation and
277                  * don't let the descriptor disappear on us if we block.
278                  */
279                 if ((error = fget(td, uap->fd, &fp)) != 0)
280                         goto done;
281                 if (fp->f_type == DTYPE_SHM) {
282                         handle = fp->f_data;
283                         handle_type = OBJT_SWAP;
284                         maxprot = VM_PROT_NONE;
285
286                         /* FREAD should always be set. */
287                         if (fp->f_flag & FREAD)
288                                 maxprot |= VM_PROT_EXECUTE | VM_PROT_READ;
289                         if (fp->f_flag & FWRITE)
290                                 maxprot |= VM_PROT_WRITE;
291                         goto map;
292                 }
293                 if (fp->f_type != DTYPE_VNODE) {
294                         error = ENODEV;
295                         goto done;
296                 }
297 #if defined(COMPAT_FREEBSD7) || defined(COMPAT_FREEBSD6) || \
298     defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4)
299                 /*
300                  * POSIX shared-memory objects are defined to have
301                  * kernel persistence, and are not defined to support
302                  * read(2)/write(2) -- or even open(2).  Thus, we can
303                  * use MAP_ASYNC to trade on-disk coherence for speed.
304                  * The shm_open(3) library routine turns on the FPOSIXSHM
305                  * flag to request this behavior.
306                  */
307                 if (fp->f_flag & FPOSIXSHM)
308                         flags |= MAP_NOSYNC;
309 #endif
310                 vp = fp->f_vnode;
311                 /*
312                  * Ensure that file and memory protections are
313                  * compatible.  Note that we only worry about
314                  * writability if mapping is shared; in this case,
315                  * current and max prot are dictated by the open file.
316                  * XXX use the vnode instead?  Problem is: what
317                  * credentials do we use for determination? What if
318                  * proc does a setuid?
319                  */
320                 if (vp->v_mount != NULL && vp->v_mount->mnt_flag & MNT_NOEXEC)
321                         maxprot = VM_PROT_NONE;
322                 else
323                         maxprot = VM_PROT_EXECUTE;
324                 if (fp->f_flag & FREAD) {
325                         maxprot |= VM_PROT_READ;
326                 } else if (prot & PROT_READ) {
327                         error = EACCES;
328                         goto done;
329                 }
330                 /*
331                  * If we are sharing potential changes (either via
332                  * MAP_SHARED or via the implicit sharing of character
333                  * device mappings), and we are trying to get write
334                  * permission although we opened it without asking
335                  * for it, bail out.
336                  */
337                 if ((flags & MAP_SHARED) != 0) {
338                         if ((fp->f_flag & FWRITE) != 0) {
339                                 maxprot |= VM_PROT_WRITE;
340                         } else if ((prot & PROT_WRITE) != 0) {
341                                 error = EACCES;
342                                 goto done;
343                         }
344                 } else if (vp->v_type != VCHR || (fp->f_flag & FWRITE) != 0) {
345                         maxprot |= VM_PROT_WRITE;
346                 }
347                 handle = (void *)vp;
348                 handle_type = OBJT_VNODE;
349         }
350 map:
351         td->td_fpop = fp;
352         error = vm_mmap(&vms->vm_map, &addr, size, prot, maxprot,
353             flags, handle_type, handle, pos);
354         td->td_fpop = NULL;
355 #ifdef HWPMC_HOOKS
356         /* inform hwpmc(4) if an executable is being mapped */
357         if (error == 0 && handle_type == OBJT_VNODE &&
358             (prot & PROT_EXEC)) {
359                 pkm.pm_file = handle;
360                 pkm.pm_address = (uintptr_t) addr;
361                 PMC_CALL_HOOK(td, PMC_FN_MMAP, (void *) &pkm);
362         }
363 #endif
364         if (error == 0)
365                 td->td_retval[0] = (register_t) (addr + pageoff);
366 done:
367         if (fp)
368                 fdrop(fp, td);
369
370         return (error);
371 }
372
373 int
374 freebsd6_mmap(struct thread *td, struct freebsd6_mmap_args *uap)
375 {
376         struct mmap_args oargs;
377
378         oargs.addr = uap->addr;
379         oargs.len = uap->len;
380         oargs.prot = uap->prot;
381         oargs.flags = uap->flags;
382         oargs.fd = uap->fd;
383         oargs.pos = uap->pos;
384         return (mmap(td, &oargs));
385 }
386
387 #ifdef COMPAT_43
388 #ifndef _SYS_SYSPROTO_H_
389 struct ommap_args {
390         caddr_t addr;
391         int len;
392         int prot;
393         int flags;
394         int fd;
395         long pos;
396 };
397 #endif
398 int
399 ommap(td, uap)
400         struct thread *td;
401         struct ommap_args *uap;
402 {
403         struct mmap_args nargs;
404         static const char cvtbsdprot[8] = {
405                 0,
406                 PROT_EXEC,
407                 PROT_WRITE,
408                 PROT_EXEC | PROT_WRITE,
409                 PROT_READ,
410                 PROT_EXEC | PROT_READ,
411                 PROT_WRITE | PROT_READ,
412                 PROT_EXEC | PROT_WRITE | PROT_READ,
413         };
414
415 #define OMAP_ANON       0x0002
416 #define OMAP_COPY       0x0020
417 #define OMAP_SHARED     0x0010
418 #define OMAP_FIXED      0x0100
419
420         nargs.addr = uap->addr;
421         nargs.len = uap->len;
422         nargs.prot = cvtbsdprot[uap->prot & 0x7];
423         nargs.flags = 0;
424         if (uap->flags & OMAP_ANON)
425                 nargs.flags |= MAP_ANON;
426         if (uap->flags & OMAP_COPY)
427                 nargs.flags |= MAP_COPY;
428         if (uap->flags & OMAP_SHARED)
429                 nargs.flags |= MAP_SHARED;
430         else
431                 nargs.flags |= MAP_PRIVATE;
432         if (uap->flags & OMAP_FIXED)
433                 nargs.flags |= MAP_FIXED;
434         nargs.fd = uap->fd;
435         nargs.pos = uap->pos;
436         return (mmap(td, &nargs));
437 }
438 #endif                          /* COMPAT_43 */
439
440
441 #ifndef _SYS_SYSPROTO_H_
442 struct msync_args {
443         void *addr;
444         size_t len;
445         int flags;
446 };
447 #endif
448 /*
449  * MPSAFE
450  */
451 int
452 msync(td, uap)
453         struct thread *td;
454         struct msync_args *uap;
455 {
456         vm_offset_t addr;
457         vm_size_t size, pageoff;
458         int flags;
459         vm_map_t map;
460         int rv;
461
462         addr = (vm_offset_t) uap->addr;
463         size = uap->len;
464         flags = uap->flags;
465
466         pageoff = (addr & PAGE_MASK);
467         addr -= pageoff;
468         size += pageoff;
469         size = (vm_size_t) round_page(size);
470         if (addr + size < addr)
471                 return (EINVAL);
472
473         if ((flags & (MS_ASYNC|MS_INVALIDATE)) == (MS_ASYNC|MS_INVALIDATE))
474                 return (EINVAL);
475
476         map = &td->td_proc->p_vmspace->vm_map;
477
478         /*
479          * Clean the pages and interpret the return value.
480          */
481         rv = vm_map_sync(map, addr, addr + size, (flags & MS_ASYNC) == 0,
482             (flags & MS_INVALIDATE) != 0);
483         switch (rv) {
484         case KERN_SUCCESS:
485                 return (0);
486         case KERN_INVALID_ADDRESS:
487                 return (EINVAL);        /* Sun returns ENOMEM? */
488         case KERN_INVALID_ARGUMENT:
489                 return (EBUSY);
490         case KERN_FAILURE:
491                 return (EIO);
492         default:
493                 return (EINVAL);
494         }
495 }
496
497 #ifndef _SYS_SYSPROTO_H_
498 struct munmap_args {
499         void *addr;
500         size_t len;
501 };
502 #endif
503 /*
504  * MPSAFE
505  */
506 int
507 munmap(td, uap)
508         struct thread *td;
509         struct munmap_args *uap;
510 {
511 #ifdef HWPMC_HOOKS
512         struct pmckern_map_out pkm;
513         vm_map_entry_t entry;
514 #endif
515         vm_offset_t addr;
516         vm_size_t size, pageoff;
517         vm_map_t map;
518
519         addr = (vm_offset_t) uap->addr;
520         size = uap->len;
521         if (size == 0)
522                 return (EINVAL);
523
524         pageoff = (addr & PAGE_MASK);
525         addr -= pageoff;
526         size += pageoff;
527         size = (vm_size_t) round_page(size);
528         if (addr + size < addr)
529                 return (EINVAL);
530
531         /*
532          * Check for illegal addresses.  Watch out for address wrap...
533          */
534         map = &td->td_proc->p_vmspace->vm_map;
535         if (addr < vm_map_min(map) || addr + size > vm_map_max(map))
536                 return (EINVAL);
537         vm_map_lock(map);
538 #ifdef HWPMC_HOOKS
539         /*
540          * Inform hwpmc if the address range being unmapped contains
541          * an executable region.
542          */
543         pkm.pm_address = (uintptr_t) NULL;
544         if (vm_map_lookup_entry(map, addr, &entry)) {
545                 for (;
546                      entry != &map->header && entry->start < addr + size;
547                      entry = entry->next) {
548                         if (vm_map_check_protection(map, entry->start,
549                                 entry->end, VM_PROT_EXECUTE) == TRUE) {
550                                 pkm.pm_address = (uintptr_t) addr;
551                                 pkm.pm_size = (size_t) size;
552                                 break;
553                         }
554                 }
555         }
556 #endif
557         vm_map_delete(map, addr, addr + size);
558
559 #ifdef HWPMC_HOOKS
560         /* downgrade the lock to prevent a LOR with the pmc-sx lock */
561         vm_map_lock_downgrade(map);
562         if (pkm.pm_address != (uintptr_t) NULL)
563                 PMC_CALL_HOOK(td, PMC_FN_MUNMAP, (void *) &pkm);
564         vm_map_unlock_read(map);
565 #else
566         vm_map_unlock(map);
567 #endif
568         /* vm_map_delete returns nothing but KERN_SUCCESS anyway */
569         return (0);
570 }
571
572 #ifndef _SYS_SYSPROTO_H_
573 struct mprotect_args {
574         const void *addr;
575         size_t len;
576         int prot;
577 };
578 #endif
579 /*
580  * MPSAFE
581  */
582 int
583 mprotect(td, uap)
584         struct thread *td;
585         struct mprotect_args *uap;
586 {
587         vm_offset_t addr;
588         vm_size_t size, pageoff;
589         vm_prot_t prot;
590
591         addr = (vm_offset_t) uap->addr;
592         size = uap->len;
593         prot = uap->prot & VM_PROT_ALL;
594
595         pageoff = (addr & PAGE_MASK);
596         addr -= pageoff;
597         size += pageoff;
598         size = (vm_size_t) round_page(size);
599         if (addr + size < addr)
600                 return (EINVAL);
601
602         switch (vm_map_protect(&td->td_proc->p_vmspace->vm_map, addr,
603             addr + size, prot, FALSE)) {
604         case KERN_SUCCESS:
605                 return (0);
606         case KERN_PROTECTION_FAILURE:
607                 return (EACCES);
608         case KERN_RESOURCE_SHORTAGE:
609                 return (ENOMEM);
610         }
611         return (EINVAL);
612 }
613
614 #ifndef _SYS_SYSPROTO_H_
615 struct minherit_args {
616         void *addr;
617         size_t len;
618         int inherit;
619 };
620 #endif
621 /*
622  * MPSAFE
623  */
624 int
625 minherit(td, uap)
626         struct thread *td;
627         struct minherit_args *uap;
628 {
629         vm_offset_t addr;
630         vm_size_t size, pageoff;
631         vm_inherit_t inherit;
632
633         addr = (vm_offset_t)uap->addr;
634         size = uap->len;
635         inherit = uap->inherit;
636
637         pageoff = (addr & PAGE_MASK);
638         addr -= pageoff;
639         size += pageoff;
640         size = (vm_size_t) round_page(size);
641         if (addr + size < addr)
642                 return (EINVAL);
643
644         switch (vm_map_inherit(&td->td_proc->p_vmspace->vm_map, addr,
645             addr + size, inherit)) {
646         case KERN_SUCCESS:
647                 return (0);
648         case KERN_PROTECTION_FAILURE:
649                 return (EACCES);
650         }
651         return (EINVAL);
652 }
653
654 #ifndef _SYS_SYSPROTO_H_
655 struct madvise_args {
656         void *addr;
657         size_t len;
658         int behav;
659 };
660 #endif
661
662 /*
663  * MPSAFE
664  */
665 /* ARGSUSED */
666 int
667 madvise(td, uap)
668         struct thread *td;
669         struct madvise_args *uap;
670 {
671         vm_offset_t start, end;
672         vm_map_t map;
673         struct proc *p;
674         int error;
675
676         /*
677          * Check for our special case, advising the swap pager we are
678          * "immortal."
679          */
680         if (uap->behav == MADV_PROTECT) {
681                 error = priv_check(td, PRIV_VM_MADV_PROTECT);
682                 if (error == 0) {
683                         p = td->td_proc;
684                         PROC_LOCK(p);
685                         p->p_flag |= P_PROTECTED;
686                         PROC_UNLOCK(p);
687                 }
688                 return (error);
689         }
690         /*
691          * Check for illegal behavior
692          */
693         if (uap->behav < 0 || uap->behav > MADV_CORE)
694                 return (EINVAL);
695         /*
696          * Check for illegal addresses.  Watch out for address wrap... Note
697          * that VM_*_ADDRESS are not constants due to casts (argh).
698          */
699         map = &td->td_proc->p_vmspace->vm_map;
700         if ((vm_offset_t)uap->addr < vm_map_min(map) ||
701             (vm_offset_t)uap->addr + uap->len > vm_map_max(map))
702                 return (EINVAL);
703         if (((vm_offset_t) uap->addr + uap->len) < (vm_offset_t) uap->addr)
704                 return (EINVAL);
705
706         /*
707          * Since this routine is only advisory, we default to conservative
708          * behavior.
709          */
710         start = trunc_page((vm_offset_t) uap->addr);
711         end = round_page((vm_offset_t) uap->addr + uap->len);
712
713         if (vm_map_madvise(map, start, end, uap->behav))
714                 return (EINVAL);
715         return (0);
716 }
717
718 #ifndef _SYS_SYSPROTO_H_
719 struct mincore_args {
720         const void *addr;
721         size_t len;
722         char *vec;
723 };
724 #endif
725
726 /*
727  * MPSAFE
728  */
729 /* ARGSUSED */
730 int
731 mincore(td, uap)
732         struct thread *td;
733         struct mincore_args *uap;
734 {
735         vm_offset_t addr, first_addr;
736         vm_offset_t end, cend;
737         pmap_t pmap;
738         vm_map_t map;
739         char *vec;
740         int error = 0;
741         int vecindex, lastvecindex;
742         vm_map_entry_t current;
743         vm_map_entry_t entry;
744         int mincoreinfo;
745         unsigned int timestamp;
746
747         /*
748          * Make sure that the addresses presented are valid for user
749          * mode.
750          */
751         first_addr = addr = trunc_page((vm_offset_t) uap->addr);
752         end = addr + (vm_size_t)round_page(uap->len);
753         map = &td->td_proc->p_vmspace->vm_map;
754         if (end > vm_map_max(map) || end < addr)
755                 return (ENOMEM);
756
757         /*
758          * Address of byte vector
759          */
760         vec = uap->vec;
761
762         pmap = vmspace_pmap(td->td_proc->p_vmspace);
763
764         vm_map_lock_read(map);
765 RestartScan:
766         timestamp = map->timestamp;
767
768         if (!vm_map_lookup_entry(map, addr, &entry)) {
769                 vm_map_unlock_read(map);
770                 return (ENOMEM);
771         }
772
773         /*
774          * Do this on a map entry basis so that if the pages are not
775          * in the current processes address space, we can easily look
776          * up the pages elsewhere.
777          */
778         lastvecindex = -1;
779         for (current = entry;
780             (current != &map->header) && (current->start < end);
781             current = current->next) {
782
783                 /*
784                  * check for contiguity
785                  */
786                 if (current->end < end &&
787                     (entry->next == &map->header ||
788                      current->next->start > current->end)) {
789                         vm_map_unlock_read(map);
790                         return (ENOMEM);
791                 }
792
793                 /*
794                  * ignore submaps (for now) or null objects
795                  */
796                 if ((current->eflags & MAP_ENTRY_IS_SUB_MAP) ||
797                         current->object.vm_object == NULL)
798                         continue;
799
800                 /*
801                  * limit this scan to the current map entry and the
802                  * limits for the mincore call
803                  */
804                 if (addr < current->start)
805                         addr = current->start;
806                 cend = current->end;
807                 if (cend > end)
808                         cend = end;
809
810                 /*
811                  * scan this entry one page at a time
812                  */
813                 while (addr < cend) {
814                         /*
815                          * Check pmap first, it is likely faster, also
816                          * it can provide info as to whether we are the
817                          * one referencing or modifying the page.
818                          */
819                         mincoreinfo = pmap_mincore(pmap, addr);
820                         if (!mincoreinfo) {
821                                 vm_pindex_t pindex;
822                                 vm_ooffset_t offset;
823                                 vm_page_t m;
824                                 /*
825                                  * calculate the page index into the object
826                                  */
827                                 offset = current->offset + (addr - current->start);
828                                 pindex = OFF_TO_IDX(offset);
829                                 VM_OBJECT_LOCK(current->object.vm_object);
830                                 m = vm_page_lookup(current->object.vm_object,
831                                         pindex);
832                                 /*
833                                  * if the page is resident, then gather information about
834                                  * it.
835                                  */
836                                 if (m != NULL && m->valid != 0) {
837                                         mincoreinfo = MINCORE_INCORE;
838                                         vm_page_lock_queues();
839                                         if (m->dirty ||
840                                                 pmap_is_modified(m))
841                                                 mincoreinfo |= MINCORE_MODIFIED_OTHER;
842                                         if ((m->flags & PG_REFERENCED) ||
843                                                 pmap_ts_referenced(m)) {
844                                                 vm_page_flag_set(m, PG_REFERENCED);
845                                                 mincoreinfo |= MINCORE_REFERENCED_OTHER;
846                                         }
847                                         vm_page_unlock_queues();
848                                 }
849                                 VM_OBJECT_UNLOCK(current->object.vm_object);
850                         }
851
852                         /*
853                          * subyte may page fault.  In case it needs to modify
854                          * the map, we release the lock.
855                          */
856                         vm_map_unlock_read(map);
857
858                         /*
859                          * calculate index into user supplied byte vector
860                          */
861                         vecindex = OFF_TO_IDX(addr - first_addr);
862
863                         /*
864                          * If we have skipped map entries, we need to make sure that
865                          * the byte vector is zeroed for those skipped entries.
866                          */
867                         while ((lastvecindex + 1) < vecindex) {
868                                 error = subyte(vec + lastvecindex, 0);
869                                 if (error) {
870                                         error = EFAULT;
871                                         goto done2;
872                                 }
873                                 ++lastvecindex;
874                         }
875
876                         /*
877                          * Pass the page information to the user
878                          */
879                         error = subyte(vec + vecindex, mincoreinfo);
880                         if (error) {
881                                 error = EFAULT;
882                                 goto done2;
883                         }
884
885                         /*
886                          * If the map has changed, due to the subyte, the previous
887                          * output may be invalid.
888                          */
889                         vm_map_lock_read(map);
890                         if (timestamp != map->timestamp)
891                                 goto RestartScan;
892
893                         lastvecindex = vecindex;
894                         addr += PAGE_SIZE;
895                 }
896         }
897
898         /*
899          * subyte may page fault.  In case it needs to modify
900          * the map, we release the lock.
901          */
902         vm_map_unlock_read(map);
903
904         /*
905          * Zero the last entries in the byte vector.
906          */
907         vecindex = OFF_TO_IDX(end - first_addr);
908         while ((lastvecindex + 1) < vecindex) {
909                 error = subyte(vec + lastvecindex, 0);
910                 if (error) {
911                         error = EFAULT;
912                         goto done2;
913                 }
914                 ++lastvecindex;
915         }
916
917         /*
918          * If the map has changed, due to the subyte, the previous
919          * output may be invalid.
920          */
921         vm_map_lock_read(map);
922         if (timestamp != map->timestamp)
923                 goto RestartScan;
924         vm_map_unlock_read(map);
925 done2:
926         return (error);
927 }
928
929 #ifndef _SYS_SYSPROTO_H_
930 struct mlock_args {
931         const void *addr;
932         size_t len;
933 };
934 #endif
935 /*
936  * MPSAFE
937  */
938 int
939 mlock(td, uap)
940         struct thread *td;
941         struct mlock_args *uap;
942 {
943         struct proc *proc;
944         vm_offset_t addr, end, last, start;
945         vm_size_t npages, size;
946         int error;
947
948         error = priv_check(td, PRIV_VM_MLOCK);
949         if (error)
950                 return (error);
951         addr = (vm_offset_t)uap->addr;
952         size = uap->len;
953         last = addr + size;
954         start = trunc_page(addr);
955         end = round_page(last);
956         if (last < addr || end < addr)
957                 return (EINVAL);
958         npages = atop(end - start);
959         if (npages > vm_page_max_wired)
960                 return (ENOMEM);
961         proc = td->td_proc;
962         PROC_LOCK(proc);
963         if (ptoa(npages +
964             pmap_wired_count(vm_map_pmap(&proc->p_vmspace->vm_map))) >
965             lim_cur(proc, RLIMIT_MEMLOCK)) {
966                 PROC_UNLOCK(proc);
967                 return (ENOMEM);
968         }
969         PROC_UNLOCK(proc);
970         if (npages + cnt.v_wire_count > vm_page_max_wired)
971                 return (EAGAIN);
972         error = vm_map_wire(&proc->p_vmspace->vm_map, start, end,
973             VM_MAP_WIRE_USER | VM_MAP_WIRE_NOHOLES);
974         return (error == KERN_SUCCESS ? 0 : ENOMEM);
975 }
976
977 #ifndef _SYS_SYSPROTO_H_
978 struct mlockall_args {
979         int     how;
980 };
981 #endif
982
983 /*
984  * MPSAFE
985  */
986 int
987 mlockall(td, uap)
988         struct thread *td;
989         struct mlockall_args *uap;
990 {
991         vm_map_t map;
992         int error;
993
994         map = &td->td_proc->p_vmspace->vm_map;
995         error = 0;
996
997         if ((uap->how == 0) || ((uap->how & ~(MCL_CURRENT|MCL_FUTURE)) != 0))
998                 return (EINVAL);
999
1000 #if 0
1001         /*
1002          * If wiring all pages in the process would cause it to exceed
1003          * a hard resource limit, return ENOMEM.
1004          */
1005         PROC_LOCK(td->td_proc);
1006         if (map->size - ptoa(pmap_wired_count(vm_map_pmap(map)) >
1007                 lim_cur(td->td_proc, RLIMIT_MEMLOCK))) {
1008                 PROC_UNLOCK(td->td_proc);
1009                 return (ENOMEM);
1010         }
1011         PROC_UNLOCK(td->td_proc);
1012 #else
1013         error = priv_check(td, PRIV_VM_MLOCK);
1014         if (error)
1015                 return (error);
1016 #endif
1017
1018         if (uap->how & MCL_FUTURE) {
1019                 vm_map_lock(map);
1020                 vm_map_modflags(map, MAP_WIREFUTURE, 0);
1021                 vm_map_unlock(map);
1022                 error = 0;
1023         }
1024
1025         if (uap->how & MCL_CURRENT) {
1026                 /*
1027                  * P1003.1-2001 mandates that all currently mapped pages
1028                  * will be memory resident and locked (wired) upon return
1029                  * from mlockall(). vm_map_wire() will wire pages, by
1030                  * calling vm_fault_wire() for each page in the region.
1031                  */
1032                 error = vm_map_wire(map, vm_map_min(map), vm_map_max(map),
1033                     VM_MAP_WIRE_USER|VM_MAP_WIRE_HOLESOK);
1034                 error = (error == KERN_SUCCESS ? 0 : EAGAIN);
1035         }
1036
1037         return (error);
1038 }
1039
1040 #ifndef _SYS_SYSPROTO_H_
1041 struct munlockall_args {
1042         register_t dummy;
1043 };
1044 #endif
1045
1046 /*
1047  * MPSAFE
1048  */
1049 int
1050 munlockall(td, uap)
1051         struct thread *td;
1052         struct munlockall_args *uap;
1053 {
1054         vm_map_t map;
1055         int error;
1056
1057         map = &td->td_proc->p_vmspace->vm_map;
1058         error = priv_check(td, PRIV_VM_MUNLOCK);
1059         if (error)
1060                 return (error);
1061
1062         /* Clear the MAP_WIREFUTURE flag from this vm_map. */
1063         vm_map_lock(map);
1064         vm_map_modflags(map, 0, MAP_WIREFUTURE);
1065         vm_map_unlock(map);
1066
1067         /* Forcibly unwire all pages. */
1068         error = vm_map_unwire(map, vm_map_min(map), vm_map_max(map),
1069             VM_MAP_WIRE_USER|VM_MAP_WIRE_HOLESOK);
1070
1071         return (error);
1072 }
1073
1074 #ifndef _SYS_SYSPROTO_H_
1075 struct munlock_args {
1076         const void *addr;
1077         size_t len;
1078 };
1079 #endif
1080 /*
1081  * MPSAFE
1082  */
1083 int
1084 munlock(td, uap)
1085         struct thread *td;
1086         struct munlock_args *uap;
1087 {
1088         vm_offset_t addr, end, last, start;
1089         vm_size_t size;
1090         int error;
1091
1092         error = priv_check(td, PRIV_VM_MUNLOCK);
1093         if (error)
1094                 return (error);
1095         addr = (vm_offset_t)uap->addr;
1096         size = uap->len;
1097         last = addr + size;
1098         start = trunc_page(addr);
1099         end = round_page(last);
1100         if (last < addr || end < addr)
1101                 return (EINVAL);
1102         error = vm_map_unwire(&td->td_proc->p_vmspace->vm_map, start, end,
1103             VM_MAP_WIRE_USER | VM_MAP_WIRE_NOHOLES);
1104         return (error == KERN_SUCCESS ? 0 : ENOMEM);
1105 }
1106
1107 /*
1108  * vm_mmap_vnode()
1109  *
1110  * MPSAFE
1111  *
1112  * Helper function for vm_mmap.  Perform sanity check specific for mmap
1113  * operations on vnodes.
1114  */
1115 int
1116 vm_mmap_vnode(struct thread *td, vm_size_t objsize,
1117     vm_prot_t prot, vm_prot_t *maxprotp, int *flagsp,
1118     struct vnode *vp, vm_ooffset_t *foffp, vm_object_t *objp)
1119 {
1120         struct vattr va;
1121         vm_object_t obj;
1122         vm_offset_t foff;
1123         struct mount *mp;
1124         struct ucred *cred;
1125         int error, flags;
1126         int vfslocked;
1127
1128         mp = vp->v_mount;
1129         cred = td->td_ucred;
1130         vfslocked = VFS_LOCK_GIANT(mp);
1131         if ((error = vget(vp, LK_SHARED, td)) != 0) {
1132                 VFS_UNLOCK_GIANT(vfslocked);
1133                 return (error);
1134         }
1135         foff = *foffp;
1136         flags = *flagsp;
1137         obj = vp->v_object;
1138         if (vp->v_type == VREG) {
1139                 /*
1140                  * Get the proper underlying object
1141                  */
1142                 if (obj == NULL) {
1143                         error = EINVAL;
1144                         goto done;
1145                 }
1146                 if (obj->handle != vp) {
1147                         vput(vp);
1148                         vp = (struct vnode*)obj->handle;
1149                         vget(vp, LK_SHARED, td);
1150                 }
1151         } else if (vp->v_type == VCHR) {
1152                 error = vm_mmap_cdev(td, objsize, prot, maxprotp, flagsp,
1153                     vp->v_rdev, foffp, objp);
1154                 if (error == 0)
1155                         goto mark_atime;
1156                 goto done;
1157         } else {
1158                 error = EINVAL;
1159                 goto done;
1160         }
1161         if ((error = VOP_GETATTR(vp, &va, cred)))
1162                 goto done;
1163 #ifdef MAC
1164         error = mac_vnode_check_mmap(cred, vp, prot, flags);
1165         if (error != 0)
1166                 goto done;
1167 #endif
1168         if ((flags & MAP_SHARED) != 0) {
1169                 if ((va.va_flags & (SF_SNAPSHOT|IMMUTABLE|APPEND)) != 0) {
1170                         if (prot & PROT_WRITE) {
1171                                 error = EPERM;
1172                                 goto done;
1173                         }
1174                         *maxprotp &= ~VM_PROT_WRITE;
1175                 }
1176         }
1177         /*
1178          * If it is a regular file without any references
1179          * we do not need to sync it.
1180          * Adjust object size to be the size of actual file.
1181          */
1182         objsize = round_page(va.va_size);
1183         if (va.va_nlink == 0)
1184                 flags |= MAP_NOSYNC;
1185         obj = vm_pager_allocate(OBJT_VNODE, vp, objsize, prot, foff, td->td_ucred);
1186         if (obj == NULL) {
1187                 error = ENOMEM;
1188                 goto done;
1189         }
1190         *objp = obj;
1191         *flagsp = flags;
1192
1193 mark_atime:
1194         vfs_mark_atime(vp, cred);
1195
1196 done:
1197         vput(vp);
1198         VFS_UNLOCK_GIANT(vfslocked);
1199         return (error);
1200 }
1201
1202 /*
1203  * vm_mmap_cdev()
1204  *
1205  * MPSAFE
1206  *
1207  * Helper function for vm_mmap.  Perform sanity check specific for mmap
1208  * operations on cdevs.
1209  */
1210 int
1211 vm_mmap_cdev(struct thread *td, vm_size_t objsize,
1212     vm_prot_t prot, vm_prot_t *maxprotp, int *flagsp,
1213     struct cdev *cdev, vm_ooffset_t *foff, vm_object_t *objp)
1214 {
1215         vm_object_t obj;
1216         struct cdevsw *dsw;
1217         int error, flags, ref;
1218
1219         flags = *flagsp;
1220
1221         dsw = dev_refthread(cdev, &ref);
1222         if (dsw == NULL)
1223                 return (ENXIO);
1224         if (dsw->d_flags & D_MMAP_ANON) {
1225                 dev_relthread(cdev, ref);
1226                 *maxprotp = VM_PROT_ALL;
1227                 *flagsp |= MAP_ANON;
1228                 return (0);
1229         }
1230         /*
1231          * cdevs do not provide private mappings of any kind.
1232          */
1233         if ((*maxprotp & VM_PROT_WRITE) == 0 &&
1234             (prot & PROT_WRITE) != 0) {
1235                 dev_relthread(cdev, ref);
1236                 return (EACCES);
1237         }
1238         if (flags & (MAP_PRIVATE|MAP_COPY)) {
1239                 dev_relthread(cdev, ref);
1240                 return (EINVAL);
1241         }
1242         /*
1243          * Force device mappings to be shared.
1244          */
1245         flags |= MAP_SHARED;
1246 #ifdef MAC_XXX
1247         error = mac_cdev_check_mmap(td->td_ucred, cdev, prot);
1248         if (error != 0) {
1249                 dev_relthread(cdev, ref);
1250                 return (error);
1251         }
1252 #endif
1253         /*
1254          * First, try d_mmap_single().  If that is not implemented
1255          * (returns ENODEV), fall back to using the device pager.
1256          * Note that d_mmap_single() must return a reference to the
1257          * object (it needs to bump the reference count of the object
1258          * it returns somehow).
1259          *
1260          * XXX assumes VM_PROT_* == PROT_*
1261          */
1262         error = dsw->d_mmap_single(cdev, foff, objsize, objp, (int)prot);
1263         dev_relthread(cdev, ref);
1264         if (error != ENODEV)
1265                 return (error);
1266         obj = vm_pager_allocate(OBJT_DEVICE, cdev, objsize, prot, *foff,
1267             td->td_ucred);
1268         if (obj == NULL)
1269                 return (EINVAL);
1270         *objp = obj;
1271         *flagsp = flags;
1272         return (0);
1273 }
1274
1275 /*
1276  * vm_mmap_shm()
1277  *
1278  * MPSAFE
1279  *
1280  * Helper function for vm_mmap.  Perform sanity check specific for mmap
1281  * operations on shm file descriptors.
1282  */
1283 int
1284 vm_mmap_shm(struct thread *td, vm_size_t objsize,
1285     vm_prot_t prot, vm_prot_t *maxprotp, int *flagsp,
1286     struct shmfd *shmfd, vm_ooffset_t foff, vm_object_t *objp)
1287 {
1288         int error;
1289
1290         if ((*flagsp & MAP_SHARED) != 0 &&
1291             (*maxprotp & VM_PROT_WRITE) == 0 &&
1292             (prot & PROT_WRITE) != 0)
1293                 return (EACCES);
1294 #ifdef MAC
1295         error = mac_posixshm_check_mmap(td->td_ucred, shmfd, prot, *flagsp);
1296         if (error != 0)
1297                 return (error);
1298 #endif
1299         error = shm_mmap(shmfd, objsize, foff, objp);
1300         if (error)
1301                 return (error);
1302         return (0);
1303 }
1304
1305 /*
1306  * vm_mmap()
1307  *
1308  * MPSAFE
1309  *
1310  * Internal version of mmap.  Currently used by mmap, exec, and sys5
1311  * shared memory.  Handle is either a vnode pointer or NULL for MAP_ANON.
1312  */
1313 int
1314 vm_mmap(vm_map_t map, vm_offset_t *addr, vm_size_t size, vm_prot_t prot,
1315         vm_prot_t maxprot, int flags,
1316         objtype_t handle_type, void *handle,
1317         vm_ooffset_t foff)
1318 {
1319         boolean_t fitit;
1320         vm_object_t object = NULL;
1321         int rv = KERN_SUCCESS;
1322         int docow, error;
1323         struct thread *td = curthread;
1324
1325         if (size == 0)
1326                 return (0);
1327
1328         size = round_page(size);
1329
1330         PROC_LOCK(td->td_proc);
1331         if (td->td_proc->p_vmspace->vm_map.size + size >
1332             lim_cur(td->td_proc, RLIMIT_VMEM)) {
1333                 PROC_UNLOCK(td->td_proc);
1334                 return (ENOMEM);
1335         }
1336         PROC_UNLOCK(td->td_proc);
1337
1338         /*
1339          * We currently can only deal with page aligned file offsets.
1340          * The check is here rather than in the syscall because the
1341          * kernel calls this function internally for other mmaping
1342          * operations (such as in exec) and non-aligned offsets will
1343          * cause pmap inconsistencies...so we want to be sure to
1344          * disallow this in all cases.
1345          */
1346         if (foff & PAGE_MASK)
1347                 return (EINVAL);
1348
1349         if ((flags & MAP_FIXED) == 0) {
1350                 fitit = TRUE;
1351                 *addr = round_page(*addr);
1352         } else {
1353                 if (*addr != trunc_page(*addr))
1354                         return (EINVAL);
1355                 fitit = FALSE;
1356         }
1357         /*
1358          * Lookup/allocate object.
1359          */
1360         switch (handle_type) {
1361         case OBJT_DEVICE:
1362                 error = vm_mmap_cdev(td, size, prot, &maxprot, &flags,
1363                     handle, &foff, &object);
1364                 break;
1365         case OBJT_VNODE:
1366                 error = vm_mmap_vnode(td, size, prot, &maxprot, &flags,
1367                     handle, &foff, &object);
1368                 break;
1369         case OBJT_SWAP:
1370                 error = vm_mmap_shm(td, size, prot, &maxprot, &flags,
1371                     handle, foff, &object);
1372                 break;
1373         case OBJT_DEFAULT:
1374                 if (handle == NULL) {
1375                         error = 0;
1376                         break;
1377                 }
1378                 /* FALLTHROUGH */
1379         default:
1380                 error = EINVAL;
1381                 break;
1382         }
1383         if (error)
1384                 return (error);
1385         if (flags & MAP_ANON) {
1386                 object = NULL;
1387                 docow = 0;
1388                 /*
1389                  * Unnamed anonymous regions always start at 0.
1390                  */
1391                 if (handle == 0)
1392                         foff = 0;
1393         } else if (flags & MAP_PREFAULT_READ)
1394                 docow = MAP_PREFAULT;
1395         else
1396                 docow = MAP_PREFAULT_PARTIAL;
1397
1398         if ((flags & (MAP_ANON|MAP_SHARED)) == 0)
1399                 docow |= MAP_COPY_ON_WRITE;
1400         if (flags & MAP_NOSYNC)
1401                 docow |= MAP_DISABLE_SYNCER;
1402         if (flags & MAP_NOCORE)
1403                 docow |= MAP_DISABLE_COREDUMP;
1404
1405         if (flags & MAP_STACK)
1406                 rv = vm_map_stack(map, *addr, size, prot, maxprot,
1407                     docow | MAP_STACK_GROWS_DOWN);
1408         else if (fitit)
1409                 rv = vm_map_find(map, object, foff, addr, size,
1410                     object != NULL && object->type == OBJT_DEVICE ?
1411                     VMFS_ALIGNED_SPACE : VMFS_ANY_SPACE, prot, maxprot, docow);
1412         else
1413                 rv = vm_map_fixed(map, object, foff, *addr, size,
1414                                  prot, maxprot, docow);
1415
1416         if (rv != KERN_SUCCESS) {
1417                 /*
1418                  * Lose the object reference. Will destroy the
1419                  * object if it's an unnamed anonymous mapping
1420                  * or named anonymous without other references.
1421                  */
1422                 vm_object_deallocate(object);
1423         } else if (flags & MAP_SHARED) {
1424                 /*
1425                  * Shared memory is also shared with children.
1426                  */
1427                 rv = vm_map_inherit(map, *addr, *addr + size, VM_INHERIT_SHARE);
1428                 if (rv != KERN_SUCCESS)
1429                         (void) vm_map_remove(map, *addr, *addr + size);
1430         }
1431
1432         /*
1433          * If the process has requested that all future mappings
1434          * be wired, then heed this.
1435          */
1436         if ((rv == KERN_SUCCESS) && (map->flags & MAP_WIREFUTURE))
1437                 vm_map_wire(map, *addr, *addr + size,
1438                     VM_MAP_WIRE_USER | ((flags & MAP_STACK) ?
1439                     VM_MAP_WIRE_HOLESOK : VM_MAP_WIRE_NOHOLES));
1440
1441         return (vm_mmap_to_errno(rv));
1442 }
1443
1444 int
1445 vm_mmap_to_errno(int rv)
1446 {
1447
1448         switch (rv) {
1449         case KERN_SUCCESS:
1450                 return (0);
1451         case KERN_INVALID_ADDRESS:
1452         case KERN_NO_SPACE:
1453                 return (ENOMEM);
1454         case KERN_PROTECTION_FAILURE:
1455                 return (EACCES);
1456         default:
1457                 return (EINVAL);
1458         }
1459 }