Kostya Kortchinsky d44cb7a656 [scudo][standalone] Introduce the C & C++ wrappers [fixed]
Summary:
This is a redo of D63612.

Two problems came up on some bots:
- `__builtin_umull_overflow` was not declared. This is likely due to an
  older clang or gcc, so add a guard with `__has_builtin` and fallback
  to a division in the event the builtin doesn't exist;
- contradicting definition for `malloc`, etc. This is AFAIU due to the
  fact that we ended up transitively including `stdlib.h` in the `.inc`
  due to it being the flags parser header: so move the include to the
  cc instead.

This should fix the issues, but since those didn't come up in my local
tests it's mostly guesswork.

Rest is the same!

Reviewers: morehouse, hctim, eugenis, vitalybuka, dyung, hans

Reviewed By: morehouse, dyung, hans

Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D63831

llvm-svn: 364547
2019-06-27 14:23:26 +00:00

56 lines
1.2 KiB
C++

//===-- flags_parser.h ------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef SCUDO_FLAGS_PARSER_H_
#define SCUDO_FLAGS_PARSER_H_
#include "report.h"
#include "string_utils.h"
#include <stddef.h>
namespace scudo {
enum class FlagType : u8 {
FT_bool,
FT_int,
};
class FlagParser {
public:
void registerFlag(const char *Name, const char *Desc, FlagType Type,
void *Var);
void parseString(const char *S);
void printFlagDescriptions();
private:
static const u32 MaxFlags = 12;
struct Flag {
const char *Name;
const char *Desc;
FlagType Type;
void *Var;
} Flags[MaxFlags];
u32 NumberOfFlags = 0;
const char *Buffer = nullptr;
uptr Pos = 0;
void reportFatalError(const char *Error);
void skipWhitespace();
void parseFlags();
void parseFlag();
bool runHandler(const char *Name, const char *Value);
};
void reportUnrecognizedFlags();
} // namespace scudo
#endif // SCUDO_FLAGS_PARSER_H_