LCOV - code coverage report
Current view: top level - ports/unix - mpconfigport.h (source / functions) Hit Total Coverage
Test: unix_coverage_v1.24.0-7-g548babf8a.info Lines: 4 4 100.0 %
Date: 2024-10-30 09:06:48 Functions: 0 0 -
Branches: 0 0 -

           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, 2014 Damien P. George
       7                 :            :  *
       8                 :            :  * Permission is hereby granted, free of charge, to any person obtaining a copy
       9                 :            :  * of this software and associated documentation files (the "Software"), to deal
      10                 :            :  * in the Software without restriction, including without limitation the rights
      11                 :            :  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      12                 :            :  * copies of the Software, and to permit persons to whom the Software is
      13                 :            :  * furnished to do so, subject to the following conditions:
      14                 :            :  *
      15                 :            :  * The above copyright notice and this permission notice shall be included in
      16                 :            :  * all copies or substantial portions of the Software.
      17                 :            :  *
      18                 :            :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      19                 :            :  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      20                 :            :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      21                 :            :  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      22                 :            :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      23                 :            :  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      24                 :            :  * THE SOFTWARE.
      25                 :            :  */
      26                 :            : 
      27                 :            : // Options to control how MicroPython is built for this port, overriding
      28                 :            : // defaults in py/mpconfig.h. This file is mostly about configuring the
      29                 :            : // features to work on Unix-like systems, see mpconfigvariant.h (and
      30                 :            : // mpconfigvariant_common.h) for feature enabling.
      31                 :            : 
      32                 :            : // For size_t and ssize_t
      33                 :            : #include <unistd.h>
      34                 :            : 
      35                 :            : // Variant-specific definitions.
      36                 :            : #include "mpconfigvariant.h"
      37                 :            : 
      38                 :            : #ifndef MICROPY_CONFIG_ROM_LEVEL
      39                 :            : #define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES)
      40                 :            : #endif
      41                 :            : 
      42                 :            : #ifndef MICROPY_PY_SYS_PLATFORM
      43                 :            : #if defined(__APPLE__) && defined(__MACH__)
      44                 :            :     #define MICROPY_PY_SYS_PLATFORM  "darwin"
      45                 :            : #else
      46                 :            :     #define MICROPY_PY_SYS_PLATFORM  "linux"
      47                 :            : #endif
      48                 :            : #endif
      49                 :            : 
      50                 :            : #ifndef MICROPY_PY_SYS_PATH_DEFAULT
      51                 :            : #define MICROPY_PY_SYS_PATH_DEFAULT ".frozen:~/.micropython/lib:/usr/lib/micropython"
      52                 :            : #endif
      53                 :            : 
      54                 :            : #define MP_STATE_PORT MP_STATE_VM
      55                 :            : 
      56                 :            : // Configure which emitter to use for this target.
      57                 :            : #if !defined(MICROPY_EMIT_X64) && defined(__x86_64__)
      58                 :            :     #define MICROPY_EMIT_X64        (1)
      59                 :            : #endif
      60                 :            : #if !defined(MICROPY_EMIT_X86) && defined(__i386__)
      61                 :            :     #define MICROPY_EMIT_X86        (1)
      62                 :            : #endif
      63                 :            : #if !defined(MICROPY_EMIT_THUMB) && defined(__thumb2__)
      64                 :            :     #define MICROPY_EMIT_THUMB      (1)
      65                 :            :     #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p) | 1))
      66                 :            : #endif
      67                 :            : // Some compilers define __thumb2__ and __arm__ at the same time, let
      68                 :            : // autodetected thumb2 emitter have priority.
      69                 :            : #if !defined(MICROPY_EMIT_ARM) && defined(__arm__) && !defined(__thumb2__)
      70                 :            :     #define MICROPY_EMIT_ARM        (1)
      71                 :            : #endif
      72                 :            : 
      73                 :            : // Type definitions for the specific machine based on the word size.
      74                 :            : #ifndef MICROPY_OBJ_REPR
      75                 :            : #ifdef __LP64__
      76                 :            : typedef long mp_int_t; // must be pointer size
      77                 :            : typedef unsigned long mp_uint_t; // must be pointer size
      78                 :            : #else
      79                 :            : // These are definitions for machines where sizeof(int) == sizeof(void*),
      80                 :            : // regardless of actual size.
      81                 :            : typedef int mp_int_t; // must be pointer size
      82                 :            : typedef unsigned int mp_uint_t; // must be pointer size
      83                 :            : #endif
      84                 :            : #else
      85                 :            : // Assume that if we already defined the obj repr then we also defined types.
      86                 :            : #endif
      87                 :            : 
      88                 :            : // Cannot include <sys/types.h>, as it may lead to symbol name clashes
      89                 :            : #if _FILE_OFFSET_BITS == 64 && !defined(__LP64__)
      90                 :            : typedef long long mp_off_t;
      91                 :            : #else
      92                 :            : typedef long mp_off_t;
      93                 :            : #endif
      94                 :            : 
      95                 :            : // We need to provide a declaration/definition of alloca()
      96                 :            : // unless support for it is disabled.
      97                 :            : #if !defined(MICROPY_NO_ALLOCA) || MICROPY_NO_ALLOCA == 0
      98                 :            : #if defined(__FreeBSD__) || defined(__NetBSD__)
      99                 :            : #include <stdlib.h>
     100                 :            : #else
     101                 :            : #include <alloca.h>
     102                 :            : #endif
     103                 :            : #endif
     104                 :            : 
     105                 :            : // Always enable GC.
     106                 :            : #define MICROPY_ENABLE_GC           (1)
     107                 :            : 
     108                 :            : #if !(defined(MICROPY_GCREGS_SETJMP) || defined(__x86_64__) || defined(__i386__) || defined(__thumb2__) || defined(__thumb__) || defined(__arm__) || (defined(__riscv) && (__riscv_xlen == 64)))
     109                 :            : // Fall back to setjmp() implementation for discovery of GC pointers in registers.
     110                 :            : #define MICROPY_GCREGS_SETJMP (1)
     111                 :            : #endif
     112                 :            : 
     113                 :            : // Enable the VFS, and enable the posix "filesystem".
     114                 :            : #define MICROPY_ENABLE_FINALISER    (1)
     115                 :            : #define MICROPY_VFS                 (1)
     116                 :            : #define MICROPY_READER_VFS          (1)
     117                 :            : #define MICROPY_HELPER_LEXER_UNIX   (1)
     118                 :            : #define MICROPY_VFS_POSIX           (1)
     119                 :            : #define MICROPY_READER_POSIX        (1)
     120                 :            : #if MICROPY_PY_FFI || MICROPY_BLUETOOTH_BTSTACK
     121                 :            : #define MICROPY_TRACKED_ALLOC       (1)
     122                 :            : #endif
     123                 :            : 
     124                 :            : // VFS stat functions should return time values relative to 1970/1/1
     125                 :            : #define MICROPY_EPOCH_IS_1970       (1)
     126                 :            : 
     127                 :            : // Assume that select() call, interrupted with a signal, and erroring
     128                 :            : // with EINTR, updates remaining timeout value.
     129                 :            : #define MICROPY_SELECT_REMAINING_TIME (1)
     130                 :            : 
     131                 :            : // Disable stackless by default.
     132                 :            : #ifndef MICROPY_STACKLESS
     133                 :            : #define MICROPY_STACKLESS           (0)
     134                 :            : #define MICROPY_STACKLESS_STRICT    (0)
     135                 :            : #endif
     136                 :            : 
     137                 :            : // Implementation of the machine module.
     138                 :            : #define MICROPY_PY_MACHINE_INCLUDEFILE "ports/unix/modmachine.c"
     139                 :            : 
     140                 :            : // Unix-specific configuration of machine.mem*.
     141                 :            : #define MICROPY_MACHINE_MEM_GET_READ_ADDR   mod_machine_mem_get_addr
     142                 :            : #define MICROPY_MACHINE_MEM_GET_WRITE_ADDR  mod_machine_mem_get_addr
     143                 :            : 
     144                 :            : #define MICROPY_FATFS_ENABLE_LFN       (1)
     145                 :            : #define MICROPY_FATFS_RPATH            (2)
     146                 :            : #define MICROPY_FATFS_MAX_SS           (4096)
     147                 :            : #define MICROPY_FATFS_LFN_CODE_PAGE    437 /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
     148                 :            : 
     149                 :            : #define MICROPY_ALLOC_PATH_MAX      (PATH_MAX)
     150                 :            : 
     151                 :            : // Ensure builtinimport.c works with -m.
     152                 :            : #define MICROPY_MODULE_OVERRIDE_MAIN_IMPORT (1)
     153                 :            : 
     154                 :            : // Don't default sys.argv and sys.path because we do that in main.
     155                 :            : #define MICROPY_PY_SYS_PATH_ARGV_DEFAULTS (0)
     156                 :            : 
     157                 :            : // Enable sys.executable.
     158                 :            : #define MICROPY_PY_SYS_EXECUTABLE (1)
     159                 :            : 
     160                 :            : #define MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT (SOMAXCONN < 128 ? SOMAXCONN : 128)
     161                 :            : 
     162                 :            : // Bare-metal ports don't have stderr. Printing debug to stderr may give tests
     163                 :            : // which check stdout a chance to pass, etc.
     164                 :            : extern const struct _mp_print_t mp_stderr_print;
     165                 :            : #define MICROPY_DEBUG_PRINTER (&mp_stderr_print)
     166                 :            : #define MICROPY_ERROR_PRINTER (&mp_stderr_print)
     167                 :            : 
     168                 :            : // For the native emitter configure how to mark a region as executable.
     169                 :            : void mp_unix_alloc_exec(size_t min_size, void **ptr, size_t *size);
     170                 :            : void mp_unix_free_exec(void *ptr, size_t size);
     171                 :            : #define MP_PLAT_ALLOC_EXEC(min_size, ptr, size) mp_unix_alloc_exec(min_size, ptr, size)
     172                 :            : #define MP_PLAT_FREE_EXEC(ptr, size) mp_unix_free_exec(ptr, size)
     173                 :            : 
     174                 :            : // If enabled, configure how to seed random on init.
     175                 :            : #ifdef MICROPY_PY_RANDOM_SEED_INIT_FUNC
     176                 :            : #include <stddef.h>
     177                 :            : void mp_hal_get_random(size_t n, void *buf);
     178                 :         16 : static inline unsigned long mp_random_seed_init(void) {
     179                 :         16 :     unsigned long r;
     180                 :         16 :     mp_hal_get_random(sizeof(r), &r);
     181                 :         16 :     return r;
     182                 :            : }
     183                 :            : #endif
     184                 :            : 
     185                 :            : #ifdef __linux__
     186                 :            : // Can access physical memory using /dev/mem
     187                 :            : #define MICROPY_PLAT_DEV_MEM  (1)
     188                 :            : #endif
     189                 :            : 
     190                 :            : #ifdef __ANDROID__
     191                 :            : #include <android/api-level.h>
     192                 :            : #if __ANDROID_API__ < 4
     193                 :            : // Bionic libc in Android 1.5 misses these 2 functions
     194                 :            : #define MP_NEED_LOG2 (1)
     195                 :            : #define nan(x) NAN
     196                 :            : #endif
     197                 :            : #endif
     198                 :            : 
     199                 :            : // From "man readdir": "Under glibc, programs can check for the availability
     200                 :            : // of the fields [in struct dirent] not defined in POSIX.1 by testing whether
     201                 :            : // the macros [...], _DIRENT_HAVE_D_TYPE are defined."
     202                 :            : // Other libc's don't define it, but proactively assume that dirent->d_type
     203                 :            : // is available on a modern *nix system.
     204                 :            : #ifndef _DIRENT_HAVE_D_TYPE
     205                 :            : #define _DIRENT_HAVE_D_TYPE (1)
     206                 :            : #endif
     207                 :            : // This macro is not provided by glibc but we need it so ports that don't have
     208                 :            : // dirent->d_ino can disable the use of this field.
     209                 :            : #ifndef _DIRENT_HAVE_D_INO
     210                 :            : #define _DIRENT_HAVE_D_INO (1)
     211                 :            : #endif
     212                 :            : 
     213                 :            : #ifndef __APPLE__
     214                 :            : // For debugging purposes, make printf() available to any source file.
     215                 :            : #include <stdio.h>
     216                 :            : #endif
     217                 :            : 
     218                 :            : // Configure the implementation of machine.idle().
     219                 :            : #include <sched.h>
     220                 :            : #define MICROPY_UNIX_MACHINE_IDLE sched_yield();
     221                 :            : 
     222                 :            : #ifndef MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
     223                 :            : #define MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE (1)
     224                 :            : #endif
     225                 :            : 
     226                 :            : #ifndef MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS
     227                 :            : #define MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS (MICROPY_BLUETOOTH_NIMBLE)
     228                 :            : #endif

Generated by: LCOV version 1.15-5-g462f71d