Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennisbonke committed Feb 3, 2025
1 parent 3e26b9f commit 27b10cb
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 8 deletions.
4 changes: 4 additions & 0 deletions abis/linux/fcntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
#define F_SEAL_GROW 0x0004
#define F_SEAL_WRITE 0x0008

#define F_OFD_GETLK 36
#define F_OFD_SETLK 37
#define F_OFD_SETLKW 38

#define F_RDLCK 0
#define F_WRLCK 1
#define F_UNLCK 2
Expand Down
25 changes: 22 additions & 3 deletions options/posix/generic/grp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,28 @@ int putgrent(const struct group *g, FILE *f) {
return r < 0 ? -1 : 0;
}

struct group *fgetgrent(FILE *) {
__ensure(!"Not implemented");
__builtin_unreachable();
struct group *fgetgrent(FILE *file) {
static group entry;
char line[512];

// if(!open_global_file()) {
// return nullptr;
// }

if(fgets(line, 512, file)) {
clear_entry(&entry);
if(!extract_entry(line, &entry)) {
errno = EINVAL;
return nullptr;
}
return &entry;
}

if(ferror(file)) {
errno = EIO;
}

return nullptr;
}

int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups) {
Expand Down
25 changes: 22 additions & 3 deletions options/posix/generic/pwd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,26 @@ int putpwent(const struct passwd *p, FILE *f) {
return fprintf(f, "%s:%s:%u:%u:%s:%s:%s\n", p->pw_name, p->pw_passwd, p->pw_uid, p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell) < 0 ? -1 : 0;
}

struct passwd *fgetpwent(FILE *) {
__ensure(!"Not implemented");
__builtin_unreachable();
struct passwd *fgetpwent(FILE *file) {
static passwd entry;
char line[NSS_BUFLEN_PASSWD];

// if(!open_global_file()) {
// return nullptr;
// }

if (fgets(line, NSS_BUFLEN_PASSWD, file)) {
clear_entry(&entry);
if(!extract_entry(line, &entry)) {
errno = EINVAL; // I suppose this can be a valid errno?
return nullptr;
}
return &entry;
}

if(ferror(file)) {
errno = EIO;
}

return nullptr;
}
16 changes: 14 additions & 2 deletions options/posix/generic/unistd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <termios.h>
#include <pwd.h>
#include <sys/ioctl.h>
#include <sys/stat.h>

#include <bits/ensure.h>
#include <mlibc/allocator.hpp>
Expand Down Expand Up @@ -908,8 +909,17 @@ char *getpass(const char *prompt) {
}

char *get_current_dir_name(void) {
__ensure(!"Not implemented");
__builtin_unreachable();
char *pwd;
struct stat dotstat, pwdstat;

pwd = getenv ("PWD");
if(pwd != NULL && stat(".", &dotstat) == 0
&& stat(pwd, &pwdstat) == 0 && pwdstat.st_dev == dotstat.st_dev
&& pwdstat.st_ino == dotstat.st_ino)
/* The PWD value is correct. Use it. */
return strdup(pwd);

return getcwd((char *) NULL, 0);
}

// This is a Linux extension
Expand Down Expand Up @@ -997,6 +1007,7 @@ int usleep(useconds_t usecs) {
}

int dup(int fd) {
mlibc::infoLogger() << "mlibc: dup called" << frg::endlog;
int newfd;
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_dup, -1);
if(int e = mlibc::sys_dup(fd, 0, &newfd); e) {
Expand All @@ -1007,6 +1018,7 @@ int dup(int fd) {
}

int dup2(int fd, int newfd) {
mlibc::infoLogger() << "mlibc: dup2 called" << frg::endlog;
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_dup2, -1);
if(int e = mlibc::sys_dup2(fd, 0, newfd); e) {
errno = e;
Expand Down
11 changes: 11 additions & 0 deletions sysdeps/managarm/generic/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,17 @@ int sys_fcntl(int fd, int request, va_list args, int *result) {
lock->l_type = F_UNLCK;
mlibc::infoLogger() << "\e[31mmlibc: F_GETLK is stubbed!\e[39m" << frg::endlog;
return 0;
} else if (request == F_OFD_SETLK) {
mlibc::infoLogger() << "\e[31mmlibc: F_OFD_SETLK\e[39m" << frg::endlog;
return 0;
} else if (request == F_OFD_SETLKW) {
mlibc::infoLogger() << "\e[31mmlibc: F_OFD_SETLKW\e[39m" << frg::endlog;
return 0;
} else if (request == F_OFD_GETLK) {
struct flock *lock = va_arg(args, struct flock *);
lock->l_type = F_UNLCK;
mlibc::infoLogger() << "\e[31mmlibc: F_OFD_GETLK is stubbed!\e[39m" << frg::endlog;
return 0;
} else if (request == F_ADD_SEALS) {
auto seals = va_arg(args, int);
auto handle = getHandleForFd(fd);
Expand Down
1 change: 1 addition & 0 deletions sysdeps/managarm/generic/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ sys_getsockopt(int fd, int layer, int number, void *__restrict buffer, socklen_t
creds.pid = resp.pid();
creds.uid = resp.uid();
creds.gid = resp.gid();
mlibc::infoLogger() << "GROTE KANKER: " << creds.pid << " and " << creds.uid << " and " << creds.gid << frg::endlog;
memcpy(buffer, &creds, sizeof(struct ucred));
return 0;
} else if (layer == SOL_SOCKET && number == SO_SNDBUF) {
Expand Down

0 comments on commit 27b10cb

Please sign in to comment.