lwip: Make LWIP_SOCKET_OFFSET signed, remove need for underflow check

This reverts commit 541493d877.
This commit is contained in:
Angus Gratton 2017-10-20 18:00:36 +08:00 committed by Angus Gratton
parent 22756b6c02
commit e5ae0f5927
5 changed files with 9 additions and 9 deletions

View File

@ -431,9 +431,9 @@ typedef struct ip_mreq {
/* Make FD_SETSIZE match NUM_SOCKETS in socket.c */
#define FD_SETSIZE MEMP_NUM_NETCONN
#define FDSETSAFESET(n, code) do { \
if (n >= LWIP_SOCKET_OFFSET && ((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \
if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \
code; }} while(0)
#define FDSETSAFEGET(n, code) (n >= LWIP_SOCKET_OFFSET && ((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\
#define FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\
(code) : 0)
#define FD_SET(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] |= (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
#define FD_CLR(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] &= ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))

View File

@ -19,7 +19,7 @@ extern "C" {
/* Internal declarations used to ingreate LWIP port layer
to ESP-IDF VFS for POSIX I/O.
*/
extern unsigned lwip_socket_offset;
extern int lwip_socket_offset;
void esp_vfs_lwip_sockets_register();

View File

@ -37,7 +37,7 @@
FDs that the user sees are the same FDs.
*/
unsigned lwip_socket_offset;
int lwip_socket_offset;
static int lwip_fcntl_r_wrapper(int fd, int cmd, va_list args);
static int lwip_ioctl_r_wrapper(int fd, int cmd, va_list args);
@ -54,14 +54,14 @@ void esp_vfs_lwip_sockets_register()
.fcntl = &lwip_fcntl_r_wrapper,
.ioctl = &lwip_ioctl_r_wrapper,
};
unsigned max_fd;
int max_fd;
ESP_ERROR_CHECK(esp_vfs_register_socket_space(&vfs, NULL, &lwip_socket_offset, &max_fd));
/* LWIP can't be allowed to create more sockets than fit in the per-VFS fd space. Currently this isn't configurable
* but it's set much larger than CONFIG_LWIP_MAX_SOCKETS should ever be (max 2^12 FDs).
*/
assert(CONFIG_LWIP_MAX_SOCKETS <= max_fd - lwip_socket_offset);
assert(max_fd >= lwip_socket_offset && CONFIG_LWIP_MAX_SOCKETS <= max_fd - lwip_socket_offset);
}
static int lwip_fcntl_r_wrapper(int fd, int cmd, va_list args)

View File

@ -205,7 +205,7 @@ esp_err_t esp_vfs_register(const char* base_path, const esp_vfs_t* vfs, void* ct
* @return ESP_OK if successful, ESP_ERR_NO_MEM if too many VFSes are
* registered.
*/
esp_err_t esp_vfs_register_socket_space(const esp_vfs_t *vfs, void *ctx, unsigned *p_min_fd, unsigned *p_max_fd);
esp_err_t esp_vfs_register_socket_space(const esp_vfs_t *vfs, void *ctx, int *p_min_fd, int *p_max_fd);
/**
* Unregister a virtual filesystem for given path prefix

View File

@ -54,7 +54,7 @@ typedef struct vfs_entry_ {
static vfs_entry_t* s_vfs[VFS_MAX_COUNT] = { 0 };
static size_t s_vfs_count = 0;
static esp_err_t esp_vfs_register_common(const char* base_path, size_t len, const esp_vfs_t* vfs, void* ctx, unsigned *p_minimum_fd, unsigned *p_maximum_fd)
static esp_err_t esp_vfs_register_common(const char* base_path, size_t len, const esp_vfs_t* vfs, void* ctx, int *p_minimum_fd, int *p_maximum_fd)
{
if (len != LEN_PATH_PREFIX_IGNORED) {
if ((len != 0 && len < 2) || (len > ESP_VFS_PATH_MAX)) {
@ -107,7 +107,7 @@ esp_err_t esp_vfs_register(const char* base_path, const esp_vfs_t* vfs, void* ct
return esp_vfs_register_common(base_path, strlen(base_path), vfs, ctx, NULL, NULL);
}
esp_err_t esp_vfs_register_socket_space(const esp_vfs_t *vfs, void *ctx, unsigned *p_min_fd, unsigned *p_max_fd)
esp_err_t esp_vfs_register_socket_space(const esp_vfs_t *vfs, void *ctx, int *p_min_fd, int *p_max_fd)
{
return esp_vfs_register_common("", LEN_PATH_PREFIX_IGNORED, vfs, ctx, p_min_fd, p_max_fd);
}