ChorusOS 4.0 Migration Guide

Chapter 3 ChorusOS 4.0 Library Changes

This chapter lists the changes and new features in the ChorusOS 4.0 libraries.

3.1 strsep()

It is no longer possible to modify string constants in the ChorusOS 4.0 operating system. As a result, the strsep() function will cause a segmentation fault if called with a pointer to a literal string. This is demonstrated in Example 3-1.


Example 3-1 Code example of strsep() causing a segmentation fault

int main(int argc, char **argv)
{
    char *s = "aaaa/bbbb";
    char *r;
    char **sp = &s;

    r = strsep(sp, "/"); /* a segmentation fault is raised */
}                

Example 3-1 does not cause a segmentation fault in the ChorusOS 3.2 operating system because the gcc .rodata section was mapped to a writable memory region. In the ChorusOS 4.0 operating system, the gcc .rodata section is mapped to a read-only memory region.

Example 3-1 can be corrected by calling strsep() with a non-literal string, shown in Example 3-2.


Example 3-2 Corrected code example using strsep()

int main(int argc, char **argv)
{
    char *s = "aaaa/bbbb";
    char *r;
    char **sp = &s;
    char *tmp;

    tmp = strdup(s);

    if (tmp == NULL) {
        printf("out of memory\n");
        return 0;
    }

    sp = &tmp;
    r = strsep(sp, "/"); /* this works */
} 

See the strsep(3STDC) man page for more information.

3.2 malloc()

The standard memory allocation package, including the malloc() and free() functions have been reimplemented in the ChorusOS 4.0 operating system. To maintain compatibility with ChorusOS 3.2 malloc(), use the lib/classix/libomalloc.a library.

The package is based on the Solaris libc implementation and extended to release freed memory to the operating system. Yet, calling free() does not automatically return memory to the system. Since memory chunks are allocated by malloc() from page-aligned regions, these regions are only returned when all the chunks in the region have been freed. Furthermore, free() buffers memory chunks so that they can be reused by malloc(). As a result, memory will not be returned to the operating system until malloc() is called again. Use malloc_trim() to explicitly release this memory.

See the malloc(3STDC) man page for more information.

3.3 getpass()

The getpass() system call has been removed from the ChorusOS 4.0 operating system. As host and target communications are based on commands sent by rsh from the host to the target, the echoing is carried out by the host and cannot be controlled by the target. As a result, it is not possible to silence password echoing. To avoid password echoing, do not use rsh for host/target communications.