mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
Demos: Add "DynamicObjectDemo" to demo the dynamic loader
This commit is contained in:
parent
79769ee74e
commit
09ccdc697b
Notes:
sideshowbarker
2024-07-19 00:51:37 +09:00
Author: https://github.com/itamar8910 Commit: https://github.com/SerenityOS/serenity/commit/09ccdc697b0 Pull-request: https://github.com/SerenityOS/serenity/pull/3738 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/awesomekling
7 changed files with 101 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
add_subdirectory(Cube)
|
||||
add_subdirectory(DynamicObject)
|
||||
add_subdirectory(DynamicLink)
|
||||
add_subdirectory(Eyes)
|
||||
add_subdirectory(Fire)
|
||||
|
|
11
Demos/DynamicObject/CMakeLists.txt
Normal file
11
Demos/DynamicObject/CMakeLists.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
set(SOURCES
|
||||
main.cpp
|
||||
../../Libraries/LibC/crt0_shared.cpp
|
||||
)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostartfiles -pie -fpic")
|
||||
|
||||
serenity_bin(DynamicObjectDemo)
|
||||
target_link_libraries(DynamicObjectDemo SampleLib LibCShared)
|
||||
|
||||
add_subdirectory(SampleLib)
|
11
Demos/DynamicObject/SampleLib/CMakeLists.txt
Normal file
11
Demos/DynamicObject/SampleLib/CMakeLists.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
set(SOURCES
|
||||
lib.cpp
|
||||
)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib -fpic")
|
||||
|
||||
add_library(SampleLib SHARED ${SOURCES})
|
||||
target_link_libraries(SampleLib LibCShared)
|
||||
#target_link_libraries(SampleLib)
|
||||
install(TARGETS SampleLib DESTINATION usr/lib)
|
20
Demos/DynamicObject/SampleLib/lib.cpp
Normal file
20
Demos/DynamicObject/SampleLib/lib.cpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
#include "../lib.h"
|
||||
|
||||
int func();
|
||||
|
||||
__thread int g_tls1 = 0;
|
||||
__thread int g_tls2 = 0;
|
||||
|
||||
static void init_function() __attribute__((constructor));
|
||||
|
||||
void init_function()
|
||||
{
|
||||
g_tls1 = 1;
|
||||
g_tls2 = 2;
|
||||
}
|
||||
|
||||
int func()
|
||||
{
|
||||
return 3;
|
||||
}
|
24
Demos/DynamicObject/main.cpp
Normal file
24
Demos/DynamicObject/main.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include "lib.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/internals.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv, char** env)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
(void)env;
|
||||
|
||||
printf("Well Hello Friends!\n");
|
||||
printf("trying to open /etc/fstab for writing..\n");
|
||||
int rc = open("/etc/fstab", O_RDWR);
|
||||
if (rc == -1) {
|
||||
int _errno = errno;
|
||||
perror("open failed");
|
||||
printf("rc: %d, errno: %d\n", rc, _errno);
|
||||
return func() + g_tls1 + g_tls2;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
set(LIBC_SOURCES
|
||||
arpa/inet.cpp
|
||||
assert.cpp
|
||||
crt0.cpp
|
||||
#crt0.cpp
|
||||
ctype.cpp
|
||||
cxxabi.cpp
|
||||
dirent.cpp
|
||||
|
@ -69,3 +69,6 @@ set(SOURCES ${LIBC_SOURCES} ${AK_SOURCES} ${ELF_SOURCES})
|
|||
serenity_libc(LibC c)
|
||||
target_link_libraries(LibC crt0)
|
||||
add_dependencies(LibC LibM)
|
||||
|
||||
add_library(LibCShared SHARED ${SOURCES})
|
||||
install(TARGETS LibCShared DESTINATION usr/lib)
|
||||
|
|
30
Libraries/LibC/crt0_shared.cpp
Normal file
30
Libraries/LibC/crt0_shared.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <AK/Types.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/internals.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
int main(int, char**, char**);
|
||||
|
||||
extern void __libc_init();
|
||||
extern void _init();
|
||||
extern char** environ;
|
||||
extern bool __environ_is_malloced;
|
||||
|
||||
int _start(int argc, char** argv, char** env);
|
||||
int _start(int argc, char** argv, char** env)
|
||||
{
|
||||
// asm("int3");
|
||||
environ = env;
|
||||
__environ_is_malloced = false;
|
||||
|
||||
__libc_init();
|
||||
_init();
|
||||
|
||||
int status = main(argc, argv, environ);
|
||||
return status;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue