diff options
Diffstat (limited to 'cpukit/libcsupport')
-rw-r--r-- | cpukit/libcsupport/include/rtems/libcsupport.h | 32 | ||||
-rw-r--r-- | cpukit/libcsupport/src/newlibc.c | 141 |
2 files changed, 59 insertions, 114 deletions
diff --git a/cpukit/libcsupport/include/rtems/libcsupport.h b/cpukit/libcsupport/include/rtems/libcsupport.h index bdd13c5136..817e9d8a5b 100644 --- a/cpukit/libcsupport/include/rtems/libcsupport.h +++ b/cpukit/libcsupport/include/rtems/libcsupport.h @@ -39,6 +39,38 @@ extern int host_errno(void); extern void fix_syscall_errno(void); extern size_t malloc_free_space(); +/* + * Prototypes required to install newlib reentrancy user extension + */ +rtems_boolean libc_create_hook( + rtems_tcb *current_task, + rtems_tcb *creating_task +); + +#if defined(RTEMS_UNIX) && !defined(hpux) + rtems_extension libc_begin_hook(rtems_tcb *current_task); + #define __RTEMS_NEWLIB_BEGIN libc_begin_hook +#else + #define __RTEMS_NEWLIB_BEGIN 0 +#endif + +rtems_extension libc_delete_hook( + rtems_tcb *current_task, + rtems_tcb *deleted_task +); + +#define RTEMS_NEWLIB_EXTENSION \ +{ \ + libc_create_hook, /* rtems_task_create */ \ + 0, /* rtems_task_start */ \ + 0, /* rtems_task_restart */ \ + libc_delete_hook, /* rtems_task_delete */ \ + 0, /* task_switch */ \ + __RTEMS_NEWLIB_BEGIN, /* task_begin */ \ + 0, /* task_exitted */ \ + 0 /* fatal */ \ +} + #ifdef __cplusplus } #endif diff --git a/cpukit/libcsupport/src/newlibc.c b/cpukit/libcsupport/src/newlibc.c index 80c5cd07ea..ff0ef21403 100644 --- a/cpukit/libcsupport/src/newlibc.c +++ b/cpukit/libcsupport/src/newlibc.c @@ -50,8 +50,8 @@ int _fwalk(struct _reent *ptr, int (*function) (FILE *) ); -int libc_reentrant; /* do we think we are reentrant? */ -struct _reent libc_global_reent __ATTRIBUTE_IMPURE_PTR__ = _REENT_INIT(libc_global_reent); +struct _reent libc_global_reent + __ATTRIBUTE_IMPURE_PTR__ = _REENT_INIT(libc_global_reent); /* * reent struct allocation moved here from libc_start_hook() to avoid @@ -71,54 +71,24 @@ rtems_boolean libc_create_hook( * it is based on the Classic API Region Manager. */ -#define REENT_MALLOCED 0 -#if REENT_MALLOCED - ptr = (struct _reent *) calloc(1, sizeof(struct _reent)); -#else - /* It is OK to allocate from the workspace because these - * hooks run with thread dispatching disabled. - */ - ptr = (struct _reent *) _Workspace_Allocate(sizeof(struct _reent)); -#endif + #define REENT_MALLOCED 0 + #if REENT_MALLOCED + ptr = (struct _reent *) calloc(1, sizeof(struct _reent)); + #else + /* It is OK to allocate from the workspace because these + * hooks run with thread dispatching disabled. + */ + ptr = (struct _reent *) _Workspace_Allocate(sizeof(struct _reent)); + #endif - if (ptr) - { - -#ifdef __GNUC__ - /* GCC extension: structure constants */ - _REENT_INIT_PTR((ptr)); -#else - /* - * WARNING: THIS IS VERY DEPENDENT ON NEWLIB!!! - * Last visual check was against newlib 1.8.2 but last known - * use was against 1.7.0. This is basically an exansion of - * REENT_INIT() in <sys/reent.h>. - */ - memset(ptr, 0, sizeof(*ptr)); - ptr->_stdin = &ptr->__sf[0]; - ptr->_stdout = &ptr->__sf[1]; - ptr->_stderr = &ptr->__sf[2]; - ptr->_current_locale = "C"; - ptr->_new._reent._rand_next = 1; -#endif + if (ptr) { + _REENT_INIT_PTR((ptr)); /* GCC extension: structure constants */ creating_task->libc_reent = ptr; return TRUE; } else - return FALSE; - -} - -/* - * Called for all user TASKS (system tasks are MPCI Receive Server and IDLE) - */ - -rtems_extension libc_start_hook( - rtems_tcb *current_task, - rtems_tcb *starting_task -) -{ + return FALSE; } /* @@ -133,27 +103,9 @@ rtems_extension libc_begin_hook(rtems_tcb *current_task) #endif /* - * Function: libc_delete_hook - * Created: 94/12/10 - * - * Description: - * Called when a task is deleted. - * Must restore the new lib reentrancy state for the new current - * task. - * - * Parameters: - * - * - * Returns: - * - * - * Side Effects: - * - * Notes: - * - * - * Deficiencies/ToDo: - * + * Called when a task is deleted. + * Must restore the new lib reentrancy state for the new current + * task. * */ @@ -222,64 +174,25 @@ rtems_extension libc_delete_hook( } /* - * Function: libc_init - * Created: 94/12/10 - * - * Description: - * Init libc for CYGNUS newlib - * Set up _REENT to use our global libc_global_reent. - * (newlib provides a global of its own, but we prefer our - * own name for it) - * - * If reentrancy is desired (which it should be), then - * we install the task extension hooks to maintain the - * newlib reentrancy global variable _REENT on task - * create, delete, switch, exit, etc. - * - * Parameters: - * reentrant non-zero if reentrant library desired. - * - * Returns: - * - * Side Effects: - * installs libc extensions if reentrant. + * Init libc for CYGNUS newlib + * + * Set up _REENT to use our global libc_global_reent. + * (newlib provides a global of its own, but we prefer our own name for it) * - * Notes: - * - * - * Deficiencies/ToDo: + * If reentrancy is desired (which it should be), then + * we install the task extension hooks to maintain the + * newlib reentrancy global variable _REENT on task + * create, delete, switch, exit, etc. * */ + void libc_init(int reentrant) { - rtems_extensions_table libc_extension; - rtems_status_code rc; - rtems_id extension_id; - -/* libc_global_reent = _REENT_INIT(libc_global_reent); */ _REENT = &libc_global_reent; - if (reentrant) { - memset(&libc_extension, 0, sizeof(libc_extension)); - - libc_extension.thread_create = libc_create_hook; - libc_extension.thread_start = libc_start_hook; -#ifdef NEED_SETVBUF - libc_extension.thread_begin = libc_begin_hook; -#endif - libc_extension.thread_delete = libc_delete_hook; - - _Thread_Set_libc_reent (&_REENT); - - rc = rtems_extension_create(rtems_build_name('L', 'I', 'B', 'C'), - &libc_extension, &extension_id); - if (rc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred( rc ); - - libc_reentrant = reentrant; - } + _Thread_Set_libc_reent (&_REENT); } #endif |