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, ...));
94
94
#define NULLTV ((struct timeval *) 0)
95
95
#define NULLFDS ((struct fd_set *) 0)
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... */
1627
void sys_printf(CIO where, char* format, ...)
1630
va_start(va,format);
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;
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));
1657
void sys_putc(int ch, CIO where)
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;
1667
else if (cerr_pos >= tmp_buf_size)
1668
erl_exit(1, "Internal buffer overflow in erl_printf\n");
1670
else if (where == COUT)
1673
sys_printf(where, "%c", ch);
1676
1642
/* Return a pointer to a vector of names of preloaded modules */
1678
1644
Preload* sys_preloaded(void)
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");
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");
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");
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");
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);
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");
2079
erl_printf(COUT,"Statistics from elib_malloc:\n");
2046
erts_printf("Statistics from elib_malloc:\n");
2082
2049
elib_stat(&statistics);
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);
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");
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");
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");
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);
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");
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);
2625
sys_printf(CERR, "CLOSED\n\n");
2592
erts_fprintf(stderr, "CLOSED\n\n");