From 0536953ded2596414510353e505bcff64f56083a Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 2 May 2020 22:30:58 +0800 Subject: [PATCH] Kernel module should prefer functions with nx/kmm prefix Signed-off-by: Xiang Xiao --- arch/arm/src/cxd56xx/cxd56_dmac.c | 2 +- arch/arm/src/cxd56xx/cxd56_gnss.c | 59 +++++---- arch/arm/src/cxd56xx/cxd56_icc.c | 3 +- arch/arm/src/cxd56xx/cxd56_scu.c | 5 +- arch/arm/src/cxd56xx/cxd56_usbdev.c | 3 +- arch/arm/src/lc823450/lc823450_ipl2.c | 49 -------- arch/arm/src/samv7/sam_eefc.c | 1 - arch/arm/src/samv7/sam_ssc.c | 2 +- arch/arm/src/xmc4/xmc4_spi.c | 2 +- arch/x86_64/include/intel64/irq.h | 1 - arch/xtensa/src/esp32/esp32_wifi_adapter.c | 116 ++++++++++-------- binfmt/builtin.c | 13 +- binfmt/libelf/libelf_init.c | 11 +- binfmt/libelf/libelf_read.c | 7 +- binfmt/libelf/libelf_uninit.c | 2 +- binfmt/libnxflat/libnxflat_init.c | 4 +- binfmt/libnxflat/libnxflat_read.c | 7 +- binfmt/libnxflat/libnxflat_uninit.c | 2 +- .../arm/cxd56xx/spresense/src/cxd56_sdcard.c | 4 +- .../arm/lpc31xx/ea3131/src/lpc31_fillpage.c | 2 +- .../arm/lpc31xx/ea3152/src/lpc31_fillpage.c | 2 +- .../stm32/nucleo-f302r8/src/stm32_highpri.c | 4 +- .../stm32/nucleo-f334r8/src/stm32_highpri.c | 4 +- boards/arm/stm32/photon/src/stm32_rgbled.c | 2 +- .../stm32f429i-disco/src/stm32_highpri.c | 4 +- boards/z80/ez80/z20x/src/w25_main.c | 2 +- drivers/analog/ads7828.c | 1 - drivers/lcd/tda19988.c | 2 +- drivers/loop/losetup.c | 6 +- drivers/modem/altair/altmdm_spi.c | 2 +- drivers/modem/altair/altmdm_sys.c | 10 +- drivers/mtd/filemtd.c | 4 +- drivers/mtd/smart.c | 4 +- drivers/power/bq769x0.c | 2 +- drivers/serial/serial_dma.c | 2 +- drivers/serial/serial_io.c | 4 +- .../wireless/ieee802154/mrf24j40/mrf24j40.c | 2 - fs/driver/fs_mtdproxy.c | 4 +- fs/hostfs/hostfs_rpmsg_server.c | 8 +- fs/mmap/fs_mmap.c | 14 +-- fs/mmap/fs_rammap.c | 16 ++- fs/vfs/fs_select.c | 4 +- graphics/nxmu/nxmu_server.c | 28 ++--- include/nuttx/power/battery_monitor.h | 3 +- include/nuttx/sensors/mpu60x0.h | 2 +- include/nuttx/usb/usbdev.h | 4 +- net/local/local_fifo.c | 2 +- net/netlink/netlink_conn.c | 4 +- net/route/net_fileroute.c | 11 +- sched/task/task_posixspawn.c | 3 +- sched/task/task_spawn.c | 3 +- sched/task/task_spawnparms.c | 11 +- 52 files changed, 207 insertions(+), 262 deletions(-) diff --git a/arch/arm/src/cxd56xx/cxd56_dmac.c b/arch/arm/src/cxd56xx/cxd56_dmac.c index a38efc96d38..38128072b0c 100644 --- a/arch/arm/src/cxd56xx/cxd56_dmac.c +++ b/arch/arm/src/cxd56xx/cxd56_dmac.c @@ -805,7 +805,7 @@ DMA_HANDLE cxd56_dmachannel(int ch, ssize_t maxsize) dmach->list = (dmac_lli_t *)kmm_malloc(n * sizeof(dmac_lli_t)); if (dmach->list == NULL) { - dmainfo("Failed to malloc\n"); + dmainfo("Failed to kmm_malloc\n"); goto err; } diff --git a/arch/arm/src/cxd56xx/cxd56_gnss.c b/arch/arm/src/cxd56xx/cxd56_gnss.c index cd15e6ed924..1e774740349 100644 --- a/arch/arm/src/cxd56xx/cxd56_gnss.c +++ b/arch/arm/src/cxd56xx/cxd56_gnss.c @@ -174,7 +174,7 @@ struct cxd56_gnss_dev_s sem_t syncsem; uint8_t num_open; uint8_t notify_data; - FAR FILE * cepfp; + struct file cepfp; FAR void * cepbuf; FAR struct pollfd *fds[CONFIG_CXD56_GNSS_NPOLLWAITERS]; #if !defined(CONFIG_DISABLE_SIGNAL) && \ @@ -906,7 +906,7 @@ static int cxd56_gnss_save_backup_data(FAR struct file *filep, unsigned long arg) { FAR char *buf; - FAR FILE *fp; + int fd; int n = 0; int32_t offset = 0; @@ -916,11 +916,11 @@ static int cxd56_gnss_save_backup_data(FAR struct file *filep, return -ENOMEM; } - fp = fopen(CONFIG_CXD56_GNSS_BACKUP_FILENAME, "wb"); - if (fp == NULL) + fd = nx_open(CONFIG_CXD56_GNSS_BACKUP_FILENAME, O_WRONLY | O_CREAT | O_TRUNC); + if (fd < 0) { kmm_free(buf); - return -ENOENT; + return fd; } do @@ -932,13 +932,13 @@ static int cxd56_gnss_save_backup_data(FAR struct file *filep, break; } - n = fwrite(buf, 1, n, fp); + n = nx_write(fd, buf, n); offset += n; } while (n == CONFIG_CXD56_GNSS_BACKUP_BUFFER_SIZE); kmm_free(buf); - fclose(fp); + nx_close(fd); return n < 0 ? n : 0; } @@ -2155,11 +2155,11 @@ static int cxd56_gnss_wait_notify(FAR sem_t *sem, time_t waitsec) * ****************************************************************************/ -static FAR char *cxd56_gnss_read_cep_file(FAR FILE *fp, int32_t offset, - size_t len, FAR int *retval) +static FAR char * +cxd56_gnss_read_cep_file(FAR struct file *fp, int32_t offset, + size_t len, FAR int *retval) { FAR char *buf; - size_t n = 0; int ret; if (fp == NULL) @@ -2175,21 +2175,19 @@ static FAR char *cxd56_gnss_read_cep_file(FAR FILE *fp, int32_t offset, goto _err0; } - ret = fseek(fp, offset, SEEK_SET); + ret = file_seek(fp, offset, SEEK_SET); if (ret < 0) { goto _err1; } - n = fread(buf, 1, len, fp); - if (n <= 0) + ret = file_read(fp, buf, len); + if (ret <= 0) { - ret = n < 0 ? n : ferror(fp) ? -errno : 0; - clearerr(fp); goto _err1; } - *retval = n; + *retval = ret; cxd56_cpu1sigsend(CXD56_CPU1_DATA_TYPE_CEP, (uint32_t)buf); return buf; @@ -2224,7 +2222,7 @@ static FAR char *cxd56_gnss_read_cep_file(FAR FILE *fp, int32_t offset, static void cxd56_gnss_read_backup_file(FAR int *retval) { FAR char * buf; - FAR FILE * fp; + int fd; int32_t offset = 0; size_t n; int ret = 0; @@ -2236,20 +2234,20 @@ static void cxd56_gnss_read_backup_file(FAR int *retval) goto _err; } - fp = fopen(CONFIG_CXD56_GNSS_BACKUP_FILENAME, "rb"); - if (fp == NULL) + fd = nx_open(CONFIG_CXD56_GNSS_BACKUP_FILENAME, O_RDONLY); + if (fd < 0) { kmm_free(buf); - ret = -ENOENT; + ret = fd; goto _err; } do { - n = fread(buf, 1, CONFIG_CXD56_GNSS_BACKUP_BUFFER_SIZE, fp); + n = nx_read(fd, buf, CONFIG_CXD56_GNSS_BACKUP_BUFFER_SIZE); if (n <= 0) { - ret = n < 0 ? n : ferror(fp) ? -ENFILE : 0; + ret = n; break; } @@ -2263,7 +2261,7 @@ static void cxd56_gnss_read_backup_file(FAR int *retval) } while (n > 0); - fclose(fp); + nx_close(fd); kmm_free(buf); /* Notify the termination of backup sequence by write zero length data */ @@ -2316,7 +2314,7 @@ static void cxd56_gnss_common_signalhandler(uint32_t data, union sigval value; value.sival_ptr = &sig->info; - sigqueue(sig->pid, sig->info.signo, value); + nxsig_queue(sig->pid, sig->info.signo, value); issetmask = 1; } } @@ -2363,7 +2361,7 @@ static void cxd56_gnss_default_sighandler(uint32_t data, FAR void *userdata) case CXD56_GNSS_NOTIFY_TYPE_REQCEPDAT: { priv->cepbuf = cxd56_gnss_read_cep_file( - priv->cepfp, priv->shared_info.argv[GNSS_ARGS_FILE_OFFSET], + &priv->cepfp, priv->shared_info.argv[GNSS_ARGS_FILE_OFFSET], priv->shared_info.argv[GNSS_ARGS_FILE_LENGTH], &priv->shared_info.retval); return; @@ -2395,19 +2393,18 @@ static void cxd56_gnss_default_sighandler(uint32_t data, FAR void *userdata) return; case CXD56_GNSS_NOTIFY_TYPE_REQCEPOPEN: - if (priv->cepfp != NULL) + if (priv->cepfp.f_inode != NULL) { - fclose(priv->cepfp); + file_close(&priv->cepfp); } - priv->cepfp = fopen(CONFIG_CXD56_GNSS_CEP_FILENAME, "rb"); + file_open(&priv->cepfp, CONFIG_CXD56_GNSS_CEP_FILENAME, O_RDONLY); return; case CXD56_GNSS_NOTIFY_TYPE_REQCEPCLOSE: - if (priv->cepfp != NULL) + if (priv->cepfp.f_inode != NULL) { - fclose(priv->cepfp); - priv->cepfp = NULL; + file_close(&priv->cepfp); } return; diff --git a/arch/arm/src/cxd56xx/cxd56_icc.c b/arch/arm/src/cxd56xx/cxd56_icc.c index 962f14b7284..d96014dcd97 100644 --- a/arch/arm/src/cxd56xx/cxd56_icc.c +++ b/arch/arm/src/cxd56xx/cxd56_icc.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -259,7 +260,7 @@ static int icc_irqhandler(int cpuid, uint32_t word[2]) union sigval value; value.sival_ptr = priv->sigdata; - sigqueue(priv->pid, priv->signo, value); + nxsig_queue(priv->pid, priv->signo, value); } #endif diff --git a/arch/arm/src/cxd56xx/cxd56_scu.c b/arch/arm/src/cxd56xx/cxd56_scu.c index 514b8e58b29..b3aede0dbd2 100644 --- a/arch/arm/src/cxd56xx/cxd56_scu.c +++ b/arch/arm/src/cxd56xx/cxd56_scu.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -1523,7 +1524,7 @@ static void seq_handlefifointr(FAR struct cxd56_scudev_s *priv, DEBUGASSERT(notify->pid != 0); value.sival_ptr = notify->ts; - sigqueue(notify->pid, notify->signo, value); + nxsig_queue(notify->pid, notify->signo, value); #endif } } @@ -1614,7 +1615,7 @@ static void seq_handlemathfintr(FAR struct cxd56_scudev_s *priv, DEBUGASSERT(notify->pid != 0); value.sival_ptr = notify->arg; - sigqueue(notify->pid, notify->signo, value); + nxsig_queue(notify->pid, notify->signo, value); detected = 0; } #endif diff --git a/arch/arm/src/cxd56xx/cxd56_usbdev.c b/arch/arm/src/cxd56xx/cxd56_usbdev.c index a2dfd20eb2a..fd27c74f541 100644 --- a/arch/arm/src/cxd56xx/cxd56_usbdev.c +++ b/arch/arm/src/cxd56xx/cxd56_usbdev.c @@ -63,6 +63,7 @@ #include #include +#include #include #include @@ -3404,7 +3405,7 @@ static void cxd56_notify_signal(uint16_t state, uint16_t power) { union sigval value; value.sival_int = state << 16 | power; - sigqueue(priv->pid, priv->signo, value); + nxsig_queue(priv->pid, priv->signo, value); } } diff --git a/arch/arm/src/lc823450/lc823450_ipl2.c b/arch/arm/src/lc823450/lc823450_ipl2.c index a598e7e076c..92da2dc7c09 100644 --- a/arch/arm/src/lc823450/lc823450_ipl2.c +++ b/arch/arm/src/lc823450/lc823450_ipl2.c @@ -616,55 +616,6 @@ static int msc_enable(int forced) } #endif -#ifdef CONFIG_LASTKMSG - -/**************************************************************************** - * Name: check_lastkmsg() - ****************************************************************************/ - -void check_lastkmsg(void) -{ - int ret; - FILE *fp; - - if (g_lastksg_buf.sig != LASTKMSG_SIG) - { - return; - } - - ret = mount(CONFIG_MTD_LOG_DEVPATH, "/log", "vfat", 0, NULL); - - if (ret) - { - _info("mount: ret = %d\n", ret); - return; - } - - /* log rotate */ - - unlink(LASTMSG_LOGPATH ".4"); - rename(LASTMSG_LOGPATH ".3", LASTMSG_LOGPATH ".4"); - rename(LASTMSG_LOGPATH ".2", LASTMSG_LOGPATH ".3"); - rename(LASTMSG_LOGPATH ".1", LASTMSG_LOGPATH ".2"); - rename(LASTMSG_LOGPATH ".0", LASTMSG_LOGPATH ".1"); - - fp = fopen(LASTMSG_LOGPATH ".0", "w"); - - if (fp) - { - lastkmsg_output(fp); - fflush(fp); - fclose(fp); - } - - umount("/log"); - - /* XXX: workaround for logfile size = 0 */ - - nxsig_usleep(100000); -} -#endif /* CONFIG_LASTKMSG */ - /**************************************************************************** * Name: ipl2_main() ****************************************************************************/ diff --git a/arch/arm/src/samv7/sam_eefc.c b/arch/arm/src/samv7/sam_eefc.c index a9f86ad44e5..8cf4e4925ec 100644 --- a/arch/arm/src/samv7/sam_eefc.c +++ b/arch/arm/src/samv7/sam_eefc.c @@ -25,7 +25,6 @@ #include #include -#include #include #include diff --git a/arch/arm/src/samv7/sam_ssc.c b/arch/arm/src/samv7/sam_ssc.c index b21473c9ad9..58e1560305b 100644 --- a/arch/arm/src/samv7/sam_ssc.c +++ b/arch/arm/src/samv7/sam_ssc.c @@ -3387,7 +3387,7 @@ struct i2s_dev_s *sam_ssc_initialize(int port) } /* Set up the initial state for this chip select structure. Other fields - * were zeroed by zalloc(). + * were zeroed by kmm_zalloc(). */ /* Initialize the common parts for the SSC device structure */ diff --git a/arch/arm/src/xmc4/xmc4_spi.c b/arch/arm/src/xmc4/xmc4_spi.c index 492d6c1eefc..4a74c50fe79 100644 --- a/arch/arm/src/xmc4/xmc4_spi.c +++ b/arch/arm/src/xmc4/xmc4_spi.c @@ -1814,7 +1814,7 @@ struct spi_dev_s *xmc4_spibus_initialize(int channel) } /* Set up the initial state for this chip select structure. Other fields - * were zeroed by zalloc(). + * were zeroed by kmm_zalloc(). */ #ifdef CONFIG_XMC4_SPI_DMA diff --git a/arch/x86_64/include/intel64/irq.h b/arch/x86_64/include/intel64/irq.h index 8310dbecfb5..09eac529563 100644 --- a/arch/x86_64/include/intel64/irq.h +++ b/arch/x86_64/include/intel64/irq.h @@ -33,7 +33,6 @@ # include # include # include -# include # include # include # include diff --git a/arch/xtensa/src/esp32/esp32_wifi_adapter.c b/arch/xtensa/src/esp32/esp32_wifi_adapter.c index 1f479cfb06a..938e02f4bbe 100644 --- a/arch/xtensa/src/esp32/esp32_wifi_adapter.c +++ b/arch/xtensa/src/esp32/esp32_wifi_adapter.c @@ -206,6 +206,7 @@ static int32_t esp_task_ms_to_tick(uint32_t ms); static void *esp_task_get_current_task(void); static int32_t esp_task_get_max_priority(void); static void *esp_malloc(uint32_t size); +static void esp_free(void *ptr); static uint32_t esp_rand(void); static void esp_dport_access_stall_other_cpu_start(void); static void esp_dport_access_stall_other_cpu_end(void); @@ -394,7 +395,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = ._task_get_current_task = esp_task_get_current_task, ._task_get_max_priority = esp_task_get_max_priority, ._malloc = esp_malloc, - ._free = free, + ._free = esp_free, ._event_post = esp_event_post, ._get_free_heap_size = esp_get_free_heap_size, ._rand = esp_rand, @@ -898,7 +899,7 @@ static void *esp_semphr_create(uint32_t max, uint32_t init) return NULL; } - ret = sem_init(sem, 0, init); + ret = nxsem_init(sem, 0, init); if (ret) { wlerr("ERROR: Failed to initialize sem error=%d\n", ret); @@ -927,7 +928,7 @@ static void esp_semphr_delete(void *semphr) { sem_t *sem = (sem_t *)semphr; - sem_destroy(sem); + nxsem_destroy(sem); kmm_free(sem); } @@ -954,7 +955,7 @@ static int32_t esp_semphr_take(void *semphr, uint32_t ticks) if (ticks == OSI_FUNCS_TIME_BLOCKING) { - ret = sem_wait(sem); + ret = nxsem_wait(sem); if (ret) { wlerr("ERROR: Failed to wait sem\n"); @@ -974,7 +975,7 @@ static int32_t esp_semphr_take(void *semphr, uint32_t ticks) esp_update_time(&timeout, ticks); } - ret = sem_timedwait(sem, &timeout); + ret = nxsem_timedwait(sem, &timeout); if (ret) { wlerr("ERROR: Failed to wait sem in %d ticks\n", ticks); @@ -1003,7 +1004,7 @@ static int32_t esp_semphr_give(void *semphr) int ret; sem_t *sem = (sem_t *)semphr; - ret = sem_post(sem); + ret = nxsem_post(sem); if (ret) { wlerr("ERROR: Failed to post sem error=%d\n", ret); @@ -1260,7 +1261,7 @@ static void *esp_queue_create(uint32_t queue_len, uint32_t item_size) mq_adpt = kmm_malloc(sizeof(struct mq_adpt)); if (!mq_adpt) { - wlerr("ERROR: Failed to malloc\n"); + wlerr("ERROR: Failed to kmm_malloc\n"); return NULL; } @@ -1763,7 +1764,7 @@ static void esp_task_delay(uint32_t tick) { useconds_t us = TICK2USEC(tick); - usleep(us); + nxsig_usleep(us); } /**************************************************************************** @@ -1841,7 +1842,26 @@ static int32_t esp_task_get_max_priority(void) static void *esp_malloc(uint32_t size) { - return malloc(size); + return kmm_malloc(size); +} + +/**************************************************************************** + * Name: esp_free + * + * Description: + * Free a block of memory + * + * Input Parameters: + * ptr - memory block + * + * Returned Value: + * No + * + ****************************************************************************/ + +static void esp_free(void *ptr) +{ + kmm_free(ptr); } /**************************************************************************** @@ -1933,10 +1953,10 @@ static void esp_evt_work_cb(FAR void *arg) break; case WIFI_ADPT_EVT_STA_CONNECT: g_connected = true; - ret = sem_post(&g_connect_sem); + ret = nxsem_post(&g_connect_sem); if (ret) { - wlerr("ERROR: Failed to post sem error=%d\n", errno); + wlerr("ERROR: Failed to post sem error=%d\n", ret); } break; case WIFI_ADPT_EVT_STA_DISCONNECT: @@ -1969,7 +1989,7 @@ static void esp_evt_work_cb(FAR void *arg) esp_event_lock(false); - free(evt_adpt); + kmm_free(evt_adpt); } } @@ -2067,7 +2087,7 @@ int32_t esp_event_post(esp_event_base_t event_base, } size = event_data_size + sizeof(struct evt_adpt); - evt_adpt = malloc(size); + evt_adpt = kmm_malloc(size); if (!evt_adpt) { wlerr("ERROR: Failed to alloc %d memory\n", size); @@ -2270,7 +2290,7 @@ static void wifi_phy_enable(void) cal_data = kmm_zalloc(sizeof(esp_phy_calibration_data_t)); if (!cal_data) { - wlerr("ERROR: Failed to malloc"); + wlerr("ERROR: Failed to kmm_zalloc"); DEBUGASSERT(0); } @@ -3023,7 +3043,7 @@ static int32_t esp_nvs_set_blob(uint32_t handle, size_t length) { #ifdef CONFIG_ESP32_WIFI_SAVE_PARAM - int fd; + struct file file; int ret; char *dir; struct nvs_adpt *nvs_adpt = (struct nvs_adpt *)handle; @@ -3036,36 +3056,36 @@ static int32_t esp_nvs_set_blob(uint32_t handle, return -1; } - ret = unlink(dir); + ret = nx_unlink(dir); if (ret) { - if (errno != ENOENT) + if (ret != -ENOENT) { - wlerr("ERROR: Failed to unlink %s error=%d\n", dir, errno); - free(dir); + wlerr("ERROR: Failed to unlink %s error=%d\n", dir, ret); + kmm_free(dir); return -1; } } - fd = open(dir, O_WRONLY | O_CREAT, NVS_FILE_MODE); - if (fd < 0) + ret = file_open(&file, dir, O_WRONLY | O_CREAT, NVS_FILE_MODE); + if (ret < 0) { wlerr("ERROR: Failed to set open %s\n", dir); - free(dir); + kmm_free(dir); return -1; } - ret = write(fd, value, length); + ret = file_write(&file, value, length); if (ret < 0) { wlerr("ERROR: Failed to write to %s\n", dir); - free(dir); - close(fd); + kmm_free(dir); + file_close(&file); return -1; } - free(dir); - close(fd); + kmm_free(dir); + file_close(&file); return 0; #else @@ -3098,7 +3118,7 @@ static int32_t esp_nvs_get_blob(uint32_t handle, size_t *length) { #ifdef CONFIG_ESP32_WIFI_SAVE_PARAM - int fd; + struct file file; int ret; char *dir; struct nvs_adpt *nvs_adpt = (struct nvs_adpt *)handle; @@ -3111,26 +3131,26 @@ static int32_t esp_nvs_get_blob(uint32_t handle, return -1; } - fd = open(dir, O_RDONLY); - if (fd < 0) + ret = file_open(&file, dir, O_RDONLY); + if (ret < 0) { - if (errno == ENOENT) + if (ret == -ENOENT) { wlinfo("INFO: No file %s\n", dir); - free(dir); + kmm_free(dir); return ESP_ERR_NVS_NOT_FOUND; } wlerr("ERROR: Failed to get open %s\n", dir); - free(dir); + kmm_free(dir); return -1; } - ret = read(fd, out_value, *length); + ret = file_read(&file, out_value, *length); if (ret <= 0) { wlerr("ERROR: Failed to write to %s\n", dir); - free(dir); - close(fd); + kmm_free(dir); + file_close(&file); return -1; } else @@ -3138,8 +3158,8 @@ static int32_t esp_nvs_get_blob(uint32_t handle, *length = ret; } - free(dir); - close(fd); + kmm_free(dir); + file_close(&file); return 0; #else @@ -3179,15 +3199,15 @@ static int32_t esp_nvs_erase_key(uint32_t handle, const char *key) return -1; } - ret = unlink(dir); + ret = nx_unlink(dir); if (ret < 0) { wlerr("ERROR: Failed to delete NVS file %s\n", dir); - free(dir); + kmm_free(dir); return -1; } - free(dir); + kmm_free(dir); return 0; #else @@ -3484,7 +3504,7 @@ static void *esp_zalloc_internal(size_t size) static void *esp_wifi_malloc(size_t size) { - return malloc(size); + return kmm_malloc(size); } /**************************************************************************** @@ -3504,7 +3524,7 @@ static void *esp_wifi_malloc(size_t size) static void *esp_wifi_realloc(void *ptr, size_t size) { - return realloc(ptr, size); + return kmm_realloc(ptr, size); } /**************************************************************************** @@ -3524,7 +3544,7 @@ static void *esp_wifi_realloc(void *ptr, size_t size) static void *esp_wifi_calloc(size_t n, size_t size) { - return calloc(n, size); + return kmm_calloc(n, size); } /**************************************************************************** @@ -3543,7 +3563,7 @@ static void *esp_wifi_calloc(size_t n, size_t size) static void *esp_wifi_zalloc(size_t size) { - return zalloc(size); + return kmm_zalloc(size); } /**************************************************************************** @@ -3568,7 +3588,7 @@ static void *esp_wifi_create_queue(int32_t queue_len, int32_t item_size) wifi_queue = kmm_malloc(sizeof(wifi_static_queue_t)); if (!wifi_queue) { - wlerr("ERROR: Failed to malloc\n"); + wlerr("ERROR: Failed to kmm_malloc\n"); return NULL; } @@ -4631,10 +4651,10 @@ int esp_wifi_connect_internal(void) clock_gettime(CLOCK_REALTIME, &timeout); timeout.tv_sec += WIFI_CONNECT_TIMEOUT; - ret = sem_timedwait(&g_connect_sem, &timeout); + ret = nxsem_timedwait(&g_connect_sem, &timeout); if (ret) { - wlerr("ERROR: Failed to wait sem error=%d\n", errno); + wlerr("ERROR: Failed to wait sem error=%d\n", ret); esp_wifi_stop(); return -1; } diff --git a/binfmt/builtin.c b/binfmt/builtin.c index 57b243160c1..3639dbf4953 100644 --- a/binfmt/builtin.c +++ b/binfmt/builtin.c @@ -107,13 +107,12 @@ static int builtin_loadbinary(struct binary_s *binp) * the file using the FIOC_FILENAME ioctl() call. */ - ret = ioctl(fd, FIOC_FILENAME, (unsigned long)((uintptr_t)&filename)); + ret = nx_ioctl(fd, FIOC_FILENAME, (unsigned long)((uintptr_t)&filename)); if (ret < 0) { - int errval = get_errno(); - berr("ERROR: FIOC_FILENAME ioctl failed: %d\n", errval); - close(fd); - return -errval; + berr("ERROR: FIOC_FILENAME ioctl failed: %d\n", ret); + nx_close(fd); + return ret; } /* Other file systems may also support FIOC_FILENAME, so the real proof @@ -124,7 +123,7 @@ static int builtin_loadbinary(struct binary_s *binp) if (index < 0) { berr("ERROR: %s is not a builtin application\n", filename); - close(fd); + nx_close(fd); return index; } @@ -136,7 +135,7 @@ static int builtin_loadbinary(struct binary_s *binp) binp->entrypt = builtin->main; binp->stacksize = builtin->stacksize; binp->priority = builtin->priority; - close(fd); + nx_close(fd); return OK; } diff --git a/binfmt/libelf/libelf_init.c b/binfmt/libelf/libelf_init.c index 063faea09e5..2b2a8ba3348 100644 --- a/binfmt/libelf/libelf_init.c +++ b/binfmt/libelf/libelf_init.c @@ -98,12 +98,11 @@ static inline int elf_filelen(FAR struct elf_loadinfo_s *loadinfo, /* Get the file stats */ - ret = stat(filename, &buf); + ret = nx_stat(filename, &buf, 1); if (ret < 0) { - int errval = get_errno(); - berr("Failed to stat file: %d\n", errval); - return -errval; + berr("Failed to stat file: %d\n", ret); + return ret; } /* Verify that it is a regular file */ @@ -177,7 +176,7 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo) if (ret < 0) { berr("Failed to read ELF header: %d\n", ret); - close(loadinfo->filfd); + nx_close(loadinfo->filfd); return ret; } @@ -197,7 +196,7 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo) */ berr("Bad ELF header: %d\n", ret); - close(loadinfo->filfd); + nx_close(loadinfo->filfd); return ret; } diff --git a/binfmt/libelf/libelf_read.c b/binfmt/libelf/libelf_read.c index ecba230b072..829e9a6d225 100644 --- a/binfmt/libelf/libelf_read.c +++ b/binfmt/libelf/libelf_read.c @@ -123,13 +123,12 @@ int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer, { /* Seek to the next read position */ - rpos = lseek(loadinfo->filfd, offset, SEEK_SET); + rpos = nx_seek(loadinfo->filfd, offset, SEEK_SET); if (rpos != offset) { - int errval = get_errno(); berr("Failed to seek to position %lu: %d\n", - (unsigned long)offset, errval); - return -errval; + (unsigned long)offset, (int)rpos); + return rpos; } /* Read the file data at offset into the user buffer */ diff --git a/binfmt/libelf/libelf_uninit.c b/binfmt/libelf/libelf_uninit.c index 0d93f358501..bbd07aef3e8 100644 --- a/binfmt/libelf/libelf_uninit.c +++ b/binfmt/libelf/libelf_uninit.c @@ -87,7 +87,7 @@ int elf_uninit(struct elf_loadinfo_s *loadinfo) if (loadinfo->filfd >= 0) { - close(loadinfo->filfd); + nx_close(loadinfo->filfd); } return OK; diff --git a/binfmt/libnxflat/libnxflat_init.c b/binfmt/libnxflat/libnxflat_init.c index a024032bf68..ce6202bc6e4 100644 --- a/binfmt/libnxflat/libnxflat_init.c +++ b/binfmt/libnxflat/libnxflat_init.c @@ -124,7 +124,7 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo) if (ret < 0) { berr("ERROR: Failed to read NXFLAT header: %d\n", ret); - close(loadinfo->filfd); + nx_close(loadinfo->filfd); return ret; } @@ -143,7 +143,7 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo) */ berr("ERROR: Bad NXFLAT header\n"); - close(loadinfo->filfd); + nx_close(loadinfo->filfd); return -ENOEXEC; } diff --git a/binfmt/libnxflat/libnxflat_read.c b/binfmt/libnxflat/libnxflat_read.c index fee19846b1d..ecaab6066cf 100644 --- a/binfmt/libnxflat/libnxflat_read.c +++ b/binfmt/libnxflat/libnxflat_read.c @@ -128,12 +128,11 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, bytesleft = readsize; do { - rpos = lseek(loadinfo->filfd, offset, SEEK_SET); + rpos = nx_seek(loadinfo->filfd, offset, SEEK_SET); if (rpos != offset) { - int errval = get_errno(); - berr("Failed to seek to position %d: %d\n", offset, errval); - return -errval; + berr("Failed to seek to position %d: %d\n", offset, (int)rpos); + return rpos; } /* Read the file data at offset into the user buffer */ diff --git a/binfmt/libnxflat/libnxflat_uninit.c b/binfmt/libnxflat/libnxflat_uninit.c index 32f0c7308eb..d1479edd546 100644 --- a/binfmt/libnxflat/libnxflat_uninit.c +++ b/binfmt/libnxflat/libnxflat_uninit.c @@ -78,7 +78,7 @@ int nxflat_uninit(struct nxflat_loadinfo_s *loadinfo) { if (loadinfo->filfd >= 0) { - close(loadinfo->filfd); + nx_close(loadinfo->filfd); } return OK; diff --git a/boards/arm/cxd56xx/spresense/src/cxd56_sdcard.c b/boards/arm/cxd56xx/spresense/src/cxd56_sdcard.c index 46cc830b794..3d34ebb9e97 100644 --- a/boards/arm/cxd56xx/spresense/src/cxd56_sdcard.c +++ b/boards/arm/cxd56xx/spresense/src/cxd56_sdcard.c @@ -138,7 +138,7 @@ static void board_sdcard_enable(FAR void *arg) /* If not initialize SD slot */ - if (!stat("/dev/mmcsd0", &stat_sdio) == 0) + if (!nx_stat("/dev/mmcsd0", &stat_sdio, 1) == 0) { /* Now bind the SDHC interface to the MMC/SD driver */ @@ -159,7 +159,7 @@ static void board_sdcard_enable(FAR void *arg) cxd56_sdhci_mediachange(g_sdhci.sdhci); - if (stat("/dev/mmcsd0", &stat_sdio) == 0) + if (nx_stat("/dev/mmcsd0", &stat_sdio, 1) == 0) { if (S_ISBLK(stat_sdio.st_mode)) { diff --git a/boards/arm/lpc31xx/ea3131/src/lpc31_fillpage.c b/boards/arm/lpc31xx/ea3131/src/lpc31_fillpage.c index 6db0970489b..90161e5a50f 100644 --- a/boards/arm/lpc31xx/ea3131/src/lpc31_fillpage.c +++ b/boards/arm/lpc31xx/ea3131/src/lpc31_fillpage.c @@ -440,7 +440,7 @@ int up_fillpage(FAR struct tcb_s *tcb, FAR void *vpage) /* Seek to that position */ - pos = lseek(g_pgsrc.fd, offset, SEEK_SET); + pos = nx_seek(g_pgsrc.fd, offset, SEEK_SET); DEBUGASSERT(pos != (off_t)-1); /* And read the page data from that offset */ diff --git a/boards/arm/lpc31xx/ea3152/src/lpc31_fillpage.c b/boards/arm/lpc31xx/ea3152/src/lpc31_fillpage.c index e2deac368c3..e15b35d9e65 100644 --- a/boards/arm/lpc31xx/ea3152/src/lpc31_fillpage.c +++ b/boards/arm/lpc31xx/ea3152/src/lpc31_fillpage.c @@ -441,7 +441,7 @@ int up_fillpage(FAR struct tcb_s *tcb, FAR void *vpage) /* Seek to that position */ - pos = lseek(g_pgsrc.fd, offset, SEEK_SET); + pos = nx_seek(g_pgsrc.fd, offset, SEEK_SET); DEBUGASSERT(pos != (off_t)-1); /* And read the page data from that offset */ diff --git a/boards/arm/stm32/nucleo-f302r8/src/stm32_highpri.c b/boards/arm/stm32/nucleo-f302r8/src/stm32_highpri.c index f5d79d6db6c..95838ac86d2 100644 --- a/boards/arm/stm32/nucleo-f302r8/src/stm32_highpri.c +++ b/boards/arm/stm32/nucleo-f302r8/src/stm32_highpri.c @@ -487,7 +487,7 @@ int highpri_main(int argc, char *argv[]) adc1->ad_ops->ao_ioctl(adc1, IO_TRIGGER_REG, 0); - usleep(100); + nxsig_usleep(100); #endif #ifdef HIGHPRI_HAVE_INJECTED @@ -495,7 +495,7 @@ int highpri_main(int argc, char *argv[]) adc1->ad_ops->ao_ioctl(adc1, IO_TRIGGER_INJ, 0); - usleep(100); + nxsig_usleep(100); #endif /* Lock global data */ diff --git a/boards/arm/stm32/nucleo-f334r8/src/stm32_highpri.c b/boards/arm/stm32/nucleo-f334r8/src/stm32_highpri.c index 161b5c0ea0d..37430be327c 100644 --- a/boards/arm/stm32/nucleo-f334r8/src/stm32_highpri.c +++ b/boards/arm/stm32/nucleo-f334r8/src/stm32_highpri.c @@ -529,7 +529,7 @@ int highpri_main(int argc, char *argv[]) adc1->ad_ops->ao_ioctl(adc1, IO_TRIGGER_REG, 0); - usleep(100); + nxsig_usleep(100); #endif #ifdef HIGHPRI_HAVE_INJECTED @@ -537,7 +537,7 @@ int highpri_main(int argc, char *argv[]) adc1->ad_ops->ao_ioctl(adc1, IO_TRIGGER_INJ, 0); - usleep(100); + nxsig_usleep(100); #endif /* Lock global data */ diff --git a/boards/arm/stm32/photon/src/stm32_rgbled.c b/boards/arm/stm32/photon/src/stm32_rgbled.c index 986e4f3891c..83e7f94e373 100644 --- a/boards/arm/stm32/photon/src/stm32_rgbled.c +++ b/boards/arm/stm32/photon/src/stm32_rgbled.c @@ -174,7 +174,7 @@ int stm32_rgbled_setup(void) /* Initialize led off */ nx_write(fd, "#000000", 8); - close(fd); + nx_close(fd); /* Now we are initialized */ diff --git a/boards/arm/stm32/stm32f429i-disco/src/stm32_highpri.c b/boards/arm/stm32/stm32f429i-disco/src/stm32_highpri.c index 67a8f288f74..656edba9b01 100644 --- a/boards/arm/stm32/stm32f429i-disco/src/stm32_highpri.c +++ b/boards/arm/stm32/stm32f429i-disco/src/stm32_highpri.c @@ -478,7 +478,7 @@ int highpri_main(int argc, char *argv[]) adc1->ad_ops->ao_ioctl(adc1, IO_TRIGGER_REG, 0); - usleep(100); + nxsig_usleep(100); #endif #ifdef HIGHPRI_HAVE_INJECTED @@ -486,7 +486,7 @@ int highpri_main(int argc, char *argv[]) adc1->ad_ops->ao_ioctl(adc1, IO_TRIGGER_INJ, 0); - usleep(100); + nxsig_usleep(100); #endif /* Lock global data */ diff --git a/boards/z80/ez80/z20x/src/w25_main.c b/boards/z80/ez80/z20x/src/w25_main.c index 053e845b964..85133c969a9 100644 --- a/boards/z80/ez80/z20x/src/w25_main.c +++ b/boards/z80/ez80/z20x/src/w25_main.c @@ -688,7 +688,7 @@ static int w25_wait_keypress(FAR char *keyset, int nseconds) /* Delay 50 Milliseconds */ - usleep(50 * 1000); + nxsig_usleep(50 * 1000); /* Output a dot to stdout every 10 * 50 = 500 milliseconds */ diff --git a/drivers/analog/ads7828.c b/drivers/analog/ads7828.c index 879f7bb7f21..e25c9afc30b 100644 --- a/drivers/analog/ads7828.c +++ b/drivers/analog/ads7828.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/drivers/lcd/tda19988.c b/drivers/lcd/tda19988.c index 3da00c916c2..32505ab9149 100644 --- a/drivers/lcd/tda19988.c +++ b/drivers/lcd/tda19988.c @@ -741,7 +741,7 @@ static int tda19988_fetch_edid(struct tda1988_dev_s *priv) if (edid == NULL) { - lcderr("ERROR: Failed to realloc EDID\n"); + lcderr("ERROR: Failed to kmm_realloc EDID\n"); ret = -ENOMEM; goto done; } diff --git a/drivers/loop/losetup.c b/drivers/loop/losetup.c index 427467cef9d..21417a3214d 100644 --- a/drivers/loop/losetup.c +++ b/drivers/loop/losetup.c @@ -344,11 +344,11 @@ int losetup(FAR const char *devname, FAR const char *filename, /* Get the size of the file */ - ret = stat(filename, &sb); + ret = nx_stat(filename, &sb, 1); if (ret < 0) { - ferr("ERROR: Failed to stat %s: %d\n", filename, get_errno()); - return -get_errno(); + ferr("ERROR: Failed to stat %s: %d\n", filename, ret); + return ret; } /* Check if the file system is big enough for one block */ diff --git a/drivers/modem/altair/altmdm_spi.c b/drivers/modem/altair/altmdm_spi.c index d2bccd6bad9..48d36284a00 100644 --- a/drivers/modem/altair/altmdm_spi.c +++ b/drivers/modem/altair/altmdm_spi.c @@ -1658,7 +1658,7 @@ static void xfer_task_init(FAR struct altmdm_dev_s *priv) sigset_t mask; sigfillset(&mask); - sigprocmask(SIG_SETMASK, &mask, NULL); + nxsig_procmask(SIG_SETMASK, &mask, NULL); init_svtimer(priv); } diff --git a/drivers/modem/altair/altmdm_sys.c b/drivers/modem/altair/altmdm_sys.c index 90f7988fd9d..06d01ca5c9a 100644 --- a/drivers/modem/altair/altmdm_sys.c +++ b/drivers/modem/altair/altmdm_sys.c @@ -671,10 +671,10 @@ timer_t altmdm_sys_starttimer(int first_ms, int interval_ms, sigemptyset(&mask); nxsig_addset(&mask, MY_TIMER_SIGNAL); - ret = sigprocmask(SIG_UNBLOCK, &mask, NULL); + ret = nxsig_procmask(SIG_UNBLOCK, &mask, NULL); if (ret != OK) { - m_err("sigprocmask() failed:%d\n", ret); + m_err("nxsig_procmask() failed:%d\n", ret); return NULL; } @@ -683,10 +683,10 @@ timer_t altmdm_sys_starttimer(int first_ms, int interval_ms, sigfillset(&sa.sa_mask); nxsig_delset(&sa.sa_mask, MY_TIMER_SIGNAL); - ret = sigaction(MY_TIMER_SIGNAL, &sa, NULL); + ret = nxsig_action(MY_TIMER_SIGNAL, &sa, NULL, false); if (ret != OK) { - m_err("sigaction() failed:%d\n", ret); + m_err("nxsig_action() failed:%d\n", ret); return NULL; } @@ -760,7 +760,7 @@ void altmdm_sys_stoptimer(timer_t timerid) timer_delete(timerid); sigfillset(&mask); - sigprocmask(SIG_SETMASK, &mask, NULL); + nxsig_procmask(SIG_SETMASK, &mask, NULL); } #endif diff --git a/drivers/mtd/filemtd.c b/drivers/mtd/filemtd.c index 9f1b0a3cb91..021a182c9ad 100644 --- a/drivers/mtd/filemtd.c +++ b/drivers/mtd/filemtd.c @@ -625,10 +625,10 @@ FAR struct mtd_dev_s *filemtd_initialize(FAR const char *path, size_t offset, /* Stat the file */ - ret = stat(path, &sb); + ret = nx_stat(path, &sb, 1); if (ret < 0) { - ferr("ERROR: Failed to stat %s: %d\n", path, get_errno()); + ferr("ERROR: Failed to stat %s: %d\n", path, ret); return NULL; } diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index bd1ebaccfa9..3990af35eb2 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -6362,8 +6362,8 @@ static int smart_losetup(int minor, FAR const char *filename, for (x = 0; x < 256; x++) { snprintf(devpath, sizeof(devpath), "/dev/smart%d", x); - ret = stat(devpath, &sb); - if (ret != 0) + ret = nx_stat(devpath, &sb, 1); + if (ret < 0) { /* We can use this minor number */ diff --git a/drivers/power/bq769x0.c b/drivers/power/bq769x0.c index 19920ffc79f..a09c7fb3138 100644 --- a/drivers/power/bq769x0.c +++ b/drivers/power/bq769x0.c @@ -1637,7 +1637,7 @@ static int bq769x0_getcurrent(FAR struct bq769x0_dev_s *priv, /* Sample is not complete, wait and try again */ - usleep(BQ769X0_CC_POLL_INTERVAL * USEC_PER_MSEC); + nxsig_usleep(BQ769X0_CC_POLL_INTERVAL * USEC_PER_MSEC); } /* CC value didn't become available in the expected amount of time */ diff --git a/drivers/serial/serial_dma.c b/drivers/serial/serial_dma.c index 87010543f99..2a4c7384055 100644 --- a/drivers/serial/serial_dma.c +++ b/drivers/serial/serial_dma.c @@ -404,7 +404,7 @@ void uart_recvchars_done(FAR uart_dev_t *dev) if (signo != 0) { - kill(dev->pid, signo); + nxsig_kill(dev->pid, signo); uart_reset_sem(dev); } #endif diff --git a/drivers/serial/serial_io.c b/drivers/serial/serial_io.c index ddd4c3a99e4..3ba8f7f9035 100644 --- a/drivers/serial/serial_io.c +++ b/drivers/serial/serial_io.c @@ -46,9 +46,9 @@ #include #include -#include #include +#include #include /**************************************************************************** @@ -297,7 +297,7 @@ void uart_recvchars(FAR uart_dev_t *dev) if (signo != 0) { - kill(dev->pid, signo); + nxsig_kill(dev->pid, signo); uart_reset_sem(dev); } #endif diff --git a/drivers/wireless/ieee802154/mrf24j40/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40/mrf24j40.c index d1dc1248c7f..6f26d7be593 100644 --- a/drivers/wireless/ieee802154/mrf24j40/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40/mrf24j40.c @@ -448,9 +448,7 @@ FAR struct ieee802154_radio_s * if (lower->attach(lower, mrf24j40_interrupt, dev) != OK) { -#if 0 kmm_free(dev); -#endif return NULL; } diff --git a/fs/driver/fs_mtdproxy.c b/fs/driver/fs_mtdproxy.c index 33aafad3dcc..9c65c500c1e 100644 --- a/fs/driver/fs_mtdproxy.c +++ b/fs/driver/fs_mtdproxy.c @@ -100,10 +100,10 @@ static FAR char *unique_blkdev(void) /* Make sure that file name is not in use */ - ret = stat(devbuf, &statbuf); + ret = nx_stat(devbuf, &statbuf, 1); if (ret < 0) { - DEBUGASSERT(errno == ENOENT); + DEBUGASSERT(ret == -ENOENT); return strdup(devbuf); } diff --git a/fs/hostfs/hostfs_rpmsg_server.c b/fs/hostfs/hostfs_rpmsg_server.c index 938472e0a55..5415f1708e1 100644 --- a/fs/hostfs/hostfs_rpmsg_server.c +++ b/fs/hostfs/hostfs_rpmsg_server.c @@ -560,12 +560,8 @@ static int hostfs_rpmsg_stat_handler(FAR struct rpmsg_endpoint *ept, struct stat buf; int ret; - ret = stat(msg->pathname, &buf); - if (ret) - { - ret = -get_errno(); - } - else + ret = nx_stat(msg->pathname, &buf, 1); + if (ret >= 0) { msg->buf = buf; } diff --git a/fs/mmap/fs_mmap.c b/fs/mmap/fs_mmap.c index cc90282741a..525b27abc65 100644 --- a/fs/mmap/fs_mmap.c +++ b/fs/mmap/fs_mmap.c @@ -127,7 +127,6 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags, int fd, off_t offset) { FAR void *addr; - int errcode; int ret = -1; /* Since only a tiny subset of mmap() functionality, we have to verify many @@ -144,7 +143,7 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags, (flags & (MAP_FIXED | MAP_DENYWRITE)) != 0) { ferr("ERROR: Unsupported options, prot=%x flags=%04x\n", prot, flags); - errcode = ENOSYS; + ret = -ENOSYS; goto errout; } @@ -153,7 +152,7 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags, if (length == 0) { ferr("ERROR: Invalid length, length=%zu\n", length); - errcode = EINVAL; + ret = -EINVAL; goto errout; } #endif @@ -178,7 +177,7 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags, if (alloc == NULL) { ferr("ERROR: kumm_alloc() failed: %d\n", ret); - errcode = ENOMEM; + ret = -ENOMEM; goto errout; } @@ -193,7 +192,7 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags, if ((flags & MAP_PRIVATE) == 0) { - ret = ioctl(fd, FIOC_MMAP, (unsigned long)((uintptr_t)&addr)); + ret = nx_ioctl(fd, FIOC_MMAP, (unsigned long)((uintptr_t)&addr)); } if (ret < 0) @@ -211,8 +210,7 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags, #else /* Error out. The errno value was already set by ioctl() */ - ferr("ERROR: ioctl(FIOC_MMAP) failed: %d\n", get_errno()); - errcode = ENOSYS; + ferr("ERROR: ioctl(FIOC_MMAP) failed: %d\n", ret); goto errout; #endif } @@ -222,6 +220,6 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags, return (FAR void *)(((FAR uint8_t *)addr) + offset); errout: - set_errno(errcode); + set_errno(-ret); return MAP_FAILED; } diff --git a/fs/mmap/fs_rammap.c b/fs/mmap/fs_rammap.c index 23e6ceb330d..8140938935f 100644 --- a/fs/mmap/fs_rammap.c +++ b/fs/mmap/fs_rammap.c @@ -122,7 +122,6 @@ FAR void *rammap(int fd, size_t length, off_t offset) FAR uint8_t *rdbuffer; ssize_t nread; off_t fpos; - int errcode; int ret; /* There is a major design flaw that I have not yet thought of fix for: @@ -144,7 +143,7 @@ FAR void *rammap(int fd, size_t length, off_t offset) if (!alloc) { ferr("ERROR: Region allocation failed, length: %d\n", (int)length); - errcode = ENOMEM; + ret = -ENOMEM; goto errout; } @@ -158,15 +157,15 @@ FAR void *rammap(int fd, size_t length, off_t offset) /* Seek to the specified file offset */ - fpos = lseek(fd, offset, SEEK_SET); - if (fpos == (off_t)-1) + fpos = nx_seek(fd, offset, SEEK_SET); + if (fpos < 0) { /* Seek failed... errno has already been set, but EINVAL is probably * the correct response. */ ferr("ERROR: Seek to position %d failed\n", (int)offset); - errcode = EINVAL; + ret = fpos; goto errout_with_region; } @@ -189,7 +188,7 @@ FAR void *rammap(int fd, size_t length, off_t offset) ferr("ERROR: Read failed: offset=%d errno=%d\n", (int)offset, (int)nread); - errcode = (int)-nread; + ret = nread; goto errout_with_region; } } @@ -217,11 +216,10 @@ FAR void *rammap(int fd, size_t length, off_t offset) ret = nxsem_wait(&g_rammaps.exclsem); if (ret < 0) { - errcode = -ret; goto errout_with_region; } - map->flink = g_rammaps.head; + map->flink = g_rammaps.head; g_rammaps.head = map; nxsem_post(&g_rammaps.exclsem); @@ -231,7 +229,7 @@ errout_with_region: kumm_free(alloc); errout: - set_errno(errcode); + set_errno(-ret); return MAP_FAILED; } diff --git a/fs/vfs/fs_select.c b/fs/vfs/fs_select.c index f7a789d42ec..56c9ca4a312 100644 --- a/fs/vfs/fs_select.c +++ b/fs/vfs/fs_select.c @@ -198,12 +198,12 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds, /* Then let poll do all of the real work. */ - ret = poll(pollset, npfds, msec); + ret = nx_poll(pollset, npfds, msec); if (ret < 0) { /* poll() failed! Save the errno value */ - errcode = get_errno(); + errcode = -ret; } /* Now set up the return values */ diff --git a/graphics/nxmu/nxmu_server.c b/graphics/nxmu/nxmu_server.c index fab4fde8f14..e457a3d8ea0 100644 --- a/graphics/nxmu/nxmu_server.c +++ b/graphics/nxmu/nxmu_server.c @@ -80,7 +80,7 @@ static inline void nxmu_disconnect(FAR struct nxmu_conn_s *conn) /* Close the outgoing client message queue */ - mq_close(conn->swrmq); + nxmq_close(conn->swrmq); } /**************************************************************************** @@ -101,10 +101,10 @@ static inline void nxmu_connect(FAR struct nxmu_conn_s *conn) * client */ - conn->swrmq = mq_open(mqname, O_WRONLY); - if (conn->swrmq == (mqd_t)-1) + ret = nxmq_open(mqname, O_WRONLY, 0, NULL, &conn->swrmq); + if (ret < 0) { - gerr("ERROR: mq_open(%s) failed: %d\n", mqname, errno); + gerr("ERROR: nxmq_open(%s) failed: %d\n", mqname, ret); outmsg.msgid = NX_CLIMSG_DISCONNECTED; } @@ -205,12 +205,11 @@ static inline int nxmu_setup(FAR const char *mqname, FAR NX_DRIVERTYPE *dev, attr.mq_msgsize = NX_MXSVRMSGLEN; attr.mq_flags = 0; - nxmu->conn.crdmq = mq_open(mqname, O_RDONLY | O_CREAT, 0666, &attr); - if (nxmu->conn.crdmq == (mqd_t)-1) + ret = nxmq_open(mqname, O_RDONLY | O_CREAT, 0666, &attr, &nxmu->conn.crdmq); + if (ret < 0) { - int errcode = get_errno(); - gerr("ERROR: mq_open(%s) failed: %d\n", mqname, errcode); - return -errcode; + gerr("ERROR: nxmq_open(%s) failed: %d\n", mqname, ret); + return ret; } /* NOTE that the outgoing client MQ (cwrmq) is not initialized. The @@ -222,13 +221,12 @@ static inline int nxmu_setup(FAR const char *mqname, FAR NX_DRIVERTYPE *dev, * the server message loop. */ - nxmu->conn.swrmq = mq_open(mqname, O_WRONLY); - if (nxmu->conn.swrmq == (mqd_t)-1) + ret = nxmq_open(mqname, O_WRONLY, 0, NULL, &nxmu->conn.swrmq); + if (ret < 0) { - int errcode = get_errno(); - gerr("ERROR: mq_open(%s) failed: %d\n", mqname, errcode); - mq_close(nxmu->conn.crdmq); - return -errcode; + gerr("ERROR: nxmq_open(%s) failed: %d\n", mqname, ret); + nxmq_close(nxmu->conn.crdmq); + return ret; } /* The server is now "connected" to itself via the background window */ diff --git a/include/nuttx/power/battery_monitor.h b/include/nuttx/power/battery_monitor.h index e032d78eafa..456ba5bf06d 100644 --- a/include/nuttx/power/battery_monitor.h +++ b/include/nuttx/power/battery_monitor.h @@ -31,9 +31,10 @@ #include #include -#include #include +#include + #ifdef CONFIG_BATTERY_MONITOR /**************************************************************************** diff --git a/include/nuttx/sensors/mpu60x0.h b/include/nuttx/sensors/mpu60x0.h index cd450921dc8..537a341d883 100644 --- a/include/nuttx/sensors/mpu60x0.h +++ b/include/nuttx/sensors/mpu60x0.h @@ -82,7 +82,7 @@ struct i2c_master_s; * Or, if using dynamic memory allocation and I2C: * * struct mpu_config_s* mpuc; - * mpuc = malloc(sizeof(*mpuc)); + * mpuc = kmm_malloc(sizeof(*mpuc)); * memset(mpuc, 0, sizeof(*mpuc)); * sets spi to NULL, if present * * mpuc.i2c = ...; * diff --git a/include/nuttx/usb/usbdev.h b/include/nuttx/usb/usbdev.h index e32602e2cd5..96ebee0fba2 100644 --- a/include/nuttx/usb/usbdev.h +++ b/include/nuttx/usb/usbdev.h @@ -89,8 +89,8 @@ # define EP_ALLOCBUFFER(ep,nb) (ep)->ops->allocbuffer(ep,nb) # define EP_FREEBUFFER(ep,buf) (ep)->ops->freebuffer(ep,buf) #else -# define EP_ALLOCBUFFER(ep,nb) malloc(nb) -# define EP_FREEBUFFER(ep,buf) free(buf) +# define EP_ALLOCBUFFER(ep,nb) kmm_malloc(nb) +# define EP_FREEBUFFER(ep,buf) kmm_free(buf) #endif /* Submit an I/O request to the endpoint */ diff --git a/net/local/local_fifo.c b/net/local/local_fifo.c index 2b4f9b741c7..ebcc6f8c629 100644 --- a/net/local/local_fifo.c +++ b/net/local/local_fifo.c @@ -155,7 +155,7 @@ static bool local_fifo_exists(FAR const char *path) /* Create the client-to-server FIFO */ - ret = stat(path, &buf); + ret = nx_stat(path, &buf, 1); if (ret < 0) { return false; diff --git a/net/netlink/netlink_conn.c b/net/netlink/netlink_conn.c index 2261cf54924..5adc7aa6c99 100644 --- a/net/netlink/netlink_conn.c +++ b/net/netlink/netlink_conn.c @@ -434,7 +434,7 @@ netlink_get_response(FAR struct netlink_conn_s *conn) /* Set up a semaphore to notify us when a response is queued. */ - sem_init(&waitsem, 0, 0); + nxsem_init(&waitsem, 0, 0); nxsem_set_protocol(&waitsem, SEM_PRIO_NONE); /* Set up a notifier to post the semaphore when a response is @@ -456,7 +456,7 @@ netlink_get_response(FAR struct netlink_conn_s *conn) /* Clean-up the semaphore */ - sem_destroy(&waitsem); + nxsem_destroy(&waitsem); netlink_notifier_teardown(conn); /* Check for any failures */ diff --git a/net/route/net_fileroute.c b/net/route/net_fileroute.c index 1c7d517cc20..bd370dcb4bd 100644 --- a/net/route/net_fileroute.c +++ b/net/route/net_fileroute.c @@ -146,17 +146,14 @@ int net_routesize(FAR const char *path, size_t entrysize) /* Get information about the file */ - ret = stat(path, &buf); + ret = nx_stat(path, &buf, 1); if (ret < 0) { - int errcode; - - /* stat() failed, but is that because the routing table has not been + /* nx_stat() failed, but is that because the routing table has not been * created yet? */ - errcode = get_errno(); - if (errcode == ENOENT) + if (ret == -ENOENT) { /* The routing table file has not been created. Return size zero. */ @@ -165,7 +162,7 @@ int net_routesize(FAR const char *path, size_t entrysize) /* Some other error */ - return -errcode; + return ret; } /* The directory entry at this path must be a regular file */ diff --git a/sched/task/task_posixspawn.c b/sched/task/task_posixspawn.c index e5d5177fd2a..5e6754d81e0 100644 --- a/sched/task/task_posixspawn.c +++ b/sched/task/task_posixspawn.c @@ -415,10 +415,9 @@ int posix_spawn(FAR pid_t *pid, FAR const char *path, * for use within the OS. */ - ret = waitpid(proxy, &status, 0); + ret = nx_waitpid(proxy, &status, 0); if (ret < 0) { - ret = -get_errno(); serr("ERROR: waitpid() failed: %d\n", ret); goto errout_with_lock; } diff --git a/sched/task/task_spawn.c b/sched/task/task_spawn.c index ac335396217..fb27f93a486 100644 --- a/sched/task/task_spawn.c +++ b/sched/task/task_spawn.c @@ -416,10 +416,9 @@ int task_spawn(FAR pid_t *pid, FAR const char *name, main_t entry, * for use within the OS. */ - ret = waitpid(proxy, &status, 0); + ret = nx_waitpid(proxy, &status, 0); if (ret < 0) { - ret = -get_errno(); serr("ERROR: waitpid() failed: %d\n", ret); goto errout_with_lock; } diff --git a/sched/task/task_spawnparms.c b/sched/task/task_spawnparms.c index 3e7dffaedeb..61f1425c3fa 100644 --- a/sched/task/task_spawnparms.c +++ b/sched/task/task_spawnparms.c @@ -84,13 +84,11 @@ static inline int nxspawn_dup2(FAR struct spawn_dup2_file_action_s *action) sinfo("Dup'ing %d->%d\n", action->fd1, action->fd2); - ret = dup2(action->fd1, action->fd2); + ret = nx_dup2(action->fd1, action->fd2); if (ret < 0) { - int errcode = get_errno(); - - serr("ERROR: dup2 failed: %d\n", errcode); - return -errcode; + serr("ERROR: dup2 failed: %d\n", ret); + return ret; } return OK; @@ -123,10 +121,9 @@ static inline int nxspawn_open(FAR struct spawn_open_file_action_s *action) sinfo("Dup'ing %d->%d\n", fd, action->fd); - ret = dup2(fd, action->fd); + ret = nx_dup2(fd, action->fd); if (ret < 0) { - ret = get_errno(); serr("ERROR: dup2 failed: %d\n", ret); }