LCOV - code coverage report
Current view: top level - ports/unix - modmachine.c (source / functions) Hit Total Coverage
Test: unix_coverage_v1.22.0-343-g7b050b366.info Lines: 4 21 19.0 %
Date: 2024-04-25 17:00:48 Functions: 1 2 50.0 %
Branches: 1 8 12.5 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * This file is part of the MicroPython project, http://micropython.org/
       3                 :            :  *
       4                 :            :  * The MIT License (MIT)
       5                 :            :  *
       6                 :            :  * Copyright (c) 2013-2023 Damien P. George
       7                 :            :  * Copyright (c) 2015 Paul Sokolovsky
       8                 :            :  *
       9                 :            :  * Permission is hereby granted, free of charge, to any person obtaining a copy
      10                 :            :  * of this software and associated documentation files (the "Software"), to deal
      11                 :            :  * in the Software without restriction, including without limitation the rights
      12                 :            :  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      13                 :            :  * copies of the Software, and to permit persons to whom the Software is
      14                 :            :  * furnished to do so, subject to the following conditions:
      15                 :            :  *
      16                 :            :  * The above copyright notice and this permission notice shall be included in
      17                 :            :  * all copies or substantial portions of the Software.
      18                 :            :  *
      19                 :            :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      20                 :            :  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      21                 :            :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      22                 :            :  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      23                 :            :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      24                 :            :  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      25                 :            :  * THE SOFTWARE.
      26                 :            :  */
      27                 :            : 
      28                 :            : // This file is never compiled standalone, it's included directly from
      29                 :            : // extmod/modmachine.c via MICROPY_PY_MACHINE_INCLUDEFILE.
      30                 :            : 
      31                 :            : #if MICROPY_PLAT_DEV_MEM
      32                 :            : #include <errno.h>
      33                 :            : #include <fcntl.h>
      34                 :            : #include <sys/mman.h>
      35                 :            : #define MICROPY_PAGE_SIZE 4096
      36                 :            : #define MICROPY_PAGE_MASK (MICROPY_PAGE_SIZE - 1)
      37                 :            : #endif
      38                 :            : 
      39                 :            : // This variable is needed for machine.soft_reset(), but the variable is otherwise unused.
      40                 :            : int pyexec_system_exit = 0;
      41                 :            : 
      42                 :         12 : uintptr_t mod_machine_mem_get_addr(mp_obj_t addr_o, uint align) {
      43                 :         12 :     uintptr_t addr = mp_obj_get_int_truncated(addr_o);
      44         [ +  - ]:          4 :     if ((addr & (align - 1)) != 0) {
      45                 :          4 :         mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("address %08x is not aligned to %d bytes"), addr, align);
      46                 :            :     }
      47                 :            :     #if MICROPY_PLAT_DEV_MEM
      48                 :            :     {
      49                 :            :         // Not thread-safe
      50                 :          0 :         static int fd;
      51                 :          0 :         static uintptr_t last_base = (uintptr_t)-1;
      52                 :          0 :         static uintptr_t map_page;
      53         [ #  # ]:          0 :         if (!fd) {
      54                 :          0 :             int _fd = open("/dev/mem", O_RDWR | O_SYNC);
      55         [ #  # ]:          0 :             if (_fd == -1) {
      56                 :          0 :                 mp_raise_OSError(errno);
      57                 :            :             }
      58                 :          0 :             fd = _fd;
      59                 :            :         }
      60                 :            : 
      61                 :          0 :         uintptr_t cur_base = addr & ~MICROPY_PAGE_MASK;
      62         [ #  # ]:          0 :         if (cur_base != last_base) {
      63                 :          0 :             map_page = (uintptr_t)mmap(NULL, MICROPY_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, cur_base);
      64                 :          0 :             last_base = cur_base;
      65                 :            :         }
      66                 :          0 :         addr = map_page + (addr & MICROPY_PAGE_MASK);
      67                 :            :     }
      68                 :            :     #endif
      69                 :            : 
      70                 :          0 :     return addr;
      71                 :            : }
      72                 :            : 
      73                 :          0 : static void mp_machine_idle(void) {
      74                 :            :     #ifdef MICROPY_UNIX_MACHINE_IDLE
      75                 :          0 :     MICROPY_UNIX_MACHINE_IDLE
      76                 :            :     #else
      77                 :            :     // Do nothing.
      78                 :            :     #endif
      79                 :          0 : }

Generated by: LCOV version 1.15-5-g462f71d