Allocate and initialize per-task state structure */
| 399 | |
| 400 | /* Allocate and initialize per-task state structure */ |
| 401 | static struct socketbase *alloc_socketbase (TrapContext *ctx) |
| 402 | { |
| 403 | SB; |
| 404 | int i; |
| 405 | |
| 406 | if ((sb = xcalloc (struct socketbase, 1)) != NULL) { |
| 407 | sb->ownertask = gettask(ctx); |
| 408 | sb->sysbase = trap_get_long(ctx, 4); |
| 409 | |
| 410 | trap_call_add_dreg(ctx, 0, -1); |
| 411 | sb->signal = trap_call_lib(ctx, sb->sysbase, -0x14A); /* AllocSignal */ |
| 412 | |
| 413 | if (sb->signal == -1) { |
| 414 | write_log (_T("bsdsocket: ERROR: Couldn't allocate signal for task 0x%08x.\n"), sb->ownertask); |
| 415 | free (sb); |
| 416 | return NULL; |
| 417 | } |
| 418 | // trap_get_dreg(ctx, 0) = SCRATCHBUFSIZE; |
| 419 | // trap_get_dreg(ctx, 1) = 0; |
| 420 | |
| 421 | sb->dtablesize = DEFAULT_DTABLE_SIZE; |
| 422 | /* @@@ check malloc() result */ |
| 423 | sb->dtable = xmalloc(SOCKET, sb->dtablesize); |
| 424 | sb->ftable = xcalloc(int, sb->dtablesize); |
| 425 | |
| 426 | for (i = sb->dtablesize; i--;) |
| 427 | sb->dtable[i] = INVALID_SOCKET; |
| 428 | |
| 429 | sb->eintrsigs = 0x1000; /* SIGBREAKF_CTRL_C */ |
| 430 | |
| 431 | sb->logfacility = 1 << 3; /* LOG_USER */ |
| 432 | sb->logmask = 0xff; |
| 433 | |
| 434 | if (!host_sbinit(ctx, sb)) { |
| 435 | /* @@@ free everything */ |
| 436 | } |
| 437 | |
| 438 | locksigqueue(); |
| 439 | |
| 440 | if (socketbases) |
| 441 | sb->next = socketbases; |
| 442 | socketbases = sb; |
| 443 | |
| 444 | unlocksigqueue(); |
| 445 | |
| 446 | return sb; |
| 447 | } |
| 448 | return NULL; |
| 449 | } |
| 450 | |
| 451 | STATIC_INLINE struct socketbase *get_socketbase (TrapContext *ctx) |
| 452 | { |
no test coverage detected