ref: 3cc0508834a26b517381707f4a448ecb4a3e43bd
parent: 99970c47ca06ce506823bd2329a37a8f439ce304
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Aug 28 11:28:46 EDT 2019
[libmach] Add forgotten files These files were forgotten in different commits.
--- /dev/null
+++ b/src/libmach/coff32/coff32getsec.c
@@ -1,0 +1,67 @@
+#include <stdio.h>
+
+#include <scc/mach.h>
+
+#include "../libmach.h"
+#include "coff32.h"
+
+Section *
+coff32getsec(Obj *obj, long *idx, Section *sec)
+{
+ long n = *idx;
+ int type;
+ unsigned sflags;
+ unsigned long flags;
+ SCNHDR *scn;
+ Coff32 *coff = obj->data;
+ FILHDR *hdr = &coff->hdr;
+
+ if (n >= hdr->f_nscns)
+ return NULL;
+
+ scn = &coff->scns[n];
+ flags = scn->s_flags;
+
+ if (flags & STYP_TEXT) {
+ type = 'T';
+ sflags = SALLOC | SRELOC | SLOAD | SEXEC | SREAD;
+ if (flags & STYP_NOLOAD)
+ sflags |= SSHARED;
+ } else if (flags & STYP_DATA) {
+ type = 'D';
+ sflags = SALLOC | SRELOC | SLOAD | SWRITE | SREAD;
+ if (flags & STYP_NOLOAD)
+ sflags |= SSHARED;
+ } else if (flags & STYP_BSS) {
+ type = 'B';
+ sflags = SALLOC | SREAD | SWRITE;
+ } else if (flags & STYP_INFO) {
+ type = 'N';
+ sflags = 0;
+ } else if (flags & STYP_LIB) {
+ type = 'T';
+ sflags = SRELOC;
+ } else if (flags & STYP_DSECT) {
+ type = 'D';
+ sflags = SRELOC;
+ } else if (flags & STYP_PAD) {
+ type = 'D';
+ sflags = SLOAD;
+ } else {
+ type = 'D'; /* We assume that STYP_REG is data */
+ sflags = SALLOC | SRELOC | SLOAD | SWRITE | SREAD;
+ }
+
+ if (flags & STYP_NOLOAD)
+ sflags &= ~SLOAD;
+
+ sec->name = scn->s_name;
+ sec->index = n;
+ sec->size = scn->s_size;
+ sec->base = 0; /* TODO: Check what is the actual value */
+ sec->type = type;
+ sec->flags = sflags;
+ sec->align = 4; /* TODO: Check how align is defined in coff */
+
+ return sec;
+}
--- /dev/null
+++ b/src/libmach/delobj.c
@@ -1,0 +1,13 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <scc/mach.h>
+
+#include "libmach.h"
+
+void
+delobj(Obj *obj)
+{
+ (*obj->ops->del)(obj);
+ free(obj);
+}
\ No newline at end of file
--- /dev/null
+++ b/src/libmach/getindex.c
@@ -1,0 +1,21 @@
+#include <errno.h>
+#include <stdio.h>
+
+#include <scc/mach.h>
+
+#include "libmach.h"
+
+int
+getindex(int type, long *nsyms, char ***names, long **offs, FILE *fp)
+{
+ int fmt;
+
+ fmt = FORMAT(type);
+ if (fmt >= NFORMATS) {
+ errno = ERANGE;
+ return -1;
+ }
+
+ return (*objops[fmt]->getidx)(nsyms, names, offs, fp);
+}
+
--- /dev/null
+++ b/src/libmach/getsec.c
@@ -1,0 +1,11 @@
+#include <stdio.h>
+
+#include <scc/mach.h>
+
+#include "libmach.h"
+
+Section *
+getsec(Obj *obj, long *idx, Section *sec)
+{
+ return (*obj->ops->getsec)(obj, idx, sec);
+}
--- /dev/null
+++ b/src/libmach/setindex.c
@@ -1,0 +1,21 @@
+#include <errno.h>
+#include <stdio.h>
+
+#include <scc/mach.h>
+
+#include "libmach.h"
+
+int
+setindex(int type, long nsyms, char **names, long *offs, FILE *fp)
+{
+ int fmt;
+
+ fmt = FORMAT(type);
+ if (fmt >= NFORMATS) {
+ errno = ERANGE;
+ return -1;
+ }
+
+ return (*objops[fmt]->setidx)(nsyms, names, offs, fp);
+}
+
--- /dev/null
+++ b/src/libmach/strip.c
@@ -1,0 +1,11 @@
+#include <stdio.h>
+
+#include <scc/mach.h>
+
+#include "libmach.h"
+
+int
+strip(Obj *obj)
+{
+ return (*obj->ops->strip)(obj);
+}
--- /dev/null
+++ b/src/libmach/writeobj.c
@@ -1,0 +1,11 @@
+#include <stdio.h>
+
+#include <scc/mach.h>
+
+#include "libmach.h"
+
+int
+writeobj(Obj *obj, FILE *fp)
+{
+ return (obj->ops->write)(obj, fp);
+}
\ No newline at end of file