~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to erts/emulator/sys/vxworks/sys.c

  • Committer: Bazaar Package Importer
  • Author(s): Erlang Packagers, Sergei Golovan
  • Date: 2006-12-03 17:07:44 UTC
  • mfrom: (2.1.11 feisty)
  • Revision ID: james.westby@ubuntu.com-20061203170744-rghjwupacqlzs6kv
Tags: 1:11.b.2-4
[ Sergei Golovan ]
Fixed erlang-base and erlang-base-hipe prerm scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
EXTERN_FUNCTION(int, driver_interrupt, (int, int));
88
88
EXTERN_FUNCTION(void, increment_time, (int));
89
89
EXTERN_FUNCTION(int, next_time, (_VOID_));
90
 
EXTERN_FUNCTION(int, send_error_to_logger, (Eterm));
91
90
EXTERN_FUNCTION(void, set_reclaim_free_function, (FreeFunction));
92
91
EXTERN_FUNCTION(int, erl_mem_info_get, (MEM_PART_STATS *));
 
92
EXTERN_FUNCTION(void, erl_crash_dump, (char* file, int line, char* fmt, ...));
93
93
 
94
94
#define NULLTV  ((struct timeval *) 0)
95
95
#define NULLFDS ((struct fd_set *) 0)
146
146
 
147
147
/********************* General functions ****************************/
148
148
 
 
149
Eterm erts_check_io_info(void *proc)
 
150
{
 
151
    return NIL;
 
152
}
 
153
 
 
154
Uint
 
155
erts_sys_misc_mem_sz(void)
 
156
{
 
157
    return (Uint) 0 /* FIXME */;
 
158
}
 
159
 
149
160
/*
150
161
 * XXX This declaration should not be here.
151
162
 */
177
188
 
178
189
    if (erlang_id != 0) {
179
190
        /* NOTE: This particular case must *not* call erl_exit() */
180
 
        sys_printf(CERR, "Sorry, erlang is already running (as task %d)\n",
 
191
        erts_fprintf(stderr, "Sorry, erlang is already running (as task %d)\n",
181
192
                   erlang_id);
182
193
        exit(1);
183
194
    }
211
222
}
212
223
 
213
224
void
 
225
erts_sys_pre_init(void)
 
226
{
 
227
 
 
228
}
 
229
 
 
230
void
214
231
erl_sys_init(void)
215
232
{
216
233
 
291
308
  sys_sigset(SIGQUIT, do_quit);
292
309
}
293
310
 
 
311
void erts_replace_intr(void) {
 
312
}
 
313
 
294
314
int sys_max_files(void) 
295
315
{
296
316
  return(max_files);
469
489
#define TMP_BUF_MAX (tmp_buf_size - 1024)
470
490
static byte *tmp_buf;
471
491
static Uint tmp_buf_size;
472
 
int cerr_pos;
473
492
 
474
493
/* II. The spawn/fd/vanilla drivers */
475
494
 
719
738
  len = strlen(sym);
720
739
  if (len > 254 && (symname = malloc(len+2)) == NULL)
721
740
    return(NULL);
722
 
#ifdef _ARCH_PPC 
723
 
  /* GCC for PPC doesn't add a leading _ to symbols */
 
741
#if defined _ARCH_PPC || defined SIMSPARCSOLARIS
 
742
  /* GCC for PPC and SIMSPARC doesn't add a leading _ to symbols */
724
743
  strcpy(symname, sym);
725
744
#else
726
745
  sprintf(symname, "_%s", sym);
1205
1224
                tmpexit = driver_data[ready_fd].exitcode;
1206
1225
            semGive(driver_data_sem);
1207
1226
            if (reported) {
1208
 
                erl_printf(CERR,"Exitcode %d reported\r\n", tmpexit);
 
1227
                erts_fprintf(stderr,"Exitcode %d reported\r\n", tmpexit);
1209
1228
                driver_report_exit(port_num, tmpexit);
1210
1229
            }
1211
1230
        }
1462
1481
    writefds = output_fds;
1463
1482
    i = select(max_fd + 1, &readfds, &writefds, NULLFDS, &wait_time);
1464
1483
 
1465
 
    erts_deliver_time(NULL);            /* sync the machine's idea of time */
 
1484
    erts_deliver_time();                /* sync the machine's idea of time */
1466
1485
 
1467
1486
    /* break handling moved here, signal handler just sets flag */
1468
1487
    if (break_requested) {
1509
1528
 
1510
1529
 
1511
1530
void
1512
 
sys_init_io(byte *buf, Uint size)
 
1531
sys_init_io(void)
1513
1532
{
1514
 
  tmp_buf = buf;
1515
 
  tmp_buf_size = size;
 
1533
  tmp_buf = (byte *) erts_alloc(ERTS_ALC_T_SYS_TMP_BUF, SYS_TMP_BUF_SIZE);
 
1534
  tmp_buf_size = SYS_TMP_BUF_SIZE;
1516
1535
  FD_ZERO(&input_fds);
1517
1536
  FD_ZERO(&output_fds);
1518
1537
  fd_data = (struct fd_data *)
1620
1639
#endif
1621
1640
 
1622
1641
 
1623
 
/* XXX It isn't possible to do this safely without "*nsprintf"
1624
 
   (i.e. something that puts a limit on the number of chars printed)
1625
 
   - the below is probably the best we can do...    */
1626
 
 
1627
 
void sys_printf(CIO where, char* format, ...)
1628
 
{
1629
 
  va_list va;
1630
 
  va_start(va,format);
1631
 
 
1632
 
  if (where == CERR)
1633
 
      erl_error(format, va);
1634
 
  else if (where == COUT) 
1635
 
    vfprintf(stdout, format, va);
1636
 
  else if (where == CBUF) {
1637
 
    if (cerr_pos < TMP_BUF_MAX) {
1638
 
      vsprintf((char*)&tmp_buf[cerr_pos],format,va);
1639
 
      cerr_pos += sys_strlen((char*)&tmp_buf[cerr_pos]);
1640
 
      if (cerr_pos >= tmp_buf_size)
1641
 
        erl_exit(1, "Internal buffer overflow in erl_printf\n");
1642
 
      if (cerr_pos >= TMP_BUF_MAX) {
1643
 
        strcpy((char*)&tmp_buf[TMP_BUF_MAX - 3], "...");
1644
 
        cerr_pos = TMP_BUF_MAX;
1645
 
      }
1646
 
    }
1647
 
  } else {
1648
 
      /* Seems only to be used in crash_dumping... */
1649
 
      vsprintf(tmp_buf, format, va);
1650
 
      if(sys_strlen(tmp_buf) >= TMP_BUF_MAX)
1651
 
          erl_exit(1, "Internal buffer overflow in erl_printf\n");
1652
 
      write((int) where, tmp_buf, strlen(tmp_buf));
1653
 
  }
1654
 
  va_end(va);
1655
 
}
1656
 
  
1657
 
void sys_putc(int ch, CIO where)
1658
 
{
1659
 
  if (where == CBUF) {
1660
 
    if (cerr_pos < TMP_BUF_MAX) {
1661
 
      tmp_buf[cerr_pos++] = ch;
1662
 
      if (cerr_pos == TMP_BUF_MAX) {
1663
 
        strcpy((char*)&tmp_buf[TMP_BUF_MAX - 3], "...");
1664
 
        cerr_pos = TMP_BUF_MAX;
1665
 
      }
1666
 
    }
1667
 
    else if (cerr_pos >= tmp_buf_size)
1668
 
      erl_exit(1, "Internal buffer overflow in erl_printf\n");
1669
 
  }
1670
 
  else if (where == COUT)
1671
 
    fputc(ch, stdout);
1672
 
  else
1673
 
    sys_printf(where, "%c", ch);
1674
 
}
1675
 
 
1676
1642
/* Return a pointer to a vector of names of preloaded modules */
1677
1643
 
1678
1644
Preload* sys_preloaded(void)
1943
1909
    if(use_save_free(ptr)){
1944
1910
        if((alloc_flags & WARN_MALLOC_MIX) && 
1945
1911
           (alloc_flags & USING_ELIB_MALLOC))
1946
 
            erl_printf(CERR,"Warning, save_malloced data realloced "
 
1912
            erts_fprintf(stderr,"Warning, save_malloced data realloced "
1947
1913
                       "by sys_realloc2\n");
1948
1914
        return save_realloc(ptr, (size_t) size);
1949
1915
    } else {    
1986
1952
         */
1987
1953
        if((alloc_flags & WARN_MALLOC_MIX) && 
1988
1954
           (alloc_flags & USING_ELIB_MALLOC))
1989
 
            erl_printf(CERR,"Warning, save_malloced data freed by "
 
1955
            erts_fprintf(stderr,"Warning, save_malloced data freed by "
1990
1956
                       "sys_free2\n");
1991
1957
        save_free(ptr);
1992
1958
    } else {
2020
1986
                         int realloc_moves, int reclaim_in_supplied, int p5,
2021
1987
                         int p6, int p7, int p8, int p9){
2022
1988
    if(erlang_id != 0){
2023
 
        erl_printf(CERR,"Error, cannot set erlang memory block while an "
2024
 
                   "erlang task is running!\n");
 
1989
        erts_fprintf(stderr,"Error, cannot set erlang memory block while an "
 
1990
                     "erlang task is running!\n");
2025
1991
        return 1;
2026
1992
    }
2027
1993
    if(isize < 8 * 1024 *1024)
2028
 
        erl_printf(CERR,"Warning, the memory pool of %dMb may be to small to "
2029
 
                   "run erlang in!\n", isize / (1024 * 1024));
 
1994
        erts_fprintf(stderr,
 
1995
                     "Warning, the memory pool of %dMb may be to small to "
 
1996
                     "run erlang in!\n", isize / (1024 * 1024));
2030
1997
    alloc_pool_size = (size_t) isize;
2031
1998
    alloc_pool_ptr = (void *) iptr;
2032
1999
    alloc_flags = 0;
2047
2014
                    int p6, int p7, int p8, int p9){
2048
2015
    struct elib_stat statistics;
2049
2016
    if(!(alloc_flags & USING_ELIB_MALLOC) && erlang_id != 0){
2050
 
        erl_printf(COUT,"Using plain save_alloc, use memShow instead.\n");
 
2017
        erts_printf("Using plain save_alloc, use memShow instead.\n");
2051
2018
        return 1;
2052
2019
    }
2053
2020
    if(erlang_id == 0 && !((alloc_flags & USER_POOL) && 
2054
2021
                           !(alloc_flags & NEW_USER_POOL))){
2055
 
        erl_printf(COUT,"Sorry, no allocation statistics until erlang "
 
2022
        erts_printf("Sorry, no allocation statistics until erlang "
2056
2023
                   "is started.\n");
2057
2024
        return 1;
2058
2025
    }
2059
 
    erl_printf(COUT,"Allocation settings:\n");
2060
 
    erl_printf(COUT,"Using elib_malloc with memory pool size of %lu bytes.\n",
 
2026
    erts_printf("Allocation settings:\n");
 
2027
    erts_printf("Using elib_malloc with memory pool size of %lu bytes.\n",
2061
2028
               (unsigned long) alloc_pool_size);
2062
 
    erl_printf(COUT,"Realloc-always-moves is %s\n", 
 
2029
    erts_printf("Realloc-always-moves is %s\n", 
2063
2030
               (alloc_flags & REALLOC_MOVES) ? "on" : "off");
2064
 
    erl_printf(COUT,"Warnings about mixed malloc/free's are %s\n", 
 
2031
    erts_printf("Warnings about mixed malloc/free's are %s\n", 
2065
2032
               (alloc_flags & WARN_MALLOC_MIX) ? "on" : "off");
2066
2033
    if(alloc_flags & USER_POOL){
2067
 
        erl_printf(COUT,"The memory block used by elib is user supplied "
 
2034
        erts_printf("The memory block used by elib is user supplied "
2068
2035
                   "at 0x%08x.\n", (unsigned int) alloc_pool_ptr);
2069
2036
        if(alloc_flags & RECLAIM_USER_POOL)
2070
 
            erl_printf(COUT,"Allocated memory within the user supplied pool\n"
 
2037
            erts_printf("Allocated memory within the user supplied pool\n"
2071
2038
                       "  will be automatically reclaimed at task exit.\n");
2072
2039
    } else {
2073
 
        erl_printf(COUT,"The memory block used by elib is save_malloc'ed "
 
2040
        erts_printf("The memory block used by elib is save_malloc'ed "
2074
2041
                   "at 0x%08x.\n", (unsigned int) alloc_pool_ptr);
2075
2042
    }
2076
2043
#ifdef NO_FIX_ALLOC
2077
 
    erl_printf(COUT,"Fix_alloc is disabled in this build\n");
 
2044
    erts_printf("Fix_alloc is disabled in this build\n");
2078
2045
#endif
2079
 
    erl_printf(COUT,"Statistics from elib_malloc:\n");
 
2046
    erts_printf("Statistics from elib_malloc:\n");
2080
2047
    ELIB_LOCK;
2081
2048
 
2082
2049
    elib_stat(&statistics);
2083
2050
    ELIB_UNLOCK;
2084
 
    erl_printf(COUT,"Type          Size (bytes) Number of blocks\n");
2085
 
    erl_printf(COUT,"============= ============ ================\n");
2086
 
    erl_printf(COUT,"Total:        %12lu %16lu\n",
 
2051
    erts_printf("Type          Size (bytes) Number of blocks\n");
 
2052
    erts_printf("============= ============ ================\n");
 
2053
    erts_printf("Total:        %12lu %16lu\n",
2087
2054
               (unsigned long) statistics.mem_total*4,
2088
2055
               (unsigned long) statistics.mem_blocks);
2089
 
    erl_printf(COUT,"Allocated:    %12lu %16lu\n",
 
2056
    erts_printf("Allocated:    %12lu %16lu\n",
2090
2057
               (unsigned long) statistics.mem_alloc*4,
2091
2058
               (unsigned long) statistics.mem_blocks-statistics.free_blocks);
2092
 
    erl_printf(COUT,"Free:         %12lu %16lu\n",
 
2059
    erts_printf("Free:         %12lu %16lu\n",
2093
2060
               (unsigned long) statistics.mem_free*4,
2094
2061
               (unsigned long) statistics.free_blocks);
2095
 
    erl_printf(COUT,"Largest free: %12lu                -\n\n",
 
2062
    erts_printf("Largest free: %12lu                -\n\n",
2096
2063
               (unsigned long) statistics.max_free*4);
2097
2064
    return 0;
2098
2065
}
2577
2544
  int drvValue;
2578
2545
 
2579
2546
  if ((drvValue = iosFdValue(fd)) == ERROR) {
2580
 
    sys_printf(CERR, "Error: file descriptor invalid\n");
 
2547
    erts_fprintf(stderr, "Error: file descriptor invalid\n");
2581
2548
    return;
2582
2549
  }
2583
2550
  pDev = (UXPIPE_DEV *)drvValue;
2584
2551
  pajp = pDev->pipe;
2585
2552
  if (pajp->drvNum != uxPipeDrvNum) {
2586
 
    sys_printf(CERR, "Error: Not a ux pipe device\n");
 
2553
    erts_fprintf(stderr, "Error: Not a ux pipe device\n");
2587
2554
    return;
2588
2555
  }
2589
 
  sys_printf(CERR, "Device              : 0x%x\n", (int) pDev);
2590
 
  sys_printf(CERR, "Buffer size         : %d\n", UXPIPE_SIZE);
2591
 
  sys_printf(CERR, "Bytes in buffer     : %d\n\n", rngNBytes(pajp->ringId));
2592
 
  sys_printf(CERR, "READ END\n\n");
 
2556
  erts_fprintf(stderr, "Device              : 0x%x\n", (int) pDev);
 
2557
  erts_fprintf(stderr, "Buffer size         : %d\n", UXPIPE_SIZE);
 
2558
  erts_fprintf(stderr, "Bytes in buffer     : %d\n\n", rngNBytes(pajp->ringId));
 
2559
  erts_fprintf(stderr, "READ END\n\n");
2593
2560
  if (pajp->reader != NULL) {
2594
 
    sys_printf(CERR, "Mode                : ");
2595
 
    sys_printf(CERR, "%s\n", 
 
2561
    erts_fprintf(stderr, "Mode                : ");
 
2562
    erts_fprintf(stderr, "%s\n", 
2596
2563
               (pajp->reader->blocking) ? "blocking" : "non-blocking");
2597
2564
  }
2598
 
  sys_printf(CERR, "Status              : ");
 
2565
  erts_fprintf(stderr, "Status              : ");
2599
2566
  if (pajp->reader != NULL) {
2600
 
    sys_printf(CERR, "OPEN\n");
2601
 
    sys_printf(CERR, "Wake-up list        : %d\n\n", 
 
2567
    erts_fprintf(stderr, "OPEN\n");
 
2568
    erts_fprintf(stderr, "Wake-up list        : %d\n\n", 
2602
2569
               selWakeupListLen(&pajp->reader->wakeupList));
2603
 
    sys_printf(CERR, "Exclusion Semaphore\n");
 
2570
    erts_fprintf(stderr, "Exclusion Semaphore\n");
2604
2571
    semShow(pajp->reader->semExcl, 1);
2605
 
    sys_printf(CERR, "Blocking Semaphore\n");
 
2572
    erts_fprintf(stderr, "Blocking Semaphore\n");
2606
2573
    semShow(pajp->reader->semBlock, 1);
2607
2574
  } else 
2608
 
    sys_printf(CERR, "CLOSED\n\n");
2609
 
  sys_printf(CERR, "WRITE END\n\n");
 
2575
    erts_fprintf(stderr, "CLOSED\n\n");
 
2576
  erts_fprintf(stderr, "WRITE END\n\n");
2610
2577
  if (pajp->writer != NULL) {
2611
 
    sys_printf(CERR, "Mode                : ");
2612
 
    sys_printf(CERR, "%s\n", 
 
2578
    erts_fprintf(stderr, "Mode                : ");
 
2579
    erts_fprintf(stderr, "%s\n", 
2613
2580
               (pajp->writer->blocking) ? "blocking" : "non-blocking");
2614
2581
  }
2615
 
  sys_printf(CERR, "Status              : ");
 
2582
  erts_fprintf(stderr, "Status              : ");
2616
2583
  if (pajp->writer != NULL) {
2617
 
    sys_printf(CERR, "OPEN\n");
2618
 
    sys_printf(CERR, "Wake-up list        : %d\n\n", 
 
2584
    erts_fprintf(stderr, "OPEN\n");
 
2585
    erts_fprintf(stderr, "Wake-up list        : %d\n\n", 
2619
2586
               selWakeupListLen(&pajp->writer->wakeupList));
2620
 
    sys_printf(CERR, "Exclusion Semaphore\n");
 
2587
    erts_fprintf(stderr, "Exclusion Semaphore\n");
2621
2588
    semShow(pajp->writer->semExcl, 1);
2622
 
    sys_printf(CERR, "Blocking Semaphore\n");
 
2589
    erts_fprintf(stderr, "Blocking Semaphore\n");
2623
2590
    semShow(pajp->writer->semBlock, 1);
2624
2591
  } else 
2625
 
    sys_printf(CERR, "CLOSED\n\n");
 
2592
    erts_fprintf(stderr, "CLOSED\n\n");
2626
2593
}
2627
2594
 
2628
2595
#ifdef DEBUG
2633
2600
    fprintf(stderr, "Assertion failed: %s in %s, line %d\n",
2634
2601
            expr, file, line);
2635
2602
    fflush(stderr);
2636
 
    erl_crash_dump(NULL, NULL);
 
2603
    erl_crash_dump(file, line, "Assertion failed: %s\n", expr);
2637
2604
    abort();
2638
2605
}
2639
2606
void