Skip to content

Commit

Permalink
ST: Enable asan for ST when configuring.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Aug 22, 2024
1 parent 4766ceb commit e507b50
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
4 changes: 4 additions & 0 deletions trunk/auto/depends.sh
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ fi
if [[ $SRS_DEBUG_STATS == YES ]]; then
_ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DDEBUG_STATS"
fi
# Whether to enable asan.
if [[ $SRS_SANITIZER == YES ]]; then
_ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_ASAN -fsanitize=address -fno-omit-frame-pointer"
fi
# Pass the global extra flags.
if [[ $SRS_EXTRA_FLAGS != '' ]]; then
_ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS $SRS_EXTRA_FLAGS"
Expand Down
4 changes: 0 additions & 4 deletions trunk/research/st/asan-switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ g++ asan-switch.cpp ../../objs/st/libst.a -fsanitize=address -fno-omit-frame-poi
#include <sys/resource.h>
#include "../../objs/st/st.h"

extern "C" {
extern void st_set_primordial_stack(void* top, void* bottom);
}

void* foo(void *args) {
for (int i = 0; ; i++) {
st_sleep(1);
Expand Down
6 changes: 6 additions & 0 deletions trunk/src/main/srs_main_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ srs_error_t do_main(int argc, char** argv, char** envp)

int main(int argc, char** argv, char** envp)
{
#ifdef SRS_SANITIZER
// Setup the primordial stack for st.
register void* stack_top asm ("sp") = NULL;
srs_set_primordial_stack(stack_top);
#endif

srs_error_t err = do_main(argc, argv, envp);

if (err != srs_success) {
Expand Down
18 changes: 18 additions & 0 deletions trunk/src/protocol/srs_protocol_st.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <st.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/resource.h>
#include <netdb.h>
using namespace std;

Expand Down Expand Up @@ -38,6 +39,23 @@ bool srs_st_epoll_is_supported(void)
}
#endif

#ifdef SRS_SANITIZER
void srs_set_primordial_stack(void *stack_top)
{
if (!stack_top) {
return;
}

struct rlimit limit;
if (getrlimit (RLIMIT_STACK, &limit) != 0) {
return;
}

void* stack_bottom = (char*)stack_top - (uint64_t)limit.rlim_cur;
st_set_primordial_stack(stack_top, stack_bottom);
}
#endif

srs_error_t srs_st_init()
{
#ifdef __linux__
Expand Down
6 changes: 6 additions & 0 deletions trunk/src/protocol/srs_protocol_st.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ typedef void* srs_thread_t;
typedef void* srs_cond_t;
typedef void* srs_mutex_t;


#ifdef SRS_SANITIZER
// Setup the primordial stack for asan detecting.
void srs_set_primordial_stack(void *top);
#endif

// Initialize ST, requires epoll for linux.
extern srs_error_t srs_st_init();
// Destroy ST, free resources for asan detecting.
Expand Down

0 comments on commit e507b50

Please sign in to comment.