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

« back to all changes in this revision

Viewing changes to erts/emulator/sys/ose/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:
56
56
EXTERN_FUNCTION(int, driver_interrupt, (int, int));
57
57
EXTERN_FUNCTION(void, increment_time, (int));
58
58
EXTERN_FUNCTION(int, next_time, (_VOID_));
59
 
EXTERN_FUNCTION(int, send_error_to_logger, (Uint));
60
59
EXTERN_FUNCTION(int, erl_dbg_fputc, (char, FILE*));
61
60
EXTERN_FUNCTION(int, erl_dbg_vfprintf, (FILE*, char*, va_list));
62
61
EXTERN_FUNCTION(int, erl_dbg_fprintf, (FILE*, char*, ...));
120
119
  initialize_allocation();
121
120
}
122
121
 
 
122
Eterm erts_check_io_info(void *proc)
 
123
{
 
124
    return NIL;
 
125
}
 
126
 
 
127
Uint
 
128
erts_sys_misc_mem_sz(void)
 
129
{
 
130
    return (Uint) 0 /* FIXME */;
 
131
}
 
132
 
 
133
void
 
134
erts_sys_pre_init(void)
 
135
{
 
136
 
 
137
}
 
138
 
123
139
void erl_sys_init(void)
124
140
{
125
141
  break_requested = 0;
452
468
 
453
469
static byte *tmp_buf;
454
470
static Uint tmp_buf_size;
455
 
int cerr_pos;
456
471
 
457
472
 
458
473
/*-------------------------- Drivers -----------------------------*/
1295
1310
      timeout = 0;              
1296
1311
    }
1297
1312
  }
1298
 
  erts_deliver_time(NULL);              /* sync the machine's idea of time */
 
1313
  erts_deliver_time();          /* sync the machine's idea of time */
1299
1314
}
1300
1315
 
1301
1316
/* add signal to be processed by check_io */
1727
1742
  return result;
1728
1743
}
1729
1744
 
1730
 
void sys_init_io(byte *buf, Uint size) 
 
1745
void sys_init_io(void) 
1731
1746
{
1732
 
  tmp_buf = buf;
1733
 
  tmp_buf_size = size;
1734
 
  printf("buf size set to %d\n", size);
 
1747
  tmp_buf = (byte *) erts_alloc(ERTS_ALC_T_SYS_TMP_BUF, SYS_TMP_BUF_SIZE);
 
1748
  tmp_buf_size = SYS_TMP_BUF_SIZE;
 
1749
  printf("buf size set to %d\n", tmp_buf_size);
1735
1750
}
1736
1751
 
1737
1752
extern const char pre_loaded_code[];
1738
1753
extern char* const pre_loaded[];
1739
1754
 
1740
 
 
1741
 
#ifndef __STDC__
1742
 
void sys_printf(va_alist)
1743
 
     va_dcl
1744
 
{
1745
 
  va_list va;
1746
 
  CIO where;
1747
 
  char   *format;
1748
 
  va_start(va);
1749
 
  where = va_arg(va, CIO);
1750
 
  format = va_arg(va, char *);
1751
 
#else
1752
 
void sys_printf(CIO where, char* format, ...)
1753
 
{
1754
 
  va_list va;
1755
 
  va_start(va,format);
1756
 
#endif
1757
 
  
1758
 
  if (where == CERR) {
1759
 
#ifndef USE_ERL_DEBUG_PRINTF
1760
 
    erl_error(format, va);
1761
 
#else
1762
 
    erl_dbg_vfprintf(stderr, format, va);
1763
 
#endif
1764
 
  }
1765
 
  else if (where == COUT) {
1766
 
#ifndef USE_ERL_DEBUG_PRINTF
1767
 
    vfprintf(stdout, format, va);
1768
 
#else
1769
 
    erl_dbg_vfprintf(stdout, format, va);
1770
 
#endif
1771
 
  }
1772
 
  else if (where == CBUF) {
1773
 
    if (cerr_pos < TMP_BUF_MAX) {
1774
 
      vsprintf((char*)&tmp_buf[cerr_pos],format,va);
1775
 
      cerr_pos += sys_strlen((char*)&tmp_buf[cerr_pos]);
1776
 
      if (cerr_pos >= tmp_buf_size)
1777
 
        erl_exit(1, "Internal buffer overflow in erl_printf\n");
1778
 
      if (cerr_pos >= TMP_BUF_MAX) {
1779
 
        strcpy((char*)&tmp_buf[TMP_BUF_MAX - 3], "...");
1780
 
        cerr_pos = TMP_BUF_MAX;
1781
 
      }
1782
 
    }
1783
 
  } else {
1784
 
    /* Seems only to be used in crash_dumping... */
1785
 
    vsprintf(tmp_buf, format, va);
1786
 
    if(sys_strlen(tmp_buf) >= TMP_BUF_MAX)
1787
 
      erl_exit(1, "Internal buffer overflow in erl_printf\n");
1788
 
    write((int) where, tmp_buf, strlen(tmp_buf));
1789
 
  }
1790
 
  va_end(va);
1791
 
}
1792
 
 
1793
 
    
1794
 
void sys_putc(int ch, CIO where)
1795
 
{
1796
 
  if (where == CBUF) {
1797
 
    if (cerr_pos < TMP_BUF_MAX) {
1798
 
      tmp_buf[cerr_pos++] = ch;
1799
 
      if (cerr_pos == TMP_BUF_MAX) {
1800
 
        strcpy((char*)&tmp_buf[TMP_BUF_MAX - 3], "...");
1801
 
        cerr_pos = TMP_BUF_MAX;
1802
 
      }
1803
 
    }
1804
 
    else if (cerr_pos >= tmp_buf_size)
1805
 
      erl_exit(1, "Internal buffer overflow in erl_printf\n");
1806
 
  }
1807
 
  else if (where == COUT)
1808
 
#ifndef USE_ERL_DEBUG_PRINTF
1809
 
    fputc(ch, stdout);
1810
 
#else
1811
 
    erl_dbg_fputc(ch, stdout);
1812
 
#endif
1813
 
  else
1814
 
    sys_printf(where, "%c", ch);
1815
 
}
1816
 
 
1817
1755
/* Return a pointer to a vector of names of preloaded modules */
1818
1756
 
1819
1757
Preload* sys_preloaded(void)
2007
1945
int erl_set_memory_block(int isize, int iptr, int warn_save, 
2008
1946
                         int realloc_moves, int reclaim_in_supplied) {
2009
1947
    if(isize < 8 * 1024 *1024)
2010
 
        erl_printf(CERR,"Warning, the memory pool of %dMb may be to small to "
2011
 
                   "run erlang in!\n", isize / (1024 * 1024));
 
1948
        erts_fprintf(stderr,
 
1949
                     "Warning, the memory pool of %dMb may be to small to "
 
1950
                     "run erlang in!\n", isize / (1024 * 1024));
2012
1951
    alloc_pool_size = (size_t) isize;
2013
1952
    alloc_pool_ptr = (void *) iptr;
2014
1953
    alloc_flags = 0;
2027
1966
/* External statistics interface */
2028
1967
int erl_memory_show() {
2029
1968
    struct elib_stat statistics;
2030
 
    erl_printf(COUT,"Allocation settings:\n");
2031
 
    erl_printf(COUT,"Using elib_malloc with memory pool size of %lu bytes.\n",
 
1969
    erts_printf("Allocation settings:\n");
 
1970
    erts_printf("Using elib_malloc with memory pool size of %lu bytes.\n",
2032
1971
               (unsigned long) alloc_pool_size);
2033
 
    erl_printf(COUT,"Realloc-always-moves is %s\n", 
 
1972
    erts_printf("Realloc-always-moves is %s\n", 
2034
1973
               (alloc_flags & REALLOC_MOVES) ? "on" : "off");
2035
 
    erl_printf(COUT,"Warnings about mixed malloc/free's are %s\n", 
 
1974
    erts_printf("Warnings about mixed malloc/free's are %s\n", 
2036
1975
               (alloc_flags & WARN_MALLOC_MIX) ? "on" : "off");
2037
1976
    if(alloc_flags & USER_POOL){
2038
 
        erl_printf(COUT,"The memory block used by elib is user supplied "
 
1977
        erts_printf("The memory block used by elib is user supplied "
2039
1978
                   "at 0x%08x.\n", (unsigned int) alloc_pool_ptr);
2040
1979
        if(alloc_flags & RECLAIM_USER_POOL)
2041
 
            erl_printf(COUT,"Allocated memory within the user supplied pool\n"
 
1980
            erts_printf("Allocated memory within the user supplied pool\n"
2042
1981
                       "  will be automatically reclaimed at task exit.\n");
2043
1982
    } else {
2044
 
        erl_printf(COUT,"The memory block used by elib is save_malloc'ed "
 
1983
        erts_printf("The memory block used by elib is save_malloc'ed "
2045
1984
                   "at 0x%08x.\n", (unsigned int) alloc_pool_ptr);
2046
1985
    }
2047
1986
#ifdef NO_FIX_ALLOC
2048
 
    erl_printf(COUT,"Fix_alloc is disabled in this build\n");
 
1987
    erts_printf("Fix_alloc is disabled in this build\n");
2049
1988
#endif
2050
 
    erl_printf(COUT,"Statistics from elib_malloc:\n");
 
1989
    erts_printf("Statistics from elib_malloc:\n");
2051
1990
    elib_stat(&statistics);
2052
 
    erl_printf(COUT,"Type          Size (bytes) Number of blocks\n");
2053
 
    erl_printf(COUT,"============= ============ ================\n");
2054
 
    erl_printf(COUT,"Total:        %12lu %16lu\n",
 
1991
    erts_printf("Type          Size (bytes) Number of blocks\n");
 
1992
    erts_printf("============= ============ ================\n");
 
1993
    erts_printf("Total:        %12lu %16lu\n",
2055
1994
               (unsigned long) statistics.mem_total*4,
2056
1995
               (unsigned long) statistics.mem_blocks);
2057
 
    erl_printf(COUT,"Allocated:    %12lu %16lu\n",
 
1996
    erts_printf("Allocated:    %12lu %16lu\n",
2058
1997
               (unsigned long) statistics.mem_alloc*4,
2059
1998
               (unsigned long) statistics.mem_blocks-statistics.free_blocks);
2060
 
    erl_printf(COUT,"Free:         %12lu %16lu\n",
 
1999
    erts_printf("Free:         %12lu %16lu\n",
2061
2000
               (unsigned long) statistics.mem_free*4,
2062
2001
               (unsigned long) statistics.free_blocks);
2063
 
    erl_printf(COUT,"Largest free: %12lu                -\n\n",
 
2002
    erts_printf("Largest free: %12lu                -\n\n",
2064
2003
               (unsigned long) statistics.max_free*4);
2065
2004
    return 0;
2066
2005
}