mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-17 18:21:43 +00:00
Merge remote-tracking branch 'Userspace/master'
This commit is contained in:
16
Userspace/apps/base/cross_test/Makefile
Normal file
16
Userspace/apps/base/cross_test/Makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
WORKSPACE := ../../../
|
||||
|
||||
# Config file
|
||||
include ../$(WORKSPACE)Makefile.conf
|
||||
|
||||
FILENAME = utest_
|
||||
|
||||
CFLAGS = -static -g -ggdb3 -O0
|
||||
|
||||
build:
|
||||
$(info Compiling $(FILENAME)linux)
|
||||
gcc linux_glibc.c $(CFLAGS) -o $(WORKSPACE)out/bin/$(FILENAME)linux
|
||||
$(info Compiling $(FILENAME)win)
|
||||
x86_64-w64-mingw32-gcc win_mingw.c $(CFLAGS) -o $(WORKSPACE)out/bin/$(FILENAME)win.exe
|
||||
|
||||
clean:
|
22
Userspace/apps/base/cross_test/expected_glibc.txt
Normal file
22
Userspace/apps/base/cross_test/expected_glibc.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
$ setarch `uname -m` -R strace ./utest_linux
|
||||
|
||||
execve("./utest_linux", ["./utest_linux"], 0x7fffffffdec0 /* 56 vars */) = 0
|
||||
arch_prctl(0x3001 /* ARCH_??? */, 0x7fffffffde40) = -1 EINVAL (Invalid argument)
|
||||
brk(NULL) = 0x4cd000
|
||||
brk(0x4cddc0) = 0x4cddc0
|
||||
arch_prctl(ARCH_SET_FS, 0x4cd3c0) = 0
|
||||
set_tid_address(0x4cd690) = 68565
|
||||
set_robust_list(0x4cd6a0, 24) = 0
|
||||
rseq(0x4cdd60, 0x20, 0, 0x53053053) = 0
|
||||
uname({sysname="Fennix", nodename="fennix", ...}) = 0
|
||||
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
|
||||
readlink("/proc/self/exe", "/bin/utest_linux"..., 4096) = 50
|
||||
getrandom("\x1e\x3c\x20\xdd\x09\xe8\x46\x0d", 8, GRND_NONBLOCK) = 8
|
||||
brk(0x4eedc0) = 0x4eedc0
|
||||
brk(0x4ef000) = 0x4ef000
|
||||
mprotect(0x4c1000, 16384, PROT_READ) = 0
|
||||
newfstatat(1, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x1), ...}, AT_EMPTY_PATH) = 0
|
||||
write(1, "Hello, World!\n", 14Hello, World!
|
||||
) = 14
|
||||
exit_group(0) = ?
|
||||
+++ exited with 0 +++
|
97
Userspace/apps/base/cross_test/linux_glibc.c
Normal file
97
Userspace/apps/base/cross_test/linux_glibc.c
Normal file
@@ -0,0 +1,97 @@
|
||||
#define _POSIX_SOURCE
|
||||
#define _DEFAULT_SOURCE
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <pty.h>
|
||||
#include <termios.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#ifndef __GLIBC__
|
||||
#define __GLIBC__ 0
|
||||
#endif
|
||||
|
||||
#ifndef __GLIBC_MINOR__
|
||||
#define __GLIBC_MINOR__ 0
|
||||
#endif
|
||||
|
||||
int ptmx_test()
|
||||
{
|
||||
int masterFD;
|
||||
int slaveFD;
|
||||
char slaveName[100];
|
||||
|
||||
masterFD = open("/dev/ptmx", O_RDWR | O_NOCTTY);
|
||||
if (masterFD < 0)
|
||||
{
|
||||
perror("Failed to open /dev/ptmx");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (grantpt(masterFD) < 0)
|
||||
{
|
||||
perror("Failed to grantpt");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (unlockpt(masterFD) < 0)
|
||||
{
|
||||
perror("Failed to unlockpt");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ptsname_r(masterFD, slaveName, sizeof(slaveName)) != 0)
|
||||
{
|
||||
perror("Failed to get slave name");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Slave terminal: %s\n", slaveName);
|
||||
|
||||
slaveFD = open(slaveName, O_RDWR | O_NOCTTY);
|
||||
if (slaveFD < 0)
|
||||
{
|
||||
perror("Failed to open slave terminal");
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct termios t;
|
||||
tcgetattr(slaveFD, &t);
|
||||
cfmakeraw(&t);
|
||||
tcsetattr(slaveFD, TCSANOW, &t);
|
||||
|
||||
char *message = "Hello from master!\n";
|
||||
write(masterFD, message, strlen(message));
|
||||
|
||||
char buffer[100];
|
||||
int len = read(slaveFD, buffer, sizeof(buffer) - 1);
|
||||
if (len > 0)
|
||||
{
|
||||
buffer[len] = '\0';
|
||||
printf("Received from slave: %s\n", buffer);
|
||||
}
|
||||
|
||||
close(masterFD);
|
||||
close(slaveFD);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[], char *envp[])
|
||||
{
|
||||
printf("glibc %d.%d: Hello, World!\n", __GLIBC__, __GLIBC_MINOR__);
|
||||
fflush(stdout);
|
||||
ptmx_test();
|
||||
return 0;
|
||||
}
|
9
Userspace/apps/base/cross_test/win_mingw.c
Normal file
9
Userspace/apps/base/cross_test/win_mingw.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[], char *envp[])
|
||||
{
|
||||
printf("mingw: Hello, World!\n");
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user