Remove old stack code and improve dirstream

This commit is contained in:
Justine Tunney 2023-08-16 07:54:40 -07:00
parent 74caabb823
commit dc6c67256f
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
61 changed files with 463 additions and 595 deletions

View file

@ -21,7 +21,9 @@
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/zipos.internal.h"
#include "libc/sysv/errfuns.h"
/**
@ -30,14 +32,27 @@
* This does *not* update the `PWD` environment variable.
*
* @return 0 on success, or -1 w/ errno
* @raise ELOOP if a loop was detected resolving components of `path`
* @raise EACCES if search permission was denied on directory
* @raise ENOTDIR if component of `path` isn't a directory
* @raise ENOMEM if insufficient memory was available
* @raise EFAULT if `path` points to invalid memory
* @raise ENOTSUP if `path` is a `/zip/...` file
* @raise ENAMETOOLONG if `path` was too long
* @raise ENOENT if `path` doesn't exist
* @raise EIO if an i/o error happened
* @asyncsignalsafe
* @see fchdir()
*/
int chdir(const char *path) {
int rc;
struct ZiposUri zipname;
GetProgramExecutableName(); // XXX: ugly workaround
if (!path || (IsAsan() && !__asan_is_valid_str(path))) {
rc = efault();
} else if (_weaken(__zipos_parseuri) &&
_weaken(__zipos_parseuri)(path, &zipname) != -1) {
rc = enotsup();
} else if (!IsWindows()) {
rc = sys_chdir(path);
} else {

View file

@ -17,22 +17,30 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sysv/errfuns.h"
/**
* Sets current directory based on file descriptor.
*
* This does *not* update the `PWD` environment variable.
*
* @raise EACCES if search permission was denied on directory
* @raise ENOTDIR if `dirfd` doesn't refer to a directory
* @raise EBADF if `dirfd` isn't a valid file descriptor
* @raise ENOTSUP if `dirfd` refers to `/zip/...` file
* @see open(path, O_DIRECTORY)
* @asyncsignalsafe
*/
int fchdir(int dirfd) {
int rc;
if (!IsWindows()) {
if (__isfdkind(dirfd, kFdZip)) {
rc = enotsup();
} else if (!IsWindows()) {
rc = sys_fchdir(dirfd);
} else {
rc = sys_fchdir_nt(dirfd);

View file

@ -22,6 +22,7 @@
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/runtime/stack.h"
#include "libc/sysv/consts/rlimit.h"
#include "libc/sysv/errfuns.h"
@ -41,6 +42,10 @@ int getrlimit(int resource, struct rlimit *rlim) {
rc = efault();
} else if (!IsWindows()) {
rc = sys_getrlimit(resource, rlim);
} else if (resource == RLIMIT_STACK) {
rlim->rlim_cur = (uintptr_t)ape_stack_memsz;
rlim->rlim_max = (uintptr_t)ape_stack_memsz;
rc = 0;
} else if (resource == RLIMIT_AS) {
rlim->rlim_cur = __virtualmax;
rlim->rlim_max = __virtualmax;

View file

@ -78,6 +78,8 @@ int setrlimit(int resource, const struct rlimit *rlim) {
// TODO(jart): What's up with XNU and NetBSD?
__virtualmax = rlim->rlim_cur;
}
} else if (resource == RLIMIT_STACK) {
rc = enotsup();
} else if (resource == RLIMIT_AS) {
__virtualmax = rlim->rlim_cur;
rc = 0;

View file

@ -78,6 +78,7 @@ unsigned __wincrash(struct NtExceptionPointers *ep) {
break;
case kNtSignalGuardPage:
case kNtSignalInPageError:
case kNtStatusStackOverflow:
code = SEGV_MAPERR;
sig = SIGSEGV;
break;
@ -128,7 +129,9 @@ unsigned __wincrash(struct NtExceptionPointers *ep) {
sig = SIGSYS;
break;
default:
return kNtExceptionContinueSearch;
code = ep->ExceptionRecord->ExceptionCode;
sig = SIGSEGV;
break;
}
rip = ep->ContextRecord->Rip;