void * tmp_alloc(size_t size) { void * p; LINK * l; assert(is_dispatch_thread()); if (!tmp_gc_posted) { post_event(gc_event, NULL); tmp_gc_posted = 1; } #if ENABLE_FastMemAlloc if (tmp_pool_pos + size + ALIGNMENT + sizeof(size_t *) > tmp_pool_max) { if (tmp_pool != NULL) { l = (LINK *)tmp_pool; list_add_last(l, &tmp_alloc_list); tmp_alloc_size += tmp_pool_pos; } tmp_pool_max = POOL_SIZE / 0x10 + size; tmp_pool = (char *)loc_alloc(tmp_pool_max); tmp_pool_pos = sizeof(LINK); } tmp_pool_pos += sizeof(size_t *); tmp_pool_pos = (tmp_pool_pos + ALIGNMENT - 1) & ~(ALIGNMENT - 1); p = tmp_pool + tmp_pool_pos; *((size_t *)p - 1) = size; tmp_pool_pos += size; return p; #else l = (LINK *)loc_alloc(sizeof(LINK) + size); list_add_last(l, &tmp_alloc_list); tmp_alloc_size += size + ALIGNMENT + sizeof(size_t *); p = l + 1; return p; #endif }
void virtual_stream_create(const char * type, const char * context_id, size_t buf_len, unsigned access, VirtualStreamCallBack * callback, void * callback_args, VirtualStream ** res) { LINK * l; VirtualStream * stream = loc_alloc_zero(sizeof(VirtualStream)); buf_len++; list_init(&stream->clients); strncpy(stream->type, type, sizeof(stream->type) - 1); stream->magic = STREAM_MAGIC; stream->id = id_cnt++; stream->access = access; stream->callback = callback; stream->callback_args = callback_args; stream->ref_cnt = 1; stream->buf = loc_alloc(buf_len); stream->buf_len = buf_len; for (l = subscriptions.next; l != &subscriptions; l = l->next) { Subscription * h = all2subscription(l); if (strcmp(type, h->type) == 0) { Trap trap; create_client(stream, h->channel); if (set_trap(&trap)) { send_event_stream_created(&h->channel->out, stream, context_id); clear_trap(&trap); } else { trace(LOG_ALWAYS, "Exception sending stream created event: %d %s", trap.error, errno_to_str(trap.error)); } } } list_add_first(&stream->link_all, &streams); *res = stream; }
static void add_report_prop(ReportBuffer * report, const char * name, ByteArrayOutputStream * buf) { ErrorReportItem * i = (ErrorReportItem *)loc_alloc(sizeof(ErrorReportItem)); i->name = loc_strdup(name); get_byte_array_output_stream_data(buf, &i->value, NULL); i->next = report->pub.props; report->pub.props = i; }
static void command_read(char * token, Channel * c) { char id[256]; OpenFileInfo * h = NULL; int64_t offset; unsigned long len; json_read_string(&c->inp, id, sizeof(id)); if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX); offset = json_read_int64(&c->inp); if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX); len = json_read_ulong(&c->inp); if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX); if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX); h = find_open_file_info(id); if (h == NULL) { reply_read(token, &c->out, EBADF, NULL, 0, 0); } else { IORequest * req = create_io_request(token, h, REQ_READ); if (offset < 0) { req->info.type = AsyncReqRead; } else { req->info.type = AsyncReqSeekRead; req->info.u.fio.offset = (off_t)offset; } req->info.u.fio.fd = h->file; req->info.u.fio.bufp = loc_alloc(len); req->info.u.fio.bufsz = len; post_io_requst(h); } }
void ini_portforward_server(int service_id, Protocol *proto, TCFBroadcastGroup * bcg) { char * service_name = loc_alloc(strlen("PortServer") + 30); if (service_id != 0) sprintf(service_name, "PortServer@%d", service_id); else sprintf(service_name, "PortServer"); add_command_handler(proto, service_name, "create", port_server_cmd_create); add_command_handler(proto, service_name, "delete", port_server_cmd_delete); }
PeerServer * peer_server_alloc(void) { PeerServer * s = (PeerServer *)loc_alloc_zero(sizeof *s); s->max = 8; s->list = (PeerServerList *)loc_alloc(s->max * sizeof *s->list); return s; }
void cache_wait(AbstractCache * cache) { #else void cache_wait_dbg(const char * file, int line, AbstractCache * cache) { #endif assert(is_dispatch_thread()); assert(client_exited == 0); if (current_client.client != NULL && cache_miss_cnt == 0) { if (cache->wait_list_cnt >= cache->wait_list_max) { cache->wait_list_max += 8; cache->wait_list_buf = (WaitingCacheClient *)loc_realloc(cache->wait_list_buf, cache->wait_list_max * sizeof(WaitingCacheClient)); } if (current_client.args != NULL && !current_client.args_copy) { void * mem = loc_alloc(current_client.args_size); memcpy(mem, current_client.args, current_client.args_size); current_client.args = mem; current_client.args_copy = 1; } #ifndef NDEBUG current_client.file = file; current_client.line = line; #endif if (cache->wait_list_cnt == 0) list_add_last(&cache->link, &cache_list); cache->wait_list_buf[cache->wait_list_cnt++] = current_client; channel_lock(current_client.channel); } #ifndef NDEBUG else if (current_client.client == NULL) { trace(LOG_ALWAYS, "cache_wait(): illegal cache access at %s:%d", file, line); } #endif cache_miss_cnt++; exception(ERR_CACHE_MISS); }
/* strdup2() with concatenation and end-of-memory checking. */ char * loc_strdup2(const char * s1, const char * s2) { size_t l1 = strlen(s1); size_t l2 = strlen(s2); char * rval = (char *)loc_alloc(l1 + l2 + 1); memcpy(rval, s1, l1); memcpy(rval + l1, s2, l2 + 1); return rval; }
void sigset_copy(SigSet * dst, SigSet * src) { dst->cnt = src->cnt; dst->max = src->cnt; dst->buf = NULL; if (dst->max > 0) { dst->buf = (unsigned *)loc_alloc(sizeof(unsigned) * dst->max); memcpy(dst->buf, src->buf, sizeof(unsigned) * dst->cnt); } }
void ini_port_server_service(const char * name_ext, Protocol * proto, TCFBroadcastGroup * bcg) { char * service_name = (char *)loc_alloc(strlen("PortServer") + (name_ext == NULL ? 1 : strlen(name_ext) + 1)); sprintf(service_name, "PortServer%s", name_ext == NULL ? "" : name_ext); add_command_handler(proto, service_name, "getConfig", port_server_cmd_get_config); add_command_handler(proto, service_name, "create", port_server_cmd_create); add_command_handler(proto, service_name, "list", port_server_cmd_list); add_command_handler(proto, service_name, "delete", port_server_cmd_delete); add_command_handler(proto, service_name, "getCapabilities", port_server_cmd_get_capabilities); }
static struct luaref *luaref_new(lua_State *L, void * owner) { struct luaref *refp = (struct luaref *)loc_alloc(sizeof *refp); refp->ref = luaL_ref(L, LUA_REGISTRYINDEX); refp->owner = owner; refp->next = refroot; refroot = refp; return refp; }
static void realloc_buf(void) { if (buf == NULL) { buf_size = 0x1000; buf = (char *)loc_alloc(buf_size); } else { buf_size *= 2; buf = (char *)loc_realloc(buf, buf_size); } }
static Location * read_location_list(InputStream * inp, unsigned * cnt) { Location * locs = NULL; buf_pos = 0; json_read_array(inp, read_location, NULL); locs = (Location *)loc_alloc(buf_pos * sizeof(Location)); memcpy(locs, buf, buf_pos * sizeof(Location)); *cnt = buf_pos; return locs; }
int run_test_process(ContextAttachCallBack * done, void * data) { #if defined(WIN32) char fnm[FILE_PATH_SIZE]; char cmd[FILE_PATH_SIZE]; int res = 0; STARTUPINFO si; PROCESS_INFORMATION prs; ContextAttachArgs * args; memset(&si, 0, sizeof(si)); memset(&prs, 0, sizeof(prs)); memset(fnm, 0, sizeof(fnm)); if (GetModuleFileName(NULL, fnm, sizeof(fnm)) == 0) { set_win32_errno(GetLastError()); return -1; } si.cb = sizeof(si); strcpy(cmd, "agent.exe -t"); if (CreateProcess(fnm, cmd, NULL, NULL, FALSE, CREATE_SUSPENDED | CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW, NULL, NULL, &si, &prs) == 0) { set_win32_errno(GetLastError()); return -1; } args = (ContextAttachArgs *)loc_alloc(sizeof(ContextAttachArgs)); args->done = done; args->data = data; args->thread = prs.hThread; args->process = prs.hProcess; res = context_attach(prs.dwProcessId, done_context_attach, args, 0); if (res != 0) loc_free(args); return res; #elif defined(_WRS_KERNEL) int tid = taskCreate("tTcf", 100, 0, 0x4000, (FUNCPTR)test_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); if (tid == 0) return -1; taskStop(tid); taskActivate(tid); assert(taskIsStopped(tid)); return context_attach(tid, done, data, 0); #else /* Create child process to debug */ int pid = fork(); if (pid < 0) return -1; if (pid == 0) { int fd; if (context_attach_self() < 0) exit(1); fd = sysconf(_SC_OPEN_MAX); while (fd-- > 2) close(fd); if (tkill(getpid(), SIGSTOP) < 0) exit(1); test_proc(); exit(0); } return context_attach(pid, done, data, CONTEXT_ATTACH_SELF); #endif }
static void run_cache_client(int retry) { Trap trap; unsigned i; unsigned id = current_client.id; void * args_copy = NULL; assert(id != 0); current_cache = NULL; cache_miss_cnt = 0; def_channel = NULL; if (current_client.args_copy) args_copy = current_client.args; for (i = 0; i < listeners_cnt; i++) listeners[i](retry ? CTLE_RETRY : CTLE_START); if (set_trap(&trap)) { current_client.client(current_client.args); clear_trap(&trap); assert(current_client.id == 0); assert(cache_miss_cnt == 0); } else if (id != current_client.id) { trace(LOG_ALWAYS, "Unhandled exception in data cache client: %s", errno_to_str(trap.error)); assert(current_client.id == 0); assert(cache_miss_cnt == 0); } else { if (get_error_code(trap.error) != ERR_CACHE_MISS || cache_miss_cnt == 0 || current_cache == NULL) { trace(LOG_ALWAYS, "Unhandled exception in data cache client: %s", errno_to_str(trap.error)); for (i = 0; i < listeners_cnt; i++) listeners[i](CTLE_COMMIT); } else { AbstractCache * cache = current_cache; if (cache->wait_list_cnt >= cache->wait_list_max) { cache->wait_list_max += 8; cache->wait_list_buf = (WaitingCacheClient *)loc_realloc(cache->wait_list_buf, cache->wait_list_max * sizeof(WaitingCacheClient)); } if (current_client.args != NULL && !current_client.args_copy) { void * mem = loc_alloc(current_client.args_size); memcpy(mem, current_client.args, current_client.args_size); current_client.args = mem; current_client.args_copy = 1; } if (cache->wait_list_cnt == 0) list_add_last(&cache->link, &cache_list); if (current_client.channel != NULL) channel_lock_with_msg(current_client.channel, channel_lock_msg); cache->wait_list_buf[cache->wait_list_cnt++] = current_client; for (i = 0; i < listeners_cnt; i++) listeners[i](CTLE_ABORT); args_copy = NULL; } memset(¤t_client, 0, sizeof(current_client)); current_cache = NULL; cache_miss_cnt = 0; def_channel = NULL; } if (args_copy != NULL) loc_free(args_copy); }
int context_attach(pid_t pid, ContextAttachCallBack * done, void * data, int mode) { AttachDoneArgs * args = (AttachDoneArgs *)loc_alloc(sizeof(AttachDoneArgs)); assert(done != NULL); assert((mode & CONTEXT_ATTACH_SELF) == 0); args->pid = pid; args->done = done; args->data = data; post_event(event_attach_done, args); return 0; }
void peer_server_add_listener(peer_server_listener fnp, void * arg) { if (listeners_max == 0) { listeners_max = 4; listeners = (PeersListener *)loc_alloc(listeners_max * sizeof(PeersListener)); } else if (listeners_cnt == listeners_max) { listeners_max *= 2; listeners = (PeersListener *)loc_realloc(listeners, listeners_max * sizeof(PeersListener)); } listeners[listeners_cnt].fnp = fnp; listeners[listeners_cnt].arg = arg; listeners_cnt++; }
static void command_write(char * token, Channel * c) { char id[256]; OpenFileInfo * h = NULL; int64_t offset; unsigned long len = 0; JsonReadBinaryState state; static size_t buf_size = 0; static char * buf = NULL; json_read_string(&c->inp, id, sizeof(id)); if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX); offset = json_read_int64(&c->inp); if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX); json_read_binary_start(&state, &c->inp); h = find_open_file_info(id); for (;;) { int rd; if (buf_size < len + BUF_SIZE) { buf_size += BUF_SIZE; buf = loc_realloc(buf, buf_size); } rd = json_read_binary_data(&state, buf + len, buf_size - len); if (rd == 0) break; len += rd; } json_read_binary_end(&state); if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX); if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX); if (h == NULL) { reply_write(token, &c->out, EBADF); } else { IORequest * req = create_io_request(token, h, REQ_WRITE); if (offset < 0) { req->info.type = AsyncReqWrite; } else { req->info.type = AsyncReqSeekWrite; req->info.u.fio.offset = (off_t)offset; } req->info.u.fio.fd = h->file; req->info.u.fio.bufp = loc_alloc(len); req->info.u.fio.bufsz = len; memcpy(req->info.u.fio.bufp, buf, len); post_io_requst(h); } }
int set_errno(int no, const char * msg) { errno = no; if (no != 0 && msg != NULL) { ErrorMessage * m = alloc_msg(SRC_MESSAGE); /* alloc_msg() assigns new value to 'errno', * need to be sure it does not change until this function exits. */ int err = errno; m->error = get_error_code(no); if (no == ERR_OTHER) { m->text = loc_strdup(msg); } else { size_t msg_len = strlen(msg); if (msg_len == 0) { m->text = loc_strdup(errno_to_str(no)); } else { const char * text0 = tmp_strdup(msg); const char * text1 = errno_to_str(no); if (text0[msg_len - 1] == '.' || text0[msg_len - 1] == '\n') { size_t len = msg_len + strlen(text1) + 2; char * text2 = (char *)loc_alloc(len); snprintf(text2, len, "%s %s", text0, text1); m->text = text2; } else { size_t len = msg_len + strlen(text1) + 3; char * text2 = (char *)loc_alloc(len); snprintf(text2, len, "%s. %s", text0, text1); m->text = text2; } } } errno = err; } return errno; }
static event_node * alloc_node(void (*handler)(void *), void * arg) { event_node * node; if (free_queue != NULL) { node = free_queue; free_queue = node->next; free_queue_size--; } else { node = (event_node *)loc_alloc(sizeof(event_node)); } memset(node, 0, sizeof(event_node)); node->handler = handler; node->arg = arg; return node; }
static MemoryCommandArgs * read_command_args(char * token, Channel * c, int cmd) { int err = 0; char id[256]; MemoryCommandArgs buf; memset(&buf, 0, sizeof(buf)); json_read_string(&c->inp, id, sizeof(id)); json_test_char(&c->inp, MARKER_EOA); buf.addr = (ContextAddress)json_read_uint64(&c->inp); json_test_char(&c->inp, MARKER_EOA); buf.word_size = (int)json_read_long(&c->inp); json_test_char(&c->inp, MARKER_EOA); buf.size = (int)json_read_long(&c->inp); json_test_char(&c->inp, MARKER_EOA); buf.mode = (int)json_read_long(&c->inp); json_test_char(&c->inp, MARKER_EOA); if (cmd == CMD_GET) json_test_char(&c->inp, MARKER_EOM); buf.ctx = id2ctx(id); if (buf.ctx == NULL) err = ERR_INV_CONTEXT; else if (buf.ctx->exited) err = ERR_ALREADY_EXITED; else if (buf.ctx->mem_access == 0) err = ERR_INV_CONTEXT; if (err != 0) { if (cmd != CMD_GET) { int ch; do ch = read_stream(&c->inp); while (ch != MARKER_EOM && ch != MARKER_EOS); } write_stringz(&c->out, "R"); write_stringz(&c->out, token); if (cmd == CMD_GET) write_stringz(&c->out, "null"); write_errno(&c->out, err); write_stringz(&c->out, "null"); write_stream(&c->out, MARKER_EOM); return NULL; } else { MemoryCommandArgs * args = (MemoryCommandArgs *)loc_alloc(sizeof(MemoryCommandArgs)); *args = buf; args->c = c; strlcpy(args->token, token, sizeof(args->token)); channel_lock(c); context_lock(buf.ctx); return args; } }
int get_symbol_children(const Symbol * sym, Symbol *** children, int * count) { static const DWORD FINDCHILDREN_BUF_SIZE = 64; static TI_FINDCHILDREN_PARAMS * params = NULL; static Symbol ** buf = NULL; static unsigned buf_len = 0; DWORD cnt = 0; Symbol type = *sym; DWORD tag = 0; assert(sym->magic == SYMBOL_MAGIC); if (sym->base || sym->info) { *children = NULL; *count = 0; return 0; } if (get_type_tag(&type, &tag)) return -1; if (get_type_info(&type, TI_GET_CHILDRENCOUNT, &cnt) < 0) return -1; if (params == NULL) params = (TI_FINDCHILDREN_PARAMS *)loc_alloc( sizeof(TI_FINDCHILDREN_PARAMS) + (FINDCHILDREN_BUF_SIZE - 1) * sizeof(ULONG)); if (buf_len < cnt) { buf = (Symbol **)loc_realloc(buf, sizeof(Symbol *) * cnt); buf_len = cnt; } params->Start = 0; while (params->Start < cnt) { DWORD i = cnt - (DWORD)params->Start; params->Count = i > FINDCHILDREN_BUF_SIZE ? FINDCHILDREN_BUF_SIZE : i; if (get_type_info(&type, TI_FINDCHILDREN, params) < 0) return -1; for (i = 0; params->Start < cnt; i++) { DWORD dword = 0; Symbol * x = alloc_symbol(); *x = *sym; x->index = params->ChildId[i]; if (get_type_info(x, TI_GET_SYMTAG, &dword) < 0) return -1; tag2symclass(x, dword); buf[params->Start++] = x; } } *children = buf; *count = cnt; return 0; }
void post_safe_event(int mem, EventCallBack * done, void * arg) { SafeEvent * i = (SafeEvent *)loc_alloc(sizeof(SafeEvent)); i->mem = mem; i->done = done; i->arg = arg; if (safe_event_list == NULL) { assert(safe_event_pid_count == 0); if (!are_channels_suspended(suspend_group)) { channels_suspend(suspend_group); cmdline_suspend(); post_event(run_safe_events, (void *)++safe_event_generation); } } assert(are_channels_suspended(suspend_group)); i->next = safe_event_list; safe_event_list = i; }
int pthread_create(pthread_t * res, const pthread_attr_t * attr, void * (*start)(void *), void * args) { HANDLE thread = NULL; DWORD thread_id = 0; ThreadArgs * a = (ThreadArgs *)loc_alloc(sizeof(ThreadArgs)); a->start = start; a->args = args; thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)start_thread, a, 0, &thread_id); if (thread == NULL) { int err = set_win32_errno(GetLastError()); loc_free(a); return errno = err; } if (!CloseHandle(thread)) return set_win32_errno(GetLastError()); *res = (pthread_t)thread_id; return 0; }
static void np_post_read(InputBuf * ibuf, unsigned char * buf, size_t size) { ChannelNP * c = ibuf2np(ibuf); NpIOReq * req; if (c->read_pending) return; req = loc_alloc(sizeof(NpIOReq)); req->bufp = buf; req->bufsz = size; req->np_sock = c->np_socket; c->read_pending = 1; c->read_buf = buf; c->read_buf_size = size; c->rd_req.u.user.func = np_wt_read_request; c->rd_req.u.user.data = req; c->rd_req.type = AsyncReqUser; async_req_post(&c->rd_req); trace(LOG_PROTOCOL, "post read request "); }
static void post_write_request(OutputBuffer * bf) { ChannelNP * c = obuf2np(bf->queue); assert(c->socket != NOPOLL_INVALID_SOCKET); c->wr_req.client_data = c; c->wr_req.done = done_write_request; { NpIOReq * req = loc_alloc( sizeof(NpIOReq)); req->bufp = bf->buf + bf->buf_pos; req->bufsz = bf->buf_len - bf->buf_pos; req->np_sock = c->np_socket; c->wr_req.type = AsyncReqUser; c->wr_req.u.user.data = req; c->wr_req.u.user.func = np_wt_write_request; async_req_post(&c->wr_req); } np_lock(&c->chan); }
static void event_attach_done(void * x) { AttachDoneArgs * args = (AttachDoneArgs *)x; if (context_find_from_pid(args->pid, 0) != NULL) { args->done(ERR_ALREADY_ATTACHED, NULL, args->data); } else { Context * ctx = NULL; if (parent_ctx == NULL) { pid_t pid = taskIdSelf(); parent_ctx = create_context(pid2id(pid, 0)); EXT(parent_ctx)->pid = pid; parent_ctx->mem = parent_ctx; parent_ctx->mem_access |= MEM_ACCESS_INSTRUCTION; parent_ctx->mem_access |= MEM_ACCESS_DATA; parent_ctx->big_endian = big_endian_host(); link_context(parent_ctx); send_context_created_event(parent_ctx); } assert(parent_ctx->ref_count > 0); ctx = create_context(pid2id(args->pid, EXT(parent_ctx)->pid)); EXT(ctx)->pid = args->pid; EXT(ctx)->regs = (REG_SET *)loc_alloc(sizeof(REG_SET)); ctx->mem = parent_ctx; ctx->big_endian = parent_ctx->big_endian; (ctx->parent = parent_ctx)->ref_count++; list_add_last(&ctx->cldl, &parent_ctx->children); link_context(ctx); trace(LOG_CONTEXT, "context: attached: ctx %#lx, id %#x", ctx, EXT(ctx)->pid); send_context_created_event(ctx); args->done(0, ctx, args->data); if (taskIsStopped(args->pid)) { struct event_info * info; ctx->pending_intercept = 1; info = event_info_alloc(EVENT_HOOK_STOP); if (info != NULL) { info->stopped_ctx.ctxId = args->pid; event_info_post(info); } } } loc_free(x); }
int terminate_debug_context(TCFBroadcastGroup * bcg, Context * ctx) { int err = 0; if (ctx == NULL) { err = ERR_INV_CONTEXT; } else if (ctx->exited) { err = ERR_ALREADY_EXITED; } else { TerminateArgs * args = (TerminateArgs *)loc_alloc(sizeof(TerminateArgs)); args->ctx = ctx; args->bcg = bcg; context_lock(ctx); post_safe_event(ctx->mem, event_terminate, args); } if (err) { errno = err; return -1; } return 0; }
static void * event_thread_func(void * arg) { taskPrioritySet(0, VX_TASK_PRIORITY_MIN); for (;;) { struct event_info * info = loc_alloc(sizeof(struct event_info)); semTake(events_signal, WAIT_FOREVER); SPIN_LOCK_ISR_TAKE(&events_lock); if (events_buf_overflow && events_inp == events_out) { SPIN_LOCK_ISR_GIVE(&events_lock); loc_free(info); break; } assert(events_inp != events_out); *info = events[events_out]; events_out = (events_out + 1) % MAX_EVENTS; SPIN_LOCK_ISR_GIVE(&events_lock); post_event(event_handler, info); } post_event(event_error, NULL); return NULL; }
static void np_server_accept_done(void * x) { AsyncReqInfo * req = (AsyncReqInfo *)x; ServerNP * si = (ServerNP *)req->client_data; if (si->sock < 0) { /* Server closed. */ loc_free(si); return; } if (req->error) { trace(LOG_ALWAYS, "Socket accept failed: %s", errno_to_str(req->error)); } else { ChannelNP * c = create_channel(si->np_sock, si->is_ssl, 1); if (c == NULL) { trace(LOG_ALWAYS, "Cannot create channel for accepted connection: %s", errno_to_str(errno)); closesocket(req->u.acc.rval); } else { struct sockaddr * addr_buf; /* Socket remote address */ socklen_t addr_len; #if defined(SOCK_MAXADDRLEN) addr_len = SOCK_MAXADDRLEN; #else addr_len = 0x1000; #endif addr_buf = (struct sockaddr *)loc_alloc(addr_len); if (getpeername(nopoll_conn_socket (si->np_sock), addr_buf, &addr_len) < 0) { trace(LOG_ALWAYS, "Unable to get peer remote name: %s", errno_to_str(errno)); closesocket(req->u.acc.rval); } else { set_peer_addr(c, addr_buf, addr_len); si->serv.new_conn(&si->serv, &c->chan); } loc_free(addr_buf); } } async_req_post(req); }