Compare commits
66 Commits
58cb1e763f
...
44f2a4e97e
Author | SHA1 | Date | |
---|---|---|---|
44f2a4e97e | |||
db9b9c53e9 | |||
a5217a1401 | |||
86e6e7aea5 | |||
3efa9e267a | |||
62673876fb | |||
ca2fb9e442 | |||
e743c83fe0 | |||
38d0a42eac | |||
1e5a762620 | |||
491e46cfcb | |||
3009920c0e | |||
bfbe166679 | |||
73e3c271ff | |||
e3a6877962 | |||
526af76d51 | |||
c6a67d9361 | |||
610e3c9c80 | |||
b55287e0a1 | |||
ec50a03f1b | |||
c233c9b98e | |||
570b9464c6 | |||
c45c153773 | |||
0d3983432e | |||
6efd55dce8 | |||
63c8f4131f | |||
03dc260ba9 | |||
cfabd62687 | |||
4c91191b4e | |||
a281a35806 | |||
c835979f9f | |||
4da16c1eaa | |||
e6ef86e620 | |||
2e50829d0a | |||
676b95af04 | |||
6b47a8c732 | |||
8346adf87f | |||
897ef6f91d | |||
290f391ea9 | |||
708b408861 | |||
d8ae676faa | |||
88961e1cc3 | |||
8f61062b72 | |||
9a47d84313 | |||
593e37a0f4 | |||
2134a55a3a | |||
a04759aa0e | |||
ec5fad5b21 | |||
6656e2164a | |||
d4ca297a68 | |||
84a7a8855a | |||
861c4454e7 | |||
1302e3dc12 | |||
37c3003ec9 | |||
4bed2d15f0 | |||
626eb7a977 | |||
787db55888 | |||
cdc01f6772 | |||
f3e73b241e | |||
505551e349 | |||
e1a7e93f52 | |||
0e75cc3feb | |||
0f95a3637d | |||
221fa360b3 | |||
fd8d8b4f34 | |||
5a13dd4dae |
@ -28,6 +28,8 @@ luna_app(stat.cpp stat)
|
||||
luna_app(uname.cpp uname)
|
||||
luna_app(base64.cpp base64)
|
||||
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(umount.cpp umount)
|
||||
luna_app(ps.cpp ps)
|
||||
@ -39,6 +41,11 @@ luna_app(pivot_root.cpp pivot_root)
|
||||
luna_app(cp.cpp cp)
|
||||
luna_app(kill.cpp kill)
|
||||
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(free.cpp free)
|
||||
luna_app(gclient.cpp gclient)
|
||||
|
27
apps/buffer-test.cpp
Normal file
27
apps/buffer-test.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#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");
|
||||
stderr = fopen("/dev/console", "w");
|
||||
|
||||
TRY(os::Security::pledge("stdio rpath wpath cpath fattr host mount proc exec id", nullptr));
|
||||
TRY(os::Security::pledge("stdio rpath wpath cpath fattr host mount proc exec signal id", nullptr));
|
||||
|
||||
mount_tmpfs();
|
||||
mount_shmfs();
|
||||
|
69
apps/input.cpp
Normal file
69
apps/input.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
#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;
|
||||
}
|
45
apps/ipc-test.cpp
Normal file
45
apps/ipc-test.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#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;
|
||||
}
|
50
apps/shmem-test.cpp
Normal file
50
apps/shmem-test.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#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;
|
||||
}
|
23
apps/signal-test.cpp
Normal file
23
apps/signal-test.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#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;
|
||||
}
|
48
apps/socket-client.cpp
Normal file
48
apps/socket-client.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#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;
|
||||
}
|
75
apps/socket-test.cpp
Normal file
75
apps/socket-test.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
#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) \
|
||||
_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(host) _p(error)
|
||||
_p(id) _p(mount) _p(signal) _p(host) _p(error)
|
||||
|
||||
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 (s_is_in_graphical_mode) return length;
|
||||
// if (s_is_in_graphical_mode) return length;
|
||||
|
||||
TextConsole::write((const char*)buf, length);
|
||||
return length;
|
||||
|
@ -19,7 +19,7 @@ Result<u64> sys_sigreturn(Registers* regs, SyscallArgs)
|
||||
Result<u64> sys_sigaction(Registers*, SyscallArgs args)
|
||||
{
|
||||
auto* current = Scheduler::current();
|
||||
TRY(check_pledge(current, Promise::p_stdio));
|
||||
TRY(check_pledge(current, Promise::p_signal));
|
||||
|
||||
int signo = (int)args[0];
|
||||
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)
|
||||
{
|
||||
auto* current = Scheduler::current();
|
||||
TRY(check_pledge(current, Promise::p_stdio));
|
||||
TRY(check_pledge(current, Promise::p_signal));
|
||||
|
||||
int how = (int)args[0];
|
||||
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
|
||||
|
||||
make all-target-libstdc++-v3 CXXFLAGS_FOR_TARGET="-fno-exceptions" -j$(nproc)
|
||||
make install-target-libstdc++-v3
|
||||
make DESTDIR=$LUNA_BASE/usr install-target-libstdc++-v3
|
||||
|
Loading…
x
Reference in New Issue
Block a user