From 843e74b038b53bde526dbf0ef35d008d1f3ff85b Mon Sep 17 00:00:00 2001 From: chengh Date: Mon, 21 Nov 2022 22:23:01 +0800 Subject: [PATCH] Support st_destroy to free resources for asan. --- README.md | 1 + common.h | 1 + event.c | 31 +++++++++++++++++++++++++++---- public.h | 1 + sched.c | 9 +++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 625aa46..67d224a 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ The branch [srs](https://github.com/ossrs/state-threads/tree/srs) was patched an - [x] Define and use a new jmpbuf, because the structure is different. - [x] Check capability for backtrack. - [x] Support set specifics for any thread. +- [x] Support st_destroy to free resources for asan. - [ ] System: Support sendmmsg for UDP, [#12](https://github.com/ossrs/state-threads/issues/12). ## GDB Tools diff --git a/common.h b/common.h index ab3a0c1..acedf3d 100644 --- a/common.h +++ b/common.h @@ -226,6 +226,7 @@ typedef struct _st_eventsys_ops { int (*fd_new)(int); /* New descriptor allocated */ int (*fd_close)(int); /* Descriptor closed */ int (*fd_getlimit)(void); /* Descriptor hard limit */ + void (*destroy)(void); /* Destroy the event object */ } _st_eventsys_t; diff --git a/event.c b/event.c index ae064af..00a951c 100644 --- a/event.c +++ b/event.c @@ -430,6 +430,11 @@ ST_HIDDEN int _st_select_fd_getlimit(void) return FD_SETSIZE; } +ST_HIDDEN void _st_select_destroy(void) +{ + /* TODO: FIXME: Implements it */ +} + static _st_eventsys_t _st_select_eventsys = { "select", ST_EVENTSYS_SELECT, @@ -439,7 +444,8 @@ static _st_eventsys_t _st_select_eventsys = { _st_select_pollset_del, _st_select_fd_new, _st_select_fd_close, - _st_select_fd_getlimit + _st_select_fd_getlimit, + _st_select_destroy }; #endif @@ -838,6 +844,11 @@ ST_HIDDEN int _st_kq_fd_getlimit(void) return 0; } +ST_HIDDEN void _st_kq_destroy(void) +{ + /* TODO: FIXME: Implements it */ +} + static _st_eventsys_t _st_kq_eventsys = { "kqueue", ST_EVENTSYS_ALT, @@ -847,7 +858,8 @@ static _st_eventsys_t _st_kq_eventsys = { _st_kq_pollset_del, _st_kq_fd_new, _st_kq_fd_close, - _st_kq_fd_getlimit + _st_kq_fd_getlimit, + _st_kq_destroy }; #endif /* MD_HAVE_KQUEUE */ @@ -856,7 +868,6 @@ static _st_eventsys_t _st_kq_eventsys = { /***************************************** * epoll event system */ - ST_HIDDEN int _st_epoll_init(void) { int fdlim; @@ -1193,6 +1204,17 @@ ST_HIDDEN int _st_epoll_is_supported(void) return (errno != ENOSYS); } +ST_HIDDEN void _st_epoll_destroy(void) +{ + if (_st_epoll_data->epfd >= 0) { + close(_st_epoll_data->epfd); + } + free(_st_epoll_data->fd_data); + free(_st_epoll_data->evtlist); + free(_st_epoll_data); + _st_epoll_data = NULL; +} + static _st_eventsys_t _st_epoll_eventsys = { "epoll", ST_EVENTSYS_ALT, @@ -1202,7 +1224,8 @@ static _st_eventsys_t _st_epoll_eventsys = { _st_epoll_pollset_del, _st_epoll_fd_new, _st_epoll_fd_close, - _st_epoll_fd_getlimit + _st_epoll_fd_getlimit, + _st_epoll_destroy }; #endif /* MD_HAVE_EPOLL */ diff --git a/public.h b/public.h index a2ef167..97da146 100644 --- a/public.h +++ b/public.h @@ -156,6 +156,7 @@ extern int st_sendmsg(st_netfd_t fd, const struct msghdr *msg, int flags, st_uti extern st_netfd_t st_open(const char *path, int oflags, mode_t mode); +extern void st_destroy(void); extern int st_thread_setspecific2(st_thread_t thread, int key, void *value); #ifdef DEBUG diff --git a/sched.c b/sched.c index 9c19765..176e9d1 100644 --- a/sched.c +++ b/sched.c @@ -229,6 +229,15 @@ int st_init(void) } +/* + * Destroy this Virtual Processor + */ +void st_destroy(void) +{ + (*_st_eventsys->destroy)(); +} + + #ifdef ST_SWITCH_CB st_switch_cb_t st_set_switch_in_cb(st_switch_cb_t cb) {