mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
research st: refine skt.
This commit is contained in:
parent
22710db911
commit
3377df0bea
1 changed files with 83 additions and 82 deletions
|
@ -46,7 +46,6 @@
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
|
||||||
/* How much space to leave between the stacks, at each end */
|
/* How much space to leave between the stacks, at each end */
|
||||||
#define REDZONE _ST_PAGE_SIZE
|
#define REDZONE _ST_PAGE_SIZE
|
||||||
|
|
||||||
|
@ -75,8 +74,9 @@ _st_stack_t *_st_stack_new(int stack_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make a new thread stack object. */
|
/* Make a new thread stack object. */
|
||||||
if ((ts = (_st_stack_t *)calloc(1, sizeof(_st_stack_t))) == NULL)
|
if ((ts = (_st_stack_t *)calloc(1, sizeof(_st_stack_t))) == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
extra = _st_randomize_stacks ? _ST_PAGE_SIZE : 0;
|
extra = _st_randomize_stacks ? _ST_PAGE_SIZE : 0;
|
||||||
ts->vaddr_size = stack_size + 2*REDZONE + extra;
|
ts->vaddr_size = stack_size + 2*REDZONE + extra;
|
||||||
ts->vaddr = _st_new_stk_segment(ts->vaddr_size);
|
ts->vaddr = _st_new_stk_segment(ts->vaddr_size);
|
||||||
|
@ -103,21 +103,20 @@ _st_stack_t *_st_stack_new(int stack_size)
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Free the stack for the current thread
|
* Free the stack for the current thread
|
||||||
*/
|
*/
|
||||||
void _st_stack_free(_st_stack_t *ts)
|
void _st_stack_free(_st_stack_t *ts)
|
||||||
{
|
{
|
||||||
if (!ts)
|
if (!ts) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Put the stack on the free list */
|
/* Put the stack on the free list */
|
||||||
ST_APPEND_LINK(&ts->links, _st_free_stacks.prev);
|
ST_APPEND_LINK(&ts->links, _st_free_stacks.prev);
|
||||||
_st_num_free_stacks++;
|
_st_num_free_stacks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *_st_new_stk_segment(int size)
|
static char *_st_new_stk_segment(int size)
|
||||||
{
|
{
|
||||||
#ifdef MALLOC_STACK
|
#ifdef MALLOC_STACK
|
||||||
|
@ -127,28 +126,29 @@ static char *_st_new_stk_segment(int size)
|
||||||
int mmap_flags = MAP_PRIVATE;
|
int mmap_flags = MAP_PRIVATE;
|
||||||
void *vaddr;
|
void *vaddr;
|
||||||
|
|
||||||
#if defined (MD_USE_SYSV_ANON_MMAP)
|
#if defined (MD_USE_SYSV_ANON_MMAP)
|
||||||
if (zero_fd < 0) {
|
if (zero_fd < 0) {
|
||||||
if ((zero_fd = open("/dev/zero", O_RDWR, 0)) < 0)
|
if ((zero_fd = open("/dev/zero", O_RDWR, 0)) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
fcntl(zero_fd, F_SETFD, FD_CLOEXEC);
|
fcntl(zero_fd, F_SETFD, FD_CLOEXEC);
|
||||||
}
|
}
|
||||||
#elif defined (MD_USE_BSD_ANON_MMAP)
|
#elif defined (MD_USE_BSD_ANON_MMAP)
|
||||||
mmap_flags |= MAP_ANON;
|
mmap_flags |= MAP_ANON;
|
||||||
#else
|
#else
|
||||||
#error Unknown OS
|
#error Unknown OS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vaddr = mmap(NULL, size, PROT_READ | PROT_WRITE, mmap_flags, zero_fd, 0);
|
vaddr = mmap(NULL, size, PROT_READ | PROT_WRITE, mmap_flags, zero_fd, 0);
|
||||||
if (vaddr == (void *)MAP_FAILED)
|
if (vaddr == (void *)MAP_FAILED) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* MALLOC_STACK */
|
#endif
|
||||||
|
|
||||||
return (char *)vaddr;
|
return (char *)vaddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Not used */
|
/* Not used */
|
||||||
#if 0
|
#if 0
|
||||||
void _st_delete_stk_segment(char *vaddr, int size)
|
void _st_delete_stk_segment(char *vaddr, int size)
|
||||||
|
@ -166,8 +166,9 @@ int st_randomize_stacks(int on)
|
||||||
int wason = _st_randomize_stacks;
|
int wason = _st_randomize_stacks;
|
||||||
|
|
||||||
_st_randomize_stacks = on;
|
_st_randomize_stacks = on;
|
||||||
if (on)
|
if (on) {
|
||||||
srandom((unsigned int) st_utime());
|
srandom((unsigned int) st_utime());
|
||||||
|
}
|
||||||
|
|
||||||
return wason;
|
return wason;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue