Skip to content

Commit

Permalink
support axlibc and solve page fault
Browse files Browse the repository at this point in the history
  • Loading branch information
lhw2002426 committed Dec 7, 2023
1 parent 40d1727 commit 343efeb
Show file tree
Hide file tree
Showing 59 changed files with 1,573 additions and 15 deletions.
1 change: 0 additions & 1 deletion api/arceos_posix_api/src/imp/fd_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ pub fn sys_dup2(old_fd: c_int, new_fd: c_int) -> c_int {
if new_fd as usize >= AX_FILE_LIMIT {
return Err(LinuxError::EBADF);
}
let _ = close_file_like(new_fd).map(|_| 0);

let f = get_file_like(old_fd)?;
FD_TABLE
Expand Down
9 changes: 8 additions & 1 deletion apps/c/nginx/axbuild.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ ifneq ($(V),)
nginx-build-args += V=$(V)
endif

ifeq ($(V9P),y)
DISK_ARG = 9p
else
DISK_ARG = no_9p
endif


disk.img:
ls
echo "nginx makefile create_nginx_img"
./$(APP)/create_nginx_img.sh
./$(APP)/create_nginx_img.sh $(DISK_ARG)

$(nginx-dir):
git clone https://github.com/lhw2002426/nginx-app.git $(APP)/nginx-app
Expand Down
13 changes: 10 additions & 3 deletions apps/c/nginx/create_nginx_img.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#!/bin/bash

# From https://github.com/rafalh/rust-fatfs/blob/master/scripts/create-test-img.sh

CUR_DIR=`dirname $0`
CUR_DIR=$(dirname $0)

echo $OUT_DIR

if [ $# -lt 1 ]; then
CONF = "$CUR_DIR/nginx.conf"
elif [ "$arg1" = "9p" ]; then
CONF = "$CUR_DIR/nginx_9p.conf"
else
CONF = "$CUR_DIR/nginx.conf"
fi

create_test_img() {
local name=$1
local blkcount=$2
Expand All @@ -21,7 +28,7 @@ create_test_img() {
echo "root:x:0:" >> "mnt/etc/group"
# echo "" >> "mnt/nginx/logs/error.log"
mkdir -p "mnt/nginx/conf"
cp "$CUR_DIR/nginx.conf" "mnt/nginx/conf/nginx.conf"
cp "$CONF" "mnt/nginx/conf/nginx.conf"
cp "$CUR_DIR/mime.types" "mnt/nginx/conf/mime.types"
mkdir -p "mnt/html"
cp -r "$CUR_DIR/html" "mnt/"
Expand Down
3 changes: 2 additions & 1 deletion apps/c/nginx/features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ pipe
epoll
poll
select
virtio-9p
virtio-9p
rtc
10 changes: 10 additions & 0 deletions apps/c/nginx/mnt/etc/group
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root:x:0:
root:x:0:
root:x:0:
root:x:0:
root:x:0:
root:x:0:
root:x:0:
root:x:0:
root:x:0:
root:x:0:
10 changes: 10 additions & 0 deletions apps/c/nginx/mnt/etc/localtime
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@










10 changes: 10 additions & 0 deletions apps/c/nginx/mnt/etc/passwd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
40 changes: 40 additions & 0 deletions apps/c/nginx/nginx_9p.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
worker_processes 1;
daemon off;
master_process off;

error_log logs/error.log debug;

events {
worker_connections 32;
}

http {
include mime.types;
default_type application/octet-stream;

keepalive_timeout 65;

server {
listen 5555;
server_name localhost;

index index.html;

root /v9fs;

location / {
try_files $uri $uri/ /404.html;
}

error_page 404 /404.html;
location = /404.html {
root /v9fs;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /v9fs;
}

}
}
6 changes: 6 additions & 0 deletions ulib/axlibc/c/fcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,10 @@ int sync_file_range(int fd, off_t pos, off_t len, unsigned flags)
return 0;
}

int openat(int dirfd, const char *pathname, int flags, ...)
{
unimplemented();
return 0;
}

#endif // AX_CONFIG_FS
46 changes: 46 additions & 0 deletions ulib/axlibc/c/grp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* Copyright (c) [2023] [Syswonder Community]
* [Rukos] is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

#include <stdio.h>
#include <grp.h>
#include <pwd.h>
#include <string.h>
#include <errno.h>

/* Group members */
static char *g_members__[] = { AX_DEFAULT_USER, NULL };

/* Default group */
static struct group g__ = {
.gr_name = AX_DEFAULT_GROUP,
.gr_passwd = AX_DEFAULT_PASS,
.gr_gid = AX_DEFAULT_GID,
.gr_mem = g_members__,
};

// TODO
int initgroups(const char *user, gid_t group)
{
unimplemented();
return 0;
}

struct group *getgrnam(const char *name)
{
struct group *res;

if (name && !strcmp(name, g__.gr_name))
res = &g__;
else {
res = NULL;
errno = ENOENT;
}

return res;
}
14 changes: 11 additions & 3 deletions ulib/axlibc/c/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@

#include <stdio.h>
#include <sys/ioctl.h>
#include <stdarg.h>

int ax_ioctl(int fd, int cmd, size_t arg);

// TODO
int ioctl(int __fd, int __request, ...)
int ioctl(int fd, int request, ...)
{
unimplemented();
return 0;
unsigned long arg;
va_list ap;
va_start(ap, request);
arg = va_arg(ap, unsigned long);
va_end(ap);

return ax_ioctl(fd, request, arg);
}
13 changes: 10 additions & 3 deletions ulib/axlibc/c/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@
// TODO:
void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off)
{
unimplemented();
return MAP_FAILED;
//unimplemented();
//return MAP_FAILED;
int *res = malloc(len);
if (res == NULL) {
return NULL;
}
printf("use malloc imp mmap: addr: %p len: %d res: %p\n",addr,len,res);
printf("if i can acess res: %d",*res);
return res;
}

// TODO:
int munmap(void *addr, size_t length)
{
unimplemented();
free(addr);
return 0;
}

Expand Down
19 changes: 19 additions & 0 deletions ulib/axlibc/c/netdb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Copyright (c) [2023] [Syswonder Community]
* [Rukos] is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

#include <stdio.h>
#include <netdb.h>


// TODO
struct hostent *gethostbyname(const char *name)
{
unimplemented();
return 0;
}
44 changes: 44 additions & 0 deletions ulib/axlibc/c/nscd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef NSCD_H
#define NSCD_H

#include <stdint.h>

#define NSCDVERSION 2
#define GETPWBYNAME 0
#define GETPWBYUID 1
#define GETGRBYNAME 2
#define GETGRBYGID 3
#define GETINITGR 15

#define REQVERSION 0
#define REQTYPE 1
#define REQKEYLEN 2
#define REQ_LEN 3

#define PWVERSION 0
#define PWFOUND 1
#define PWNAMELEN 2
#define PWPASSWDLEN 3
#define PWUID 4
#define PWGID 5
#define PWGECOSLEN 6
#define PWDIRLEN 7
#define PWSHELLLEN 8
#define PW_LEN 9

#define GRVERSION 0
#define GRFOUND 1
#define GRNAMELEN 2
#define GRPASSWDLEN 3
#define GRGID 4
#define GRMEMCNT 5
#define GR_LEN 6

#define INITGRVERSION 0
#define INITGRFOUND 1
#define INITGRNGRPS 2
#define INITGR_LEN 3

FILE *__nscd_query(int32_t req, const char *key, int32_t *buf, size_t len, int *swap);

#endif
Loading

0 comments on commit 343efeb

Please sign in to comment.