early_init.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #include <sys/mount.h>
  17. #include <sys/stat.h>
  18. #include <stdlib.h>
  19. __attribute__((constructor(101))) void early_mounts(void) {
  20. mkdir("/proc", 0755);
  21. mount("proc", "/proc", "proc", 0, 0);
  22. mkdir("/sys", 0755);
  23. mount("sysfs", "/sys", "sysfs", 0, 0);
  24. mkdir("/dev", 0755);
  25. mount("devtmpfs", "/dev", "devtmpfs", 0, 0);
  26. mkdir("/run", 0755);
  27. mount("tmpfs", "/run", "tmpfs", 0, 0);
  28. setenv("XDG_RUNTIME_DIR", "/run", 1);
  29. setenv("LD_LIBRARY_PATH", "/lib", 1);
  30. }
  31. #include <dirent.h>
  32. #include <stdio.h>
  33. void* ark_opendir(const char* name) {
  34. return opendir(name);
  35. }
  36. int ark_closedir(void* dirp) {
  37. return closedir((DIR*)dirp);
  38. }
  39. void* ark_readdir(void* dirp) {
  40. return readdir((DIR*)dirp);
  41. }
  42. const char* ark_dirent_name(void* entry) {
  43. if (!entry) return NULL;
  44. return ((struct dirent*)entry)->d_name;
  45. }
  46. int ark_getline(char** lineptr, size_t* n, void* stream) {
  47. return getline(lineptr, n, (FILE*)stream);
  48. }
  49. #include <fcntl.h>
  50. int ark_open2_c(const char* path, int flags) {
  51. return open(path, flags);
  52. }
  53. int ark_open3_c(const char* path, int flags, int mode) {
  54. return open(path, flags, mode);
  55. }
  56. #include <errno.h>
  57. int ark_errno(void) {
  58. return errno;
  59. }