Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3221 → Rev 3222

/trunk/uspace/lib/libc/include/as.h
42,6 → 42,7
 
extern void *as_area_create(void *address, size_t size, int flags);
extern int as_area_resize(void *address, size_t size, int flags);
extern int as_area_change_flags(void *address, int flags);
extern int as_area_destroy(void *address);
extern void *set_maxheapsize(size_t mhs);
extern void * as_get_mappable_page(size_t sz);
/trunk/uspace/lib/libc/include/task.h
40,7 → 40,7
typedef uint64_t task_id_t;
 
extern task_id_t task_get_id(void);
extern int task_spawn(void *image, size_t size);
extern task_id_t task_spawn(const char *path, const char *argv[]);
 
#endif
 
/trunk/uspace/lib/libc/include/libc.h
48,7 → 48,7
#define __SYSCALL6(id, p1, p2, p3, p4, p5, p6) \
__syscall(p1, p2, p3, p4, p5, p6,id)
 
extern void __main(void);
extern void __main(void *pcb_ptr);
extern void __exit(void);
 
#endif
/trunk/uspace/lib/libc/include/loader/pcb.h
0,0 → 1,74
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup fs
* @{
*/
/** @file
* @brief Program Control Block interface.
*/
 
#ifndef LIBC_PCB_H_
#define LIBC_PCB_H_
 
#include <sys/types.h>
 
typedef void (*entry_point_t)(void);
 
/**
* Holds pointers to data passed from the program loader to the program
* and/or to the dynamic linker. This includes the program entry point,
* arguments, environment variables etc.
*/
typedef struct {
/** Program entry point */
entry_point_t entry;
 
/** Number of command-line arguments */
int argc;
/** Command-line arguments */
char **argv;
 
/*
* ELF-specific data
*/
/** Pointer to ELF dynamic section of the program */
void *dynamic;
/** Pointer to dynamic section of the runtime linker */
void *rtld_dynamic;
/** Runtime-linker load bias */
uintptr_t rtld_bias;
} pcb_t;
 
extern pcb_t *__pcb;
 
#endif
 
/**
* @}
*/
/trunk/uspace/lib/libc/include/io/stream.h
40,6 → 40,7
#define EMFILE -17
 
extern void open_console(void);
extern void close_console(void);
extern void klog_update(void);
 
extern ssize_t read_stdin(void *, size_t);
/trunk/uspace/lib/libc/include/smc.h
0,0 → 1,45
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup libc
* @{
*/
/** @file
*/
 
#ifndef LIBC_SMC_H_
#define LIBC_SMC_H_
 
#include <sys/types.h>
 
extern int smc_coherence(void *address, size_t size);
 
#endif
 
/** @}
*/
/trunk/uspace/lib/libc/include/ipc/loader.h
0,0 → 1,50
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup libcipc
* @{
*/
/** @file
*/
 
#ifndef LIBC_LOADER_H_
#define LIBC_LOADER_H_
 
#include <ipc/ipc.h>
 
typedef enum {
LOADER_HELLO = IPC_FIRST_USER_METHOD,
LOADER_SET_PATHNAME,
LOADER_SET_ARGS,
LOADER_RUN
} fb_request_t;
 
#endif
 
/** @}
*/
/trunk/uspace/lib/libc/generic/task.c
1,5 → 1,6
/*
* Copyright (c) 2006 Jakub Jermar
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
33,7 → 34,13
*/
 
#include <task.h>
#include <ipc/ipc.h>
#include <ipc/loader.h>
#include <libc.h>
#include <string.h>
#include <stdlib.h>
#include <async.h>
#include <errno.h>
 
task_id_t task_get_id(void)
{
44,10 → 51,124
return task_id;
}
 
int task_spawn(void *image, size_t size)
static int task_spawn_loader(void)
{
return __SYSCALL2(SYS_TASK_SPAWN, (sysarg_t) image, (sysarg_t) size);
int phone_id, rc;
 
rc = __SYSCALL1(SYS_PROGRAM_SPAWN_LOADER, (sysarg_t) &phone_id);
if (rc != 0)
return rc;
 
return phone_id;
}
 
static int loader_set_args(int phone_id, const char *argv[])
{
aid_t req;
ipc_call_t answer;
ipcarg_t rc;
 
const char **ap;
char *dp;
char *arg_buf;
size_t buffer_size;
size_t len;
 
/*
* Serialize the arguments into a single array. First
* compute size of the buffer needed.
*/
ap = argv;
buffer_size = 0;
while (*ap != NULL) {
buffer_size += strlen(*ap) + 1;
++ap;
}
 
arg_buf = malloc(buffer_size);
if (arg_buf == NULL) return ENOMEM;
 
/* Now fill the buffer with null-terminated argument strings */
ap = argv;
dp = arg_buf;
while (*ap != NULL) {
strcpy(dp, *ap);
dp += strlen(*ap) + 1;
 
++ap;
}
 
/* Send serialized arguments to the loader */
 
req = async_send_0(phone_id, LOADER_SET_ARGS, &answer);
rc = ipc_data_write_start(phone_id, (void *)arg_buf, buffer_size);
if (rc != EOK) {
async_wait_for(req, NULL);
return rc;
}
 
async_wait_for(req, &rc);
if (rc != EOK) return rc;
 
/* Free temporary buffer */
free(arg_buf);
 
return EOK;
}
 
/** Create a new task by running an executable from VFS.
*
* @param path pathname of the binary to execute
* @param argv command-line arguments
* @return ID of the newly created task or zero on error.
*/
task_id_t task_spawn(const char *path, const char *argv[])
{
int phone_id;
ipc_call_t answer;
aid_t req;
int rc;
ipcarg_t retval;
 
/* Spawn a program loader */
phone_id = task_spawn_loader();
if (phone_id < 0) return 0;
 
/*
* Say hello so that the loader knows the incoming connection's
* phone hash.
*/
rc = async_req_0_0(phone_id, LOADER_HELLO);
if (rc != EOK) return 0;
 
/* Send program pathname */
req = async_send_0(phone_id, LOADER_SET_PATHNAME, &answer);
rc = ipc_data_write_start(phone_id, (void *)path, strlen(path));
if (rc != EOK) {
async_wait_for(req, NULL);
return 1;
}
 
async_wait_for(req, &retval);
if (retval != EOK) goto error;
 
/* Send arguments */
rc = loader_set_args(phone_id, argv);
if (rc != EOK) goto error;
 
/* Request loader to start the program */
rc = async_req_0_0(phone_id, LOADER_RUN);
if (rc != EOK) goto error;
 
/* Success */
ipc_hangup(phone_id);
return 1;
 
/* Error exit */
error:
ipc_hangup(phone_id);
return 0;
}
 
/** @}
*/
/trunk/uspace/lib/libc/generic/as.c
85,6 → 85,20
return __SYSCALL1(SYS_AS_AREA_DESTROY, (sysarg_t ) address);
}
 
/** Change address-space area flags.
*
* @param address Virtual address pointing into the address space area being
* modified.
* @param flags New flags describing type of the area.
*
* @return Zero on success or a code from @ref errno.h on failure.
*/
int as_area_change_flags(void *address, int flags)
{
return __SYSCALL2(SYS_AS_AREA_CHANGE_FLAGS, (sysarg_t) address,
(sysarg_t) flags);
}
 
static size_t heapsize = 0;
static size_t maxheapsize = (size_t) (-1);
 
/trunk/uspace/lib/libc/generic/pcb.c
0,0 → 1,40
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup libc
* @{
*/
/** @file
*/
 
#include <loader/pcb.h>
 
pcb_t *__pcb;
 
/** @}
*/
/trunk/uspace/lib/libc/generic/libc.c
48,8 → 48,10
#include <ipc/ipc.h>
#include <async.h>
#include <as.h>
#include <loader/pcb.h>
 
extern char _heap;
extern int main(int argc, char *argv[]);
 
void _exit(int status)
{
56,9 → 58,11
thread_exit(status);
}
 
void __main(void)
void __main(void *pcb_ptr)
{
fibril_t *f;
int argc;
char **argv;
 
(void) as_area_create(&_heap, 1, AS_AREA_WRITE | AS_AREA_READ);
_async_init();
66,6 → 70,19
__tcb_set(f->tcb);
open_console();
 
/* Save the PCB pointer */
__pcb = (pcb_t *)pcb_ptr;
 
if (__pcb == NULL) {
argc = 0;
argv = NULL;
} else {
argc = __pcb->argc;
argv = __pcb->argv;
}
 
main(argc, argv);
}
 
void __exit(void)
/trunk/uspace/lib/libc/generic/smc.c
0,0 → 1,45
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup libc
* @{
*/
/** @file
*/
 
#include <libc.h>
#include <sys/types.h>
 
int smc_coherence(void *address, size_t size)
{
return __SYSCALL2(SYS_SMC_COHERENCE, (sysarg_t) address,
(sysarg_t) size);
}
 
/** @}
*/
/trunk/uspace/lib/libc/generic/io/stream.c
96,6 → 96,15
}
}
 
void close_console(void)
{
if (console_phone >= 0) {
if (ipc_hangup(console_phone) == 0) {
console_phone = -1;
}
}
}
 
void klog_update(void)
{
(void) __SYSCALL3(SYS_KLOG, 1, NULL, 0);
/trunk/uspace/lib/libc/Makefile
51,6 → 51,8
generic/cap.c \
generic/string.c \
generic/fibril.c \
generic/pcb.c \
generic/smc.c \
generic/thread.c \
generic/tls.c \
generic/task.c \
/trunk/uspace/lib/libc/arch/sparc64/src/entry.s
34,12 → 34,15
 
## User-space task entry point
#
# %o0 contains uarg
# %o1 contains pcb_ptr
#
__entry:
# Pass pcb_ptr as the first argument to __main()
mov %o1, %o0
sethi %hi(_gp), %l7
call __main
or %l7, %lo(_gp), %l7
call main
nop
 
call __exit
nop
/trunk/uspace/lib/libc/arch/ia64/src/entry.s
34,12 → 34,14
 
## User-space task entry point
#
# r2 contains the PCB pointer
#
__entry:
alloc loc0 = ar.pfs, 0, 1, 2, 0
mov r1 = _gp
mov r1 = _gp
 
# Pass PCB pointer as the first argument to __main
mov out0 = r2
br.call.sptk.many b0 = __main
0:
br.call.sptk.many b0 = main
1:
br.call.sptk.many b0 = __exit
/trunk/uspace/lib/libc/arch/arm32/src/entry.s
34,8 → 34,11
 
## User-space task entry point
#
# r1 contains the PCB pointer
#
__entry:
# Pass pcb_ptr to __main as the first argument (in r0)
mov r0, r1
bl __main
bl main
 
bl __exit
/trunk/uspace/lib/libc/arch/ppc32/src/entry.s
34,8 → 34,11
 
## User-space task entry point
#
# r3 contains the PCB pointer
#
__entry:
# Pass the PCB pointer to __main() as the first argument.
# Since the first argument is passed in r3, no operation is needed.
bl __main
bl main
 
bl __exit
/trunk/uspace/lib/libc/arch/amd64/src/entry.s
34,8 → 34,11
 
## User-space task entry point
#
# %rdi contains the PCB pointer
#
__entry:
# %rdi was deliberately chosen as the first argument is also in %rdi
# Pass PCB pointer to __main (no operation)
call __main
call main
 
call __exit
/trunk/uspace/lib/libc/arch/ppc64/src/entry.s
31,7 → 31,6
.org 0
 
.globl __entry
.globl __entry_driver
 
## User-space task entry point
#
38,11 → 37,4
#
__entry:
bl __main
bl __io_init
bl main
bl __exit
 
__entry_driver:
bl __main
bl main
bl __exit
/trunk/uspace/lib/libc/arch/mips32/src/entry.s
35,13 → 35,13
 
## User-space task entry point
#
# $a0 ($4) contains the PCB pointer
#
.ent __entry
__entry:
.frame $sp, 32, $31
.cpload $25
 
# Mips o32 may store its arguments on stack, make space (16 bytes),
# so that it could work with -O0
# Make space additional 16 bytes for the stack frame
48,13 → 48,14
 
addiu $sp, -32
.cprestore 16 # Allow PIC code
 
# Pass pcb_ptr to __main() as the first argument. pcb_ptr is already
# in $a0. As the first argument is passed in $a0, no operation
# is needed.
 
jal __main
nop
jal main
nop
jal __exit
nop
.end
/trunk/uspace/lib/libc/arch/ia32/src/entry.s
34,6 → 34,7
 
## User-space task entry point
#
# %ebx contains the PCB pointer
#
__entry:
mov %ss, %ax
41,7 → 42,9
mov %ax, %es
mov %ax, %fs
# Do not set %gs, it contains descriptor that can see TLS
 
# Pass the PCB pointer to __main as the first argument
pushl %ebx
call __main
call main
 
call __exit