LCOV - code coverage report
Current view: directory - src/trusted/service_runtime - nacl_desc_effector_ldr.c (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 13 6 46.2 %
Date: 2012-02-16 Functions: 0 0 -

       1                 : /*
       2                 :  * Copyright 2008 The Native Client Authors. All rights reserved.
       3                 :  * Use of this source code is governed by a BSD-style license that can
       4                 :  * be found in the LICENSE file.
       5                 :  */
       6                 : 
       7                 : /* @file
       8                 :  *
       9                 :  * Implementation of service runtime effector subclass used for all
      10                 :  * application threads.
      11                 :  */
      12                 : #include "native_client/src/shared/platform/nacl_host_desc.h"
      13                 : 
      14                 : #include "native_client/src/trusted/service_runtime/nacl_desc_effector_ldr.h"
      15                 : 
      16                 : #include "native_client/src/trusted/service_runtime/include/bits/mman.h"
      17                 : #include "native_client/src/trusted/service_runtime/nacl_memory_object.h"
      18                 : #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h"
      19                 : 
      20                 : 
      21                 : static struct NaClDescEffectorVtbl const NaClDescEffectorLdrVtbl;  /* fwd */
      22                 : 
      23                 : int NaClDescEffectorLdrCtor(struct NaClDescEffectorLdr *self,
      24              19 :                             struct NaClApp             *nap) {
      25              19 :   self->base.vtbl = &NaClDescEffectorLdrVtbl;
      26              19 :   self->nap = nap;
      27              19 :   return 1;
      28                 : }
      29                 : 
      30               0 : static void NaClDescEffLdrDtor(struct NaClDescEffector *vself) {
      31               0 :   struct NaClDescEffectorLdr *self = (struct NaClDescEffectorLdr *) vself;
      32                 : 
      33               0 :   self->nap = NULL;
      34                 :   /* we did not take ownership of nap */
      35               0 :   vself->vtbl = (struct NaClDescEffectorVtbl const *) NULL;
      36               0 : }
      37                 : 
      38                 : #if NACL_WINDOWS
      39                 : static int NaClDescEffLdrUnmapMemory(struct NaClDescEffector  *vself,
      40                 :                                      uintptr_t                sysaddr,
      41                 :                                      size_t                   nbytes) {
      42                 :   struct NaClDescEffectorLdr  *self = (struct NaClDescEffectorLdr *) vself;
      43                 :   uintptr_t                   addr;
      44                 :   uintptr_t                   endaddr;
      45                 :   uintptr_t                   usraddr;
      46                 :   struct NaClVmmapEntry const *map_region;
      47                 : 
      48                 :   for (addr = sysaddr, endaddr = sysaddr + nbytes;
      49                 :        addr < endaddr;
      50                 :        addr += NACL_MAP_PAGESIZE) {
      51                 :     usraddr = NaClSysToUser(self->nap, addr);
      52                 : 
      53                 :     map_region = NaClVmmapFindPage(&self->nap->mem_map,
      54                 :                                    usraddr >> NACL_PAGESHIFT);
      55                 :     if (NULL == map_region || NULL == map_region->nmop) {
      56                 :       /*
      57                 :        * No memory in address space, and we have only MEM_RESERVE'd
      58                 :        * the address space; or memory is in address space, but not
      59                 :        * backed by a file.
      60                 :        */
      61                 :       if (0 == VirtualFree((void *) addr, 0, MEM_RELEASE)) {
      62                 :         NaClLog(LOG_FATAL,
      63                 :                 ("NaClMMap: VirtualFree at user addr 0x%08"NACL_PRIxPTR
      64                 :                  " (sys 0x%08"NACL_PRIxPTR") failed: windows error %d\n"),
      65                 :                 usraddr,
      66                 :                 addr,
      67                 :                 GetLastError());
      68                 :       }
      69                 :     } else {
      70                 :       struct NaClDesc *backing_ndp;
      71                 :       int             retval;
      72                 : 
      73                 :       backing_ndp = map_region->nmop->ndp;
      74                 : 
      75                 :       retval = (*((struct NaClDescVtbl const *) backing_ndp->base.vtbl)->
      76                 :                 UnmapUnsafe)(backing_ndp,
      77                 :                              vself,
      78                 :                              (void *) addr,
      79                 :                              NACL_MAP_PAGESIZE);
      80                 :       if (0 != retval) {
      81                 :         NaClLog(LOG_FATAL,
      82                 :                 ("NaClMMap: UnmapUnsafe failed at user addr 0x%08"NACL_PRIxPTR
      83                 :                  " (sys 0x%08"NACL_PRIxPTR") failed: syscall return %d\n"),
      84                 :                 addr,
      85                 :                 NaClUserToSys(self->nap, addr),
      86                 :                 retval);
      87                 :       }
      88                 :     }
      89                 :   }
      90                 : 
      91                 :   return 0;
      92                 : }
      93                 : 
      94                 : #else  /* NACL_WINDOWS */
      95                 : 
      96                 : static int NaClDescEffLdrUnmapMemory(struct NaClDescEffector  *vself,
      97                 :                                      uintptr_t                sysaddr,
      98               3 :                                      size_t                   nbytes) {
      99                 :   UNREFERENCED_PARAMETER(vself);
     100                 :   UNREFERENCED_PARAMETER(sysaddr);
     101                 :   UNREFERENCED_PARAMETER(nbytes);
     102               3 :   return 0;
     103                 : }
     104                 : #endif  /* NACL_WINDOWS */
     105                 : 
     106                 : static uintptr_t NaClDescEffLdrMapAnonMem(struct NaClDescEffector *vself,
     107                 :                                           uintptr_t               sysaddr,
     108                 :                                           size_t                  nbytes,
     109               0 :                                           int                     prot) {
     110                 :   UNREFERENCED_PARAMETER(vself);
     111               0 :   return NaClHostDescMap((struct NaClHostDesc *) NULL,
     112                 :                          (void *) sysaddr,
     113                 :                          nbytes,
     114                 :                          prot,
     115                 :                          (NACL_ABI_MAP_PRIVATE |
     116                 :                           NACL_ABI_MAP_ANONYMOUS |
     117                 :                           NACL_ABI_MAP_FIXED),
     118                 :                          (off_t) 0);
     119                 : }
     120                 : 
     121                 : static struct NaClDescEffectorVtbl const NaClDescEffectorLdrVtbl = {
     122                 :   NaClDescEffLdrDtor,
     123                 :   NaClDescEffLdrUnmapMemory,
     124                 :   NaClDescEffLdrMapAnonMem,
     125                 : };

Generated by: LCOV version 1.7