Compare commits
71 Commits
44f2a4e97e
...
58cb1e763f
Author | SHA1 | Date | |
---|---|---|---|
58cb1e763f | |||
35d8075c4e | |||
4462651138 | |||
686db5a1de | |||
550c93318c | |||
55660511f7 | |||
76ac39b3b4 | |||
97305c0212 | |||
c54504bd22 | |||
c632112213 | |||
db2710099b | |||
042e154271 | |||
2ea0a303b4 | |||
da759d3b96 | |||
390d55243d | |||
cac62db038 | |||
0e61c7b62d | |||
69bf171787 | |||
46524ecc1d | |||
87f3922486 | |||
ade6493fe6 | |||
4a4e193559 | |||
7e4f4b91f8 | |||
2bf0881fc1 | |||
180e9bd5b4 | |||
886c393024 | |||
4de29a09d2 | |||
e1d7de2f21 | |||
7449f1a519 | |||
688bd652dc | |||
e679731a18 | |||
6727dc034a | |||
f31a90df16 | |||
3686a25a76 | |||
0871895cc5 | |||
5085604aab | |||
aa82c088a0 | |||
ecd8c4c29c | |||
88141727a2 | |||
bcf6bc3c97 | |||
3e6c9dbaa2 | |||
b1299aef9e | |||
594f42fdd6 | |||
45ff38f5e3 | |||
8b02bfebdb | |||
9382ec9eca | |||
58f839927c | |||
72704e445a | |||
7bc0f36661 | |||
c58f91c48d | |||
94f297a47f | |||
00db974b97 | |||
dc69f144ad | |||
714f6a90cc | |||
9d412b7a32 | |||
62d56d31a3 | |||
38912dce51 | |||
eba2960df3 | |||
54bfcfc8cb | |||
f02bf4bc95 | |||
7d35964c5c | |||
971e69ee8c | |||
4b04ce1917 | |||
fa6534004a | |||
995aa97a58 | |||
b4d9363302 | |||
e5905a33e1 | |||
993e94cc76 | |||
746834e2d9 | |||
ce3542e2bd | |||
e72bc55c6f |
@ -28,8 +28,6 @@ luna_app(stat.cpp stat)
|
|||||||
luna_app(uname.cpp uname)
|
luna_app(uname.cpp uname)
|
||||||
luna_app(base64.cpp base64)
|
luna_app(base64.cpp base64)
|
||||||
luna_app(login.cpp login)
|
luna_app(login.cpp login)
|
||||||
luna_app(ipc-test.cpp ipc-test)
|
|
||||||
luna_app(signal-test.cpp signal-test)
|
|
||||||
luna_app(mount.cpp mount)
|
luna_app(mount.cpp mount)
|
||||||
luna_app(umount.cpp umount)
|
luna_app(umount.cpp umount)
|
||||||
luna_app(ps.cpp ps)
|
luna_app(ps.cpp ps)
|
||||||
@ -41,11 +39,6 @@ luna_app(pivot_root.cpp pivot_root)
|
|||||||
luna_app(cp.cpp cp)
|
luna_app(cp.cpp cp)
|
||||||
luna_app(kill.cpp kill)
|
luna_app(kill.cpp kill)
|
||||||
luna_app(gol.cpp gol)
|
luna_app(gol.cpp gol)
|
||||||
luna_app(buffer-test.cpp buffer-test)
|
|
||||||
luna_app(socket-test.cpp socket-test)
|
|
||||||
luna_app(socket-client.cpp socket-client)
|
|
||||||
luna_app(input.cpp input)
|
|
||||||
luna_app(shmem-test.cpp shmem-test)
|
|
||||||
luna_app(touch.cpp touch)
|
luna_app(touch.cpp touch)
|
||||||
luna_app(free.cpp free)
|
luna_app(free.cpp free)
|
||||||
luna_app(gclient.cpp gclient)
|
luna_app(gclient.cpp gclient)
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
#include <assert.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Writing incomplete line to stdout (_IOLBF=%d)...\n", stdout->_buf.mode);
|
|
||||||
fputs("hi!", stdout);
|
|
||||||
sleep(3);
|
|
||||||
putchar('\n');
|
|
||||||
fprintf(stderr, "Incomplete line should have been written.\n");
|
|
||||||
|
|
||||||
FILE* f = fopen("/dev/console", "w+");
|
|
||||||
assert(f);
|
|
||||||
assert(setvbuf(f, NULL, _IOFBF, 0) == 0);
|
|
||||||
|
|
||||||
fprintf(stderr, "Writing long text to file (_IOFBF=%d)...\n", f->_buf.mode);
|
|
||||||
|
|
||||||
fputs("Hello world!\nHow are you doing!\nThis is a test for many lines of buffering.\n", f);
|
|
||||||
|
|
||||||
sleep(3);
|
|
||||||
fflush(f);
|
|
||||||
|
|
||||||
fprintf(stderr, "Long text should have been written.\n");
|
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
}
|
|
@ -339,7 +339,7 @@ Result<int> sysinit()
|
|||||||
stdout = fopen("/dev/console", "w");
|
stdout = fopen("/dev/console", "w");
|
||||||
stderr = fopen("/dev/console", "w");
|
stderr = fopen("/dev/console", "w");
|
||||||
|
|
||||||
TRY(os::Security::pledge("stdio rpath wpath cpath fattr host mount proc exec signal id", nullptr));
|
TRY(os::Security::pledge("stdio rpath wpath cpath fattr host mount proc exec id", nullptr));
|
||||||
|
|
||||||
mount_tmpfs();
|
mount_tmpfs();
|
||||||
mount_shmfs();
|
mount_shmfs();
|
||||||
|
@ -1,69 +0,0 @@
|
|||||||
#include <errno.h>
|
|
||||||
#include <luna/String.h>
|
|
||||||
#include <moon/Keyboard.h>
|
|
||||||
#include <moon/Mouse.h>
|
|
||||||
#include <os/File.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/poll.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
Result<void> process_mouse_packet(const moon::MousePacket& packet)
|
|
||||||
{
|
|
||||||
bool right = packet.buttons & moon::MouseButton::Right;
|
|
||||||
bool left = packet.buttons & moon::MouseButton::Left;
|
|
||||||
bool middle = packet.buttons & moon::MouseButton::Middle;
|
|
||||||
|
|
||||||
Vector<StringView> buttons;
|
|
||||||
if (right) TRY(buttons.try_append("RIGHT"_sv));
|
|
||||||
if (left) TRY(buttons.try_append("LEFT"_sv));
|
|
||||||
if (middle) TRY(buttons.try_append("MIDDLE"_sv));
|
|
||||||
|
|
||||||
String button_string;
|
|
||||||
if (!buttons.size()) button_string = TRY(String::from_cstring("NONE"));
|
|
||||||
else
|
|
||||||
button_string = TRY(String::join(buttons, " | "_sv));
|
|
||||||
|
|
||||||
os::println("Mouse packet: xdelta=%d, ydelta=%d, buttons=(%s)", packet.xdelta, packet.ydelta,
|
|
||||||
button_string.chars());
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<int> luna_main(int, char**)
|
|
||||||
{
|
|
||||||
auto mouse = TRY(os::File::open("/dev/mouse", os::File::ReadOnly));
|
|
||||||
mouse->set_buffer(os::File::NotBuffered);
|
|
||||||
|
|
||||||
auto keyboard = TRY(os::File::open("/dev/kbd", os::File::ReadOnly));
|
|
||||||
keyboard->set_buffer(os::File::NotBuffered);
|
|
||||||
|
|
||||||
ioctl(STDIN_FILENO, TTYSETGFX, 1);
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
struct pollfd fds[] = {
|
|
||||||
{ .fd = mouse->fd(), .events = POLLIN, .revents = 0 },
|
|
||||||
{ .fd = keyboard->fd(), .events = POLLIN, .revents = 0 },
|
|
||||||
};
|
|
||||||
|
|
||||||
int rc = poll(fds, 2, 1000);
|
|
||||||
if (!rc) continue;
|
|
||||||
if (rc < 0) { os::println("poll: error: %s", strerror(errno)); }
|
|
||||||
|
|
||||||
if (fds[0].revents & POLLIN)
|
|
||||||
{
|
|
||||||
moon::MousePacket packet;
|
|
||||||
TRY(mouse->read_typed(packet));
|
|
||||||
TRY(process_mouse_packet(packet));
|
|
||||||
}
|
|
||||||
if (fds[1].revents & POLLIN)
|
|
||||||
{
|
|
||||||
moon::KeyboardPacket packet;
|
|
||||||
TRY(keyboard->read_typed(packet));
|
|
||||||
os::println("Keyboard packet: %s key %u", packet.released ? "released" : "pressed", packet.key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
int pfds[2];
|
|
||||||
|
|
||||||
if (pipe(pfds) < 0)
|
|
||||||
{
|
|
||||||
perror("pipe");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid_t child = fork();
|
|
||||||
if (child == 0)
|
|
||||||
{
|
|
||||||
close(pfds[1]);
|
|
||||||
|
|
||||||
char buffer[4096];
|
|
||||||
size_t nread = read(pfds[0], buffer, sizeof(buffer) - 1);
|
|
||||||
buffer[nread] = 0;
|
|
||||||
close(pfds[0]);
|
|
||||||
|
|
||||||
puts(buffer);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if (child == -1)
|
|
||||||
{
|
|
||||||
perror("fork");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
close(pfds[0]);
|
|
||||||
|
|
||||||
const char* string = "Hello from a child process who just received this message from its parent!";
|
|
||||||
write(pfds[1], string, strlen(string));
|
|
||||||
close(pfds[1]);
|
|
||||||
|
|
||||||
wait(NULL);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
pledge("stdio rpath wpath cpath proc", nullptr);
|
|
||||||
|
|
||||||
int fd = shm_open("/shared", O_CREAT | O_RDWR, 0666);
|
|
||||||
if (fd < 0)
|
|
||||||
{
|
|
||||||
perror("shm_open");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ftruncate(fd, PAGE_SIZE);
|
|
||||||
|
|
||||||
void* address = mmap(nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
||||||
if (address == MAP_FAILED)
|
|
||||||
{
|
|
||||||
perror("mmap");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* ptr = (char*)address;
|
|
||||||
|
|
||||||
printf("the value is %c\n", *ptr);
|
|
||||||
|
|
||||||
*ptr = 'a';
|
|
||||||
|
|
||||||
pid_t child = fork();
|
|
||||||
if (child < 0)
|
|
||||||
{
|
|
||||||
perror("fork");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (child == 0)
|
|
||||||
{
|
|
||||||
*ptr = 'e';
|
|
||||||
_exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
waitpid(child, NULL, 0);
|
|
||||||
|
|
||||||
printf("the value is %c\n", *ptr);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
#include <signal.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
void handler(int)
|
|
||||||
{
|
|
||||||
puts("I caught a segfault!");
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
struct sigaction sa;
|
|
||||||
sa.sa_handler = handler;
|
|
||||||
sigemptyset(&sa.sa_mask);
|
|
||||||
sa.sa_flags = SA_RESETHAND;
|
|
||||||
sigaction(SIGSEGV, &sa, NULL);
|
|
||||||
|
|
||||||
#pragma GCC diagnostic ignored "-Wnonnull"
|
|
||||||
char* str = nullptr;
|
|
||||||
memset(str, 0, 2);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
#include <os/ArgumentParser.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/un.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
Result<int> luna_main(int argc, char** argv)
|
|
||||||
{
|
|
||||||
StringView message;
|
|
||||||
|
|
||||||
os::ArgumentParser parser;
|
|
||||||
parser.add_description("A UNIX domain socket client, to test said sockets.");
|
|
||||||
parser.add_system_program_info("socket-client"_sv);
|
|
||||||
parser.add_positional_argument(message, "message"_sv, "exit"_sv);
|
|
||||||
parser.parse(argc, argv);
|
|
||||||
|
|
||||||
int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
||||||
if (sockfd < 0)
|
|
||||||
{
|
|
||||||
perror("socket");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sockaddr_un un;
|
|
||||||
un.sun_family = AF_UNIX;
|
|
||||||
strncpy(un.sun_path, "/tmp/local.sock", sizeof(un.sun_path));
|
|
||||||
|
|
||||||
if (connect(sockfd, (struct sockaddr*)&un, sizeof(un)) < 0)
|
|
||||||
{
|
|
||||||
perror("connect");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char buf[4096];
|
|
||||||
ssize_t nread = read(sockfd, buf, sizeof(buf) - 1);
|
|
||||||
if (nread > 0)
|
|
||||||
{
|
|
||||||
buf[nread] = 0;
|
|
||||||
printf("Message from server: %s\n", buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
write(sockfd, message.chars(), message.length());
|
|
||||||
|
|
||||||
close(sockfd);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/un.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
setgid(1000);
|
|
||||||
setuid(1000);
|
|
||||||
|
|
||||||
remove("/tmp/local.sock");
|
|
||||||
|
|
||||||
int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
||||||
if (sockfd < 0)
|
|
||||||
{
|
|
||||||
perror("socket");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sockaddr_un un;
|
|
||||||
un.sun_family = AF_UNIX;
|
|
||||||
strncpy(un.sun_path, "/tmp/local.sock", sizeof(un.sun_path));
|
|
||||||
|
|
||||||
if (bind(sockfd, (struct sockaddr*)&un, sizeof(un)) < 0)
|
|
||||||
{
|
|
||||||
perror("bind");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (listen(sockfd, 10) < 0)
|
|
||||||
{
|
|
||||||
perror("listen");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
int fd = accept(sockfd, NULL, NULL);
|
|
||||||
if (fd < 0)
|
|
||||||
{
|
|
||||||
perror("accept");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
puts("New connection from client, sending hello");
|
|
||||||
|
|
||||||
const char* message = "Hello, client!";
|
|
||||||
write(fd, message, strlen(message));
|
|
||||||
|
|
||||||
puts("Now waiting for client to message back");
|
|
||||||
|
|
||||||
char buf[4096];
|
|
||||||
ssize_t nread = read(fd, buf, sizeof(buf) - 1);
|
|
||||||
if (nread >= 0)
|
|
||||||
{
|
|
||||||
buf[nread] = 0;
|
|
||||||
printf("Message from client: %s\n", buf);
|
|
||||||
if (!strcasecmp(buf, "exit"))
|
|
||||||
{
|
|
||||||
close(fd);
|
|
||||||
close(sockfd);
|
|
||||||
remove("/tmp/local.sock");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else { printf("Error reading from client: %s\n", strerror(errno)); }
|
|
||||||
|
|
||||||
puts("Transmission ended, closing connection");
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#define enumerate_promises(_p) \
|
#define enumerate_promises(_p) \
|
||||||
_p(stdio) _p(rpath) _p(wpath) _p(cpath) _p(fattr) _p(chown) _p(unix) _p(tty) _p(proc) _p(exec) _p(prot_exec) \
|
_p(stdio) _p(rpath) _p(wpath) _p(cpath) _p(fattr) _p(chown) _p(unix) _p(tty) _p(proc) _p(exec) _p(prot_exec) \
|
||||||
_p(id) _p(mount) _p(signal) _p(host) _p(error)
|
_p(id) _p(mount) _p(host) _p(error)
|
||||||
|
|
||||||
enum class Promise
|
enum class Promise
|
||||||
{
|
{
|
||||||
|
@ -63,7 +63,7 @@ Result<usize> ConsoleDevice::write(const u8* buf, usize, usize length)
|
|||||||
{
|
{
|
||||||
if (m_settings.c_lflag & TOSTOP) TRY(handle_background_process_group(true, SIGTTOU));
|
if (m_settings.c_lflag & TOSTOP) TRY(handle_background_process_group(true, SIGTTOU));
|
||||||
|
|
||||||
// if (s_is_in_graphical_mode) return length;
|
if (s_is_in_graphical_mode) return length;
|
||||||
|
|
||||||
TextConsole::write((const char*)buf, length);
|
TextConsole::write((const char*)buf, length);
|
||||||
return length;
|
return length;
|
||||||
|
@ -19,7 +19,7 @@ Result<u64> sys_sigreturn(Registers* regs, SyscallArgs)
|
|||||||
Result<u64> sys_sigaction(Registers*, SyscallArgs args)
|
Result<u64> sys_sigaction(Registers*, SyscallArgs args)
|
||||||
{
|
{
|
||||||
auto* current = Scheduler::current();
|
auto* current = Scheduler::current();
|
||||||
TRY(check_pledge(current, Promise::p_signal));
|
TRY(check_pledge(current, Promise::p_stdio));
|
||||||
|
|
||||||
int signo = (int)args[0];
|
int signo = (int)args[0];
|
||||||
const struct sigaction* act = (const struct sigaction*)args[1];
|
const struct sigaction* act = (const struct sigaction*)args[1];
|
||||||
@ -71,7 +71,7 @@ Result<u64> sys_kill(Registers*, SyscallArgs args)
|
|||||||
Result<u64> sys_sigprocmask(Registers*, SyscallArgs args)
|
Result<u64> sys_sigprocmask(Registers*, SyscallArgs args)
|
||||||
{
|
{
|
||||||
auto* current = Scheduler::current();
|
auto* current = Scheduler::current();
|
||||||
TRY(check_pledge(current, Promise::p_signal));
|
TRY(check_pledge(current, Promise::p_stdio));
|
||||||
|
|
||||||
int how = (int)args[0];
|
int how = (int)args[0];
|
||||||
const sigset_t* set = (const sigset_t*)args[1];
|
const sigset_t* set = (const sigset_t*)args[1];
|
||||||
|
@ -68,4 +68,4 @@ cmake -S $LUNA_ROOT -B $LUNA_BUILD_DIR -G "$LUNA_CMAKE_GENERATOR_NAME"
|
|||||||
cmake --build $LUNA_BUILD_DIR --target libc
|
cmake --build $LUNA_BUILD_DIR --target libc
|
||||||
|
|
||||||
make all-target-libstdc++-v3 CXXFLAGS_FOR_TARGET="-fno-exceptions" -j$(nproc)
|
make all-target-libstdc++-v3 CXXFLAGS_FOR_TARGET="-fno-exceptions" -j$(nproc)
|
||||||
make DESTDIR=$LUNA_BASE/usr install-target-libstdc++-v3
|
make install-target-libstdc++-v3
|
||||||
|
Loading…
Reference in New Issue
Block a user