1/*
2 * QuickThreads -- Threads-building toolkit.
3 * Copyright (c) 1993 by David Keppel
4 *
5 * Permission to use, copy, modify and distribute this software and
6 * its documentation for any purpose and without fee is hereby
7 * granted, provided that the above copyright notice and this notice
8 * appear in all copies.  This software is provided as a
9 * proof-of-concept and for demonstration purposes; there is no
10 * representation about the suitability of this software for any
11 * purpose.
12 */
13
14
15#include <stdarg.h>
16#include "qt.h"
17
18// This static is used to find the end of the stack for variable
19
20static void *qt_sp_bottom_save;
21
22/* We actually don't know how the compiler accomodates arguments in the
23 * va_list. In some implementation (e.g. Linux PPC) we cannot scan the
24 * list as an array. To avoid this problem, this version of "qt_varg",
25 * retrieves arguments by means of the standard "va_arg" macro defined
26 * in stdargs.h.
27 *
28 * Notice that we still suppose that the number of arguments is given
29 * by nbytes/sizeof(qt_word_t) and we load the stack of "qt_vstart"
30 * assuming that all parameters are alligned to the size of qt_word_t.
31 *
32 * Marco Bucci <marco.bucci@inwind.it>
33 * December 2002
34 */
35
36/*
37
38qt_t *qt_vargs (qt_t *sp, int nbytes, void *vargs,
39	  void *pt, qt_startup_t *startup,
40	  qt_vuserf_t *vuserf, qt_cleanup_t *cleanup)
41
42*/
43
44  qt_t *
45qt_vargs_stdarg (qt_t *sp, int nbytes, va_list vargs,
46	  void *pt, qt_startup_t *startup,
47	  qt_vuserf_t *vuserf, qt_cleanup_t *cleanup)
48
49
50
51{
52	int i;
53	qt_word_t arg;
54
55	sp = QUICKTHREADS_VARGS_MD0 (sp, nbytes);
56
57	for ( i=0;i<(int)(nbytes/sizeof(qt_word_t)); i++)
58    {
59    	arg = va_arg(vargs, qt_word_t);
60      	QUICKTHREADS_SPUT (QUICKTHREADS_VARGS_ADJUST(sp), i, arg);
61    }
62
63	QUICKTHREADS_VARGS_MD1 (QUICKTHREADS_VADJ(sp));
64	QUICKTHREADS_SPUT (QUICKTHREADS_VADJ(sp), QUICKTHREADS_VARGT_INDEX, pt);
65	QUICKTHREADS_SPUT (QUICKTHREADS_VADJ(sp), QUICKTHREADS_VSTARTUP_INDEX, startup);
66	QUICKTHREADS_SPUT (QUICKTHREADS_VADJ(sp), QUICKTHREADS_VUSERF_INDEX, vuserf);
67	QUICKTHREADS_SPUT (QUICKTHREADS_VADJ(sp), QUICKTHREADS_VCLEANUP_INDEX, cleanup);
68	return ((qt_t *)QUICKTHREADS_VADJ(sp));
69}
70