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*, ...));
1730
void sys_init_io(byte *buf, Uint size)
1745
void sys_init_io(void)
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);
1737
1752
extern const char pre_loaded_code[];
1738
1753
extern char* const pre_loaded[];
1742
void sys_printf(va_alist)
1749
where = va_arg(va, CIO);
1750
format = va_arg(va, char *);
1752
void sys_printf(CIO where, char* format, ...)
1755
va_start(va,format);
1758
if (where == CERR) {
1759
#ifndef USE_ERL_DEBUG_PRINTF
1760
erl_error(format, va);
1762
erl_dbg_vfprintf(stderr, format, va);
1765
else if (where == COUT) {
1766
#ifndef USE_ERL_DEBUG_PRINTF
1767
vfprintf(stdout, format, va);
1769
erl_dbg_vfprintf(stdout, format, va);
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;
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));
1794
void sys_putc(int ch, CIO where)
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;
1804
else if (cerr_pos >= tmp_buf_size)
1805
erl_exit(1, "Internal buffer overflow in erl_printf\n");
1807
else if (where == COUT)
1808
#ifndef USE_ERL_DEBUG_PRINTF
1811
erl_dbg_fputc(ch, stdout);
1814
sys_printf(where, "%c", ch);
1817
1755
/* Return a pointer to a vector of names of preloaded modules */
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");
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);
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");
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);