LCOV - code coverage report
Current view: directory - src/shared/platform/win - xlate_system_error.c (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 25 5 20.0 %
Date: 2014-09-25 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 be
       4                 :  * found in the LICENSE file.
       5                 :  */
       6                 : 
       7                 : /*
       8                 :  * NaCl Service Runtime.  Windows error code to errno translation.
       9                 :  */
      10                 : 
      11                 : #include <errno.h>
      12                 : #include <WinError.h>
      13                 : 
      14                 : #include "native_client/src/shared/platform/nacl_log.h"
      15                 : #include "native_client/src/shared/platform/win/xlate_system_error.h"
      16                 : 
      17                 : #include "native_client/src/trusted/service_runtime/include/sys/errno.h"
      18                 : 
      19                 : /*
      20                 :  * we attempt to map error codes that are relevant for the following
      21                 :  * system calls:
      22                 :  *
      23                 :  * - CreateFile
      24                 :  * - CreateFileMapping
      25                 :  * - MapViewOfFileEx
      26                 :  * - UnmapViewOfFile
      27                 :  * - ReadFile
      28                 :  * - WriteFile
      29                 :  * - CloseHandle
      30                 :  *
      31                 :  * because the msdn pages do not specify what error codes might be
      32                 :  * returned by any of the system calls, the preimage set is likely to
      33                 :  * be incomplete.
      34                 :  */
      35                 : 
      36               3 : int NaClXlateSystemError(int sys_error_code) {
      37                 : #define E(c, err) \
      38                 :     case c: do { \
      39                 :       NaClLog(2, "NaClXlateSystemError: windows error code %d (%s) -> %d\n", \
      40                 :               c, #c, err); \
      41                 :       return err; } while (0)
      42                 : 
      43               3 :   switch (sys_error_code) {
      44               0 :     E(ERROR_SUCCESS, 0);
      45               0 :     E(ERROR_FILE_NOT_FOUND, NACL_ABI_ENOENT);
      46               0 :     E(ERROR_PATH_NOT_FOUND, NACL_ABI_ENOENT);
      47               0 :     E(ERROR_TOO_MANY_OPEN_FILES, NACL_ABI_EMFILE);
      48                 :       /*
      49                 :        * TODO(bsy) distinguishability?
      50                 :        *
      51                 :        * note EPERM might be reasonable; that is typically used for a
      52                 :        * minor request parmeter asking for something that is not
      53                 :        * allowed, e.g. mmap with PROT_EXEC but filesystem is mounted
      54                 :        * no-exec, rather than simple access denial.
      55                 :        */
      56               1 :     E(ERROR_ACCESS_DENIED, NACL_ABI_EACCES);
      57               0 :     E(ERROR_INVALID_HANDLE, NACL_ABI_EBADF);
      58               0 :     E(ERROR_NOT_ENOUGH_MEMORY, NACL_ABI_ENOMEM);
      59               0 :     E(ERROR_OUTOFMEMORY, NACL_ABI_ENOMEM);
      60               0 :     E(ERROR_INVALID_DRIVE, NACL_ABI_EACCES);
      61               0 :     E(ERROR_NOT_SAME_DEVICE, NACL_ABI_EXDEV);
      62               0 :     E(ERROR_NO_MORE_FILES, NACL_ABI_ENFILE);
      63               0 :     E(ERROR_WRITE_PROTECT, NACL_ABI_EBADF);
      64               0 :     E(ERROR_OPEN_FAILED, NACL_ABI_EIO);
      65               0 :     E(ERROR_INVALID_USER_BUFFER, NACL_ABI_EFAULT);
      66               0 :     E(ERROR_NOT_ENOUGH_QUOTA, NACL_ABI_EDQUOT);
      67               0 :     E(ERROR_INVALID_PARAMETER, NACL_ABI_EINVAL);
      68               0 :     E(ERROR_INVALID_ADDRESS, NACL_ABI_EFAULT);
      69               0 :     E(ERROR_PIPE_LISTENING, NACL_ABI_EAGAIN);
      70               2 :     E(ERROR_BROKEN_PIPE, NACL_ABI_EPIPE);
      71               0 :     E(ERROR_NO_DATA, NACL_ABI_EPIPE);
      72                 :     default:
      73                 :       NaClLog(LOG_ERROR,
      74                 :               ("NaClXlateSystemError: UNEXPECTED ERROR %d (0x%x),"
      75                 :                " returning EINVAL\n"),
      76               0 :               sys_error_code, sys_error_code);
      77               0 :       return NACL_ABI_EINVAL;  /* as a default? */
      78                 :   }
      79               3 : }

Generated by: LCOV version 1.7