current_process->cmdline[sizeof(current_process->cmdline) - 1] = '\0';
vmm_as_activate(user_as);
- /* Register this process as "init" for orphan reparenting */
- extern void sched_set_init_pid(uint32_t);
- sched_set_init_pid(current_process->pid);
+ /* Assign PID 1 to init, like Linux */
+ extern void sched_assign_pid1(struct process*);
+ sched_assign_pid1(current_process);
/* Open /dev/console as fd 0, 1, 2 — mirrors Linux kernel_init:
* sys_open("/dev/console", O_RDWR, 0);
#endif
struct process* ready_queue_head = NULL;
struct process* ready_queue_tail = NULL;
-static uint32_t next_pid = 1;
+static uint32_t next_pid = 2; /* PID 1 reserved for init */
static uint32_t init_pid = 0; /* PID of the first userspace process ("init") */
spinlock_t sched_lock = {0};
init_pid = pid;
}
+void sched_assign_pid1(struct process* p) {
+ if (!p) return;
+ uintptr_t flags = spin_lock_irqsave(&sched_lock);
+ p->pid = 1;
+ p->tgid = 1;
+ init_pid = 1;
+ spin_unlock_irqrestore(&sched_lock, flags);
+}
+
void process_exit_notify(int status) {
if (!current_process) return;
# The output is doom.elf which gets packaged into the AdrOS initrd.
CC := i686-elf-gcc
-AR := i686-elf-ar
+LD := i686-elf-ld
ULIBC_DIR := ../ulibc
ULIBC_INC := $(ULIBC_DIR)/include
-ULIBC_LIB := $(ULIBC_DIR)/libulibc.a
CRT0 := $(ULIBC_DIR)/src/crt0.o
-LINKER := ../linker.ld
+DYN_LINKER := ../dyn_linker.ld
-CFLAGS := -m32 -O2 -ffreestanding -fno-pie -no-pie -nostdlib \
+CFLAGS := -m32 -O2 -ffreestanding -nostdlib -fPIC -fno-plt \
-Wall -Wno-unused-parameter -Wno-sign-compare -Wno-pointer-sign \
-Wno-missing-field-initializers -Wno-implicit-fallthrough \
-Wno-format \
-I$(ULIBC_INC) -I. -Idoomgeneric/doomgeneric \
-DNORMALUNIX -DLINUX
-LDFLAGS := -m32 -nostdlib -fno-pie -no-pie -Wl,-T,$(LINKER)
+LDFLAGS := -m elf_i386 --dynamic-linker=/lib/ld.so -T $(DYN_LINKER) -L$(ULIBC_DIR) -rpath /lib
# doomgeneric engine sources (nested inside cloned repo)
# Exclude platform adapters and files requiring external libraries
exit 1; \
fi
-doom.elf: $(ALL_OBJ) $(ULIBC_LIB) $(CRT0)
- @$(CC) $(LDFLAGS) -o $@ $(CRT0) $(ALL_OBJ) $(ULIBC_LIB) -lgcc
+doom.elf: $(ALL_OBJ) $(CRT0)
+ @$(LD) $(LDFLAGS) -o $@ $(CRT0) $(ALL_OBJ) -lc
@echo " LD $@"
doomgeneric/doomgeneric/%.o: doomgeneric/doomgeneric/%.c
for (int i = 0; i < count; i++) {
if (lflag) {
+ char fullpath[512];
+ size_t plen = strlen(path);
+ if (plen > 0 && path[plen - 1] == '/')
+ snprintf(fullpath, sizeof(fullpath), "%s%s", path, entries[i].name);
+ else
+ snprintf(fullpath, sizeof(fullpath), "%s/%s", path, entries[i].name);
+
+ struct stat st;
+ int have_stat = (stat(fullpath, &st) == 0);
+
char type = '-';
if (entries[i].type == DT_DIR) type = 'd';
else if (entries[i].type == DT_CHR) type = 'c';
else if (entries[i].type == DT_LNK) type = 'l';
else if (entries[i].type == DT_BLK) type = 'b';
- printf("%c %s\n", type, entries[i].name);
+
+ char perms[10];
+ if (have_stat) {
+ unsigned m = (unsigned)st.st_mode;
+ perms[0] = (m & S_IRUSR) ? 'r' : '-';
+ perms[1] = (m & S_IWUSR) ? 'w' : '-';
+ perms[2] = (m & S_IXUSR) ? 'x' : '-';
+ perms[3] = (m & S_IRGRP) ? 'r' : '-';
+ perms[4] = (m & S_IWGRP) ? 'w' : '-';
+ perms[5] = (m & S_IXGRP) ? 'x' : '-';
+ perms[6] = (m & S_IROTH) ? 'r' : '-';
+ perms[7] = (m & S_IWOTH) ? 'w' : '-';
+ perms[8] = (m & S_IXOTH) ? 'x' : '-';
+ perms[9] = '\0';
+ } else {
+ strcpy(perms, "---------");
+ }
+
+ unsigned long sz = have_stat ? (unsigned long)st.st_size : 0;
+ unsigned nlink = have_stat ? (unsigned)st.st_nlink : 1;
+
+ printf("%c%s %2u root root %8lu %s\n",
+ type, perms, nlink, sz, entries[i].name);
} else {
printf("%s\n", entries[i].name);
}