summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
ec99de1)
feat: environ access
refactor: status code user space port
12 files changed:
u32_t type; // region type
};
u32_t type; // region type
};
+int
+mem_adjust_inplace(vm_regions_t* regions,
+ struct mm_region* region,
+ ptr_t newend);
+
int
mem_map(void** addr_out,
struct mm_region** created,
int
mem_map(void** addr_out,
struct mm_region** created,
#include <lunaix/spike.h>
#include <lunaix/status.h>
#include <lunaix/syscall.h>
#include <lunaix/spike.h>
#include <lunaix/status.h>
#include <lunaix/syscall.h>
+#include <lunaix/syscall_utils.h>
#include <klibc/string.h>
#include <klibc/string.h>
.flags = MAP_ANON | MAP_PRIVATE,
.type = REGION_TYPE_HEAP,
.proct = PROT_READ | PROT_WRITE,
.flags = MAP_ANON | MAP_PRIVATE,
.type = REGION_TYPE_HEAP,
.proct = PROT_READ | PROT_WRITE,
- .mlen = DEFAULT_HEAP_PAGES * PG_SIZE };
int status = 0;
struct mm_region* heap;
if ((status = mem_map(NULL, &heap, param->info.end, NULL, &map_param))) {
int status = 0;
struct mm_region* heap;
if ((status = mem_map(NULL, &heap, param->info.end, NULL, &map_param))) {
// return so execve 'will not return' from the perspective of it's invoker
done:
// return so execve 'will not return' from the perspective of it's invoker
done:
+ return DO_STATUS(errno);
}
\ No newline at end of file
}
\ No newline at end of file
-#include <lunaix/mm/page.h>
-#include <lunaix/mm/vmm.h>
+#include <lunaix/mm/mmap.h>
+#include <lunaix/process.h>
#include <lunaix/status.h>
#include <lunaix/spike.h>
#include <lunaix/syscall.h>
#include <lunaix/status.h>
#include <lunaix/spike.h>
#include <lunaix/syscall.h>
+#include <lunaix/syscall_utils.h>
-__DEFINE_LXSYSCALL1(int, sbrk, size_t, size)
+__DEFINE_LXSYSCALL1(void*, sbrk, ssize_t, incr)
- // TODO mem_remap to expand heap region
- return 0;
+ struct proc_mm* pvms = &__current->mm;
+ struct mm_region* heap = pvms->heap;
+
+ assert(heap);
+ int err = mem_adjust_inplace(&pvms->regions, heap, heap->end + incr);
+ if (err) {
+ return (void*)DO_STATUS(err);
+ }
+ return (void*)heap->end;
-__DEFINE_LXSYSCALL1(void*, brk, void*, addr)
+__DEFINE_LXSYSCALL1(int, brk, void*, addr)
- // TODO mem_remap to expand heap region
- return 0;
+ struct proc_mm* pvms = &__current->mm;
+ struct mm_region* heap = pvms->heap;
+
+ assert(heap);
+ int err = mem_adjust_inplace(&pvms->regions, heap, (ptr_t)addr);
+ return DO_STATUS(err);
}
\ No newline at end of file
}
\ No newline at end of file
#define BS_SIZE (KERNEL_MM_BASE - UMMAP_START)
int
#define BS_SIZE (KERNEL_MM_BASE - UMMAP_START)
int
-mem_has_overlap(vm_regions_t* regions, ptr_t start, size_t len)
+mem_has_overlap(vm_regions_t* regions, ptr_t start, ptr_t end)
- ptr_t end = start + end - 1;
struct mm_region *pos, *n;
llist_for_each(pos, n, regions, head)
{
struct mm_region *pos, *n;
llist_for_each(pos, n, regions, head)
{
+int
+mem_adjust_inplace(vm_regions_t* regions,
+ struct mm_region* region,
+ ptr_t newend)
+{
+ ssize_t len = newend - region->start;
+ if (len == 0) {
+ return 0;
+ }
+
+ if (len < 0) {
+ return EINVAL;
+ }
+
+ if (mem_has_overlap(regions, region->start, newend)) {
+ return ENOMEM;
+ }
+
+ region->end = newend;
+
+ return 0;
+}
+
int
mem_map(void** addr_out,
struct mm_region** created,
int
mem_map(void** addr_out,
struct mm_region** created,
vm_regions_t* vm_regions = ¶m->pvms->regions;
if ((param->flags & MAP_FIXED_NOREPLACE)) {
vm_regions_t* vm_regions = ¶m->pvms->regions;
if ((param->flags & MAP_FIXED_NOREPLACE)) {
- if (mem_has_overlap(vm_regions, found_loc, param->mlen)) {
+ if (mem_has_overlap(vm_regions, found_loc, param->mlen + found_loc)) {
return EEXIST;
}
goto found;
return EEXIST;
}
goto found;
-__LXSYSCALL1(int, sbrk, void*, addr)
+__LXSYSCALL1(int, brk, void*, addr)
-__LXSYSCALL1(void*, brk, unsigned long, size)
+__LXSYSCALL1(void*, sbrk, ssize_t, size)
__LXSYSCALL(pid_t, getpid)
__LXSYSCALL(pid_t, getpid)
#ifndef __LUNAIX_SYS_ERRNO_H
#define __LUNAIX_SYS_ERRNO_H
#ifndef __LUNAIX_SYS_ERRNO_H
#define __LUNAIX_SYS_ERRNO_H
+#define EINVAL -(6)
+#define EINTR -(7)
+#define EMFILE -8
+#define ENOENT -9
+#define ENAMETOOLONG -10
+#define ENOTDIR -11
+#define EEXIST -12
+#define EBADF -13
+#define ENOTSUP -14
+#define EIO -15
+#define ELOOP -16
+#define ENOTEMPTY -17
+#define EROFS -18
+#define EISDIR -19
+#define EBUSY -20
+#define EXDEV -21
+#define ENODEV -22
+#define ERANGE -23
+#define ENOMEM -(3)
+#define ENOTDEV -24
+#define EOVERFLOW -25
+#define ENOTBLK -26
+#define ENOEXEC -27
+#define E2BIG -28
+
const char*
strchr(const char* str, int character);
const char*
strchr(const char* str, int character);
+char*
+strcpy(char* dest, const char* src);
+
#endif /* __LUNAIX_STRING_H */
#endif /* __LUNAIX_STRING_H */
#ifndef __LUNAIX_SYS_IOCTL_H
#define __LUNAIX_SYS_IOCTL_H
#ifndef __LUNAIX_SYS_IOCTL_H
#define __LUNAIX_SYS_IOCTL_H
+#include <sys/ioctl_defs.h>
+
int
ioctl(int fd, int req, ...);
int
ioctl(int fd, int req, ...);
+extern const char** environ;
+
setpgid(pid_t pid, pid_t pgid);
int
setpgid(pid_t pid, pid_t pgid);
int
while (i <= n)
dest[i++] = 0;
return dest;
while (i <= n)
dest[i++] = 0;
return dest;
-}
\ No newline at end of file
+}
+
+char*
+strcpy(char* dest, const char* src)
+{
+ char c;
+ unsigned int i = 0;
+ while ((c = src[i])) {
+ dest[i] = c;
+ i++;
+ }
+ dest[i] = '\0';
+ return dest;
+}
{
// TODO some inits before executing user program
{
// TODO some inits before executing user program
+ extern ptr_t environ;
+ environ = (ptr_t)param->envp;
+
return 0;
}
\ No newline at end of file
return 0;
}
\ No newline at end of file
#define __ASM__
#include <lunaix/syscall.h>
#define __ASM__
#include <lunaix/syscall.h>
+.section .data
+ .global environ
+ environ:
+ .long 0
+
.section .text
.global _u_start
_u_start:
.section .text
.global _u_start
_u_start: