XINU
addargs.c
Go to the documentation of this file.
1 
5 #include <xinu.h>
6 #include "shprototypes.h"
7 
33 status addargs(pid32 pid, int32 ntok, int32 tok[], int32 tlen, char *tokbuf, void *dummy)
34 {
35  intmask mask; /* Saved interrupt mask */
36  struct procent *prptr; /* Ptr to process' table entry */
37  uint32 aloc; /* Argument location in process stack as an integer */
38  uint32 *argloc; /* Location in process's stack to place args vector */
39  char *argstr; /* Location in process's stack to place arg strings */
40  uint32 *search; /* pointer that searches for dummy argument on stack */
41  uint32 *aptr; /* Walks through args array */
42  int32 i; /* Index into tok array */
43 
44  mask = disable();
45 
46  /* Check argument count and data length */
47 
48  if ((ntok <= 0) || (tlen < 0))
49  {
50  restore(mask);
51  return SYSERR;
52  }
53 
54  prptr = &proctab[pid];
55 
56  /* Compute lowest location in the process stack where the */
57  /* args array will be stored followed by the argument */
58  /* strings */
59 
60  aloc = (uint32)(prptr->prstkbase - prptr->prstklen + sizeof(uint32));
61  argloc = (uint32 *)((aloc + 3) & ~0x3); /* round multiple of 4 */
62 
63  /* Compute the first location beyond args array for the strings */
64 
65  argstr = (char *)(argloc + (ntok + 1)); /* +1 for a null ptr */
66 
67  /* Set each location in the args vector to be the address of */
68  /* string area plus the offset of this argument */
69 
70  for (aptr = argloc, i = 0; i < ntok; i++)
71  {
72  *aptr++ = (uint32)(argstr + tok[i]);
73  }
74 
75  /* Add a null pointer to the args array */
76 
77  *aptr++ = (uint32)NULL;
78 
79  /* Copy the argument strings from tokbuf into process's stack */
80  /* just beyond the args vector */
81 
82  memcpy(aptr, tokbuf, tlen);
83 
84  /* Find the second argument in process's stack */
85 
86  for (search = (uint32 *)prptr->prstkptr;
87  search < (uint32 *)prptr->prstkbase; search++)
88  {
89 
90  /* If found, replace with the address of the args vector*/
91 
92  if (*search == (uint32)dummy)
93  {
94  *search = (uint32)argloc;
95  restore(mask);
96  return OK;
97  }
98  }
99 
100  /* Argument value not found on the stack - report an error */
101 
102  restore(mask);
103  return SYSERR;
104 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
void restore(intmask)
全てのシステムヘッダファイルをインクルードする。
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
int32 status
ステータスを意味する返り値の型(OK/SYSERR)
Definition: kernel.h:57
uint32 prstklen
Bytesで表されたスタックの長さ(最大値。Byte)。
Definition: process.h:96
status addargs(pid32 pid, int32 ntok, int32 tok[], int32 tlen, char *tokbuf, void *dummy)
XINUシェルが作成したコマンドプロセスのスタックに引数argv(任意個)のローカルコピーを追加する。 ...
Definition: addargs.c:33
char * prstkbase
ランタイムスタックの基点(メモリ領域で最上位のアドレス)。
Definition: process.h:94
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
int32 pid32
プロセスID
Definition: kernel.h:26
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
char * prstkptr
保存されたスタックポインタ。
Definition: process.h:92