mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:37:36 +00:00
Rage hacking to get bash to run. It finally runs. So cool! :^)
This commit is contained in:
parent
9b70808ab5
commit
d5d45d1088
31 changed files with 567 additions and 61 deletions
|
@ -28,6 +28,8 @@ LIBC_OBJS = \
|
|||
ctype.o \
|
||||
fcntl.o \
|
||||
termios.o \
|
||||
ulimit.o \
|
||||
qsort.o \
|
||||
entry.o
|
||||
|
||||
OBJS = $(AK_OBJS) $(LIBC_OBJS)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
|
||||
extern "C" {
|
||||
|
|
77
LibC/qsort.cpp
Normal file
77
LibC/qsort.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*-
|
||||
* Copyright (c) 1980, 1983, 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)qsort.c 5.9 (Berkeley) 2/23/91";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void insertion_sort(void* bot, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
|
||||
|
||||
void qsort(void* bot, size_t nmemb, size_t size, int (*compar)(const void *, const void *))
|
||||
{
|
||||
if (nmemb <= 1)
|
||||
return;
|
||||
|
||||
insertion_sort(bot, nmemb, size, compar);
|
||||
}
|
||||
|
||||
void insertion_sort(void* bot, size_t nmemb, size_t size, int (*compar)(const void *, const void *))
|
||||
{
|
||||
int cnt;
|
||||
unsigned char ch;
|
||||
char *s1, *s2, *t1, *t2, *top;
|
||||
|
||||
/*
|
||||
* A simple insertion sort (see Knuth, Vol. 3, page 81, Algorithm
|
||||
* S). Insertion sort has the same worst case as most simple sorts
|
||||
* (O N^2). It gets used here because it is (O N) in the case of
|
||||
* sorted data.
|
||||
*/
|
||||
top = (char*)bot + nmemb * size;
|
||||
for (t1 = (char*)bot + size; t1 < top;) {
|
||||
for (t2 = t1; (t2 -= size) >= bot && compar(t1, t2) < 0;);
|
||||
if (t1 != (t2 += size)) {
|
||||
/* Bubble bytes up through each element. */
|
||||
for (cnt = size; cnt--; ++t1) {
|
||||
ch = *t1;
|
||||
for (s1 = s2 = t1; (s2 -= size) >= t2; s1 = s2)
|
||||
*s1 = *s2;
|
||||
*s1 = ch;
|
||||
}
|
||||
} else
|
||||
t1 += size;
|
||||
}
|
||||
}
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
int setjmp(jmp_buf)
|
||||
{
|
||||
assert(false);
|
||||
//assert(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void longjmp(jmp_buf, int)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
|
||||
extern "C" {
|
||||
|
|
|
@ -45,6 +45,7 @@ void __stdio_init()
|
|||
|
||||
int setvbuf(FILE* stream, char* buf, int mode, size_t size)
|
||||
{
|
||||
fprintf(stderr, "setvbuf(%p [fd=%d], %p, %d, %u)\n", stream, stream->fd, buf, mode, size);
|
||||
if (mode != _IONBF && mode != _IOLBF && mode != _IOFBF) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
|
@ -57,6 +58,7 @@ int setvbuf(FILE* stream, char* buf, int mode, size_t size)
|
|||
stream->buffer = stream->default_buffer;
|
||||
stream->buffer_size = BUFSIZ;
|
||||
}
|
||||
stream->buffer_index = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -65,9 +67,9 @@ void setbuf(FILE* stream, char* buf)
|
|||
setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
|
||||
}
|
||||
|
||||
void setlinebuf(FILE* stream, char* buf)
|
||||
void setlinebuf(FILE* stream)
|
||||
{
|
||||
setvbuf(stream, buf, buf ? _IOLBF : _IONBF, BUFSIZ);
|
||||
setvbuf(stream, nullptr, _IOLBF, 0);
|
||||
}
|
||||
|
||||
int fileno(FILE* stream)
|
||||
|
@ -138,7 +140,7 @@ int fputc(int ch, FILE* stream)
|
|||
stream->buffer[stream->buffer_index++] = ch;
|
||||
if (stream->buffer_index >= stream->buffer_size)
|
||||
fflush(stream);
|
||||
else if (stream->mode == _IOLBF && ch == '\n')
|
||||
else if (stream->mode == _IONBF || (stream->mode == _IOLBF && ch == '\n'))
|
||||
fflush(stream);
|
||||
if (stream->eof)
|
||||
return EOF;
|
||||
|
|
|
@ -61,7 +61,7 @@ int sscanf (const char* buf, const char* fmt, ...);
|
|||
int fscanf(FILE*, const char* fmt, ...);
|
||||
int setvbuf(FILE*, char* buf, int mode, size_t);
|
||||
void setbuf(FILE*, char* buf);
|
||||
void setlinebuf(FILE*, char* buf);
|
||||
void setlinebuf(FILE*);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#include <stdlib.h>
|
||||
#include <mman.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <alloca.h>
|
||||
#include <assert.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
#include <AK/Assertions.h>
|
||||
|
||||
|
@ -54,11 +55,12 @@ void* calloc(size_t nmemb, size_t)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void* realloc(void *ptr, size_t)
|
||||
void* realloc(void *ptr, size_t size)
|
||||
{
|
||||
(void) ptr;
|
||||
ASSERT_NOT_REACHED();
|
||||
return nullptr;
|
||||
// FIXME: This is broken as shit.
|
||||
auto* new_ptr = malloc(size);
|
||||
memcpy(new_ptr, ptr, size);
|
||||
return new_ptr;
|
||||
}
|
||||
|
||||
void exit(int status)
|
||||
|
@ -116,4 +118,13 @@ long atol(const char* str)
|
|||
return atoi(str);
|
||||
}
|
||||
|
||||
void __qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *))
|
||||
{
|
||||
(void) base;
|
||||
(void) nmemb;
|
||||
(void) size;
|
||||
(void) compar;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ void* realloc(void *ptr, size_t);
|
|||
char* getenv(const char* name);
|
||||
int atoi(const char*);
|
||||
long atol(const char*);
|
||||
|
||||
void qsort(void* base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
|
||||
void exit(int status) __NORETURN;
|
||||
void abort() __NORETURN;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <assert.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
@ -97,6 +98,14 @@ void memcpy(void* dest, const void* src, size_t n)
|
|||
*(bdest++) = *(bsrc++);
|
||||
}
|
||||
|
||||
void memmove(void* dest, const void* src, size_t n)
|
||||
{
|
||||
if (dest < src)
|
||||
return memcpy(dest, src, n);
|
||||
// FIXME: Implement backwards copy.
|
||||
assert(false);
|
||||
}
|
||||
|
||||
char* strcpy(char* dest, const char *src)
|
||||
{
|
||||
char* originalDest = dest;
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
#include <termcap.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/String.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
@ -6,5 +11,94 @@ char PC;
|
|||
char* UP;
|
||||
char* BC;
|
||||
|
||||
int tgetent(char* bp, const char* name)
|
||||
{
|
||||
fprintf(stderr, "tgetent: bp=%p, name='%s'\n", bp, name);
|
||||
if (!strcmp(name, "ansi")) {
|
||||
PC = '\0';
|
||||
BC = const_cast<char*>("\033[D");
|
||||
UP = const_cast<char*>("\033[A");
|
||||
return 1;
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
|
||||
static HashMap<String, String>* caps = nullptr;
|
||||
|
||||
void ensure_caps()
|
||||
{
|
||||
if (caps)
|
||||
return;
|
||||
caps = new HashMap<String, String>;
|
||||
caps->set("DC", "\033[%p1%dP");
|
||||
caps->set("IC", "\033[%p1%d@");
|
||||
caps->set("ce", "\033[K");
|
||||
caps->set("cl", "\033[H\033[J");
|
||||
caps->set("cr", "\015");
|
||||
caps->set("dc", "\033[P");
|
||||
caps->set("ei", "");
|
||||
caps->set("ic", "");
|
||||
caps->set("im", "");
|
||||
caps->set("kd", "\033[B");
|
||||
caps->set("kl", "\033[D");
|
||||
caps->set("kr", "\033[C");
|
||||
caps->set("ku", "\033[A");
|
||||
caps->set("ks", "");
|
||||
caps->set("ke", "");
|
||||
caps->set("le", "\033[D");
|
||||
caps->set("mm", "");
|
||||
caps->set("mo", "");
|
||||
caps->set("pc", "");
|
||||
caps->set("up", "\033[A");
|
||||
caps->set("vb", "");
|
||||
caps->set("am", "");
|
||||
|
||||
caps->set("co", "80");
|
||||
caps->set("li", "25");
|
||||
}
|
||||
|
||||
char* tgetstr(char* id, char** area)
|
||||
{
|
||||
ensure_caps();
|
||||
fprintf(stderr, "tgetstr: id='%s', area=%p\n", id, area);
|
||||
auto it = caps->find(id);
|
||||
if (it != caps->end()) {
|
||||
char* ret = *area;
|
||||
strcpy(*area, (*it).value.characters());
|
||||
*area += (*it).value.length() + 1;
|
||||
return ret;
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
|
||||
int tgetflag(char* id)
|
||||
{
|
||||
fprintf(stderr, "tgetflag: '%s'\n", id);
|
||||
auto it = caps->find(id);
|
||||
if (it != caps->end())
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tgetnum(char* id)
|
||||
{
|
||||
fprintf(stderr, "tgetnum: '%s'\n", id);
|
||||
auto it = caps->find(id);
|
||||
if (it != caps->end()) {
|
||||
return atoi((*it).value.characters());
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
|
||||
char* tgoto(const char* cap, int col, int row)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
int tputs(const char* str, int affcnt, int (*putc)(int))
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -8,5 +8,12 @@ extern char PC;
|
|||
extern char* UP;
|
||||
extern char* BC;
|
||||
|
||||
int tgetent(char* bp, const char* name);
|
||||
int tgetflag(char* id);
|
||||
int tgetnum(char* id);
|
||||
char* tgetstr(char* id, char** area);
|
||||
char* tgoto(const char* cap, int col, int row);
|
||||
int tputs(const char* str, int affcnt, int (*putc)(int));
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <termios.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
|
@ -16,5 +17,12 @@ int tcsetattr(int fd, int optional_actions, const struct termios* t)
|
|||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int tcflow(int fd, int action)
|
||||
{
|
||||
(void) fd;
|
||||
(void) action;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ struct termios {
|
|||
|
||||
int tcgetattr(int fd, struct termios*);
|
||||
int tcsetattr(int fd, int optional_actions, const struct termios*);
|
||||
int tcflow(int fd, int action);
|
||||
|
||||
/* c_cc characters */
|
||||
#define VINTR 0
|
||||
|
|
14
LibC/ulimit.cpp
Normal file
14
LibC/ulimit.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <ulimit.h>
|
||||
#include <assert.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
long ulimit(int cmd, long newlimit)
|
||||
{
|
||||
(void) cmd;
|
||||
(void) newlimit;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
10
LibC/ulimit.h
Normal file
10
LibC/ulimit.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
long ulimit(int cmd, long newlimit);
|
||||
|
||||
__END_DECLS
|
||||
|
|
@ -167,7 +167,8 @@ char* getcwd(char* buffer, size_t size)
|
|||
|
||||
char* getwd(char* buf)
|
||||
{
|
||||
return getcwd(buf, PATH_MAX);
|
||||
auto* p = getcwd(buf, PATH_MAX);
|
||||
return p;
|
||||
}
|
||||
|
||||
int sleep(unsigned seconds)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue