Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F109084029
D15469.id51374.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D15469.id51374.diff
View Options
Index: sys/kern/init_main.c
===================================================================
--- sys/kern/init_main.c
+++ sys/kern/init_main.c
@@ -56,6 +56,7 @@
#include <sys/exec.h>
#include <sys/file.h>
#include <sys/filedesc.h>
+#include <sys/imgact.h>
#include <sys/jail.h>
#include <sys/ktr.h>
#include <sys/lock.h>
@@ -716,13 +717,12 @@
static void
start_init(void *dummy)
{
- vm_offset_t addr;
- struct execve_args args;
+ struct image_args args;
int options, error;
size_t pathlen;
+ char flags[8], *flagp;
char *var, *path;
char *free_init_path, *tmp_init_path;
- char *ucp, **uap, *arg0, *arg1;
struct thread *td;
struct proc *p;
@@ -736,16 +736,6 @@
/* Wipe GELI passphrase from the environment. */
kern_unsetenv("kern.geom.eli.passphrase");
- /*
- * Need just enough stack to hold the faked-up "execve()" arguments.
- */
- addr = p->p_sysent->sv_usrstack - PAGE_SIZE;
- if (vm_map_find(&p->p_vmspace->vm_map, NULL, 0, &addr, PAGE_SIZE, 0,
- VMFS_NO_SPACE, VM_PROT_ALL, VM_PROT_ALL, 0) != 0)
- panic("init: couldn't allocate argument space");
- p->p_vmspace->vm_maxsaddr = (caddr_t)addr;
- p->p_vmspace->vm_ssize = 1;
-
if ((var = kern_getenv("init_path")) != NULL) {
strlcpy(init_path, var, sizeof(init_path));
freeenv(var);
@@ -757,54 +747,44 @@
if (bootverbose)
printf("start_init: trying %s\n", path);
- /*
- * Move out the boot flag argument.
- */
+ memset(&args, 0, sizeof(args));
+ error = exec_alloc_args(&args);
+ if (error != 0)
+ panic("%s: Can't allocate space for init arguments %d",
+ __func__, error);
+
+ error = exec_args_add_fname(&args, path, UIO_SYSSPACE);
+ if (error != 0)
+ panic("%s: Can't add fname %d", __func__, error);
+
+ error = exec_args_add_arg(&args, path, UIO_SYSSPACE);
+ if (error != 0)
+ panic("%s: Can't add argv[0] %d", __func__, error);
+
options = 0;
- ucp = (char *)p->p_sysent->sv_usrstack;
- (void)subyte(--ucp, 0); /* trailing zero */
- if (boothowto & RB_SINGLE) {
- (void)subyte(--ucp, 's');
- options = 1;
- }
+ flagp = &flags[0];
+ *flagp++ = '-';
+#ifdef BOOTCDROM
+ *flagp++ = 'C';
+ options++;
+#endif
#ifdef notyet
if (boothowto & RB_FASTBOOT) {
- (void)subyte(--ucp, 'f');
- options = 1;
+ *flagp++ = 'f';
+ options++;
}
#endif
-
-#ifdef BOOTCDROM
- (void)subyte(--ucp, 'C');
- options = 1;
-#endif
-
+ if (boothowto & RB_SINGLE) {
+ *flagp++ = 's';
+ options++;
+ }
if (options == 0)
- (void)subyte(--ucp, '-');
- (void)subyte(--ucp, '-'); /* leading hyphen */
- arg1 = ucp;
-
- /*
- * Move out the file name (also arg 0).
- */
- ucp -= pathlen;
- copyout(path, ucp, pathlen);
- arg0 = ucp;
-
- /*
- * Move out the arg pointers.
- */
- uap = (char **)rounddown2((intptr_t)ucp, sizeof(intptr_t));
- (void)suword((caddr_t)--uap, (long)0); /* terminator */
- (void)suword((caddr_t)--uap, (long)(intptr_t)arg1);
- (void)suword((caddr_t)--uap, (long)(intptr_t)arg0);
-
- /*
- * Point at the arguments.
- */
- args.fname = arg0;
- args.argv = uap;
- args.envv = NULL;
+ *flagp++ = '-';
+ *flagp++ = 0;
+ KASSERT(flagp <= &flags[0] + sizeof(flags), ("Overran flags"));
+ error = exec_args_add_arg(&args, flags, UIO_SYSSPACE);
+ if (error != 0)
+ panic("%s: Can't add argv[0] %d", __func__, error);
/*
* Now try to exec the program. If can't for any reason
@@ -813,7 +793,7 @@
* Otherwise, return via fork_trampoline() all the way
* to user mode as init!
*/
- if ((error = sys_execve(td, &args)) == EJUSTRETURN) {
+ if ((error = kern_execve(td, &args, NULL)) == EJUSTRETURN) {
free(free_init_path, M_TEMP);
TSEXIT();
return;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Feb 1, 2:27 PM (15 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16384372
Default Alt Text
D15469.id51374.diff (3 KB)
Attached To
Mode
D15469: Remove a needlessly clever hack to start init with sys_exec().
Attached
Detach File
Event Timeline
Log In to Comment