LCOV - code coverage report
Current view: top level - ports/unix - mpconfigport.h (source / functions) Hit Total Coverage
Test: unix_coverage_v1.22.0-344-ge60e8079a.info Lines: 4 4 100.0 %
Date: 2024-04-26 14:58:11 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__))
     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                 :            : #ifndef MICROPY_TRACKED_ALLOC
     121                 :            : #define MICROPY_TRACKED_ALLOC       (MICROPY_BLUETOOTH_BTSTACK)
     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                 :            : void mp_unix_mark_exec(void);
     172                 :            : #define MP_PLAT_ALLOC_EXEC(min_size, ptr, size) mp_unix_alloc_exec(min_size, ptr, size)
     173                 :            : #define MP_PLAT_FREE_EXEC(ptr, size) mp_unix_free_exec(ptr, size)
     174                 :            : #ifndef MICROPY_FORCE_PLAT_ALLOC_EXEC
     175                 :            : // Use MP_PLAT_ALLOC_EXEC for any executable memory allocation, including for FFI
     176                 :            : // (overriding libffi own implementation)
     177                 :            : #define MICROPY_FORCE_PLAT_ALLOC_EXEC (1)
     178                 :            : #endif
     179                 :            : 
     180                 :            : // If enabled, configure how to seed random on init.
     181                 :            : #ifdef MICROPY_PY_RANDOM_SEED_INIT_FUNC
     182                 :            : #include <stddef.h>
     183                 :            : void mp_hal_get_random(size_t n, void *buf);
     184                 :         16 : static inline unsigned long mp_random_seed_init(void) {
     185                 :         16 :     unsigned long r;
     186                 :         16 :     mp_hal_get_random(sizeof(r), &r);
     187                 :         16 :     return r;
     188                 :            : }
     189                 :            : #endif
     190                 :            : 
     191                 :            : #ifdef __linux__
     192                 :            : // Can access physical memory using /dev/mem
     193                 :            : #define MICROPY_PLAT_DEV_MEM  (1)
     194                 :            : #endif
     195                 :            : 
     196                 :            : #ifdef __ANDROID__
     197                 :            : #include <android/api-level.h>
     198                 :            : #if __ANDROID_API__ < 4
     199                 :            : // Bionic libc in Android 1.5 misses these 2 functions
     200                 :            : #define MP_NEED_LOG2 (1)
     201                 :            : #define nan(x) NAN
     202                 :            : #endif
     203                 :            : #endif
     204                 :            : 
     205                 :            : // From "man readdir": "Under glibc, programs can check for the availability
     206                 :            : // of the fields [in struct dirent] not defined in POSIX.1 by testing whether
     207                 :            : // the macros [...], _DIRENT_HAVE_D_TYPE are defined."
     208                 :            : // Other libc's don't define it, but proactively assume that dirent->d_type
     209                 :            : // is available on a modern *nix system.
     210                 :            : #ifndef _DIRENT_HAVE_D_TYPE
     211                 :            : #define _DIRENT_HAVE_D_TYPE (1)
     212                 :            : #endif
     213                 :            : // This macro is not provided by glibc but we need it so ports that don't have
     214                 :            : // dirent->d_ino can disable the use of this field.
     215                 :            : #ifndef _DIRENT_HAVE_D_INO
     216                 :            : #define _DIRENT_HAVE_D_INO (1)
     217                 :            : #endif
     218                 :            : 
     219                 :            : #ifndef __APPLE__
     220                 :            : // For debugging purposes, make printf() available to any source file.
     221                 :            : #include <stdio.h>
     222                 :            : #endif
     223                 :            : 
     224                 :            : // Configure the implementation of machine.idle().
     225                 :            : #include <sched.h>
     226                 :            : #define MICROPY_UNIX_MACHINE_IDLE sched_yield();
     227                 :            : 
     228                 :            : #ifndef MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
     229                 :            : #define MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE (1)
     230                 :            : #endif
     231                 :            : 
     232                 :            : #ifndef MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS
     233                 :            : #define MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS (MICROPY_BLUETOOTH_NIMBLE)
     234                 :            : #endif

Generated by: LCOV version 1.15-5-g462f71d