Skip to content

Commit

Permalink
Add storage offset support in dt_ident_t and dt_idhash_t
Browse files Browse the repository at this point in the history
Variables (especially of a complex type) and aggregations will need
to be allocated from a memory block.  They will therefore require a
storage offset to be associated with them so that the code generator
can access the correct memory locations.

The dt_ident_t structure now has a di_offset member to hold the
storage offset for the identifier (if applicable) and the dt_idhash_t
structure has a dh_nextoff member to hold the offset to allocate the
next item at.

The dt_idhash_nextoff(dt_idhash_t *dhp, uint_t alignment, uint_t size)
function will return the offset where the next data item is to be
allocated.  The size argument specifies the size (in bytes) of the
data item.  The returned value is guaranteed to be properly aligned to
the number of bytes specified by the alignment argument, and the next
offset member (dh_nextoff in dt_idhash_t) will be advanced by the
given number of bytes.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Nov 30, 2020
1 parent 3a64442 commit 1ca381c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libdtrace/dt_ident.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ dt_idhash_create(const char *name, const dt_ident_t *tmpl,
dhp->dh_nextid = min;
dhp->dh_minid = min;
dhp->dh_maxid = max;
dhp->dh_nextoff = 0;
dhp->dh_hashsz = _dtrace_strbuckets;

return (dhp);
Expand Down Expand Up @@ -768,6 +769,16 @@ dt_idhash_peekid(dt_idhash_t *dhp)
return dhp->dh_nextid;
}

uint_t
dt_idhash_nextoff(dt_idhash_t *dhp, uint_t alignment, uint_t size)
{
uint_t off = (dhp->dh_nextoff + (alignment - 1)) & ~(alignment - 1);

dhp->dh_nextoff = off + size;

return off;
}

ulong_t
dt_idhash_size(const dt_idhash_t *dhp)
{
Expand Down Expand Up @@ -947,6 +958,7 @@ dt_ident_create(const char *name, ushort_t kind, ushort_t flags, uint_t id,
idp->di_data = NULL;
idp->di_ctfp = NULL;
idp->di_type = CTF_ERR;
idp->di_offset = -1;
idp->di_next = NULL;
idp->di_gen = gen;
idp->di_lineno = yylineno;
Expand Down
3 changes: 3 additions & 0 deletions libdtrace/dt_ident.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ typedef struct dt_ident {
void *di_data; /* private data pointer for ops vector */
ctf_file_t *di_ctfp; /* CTF container for the variable data type */
ctf_id_t di_type; /* CTF identifier for the variable data type */
int di_offset; /* storage offset */
struct dt_ident *di_next; /* pointer to next ident in hash chain */
ulong_t di_gen; /* generation number (pass that created me) */
int di_lineno; /* line number that defined this identifier */
Expand Down Expand Up @@ -102,6 +103,7 @@ typedef struct dt_idhash {
uint_t dh_nextid; /* next id to be returned by idhash_nextid() */
uint_t dh_minid; /* min id to be returned by idhash_nextid() */
uint_t dh_maxid; /* max id to be returned by idhash_nextid() */
uint_t dh_nextoff; /* next offset to return at idhash_nextoff() */
ulong_t dh_nelems; /* number of identifiers in hash table */
ulong_t dh_hashsz; /* number of entries in dh_buckets array */
dt_ident_t *dh_hash[1]; /* array of hash table bucket pointers */
Expand All @@ -128,6 +130,7 @@ extern void dt_idhash_update(dt_idhash_t *);
extern dt_ident_t *dt_idhash_lookup(dt_idhash_t *, const char *);
extern int dt_idhash_nextid(dt_idhash_t *, uint_t *);
extern uint_t dt_idhash_peekid(dt_idhash_t *);
extern uint_t dt_idhash_nextoff(dt_idhash_t *, uint_t, uint_t);
extern ulong_t dt_idhash_size(const dt_idhash_t *);
extern const char *dt_idhash_name(const dt_idhash_t *);

Expand Down

0 comments on commit 1ca381c

Please sign in to comment.