+++ /dev/null
-#ifndef __LUNAIX_DIRENT_H
-#define __LUNAIX_DIRENT_H
-
-#define DIRENT_NAME_MAX_LEN 256
-
-#define DT_FILE 0x0
-#define DT_DIR 0x1
-#define DT_SYMLINK 0x2
-#define DT_PIPE 0x2
-
-struct dirent
-{
- unsigned int d_type;
- unsigned int d_offset;
- unsigned int d_nlen;
- char d_name[DIRENT_NAME_MAX_LEN];
-};
-
-#endif /* __LUNAIX_DIRENT_H */
.skip 128
tmp_stack:
+/*
+ This perhaps the ugliest part in the project.
+ It contains code to handle arbitrary depth of
+ nested interrupt and all those corner cases and
+ nasty gotchas.
+
+ Be aware the twists, offsets and hidden dependencies!
+
+*/
+
.section .text
.global interrupt_wrapper
interrupt_wrapper:
}
*pte = *pte | pa | PG_PRESENT;
+ memset(PG_ALIGN(ptr), 0, PG_SIZE);
goto resolved;
}
// permission denied on anon page (e.g., write on readonly page)
// if mfile is set (Non-anonymous), then it is a mem map
if (hit_region->mfile && !PG_IS_PRESENT(*pte)) {
struct v_file* file = hit_region->mfile;
- u32_t offset =
- ((ptr - hit_region->start) & (PG_SIZE - 1)) + hit_region->foff;
+
+ ptr = PG_ALIGN(ptr);
+
+ u32_t offset = (ptr - hit_region->start) + hit_region->foff;
uintptr_t pa = pmm_alloc_page(__current->pid, 0);
if (!pa) {
cpu_invplg(pte);
*pte = (*pte & 0xFFF) | pa | PG_PRESENT;
- ptr = PG_ALIGN(ptr);
memset(ptr, 0, PG_SIZE);
int errno = 0;
struct mmap_param map_param = { .pvms = pvms,
.vms_mnt = param->vms_mnt,
- .flags = MAP_ANON | MAP_PRIVATE | MAP_FIXED,
+ .flags = MAP_ANON | MAP_PRIVATE,
.type = REGION_TYPE_HEAP,
.proct = PROT_READ | PROT_WRITE,
.mlen = DEFAULT_HEAP_PAGES * PG_SIZE };
schedule();
fail("should not reach");
}
+ goto done;
}
- isr_param* intr_ctx = &__current->intr_ctx;
- intr_ctx->esp = ldparam.info.stack_top;
- intr_ctx->eip = ldparam.info.entry;
+ volatile struct exec_param* execp = __current->intr_ctx.execp;
+ execp->esp = ldparam.info.stack_top;
+ execp->eip = ldparam.info.entry;
// we will jump to new entry point (_u_start) upon syscall's
// return so execve 'will not return' from the perspective of it's invoker
{
if (last_end < found_loc) {
size_t avail_space = pos->start - found_loc;
- if ((int)avail_space > 0 && avail_space > param->mlen) {
+ if (pos->start > found_loc && avail_space > param->mlen) {
goto found;
}
found_loc = pos->end + PG_SIZE;
}
- last_end = pos->end + PG_SIZE;
+ last_end = pos->end;
}
return ENOMEM;
}
}
- while (&pos->head != regions && cur_addr > pos->start) {
+ while (&pos->head != regions && cur_addr >= pos->start) {
u32_t l = pos->end - cur_addr;
pos->end = cur_addr;
cur_end = n->end;
pos = n;
n = list_entry(n->head.next, struct mm_region, head);
- } while ((ptr_t)&pos->head != (ptr_t)lead);
+ } while ((ptr_t)&n->head != (ptr_t)lead);
// XXX caution. require mm_region::head to be the lead of struct
llist_insert_after(&pos->head, &vmregion->head);
$(USR_DIR)/%:
@echo " BUILD $(*F)"
- @$(CC) -T usr/link-usr.ld $(INCLUDES) $(CFLAGS) $(LDFLAGS) uprog/$(*F).c $(BIN_DIR)/$(USR_LIB) -o $@
+ @$(CC) -T usr/link-usr.ld $(INCLUDES) $(CFLAGS) -g $(LDFLAGS) uprog/$(*F).c $(BIN_DIR)/$(USR_LIB) -o $@
all: $(PROGRAMES)
\ No newline at end of file
$(OBJECT_DIR)/%.c.o: %.c
@mkdir -p $(@D)
@echo " CC $<"
- @$(CC) $(INCLUDES) -c $< -o $@ $(CFLAGS)
+ @$(CC) $(INCLUDES) $(CFLAGS) -g -c $< -o $@
$(BIN_DIR)/$(USR_LIB): $(OBJS)
@echo " AR $@"
return 0;
}
- printf("(%p) user space!\n", main);
+ printf("(%p) user space!\n", (void*)main);
pid_t pid;
if (!(pid = fork())) {
}
}
+ closedir(dir);
+
return 0;
}
\ No newline at end of file
#include <lunaix/syscall.h>
-#include <sys/dirent.h>
+#include <sys/lxdirent.h>
__LXSYSCALL2(int, sys_readdir, int, fd, struct lx_dirent*, dent)
typedef struct
{
int dirfd;
- int prev_res;
+ struct lx_dirent _lxd;
} DIR;
struct dirent
};
DIR*
-opendir(const char* dir);
+opendir(const char* dirp);
+
+int
+closedir(DIR* dirp);
struct dirent*
readdir(DIR* dir);
#define stdout 0
#define stdin 1
-void
+int
printf(const char* fmt, ...);
-const char*
-strchr(const char* str, int character);
-
#endif /* __LUNAIX_USTDIO_H */
char*
strncpy(char* dest, const char* src, size_t n);
+const char*
+strchr(const char* str, int character);
+
#endif /* __LUNAIX_STRING_H */
#include <stdio.h>
#include <unistd.h>
-void
+int
printf(const char* fmt, ...)
{
char buf[1024];
#include <fcntl.h>
#include <string.h>
#include <sys/lxdirent.h>
+#include <unistd.h>
DIR*
opendir(const char* dir)
return NULL;
}
- _dir = (DIR){ .dirfd = fd, .prev_res = 0 };
+ _dir = (DIR){ .dirfd = fd };
return &_dir;
}
+int
+closedir(DIR* dirp)
+{
+ if (!dirp || dirp->dirfd == -1) {
+ // TODO migrate the status.h
+ return -1;
+ }
+
+ int err = close(dirp->dirfd);
+
+ if (!err) {
+ dirp->dirfd = -1;
+ return 0;
+ }
+
+ return -1;
+}
+
struct dirent*
readdir(DIR* dir)
{
return NULL;
}
- struct lx_dirent _lxd;
- int more = sys_readdir(dir->dirfd, &_lxd);
+ struct lx_dirent* _lxd = &dir->_lxd;
+
+ int more = sys_readdir(dir->dirfd, _lxd);
- _dirent.d_type = _lxd.d_type;
- strncpy(_dirent.d_name, _lxd.d_name, 256);
+ _dirent.d_type = _lxd->d_type;
+ strncpy(_dirent.d_name, _lxd->d_name, 256);
- if (more || dir->prev_res) {
- dir->prev_res = more;
+ if (more) {
return &_dirent;
}
- if (!dir->prev_res) {
- return NULL;
- }
+ return NULL;
}
\ No newline at end of file